Skip to content

Commit

Permalink
Migrate to mantle fluid transfer util
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Jun 6, 2022
1 parent 0a3f650 commit 2407467
Show file tree
Hide file tree
Showing 33 changed files with 78 additions and 705 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:empty_item",
"type": "mantle:empty_item",
"input": {
"item": "minecraft:beetroot_soup"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_item",
"type": "mantle:fill_item",
"input": {
"item": "minecraft:bowl"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:empty_item",
"type": "mantle:empty_item",
"input": {
"item": "minecraft:honey_bottle"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_item",
"type": "mantle:fill_item",
"input": {
"item": "minecraft:glass_bottle"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:empty_item",
"type": "mantle:empty_item",
"input": {
"item": "minecraft:mushroom_stew"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_item",
"type": "mantle:fill_item",
"input": {
"item": "minecraft:bowl"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_nbt",
"type": "mantle:fill_nbt",
"input": {
"item": "minecraft:glass_bottle"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_nbt",
"type": "mantle:fill_nbt",
"input": {
"tag": "forge:bottles/lingering"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_item",
"type": "mantle:fill_item",
"input": {
"tag": "forge:bottles/lingering"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_nbt",
"type": "mantle:fill_nbt",
"input": {
"tag": "forge:bottles/splash"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_item",
"type": "mantle:fill_item",
"input": {
"tag": "forge:bottles/splash"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_item",
"type": "mantle:fill_item",
"input": {
"item": "minecraft:glass_bottle"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:empty_item",
"type": "mantle:empty_item",
"input": {
"item": "minecraft:rabbit_stew"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "tconstruct:fill_item",
"type": "mantle:fill_item",
"input": {
"item": "minecraft:bowl"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraftforge.network.PacketDistributor;
import slimeknights.mantle.network.NetworkWrapper;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.fluid.transfer.FluidContainerTransferPacket;
import slimeknights.tconstruct.library.materials.definition.UpdateMaterialsPacket;
import slimeknights.tconstruct.library.materials.stats.UpdateMaterialStatsPacket;
import slimeknights.tconstruct.library.materials.traits.UpdateMaterialTraitsPacket;
Expand Down Expand Up @@ -102,7 +101,6 @@ public static void setup() {
instance.registerPacket(StructureUpdatePacket.class, StructureUpdatePacket::new, NetworkDirection.PLAY_TO_CLIENT);
instance.registerPacket(SmelteryFluidClickedPacket.class, SmelteryFluidClickedPacket::new, NetworkDirection.PLAY_TO_SERVER);
instance.registerPacket(StructureErrorPositionPacket.class, StructureErrorPositionPacket::new, NetworkDirection.PLAY_TO_CLIENT);
instance.registerPacket(FluidContainerTransferPacket.class, FluidContainerTransferPacket::new, NetworkDirection.PLAY_TO_CLIENT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.material.Fluids;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.mantle.fluid.transfer.EmptyFluidWithNBTTransfer;
import slimeknights.mantle.recipe.helper.ItemOutput;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.fluid.transfer.EmptyFluidContainerTransfer;
import slimeknights.tconstruct.library.fluid.transfer.EmptyFluidWithNBTTransfer;
import slimeknights.tconstruct.library.fluid.transfer.IFluidContainerTransfer;

/** Fluid transfer info that empties a fluid from an item, copying the fluid's NBT to the stack */
public class EmptyPotionTransfer extends EmptyFluidWithNBTTransfer {
public class EmptyPotionTransfer extends EmptyFluidWithNBTTransfer implements IFluidContainerTransfer {
public static final ResourceLocation ID = TConstruct.getResource("empty_potion");
public EmptyPotionTransfer(Ingredient input, ItemOutput filled, FluidStack fluid) {
super(input, filled, fluid);
Expand All @@ -38,5 +38,5 @@ public JsonObject serialize(JsonSerializationContext context) {
}

/** Unique loader instance */
public static final JsonDeserializer<EmptyFluidContainerTransfer> DESERIALIZER = new Deserializer<>(EmptyPotionTransfer::new);
public static final JsonDeserializer<EmptyPotionTransfer> DESERIALIZER = new Deserializer<>(EmptyPotionTransfer::new);
}
Original file line number Diff line number Diff line change
@@ -1,69 +1,11 @@
package slimeknights.tconstruct.library.data.tinkering;

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.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.mantle.data.GenericDataProvider;
import slimeknights.mantle.recipe.helper.ItemOutput;
import slimeknights.mantle.recipe.ingredient.FluidIngredient;
import slimeknights.tconstruct.library.fluid.transfer.EmptyFluidContainerTransfer;
import slimeknights.tconstruct.library.fluid.transfer.EmptyFluidWithNBTTransfer;
import slimeknights.tconstruct.library.fluid.transfer.FillFluidContainerTransfer;
import slimeknights.tconstruct.library.fluid.transfer.FillFluidWithNBTTransfer;
import slimeknights.tconstruct.library.fluid.transfer.FluidContainerTransferManager;
import slimeknights.tconstruct.library.fluid.transfer.IFluidContainerTransfer;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/** Datagen for fluid transfer logic */
public abstract class AbstractFluidContainerTransferProvider extends GenericDataProvider {
private final Map<ResourceLocation,IFluidContainerTransfer> allTransfers = new HashMap<>();
private final String modId;

/** @deprecated use {@link slimeknights.mantle.fluid.transfer.AbstractFluidContainerTransferProvider} */
@Deprecated
public abstract class AbstractFluidContainerTransferProvider extends slimeknights.mantle.fluid.transfer.AbstractFluidContainerTransferProvider {
public AbstractFluidContainerTransferProvider(DataGenerator generator, String modId) {
super(generator, PackType.SERVER_DATA, FluidContainerTransferManager.FOLDER, FluidContainerTransferManager.GSON);
this.modId = modId;
}

/** Function to add all relevant transfers */
protected abstract void addTransfers();

/** Adds a transfer to be saved */
protected void addTransfer(ResourceLocation id, IFluidContainerTransfer transfer) {
IFluidContainerTransfer previous = allTransfers.putIfAbsent(id, transfer);
if (previous != null) {
throw new IllegalArgumentException("Duplicate fluid container transfer " + id);
}
}

/** Adds a transfer to be saved */
protected void addTransfer(String name, IFluidContainerTransfer transfer) {
addTransfer(new ResourceLocation(modId, name), transfer);
}

/** Adds generic fill and empty for a container */
protected void addFillEmpty(String prefix, ItemLike item, ItemLike container, Fluid fluid, TagKey<Fluid> tag, int amount) {
addTransfer(prefix + "empty", new EmptyFluidContainerTransfer(Ingredient.of(item), ItemOutput.fromItem(container), new FluidStack(fluid, amount)));
addTransfer(prefix + "fill", new FillFluidContainerTransfer(Ingredient.of(container), ItemOutput.fromItem(item), FluidIngredient.of(tag, amount)));
}

/** Adds generic fill and empty for a container */
protected void addFillEmptyNBT(String prefix, ItemLike item, ItemLike container, Fluid fluid, TagKey<Fluid> tag, int amount) {
addTransfer(prefix + "empty", new EmptyFluidWithNBTTransfer(Ingredient.of(item), ItemOutput.fromItem(container), new FluidStack(fluid, amount)));
addTransfer(prefix + "fill", new FillFluidWithNBTTransfer(Ingredient.of(container), ItemOutput.fromItem(item), FluidIngredient.of(tag, amount)));
}

@Override
public void run(HashCache cache) throws IOException {
addTransfers();
allTransfers.forEach((id, data) -> saveThing(cache, id, data));
super(generator, modId);
}
}

0 comments on commit 2407467

Please sign in to comment.