Skip to content

Commit

Permalink
Migrate to mantle fluid tooltip handler
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Jun 6, 2022
1 parent 45ad6ba commit 0a3f650
Show file tree
Hide file tree
Showing 31 changed files with 79 additions and 442 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"tag": "tconstruct:tooltips/water",
"units": [
{
"key": "gui.tconstruct.fluid.kilobucket",
"key": "gui.mantle.fluid.kilobucket",
"needed": 1000000
},
{
"key": "gui.tconstruct.fluid.bucket",
"key": "gui.mantle.fluid.bucket",
"needed": 1000
},
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import slimeknights.mantle.registration.object.FluidObject;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.common.ClientEventBase;
import slimeknights.tconstruct.library.fluid.FluidTooltipHandler;

@EventBusSubscriber(modid = TConstruct.MOD_ID, value = Dist.CLIENT, bus = Bus.MOD)
public class FluidClientEvents extends ClientEventBase {
@SubscribeEvent
static void addResourceListeners(RegisterClientReloadListenersEvent event) {
FluidTooltipHandler.init(event);
}

@SubscribeEvent
static void clientSetup(final FMLClientSetupEvent event) {
setTranslucent(TinkerFluids.honey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import net.minecraft.data.DataGenerator;
import net.minecraftforge.fluids.FluidAttributes;
import slimeknights.mantle.fluid.tooltip.AbstractFluidTooltipProvider;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.library.client.data.AbstractFluidTooltipProvider;
import slimeknights.tconstruct.library.fluid.FluidTooltipHandler;
import slimeknights.tconstruct.library.recipe.FluidValues;
import slimeknights.tconstruct.smeltery.TinkerSmeltery;
import slimeknights.tconstruct.smeltery.menu.AlloyerContainerMenu;
Expand All @@ -27,11 +26,6 @@ public FluidTooltipProvider(DataGenerator generator) {

@Override
protected void addFluids() {
add("buckets")
.addUnit("kilobucket", FluidAttributes.BUCKET_VOLUME * 1000)
.addUnit("bucket", FluidAttributes.BUCKET_VOLUME);
addRedirect(FluidTooltipHandler.DEFAULT_ID, id("buckets"));

// screen capacities
add("ingots").addUnit("ingot", FluidValues.INGOT);
addRedirect(AlloyerContainerMenu.TOOLTIP_FORMAT, id("ingots"));
Expand Down Expand Up @@ -64,8 +58,8 @@ protected void addFluids() {
.addUnit("pane", FluidValues.GLASS_PANE);

add("water", WATER_TOOLTIPS)
.addUnit("kilobucket", FluidAttributes.BUCKET_VOLUME * 1000)
.addUnit("bucket", FluidAttributes.BUCKET_VOLUME)
.addUnit("kilobucket", "mantle", FluidAttributes.BUCKET_VOLUME * 1000)
.addUnit("bucket", "mantle", FluidAttributes.BUCKET_VOLUME)
.addUnit("bottle", FluidValues.BOTTLE);
add("honey", TinkerFluids.honey.getForgeTag())
.addUnit("block", FluidValues.BOTTLE * 4)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,126 +1,11 @@
package slimeknights.tconstruct.library.client.data;

import com.google.common.collect.ImmutableList;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.HashCache;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.material.Fluid;
import slimeknights.mantle.data.GenericDataProvider;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.fluid.FluidTooltipHandler;
import slimeknights.tconstruct.library.fluid.FluidTooltipHandler.FluidUnit;
import slimeknights.tconstruct.library.fluid.FluidTooltipHandler.FluidUnitList;
import slimeknights.tconstruct.library.utils.JsonUtils;
import slimeknights.tconstruct.library.utils.Util;

import javax.annotation.Nullable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/** Provider for fluid tooltip information */
public abstract class AbstractFluidTooltipProvider extends GenericDataProvider {
private final Map<ResourceLocation,ResourceLocation> redirects = new HashMap<>();;
private final Map<ResourceLocation,FluidUnitListBuilder> builders = new HashMap<>();
private final String modId;

/** @deprecated use {@link slimeknights.tconstruct.smeltery.block.AbstractCastingBlock} */
@Deprecated
public abstract class AbstractFluidTooltipProvider extends slimeknights.mantle.fluid.tooltip.AbstractFluidTooltipProvider {
public AbstractFluidTooltipProvider(DataGenerator generator, String modId) {
super(generator, PackType.CLIENT_RESOURCES, FluidTooltipHandler.FOLDER, FluidTooltipHandler.GSON);
this.modId = modId;
}

/** Adds all relevant fluids to the maps */
protected abstract void addFluids();

@Override
public final void run(HashCache cache) throws IOException {
addFluids();
builders.forEach((key, builder) -> saveThing(cache, key, builder.build()));
redirects.forEach((key, target) -> saveThing(cache, key, JsonUtils.withLocation("redirect", target)));
}


/* Helpers */

/** Creates a ResourceLocation for the local mod */
protected ResourceLocation id(String name) {
return new ResourceLocation(modId, name);
}

/** Adds a fluid to the builder */
protected FluidUnitListBuilder add(ResourceLocation id, @Nullable TagKey<Fluid> tag) {
if (redirects.containsKey(id)) {
throw new IllegalArgumentException(id + " is already registered as a redirect");
}
FluidUnitListBuilder newBuilder = new FluidUnitListBuilder(tag);
FluidUnitListBuilder original = builders.put(id, newBuilder);
if (original != null) {
throw new IllegalArgumentException(id + " is already registered");
}
return newBuilder;
}

/** Adds a fluid to the builder */
protected FluidUnitListBuilder add(String id, TagKey<Fluid> tag) {
return add(id(id), tag);
}

/** Adds a fluid to the builder using the tag name as the ID */
protected FluidUnitListBuilder add(TagKey<Fluid> tag) {
return add(id(tag.location().getPath()), tag);
}

/** Adds a fluid to the builder with no tag */
protected FluidUnitListBuilder add(ResourceLocation id) {
return add(id, null);
}

/** Adds a fluid to the builder with no tag */
protected FluidUnitListBuilder add(String id) {
return add(id(id), null);
}

/** Adds a redirect from a named builder to a target */
protected void addRedirect(ResourceLocation id, ResourceLocation target) {
if (builders.containsKey(id)) {
throw new IllegalArgumentException(id + " is already registered as a unit list");
}
ResourceLocation original = redirects.put(id, target);
if (original != null) {
throw new IllegalArgumentException(id + " is already redirecting to " + original);
}
}

/** Builder for a unit list */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
protected class FluidUnitListBuilder {
@Nullable
private final TagKey<Fluid> tag;
private final ImmutableList.Builder<FluidUnit> units = ImmutableList.builder();

/** Adds a unit with a full translation key */
public FluidUnitListBuilder addUnitRaw(String key, int amount) {
units.add(new FluidUnit(key, amount));
return this;
}

/** Adds a unit local to the current mod */
public FluidUnitListBuilder addTinkerUnit(String key, int amount) {
return addUnitRaw(TConstruct.makeTranslationKey("gui", "fluid." + key), amount);
}

/** Adds a unit local to the current mod */
public FluidUnitListBuilder addUnit(String key, int amount) {
return addUnitRaw(Util.makeTranslationKey("gui", id("fluid." + key)), amount);
}

/** Builds the final instance */
private FluidUnitList build() {
return new FluidUnitList(tag, units.build());
}
super(generator, modId);
}
}

0 comments on commit 0a3f650

Please sign in to comment.