From 0d4a416d2dafc5946bc9ee974ab5e0c667fca72c Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Mon, 4 Mar 2024 15:36:15 +0530 Subject: [PATCH 01/14] basic VAT block + BE impl --- .../assets/enderio/blockstates/vat.json | 19 +++ .../resources/assets/enderio/lang/en_us.json | 1 + .../enderio/models/block/vat_combined.json | 19 +++ .../assets/enderio/models/item/vat.json | 3 + .../data/enderio/loot_tables/blocks/vat.json | 29 ++++ .../tags/blocks/mineable/pickaxe.json | 5 +- .../tags/blocks/needs_iron_tool.json | 1 + .../machines/client/gui/screen/VatScreen.java | 28 ++++ .../common/blockentity/VatBlockEntity.java | 138 ++++++++++++++++++ .../common/init/MachineBlockEntities.java | 26 +++- .../machines/common/init/MachineBlocks.java | 2 + .../machines/common/init/MachineMenus.java | 3 + .../enderio/machines/common/menu/VatMenu.java | 26 ++++ .../assets/enderio/models/block/vat.json | 12 ++ .../enderio/textures/block/vat_back.png | Bin 0 -> 497 bytes .../enderio/textures/block/vat_front.png | Bin 0 -> 526 bytes .../assets/enderio/textures/block/vat_top.png | Bin 0 -> 442 bytes .../assets/enderio/textures/gui/vat.png | Bin 0 -> 2148 bytes 18 files changed, 309 insertions(+), 3 deletions(-) create mode 100644 src/generated/resources/assets/enderio/blockstates/vat.json create mode 100644 src/generated/resources/assets/enderio/models/block/vat_combined.json create mode 100644 src/generated/resources/assets/enderio/models/item/vat.json create mode 100644 src/generated/resources/data/enderio/loot_tables/blocks/vat.json create mode 100644 src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java create mode 100644 src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java create mode 100644 src/machines/java/com/enderio/machines/common/menu/VatMenu.java create mode 100644 src/machines/resources/assets/enderio/models/block/vat.json create mode 100644 src/machines/resources/assets/enderio/textures/block/vat_back.png create mode 100644 src/machines/resources/assets/enderio/textures/block/vat_front.png create mode 100644 src/machines/resources/assets/enderio/textures/block/vat_top.png create mode 100644 src/main/resources/assets/enderio/textures/gui/vat.png diff --git a/src/generated/resources/assets/enderio/blockstates/vat.json b/src/generated/resources/assets/enderio/blockstates/vat.json new file mode 100644 index 0000000000..1c3e62e96b --- /dev/null +++ b/src/generated/resources/assets/enderio/blockstates/vat.json @@ -0,0 +1,19 @@ +{ + "variants": { + "facing=east": { + "model": "enderio:block/vat_combined", + "y": 90 + }, + "facing=north": { + "model": "enderio:block/vat_combined" + }, + "facing=south": { + "model": "enderio:block/vat_combined", + "y": 180 + }, + "facing=west": { + "model": "enderio:block/vat_combined", + "y": 270 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/lang/en_us.json b/src/generated/resources/assets/enderio/lang/en_us.json index e6c7f72137..cf0d8f4b1a 100644 --- a/src/generated/resources/assets/enderio/lang/en_us.json +++ b/src/generated/resources/assets/enderio/lang/en_us.json @@ -203,6 +203,7 @@ "block.enderio.travel_anchor": "Travel Anchor", "block.enderio.vacuum_chest": "Vacuum Chest", "block.enderio.vapor_of_levity": "Vapor Of Levity", + "block.enderio.vat": "VAT", "block.enderio.vibrant_alloy_block": "Vibrant Alloy Block", "block.enderio.vibrant_capacitor_bank": "Vibrant Capacitor Bank", "block.enderio.vibrant_photovoltaic_module": "Vibrant Photovoltaic Module", diff --git a/src/generated/resources/assets/enderio/models/block/vat_combined.json b/src/generated/resources/assets/enderio/models/block/vat_combined.json new file mode 100644 index 0000000000..f1fd6a8292 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/vat_combined.json @@ -0,0 +1,19 @@ +{ + "parent": "minecraft:block/block", + "children": { + "machine": { + "parent": "enderio:block/vat" + }, + "overlay": { + "parent": "enderio:block/io_overlay" + } + }, + "item_render_order": [ + "machine", + "overlay" + ], + "loader": "neoforge:composite", + "textures": { + "particle": "enderio:block/vat_front" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/item/vat.json b/src/generated/resources/assets/enderio/models/item/vat.json new file mode 100644 index 0000000000..7eec742c9c --- /dev/null +++ b/src/generated/resources/assets/enderio/models/item/vat.json @@ -0,0 +1,3 @@ +{ + "parent": "enderio:block/vat" +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/loot_tables/blocks/vat.json b/src/generated/resources/data/enderio/loot_tables/blocks/vat.json new file mode 100644 index 0000000000..c977ab4851 --- /dev/null +++ b/src/generated/resources/data/enderio/loot_tables/blocks/vat.json @@ -0,0 +1,29 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_nbt", + "ops": [ + { + "op": "replace", + "source": "", + "target": "BlockEntityTag" + } + ], + "source": "block_entity" + } + ], + "name": "enderio:vat" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "enderio:blocks/vat" +} \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 32ca0c1d46..d906e91704 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -35,7 +35,6 @@ "enderio:silent_heavy_weighted_pressure_plate", "enderio:silent_light_weighted_pressure_plate", "enderio:painted_redstone_block", - "enderio:conduit", "enderio:fluid_tank", "enderio:pressurized_fluid_tank", "enderio:enchanter", @@ -61,6 +60,8 @@ "enderio:crafter", "enderio:soul_engine", "enderio:drain", - "enderio:xp_obelisk" + "enderio:vat", + "enderio:xp_obelisk", + "enderio:conduit" ] } \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json index 6007bc9f31..48a3f0dac5 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json +++ b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json @@ -25,6 +25,7 @@ "enderio:crafter", "enderio:soul_engine", "enderio:drain", + "enderio:vat", "enderio:xp_obelisk" ] } \ No newline at end of file diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java new file mode 100644 index 0000000000..1a58fb5b6e --- /dev/null +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -0,0 +1,28 @@ +package com.enderio.machines.client.gui.screen; + +import com.enderio.EnderIO; +import com.enderio.api.misc.Vector2i; +import com.enderio.core.client.gui.screen.EIOScreen; +import com.enderio.machines.common.menu.VatMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +public class VatScreen extends EIOScreen { + + private static final ResourceLocation VAT_BG = EnderIO.loc("textures/gui/vat.png"); + + public VatScreen(VatMenu pMenu, Inventory pPlayerInventory, Component pTitle) { + super(pMenu, pPlayerInventory, pTitle, true); + } + + @Override + public ResourceLocation getBackgroundImage() { + return VAT_BG; + } + + @Override + protected Vector2i getBackgroundImageSize() { + return new Vector2i(176, 166); + } +} diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java new file mode 100644 index 0000000000..1249b045ff --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -0,0 +1,138 @@ +package com.enderio.machines.common.blockentity; + +import com.enderio.machines.common.attachment.IFluidTankUser; +import com.enderio.machines.common.blockentity.base.MachineBlockEntity; +import com.enderio.machines.common.init.MachineBlockEntities; +import com.enderio.machines.common.io.fluid.MachineFluidHandler; +import com.enderio.machines.common.io.fluid.MachineTankLayout; +import com.enderio.machines.common.io.fluid.TankAccess; +import com.enderio.machines.common.io.item.MachineInventoryLayout; +import com.enderio.machines.common.io.item.MultiSlotAccess; +import com.enderio.machines.common.menu.VatMenu; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.fluids.FluidType; +import org.jetbrains.annotations.Nullable; + +public class VatBlockEntity extends MachineBlockEntity implements IFluidTankUser { + + public static final int TANK_CAPACITY_COMMON = 8 * FluidType.BUCKET_VOLUME; + private static final TankAccess INPUT_TANK = new TankAccess(); + private static final TankAccess OUTPUT_TANK = new TankAccess(); + public static final MultiSlotAccess REAGENTS = new MultiSlotAccess(); + private final MachineFluidHandler fluidHandler; + // private final CraftingMachineTaskHost craftingTaskHost; + + public VatBlockEntity(BlockPos worldPosition, BlockState blockState) { + super(MachineBlockEntities.VAT.get(), worldPosition, blockState); + fluidHandler = createFluidHandler(); + + // craftingTaskHost = new CraftingMachineTaskHost<>(this, () -> true, MachineRecipes.VAT_FERMENTING.type().get(), + // new VatFermentingRecipe.Container(getInventoryNN(), getFluidTankNN()), this::createTask); + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int containerId, Inventory playerInventory, Player player) { + return new VatMenu(this, playerInventory, containerId); + } + + @Override + public void serverTick() { + super.serverTick(); + + if (canAct()) { + // craftingTaskHost.tick(); + } + } + + @Override + public void onLoad() { + super.onLoad(); + // craftingTaskHost.onLevelReady(); + } + + // protected VatBlockEntity.VatCraftingMachineTask createTask(Level level, VatFermentingRecipe.Container container, @Nullable VatFermentingRecipe recipe) { + // return new VatBlockEntity.VatCraftingMachineTask(level, getInventoryNN(), container, null, recipe); + // } + + @Override + public @Nullable MachineInventoryLayout getInventoryLayout() { + return MachineInventoryLayout.builder().inputSlot(2).slotAccess(REAGENTS).build(); + } + + @Override + public MachineTankLayout getTankLayout() { + return MachineTankLayout + .builder() + .tank(INPUT_TANK, TANK_CAPACITY_COMMON, true, false, (stack) -> true) + .tank(OUTPUT_TANK, TANK_CAPACITY_COMMON, false, true, (stack) -> true) + .build(); + } + + @Override + public MachineFluidHandler getFluidHandler() { + return fluidHandler; + } + + @Override + public MachineFluidHandler createFluidHandler() { + return new MachineFluidHandler(getIOConfig(), getTankLayout()) { + @Override + protected void onContentsChanged(int slot) { + super.onContentsChanged(slot); + // craftingTaskHost.newTaskAvailable(); + setChanged(); + } + }; + } + + // protected static class VatCraftingMachineTask extends CraftingMachineTask { + // + // public VatCraftingMachineTask(@NotNull Level level, MachineInventory inventory, VatFermentingRecipe.Container container, MultiSlotAccess outputSlots, + // @Nullable VatFermentingRecipe recipe) { + // super(level, inventory, container, outputSlots, recipe); + // } + // + // @Override + // protected void consumeInputs(VatFermentingRecipe recipe) { + // container.getItem(0).shrink(1); + // container.getItem(1).shrink(1); + // // TODO: Extract fluid from first tank + // // container.getTank().getFluidInTank(0).shrink(recipe.getInputFluid().getAmount()); + // } + // + // @Override + // protected boolean placeOutputs(List outputs, boolean simulate) { + // // TODO: Place the output fluid in the second tank + // return super.placeOutputs(outputs, simulate); + // } + // + // @Override + // protected int makeProgress(int remainingProgress) { + // return 1; + // } + // + // @Override + // protected int getProgressRequired(VatFermentingRecipe recipe) { + // return recipe.getTicks(); + // } + // + // } + + @Override + public void saveAdditional(CompoundTag pTag) { + super.saveAdditional(pTag); + // craftingTaskHost.save(pTag); + } + + @Override + public void load(CompoundTag pTag) { + super.load(pTag); + // craftingTaskHost.load(pTag); + } +} diff --git a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java index 607443f29c..afe5bb83fd 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java @@ -6,7 +6,27 @@ import com.enderio.machines.client.rendering.blockentity.FluidTankBER; import com.enderio.machines.client.rendering.blockentity.XPObeliskBER; import com.enderio.machines.common.attachment.IFluidTankUser; -import com.enderio.machines.common.blockentity.*; +import com.enderio.machines.common.blockentity.AlloySmelterBlockEntity; +import com.enderio.machines.common.blockentity.CrafterBlockEntity; +import com.enderio.machines.common.blockentity.CreativePowerBlockEntity; +import com.enderio.machines.common.blockentity.DrainBlockEntity; +import com.enderio.machines.common.blockentity.EnchanterBlockEntity; +import com.enderio.machines.common.blockentity.FluidTankBlockEntity; +import com.enderio.machines.common.blockentity.ImpulseHopperBlockEntity; +import com.enderio.machines.common.blockentity.PaintingMachineBlockEntity; +import com.enderio.machines.common.blockentity.PoweredSpawnerBlockEntity; +import com.enderio.machines.common.blockentity.PrimitiveAlloySmelterBlockEntity; +import com.enderio.machines.common.blockentity.SagMillBlockEntity; +import com.enderio.machines.common.blockentity.SlicerBlockEntity; +import com.enderio.machines.common.blockentity.SoulBinderBlockEntity; +import com.enderio.machines.common.blockentity.SoulEngineBlockEntity; +import com.enderio.machines.common.blockentity.StirlingGeneratorBlockEntity; +import com.enderio.machines.common.blockentity.TravelAnchorBlockEntity; +import com.enderio.machines.common.blockentity.VacuumChestBlockEntity; +import com.enderio.machines.common.blockentity.VatBlockEntity; +import com.enderio.machines.common.blockentity.WiredChargerBlockEntity; +import com.enderio.machines.common.blockentity.XPObeliskBlockEntity; +import com.enderio.machines.common.blockentity.XPVacuumBlockEntity; import com.enderio.machines.common.blockentity.base.MachineBlockEntity; import com.enderio.machines.common.blockentity.base.PoweredMachineBlockEntity; import com.enderio.machines.common.blockentity.capacitorbank.CapacitorBankBlockEntity; @@ -153,6 +173,10 @@ public class MachineBlockEntities { .apply(MachineBlockEntities::machineBlockEntityCapabilities) .addCapability(Capabilities.FluidHandler.BLOCK, IFluidTankUser.FLUID_HANDLER_PROVIDER); + public static final RegiliteBlockEntity VAT = register("vat", VatBlockEntity::new, MachineBlocks.VAT) + .apply(MachineBlockEntities::machineBlockEntityCapabilities) + .addCapability(Capabilities.FluidHandler.BLOCK, IFluidTankUser.FLUID_HANDLER_PROVIDER); + @SafeVarargs private static RegiliteBlockEntity register(String name, BlockEntityType.BlockEntitySupplier beFactory, Supplier... blocks) { diff --git a/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java b/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java index e7c42b1ff7..68d2db5d9d 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java @@ -198,6 +198,8 @@ public class MachineBlocks { public static final RegiliteBlock DRAIN = progressMachine("drain", () -> MachineBlockEntities.DRAIN); + public static final RegiliteBlock VAT = machine("vat", () -> MachineBlockEntities.VAT).setTranslation("VAT"); + public static final RegiliteBlock XP_OBELISK = BLOCK_REGISTRY .registerBlock("xp_obelisk", props -> new MachineBlock(MachineBlockEntities.XP_OBELISK, props), BlockBehaviour.Properties.of().strength(2.5f, 8).isViewBlocking((pState, pLevel, pPos) -> false).noOcclusion()) diff --git a/src/machines/java/com/enderio/machines/common/init/MachineMenus.java b/src/machines/java/com/enderio/machines/common/init/MachineMenus.java index d91e74d9b0..9f670b3549 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineMenus.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineMenus.java @@ -18,6 +18,7 @@ import com.enderio.machines.client.gui.screen.StirlingGeneratorScreen; import com.enderio.machines.client.gui.screen.TravelAnchorScreen; import com.enderio.machines.client.gui.screen.VacuumChestScreen; +import com.enderio.machines.client.gui.screen.VatScreen; import com.enderio.machines.client.gui.screen.WiredChargerScreen; import com.enderio.machines.client.gui.screen.XPObeliskScreen; import com.enderio.machines.client.gui.screen.XPVacuumScreen; @@ -38,6 +39,7 @@ import com.enderio.machines.common.menu.StirlingGeneratorMenu; import com.enderio.machines.common.menu.TravelAnchorMenu; import com.enderio.machines.common.menu.VacuumChestMenu; +import com.enderio.machines.common.menu.VatMenu; import com.enderio.machines.common.menu.WiredChargerMenu; import com.enderio.machines.common.menu.XPObeliskMenu; import com.enderio.machines.common.menu.XPVacuumMenu; @@ -90,6 +92,7 @@ private MachineMenus() {} .registerMenu("travel_anchor", TravelAnchorMenu::factory, () -> TravelAnchorScreen::new); public static final RegiliteMenu XP_OBELISK = MENU_REGISTRY .registerMenu("xp_obelisk", XPObeliskMenu::factory, () -> XPObeliskScreen::new); + public static final RegiliteMenu VAT = MENU_REGISTRY.registerMenu("vat", VatMenu::factory, () -> VatScreen::new); public static void register(IEventBus bus) { MENU_REGISTRY.register(bus); diff --git a/src/machines/java/com/enderio/machines/common/menu/VatMenu.java b/src/machines/java/com/enderio/machines/common/menu/VatMenu.java new file mode 100644 index 0000000000..5d88a53050 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/menu/VatMenu.java @@ -0,0 +1,26 @@ +package com.enderio.machines.common.menu; + +import com.enderio.machines.common.blockentity.VatBlockEntity; +import com.enderio.machines.common.init.MachineMenus; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.level.block.entity.BlockEntity; +import org.apache.logging.log4j.LogManager; +import org.jetbrains.annotations.Nullable; + +public class VatMenu extends MachineMenu { + public VatMenu(@Nullable VatBlockEntity blockEntity, Inventory inventory, int pContainerId) { + super(blockEntity, inventory, MachineMenus.VAT.get(), pContainerId); + addInventorySlots(8, 84); + } + + public static VatMenu factory(int pContainerId, Inventory inventory, FriendlyByteBuf buf) { + BlockEntity entity = inventory.player.level().getBlockEntity(buf.readBlockPos()); + if (entity instanceof VatBlockEntity castBlockEntity) { + return new VatMenu(castBlockEntity, inventory, pContainerId); + } + + LogManager.getLogger().warn("couldn't find BlockEntity"); + return new VatMenu(null, inventory, pContainerId); + } +} diff --git a/src/machines/resources/assets/enderio/models/block/vat.json b/src/machines/resources/assets/enderio/models/block/vat.json new file mode 100644 index 0000000000..515ee6ce83 --- /dev/null +++ b/src/machines/resources/assets/enderio/models/block/vat.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "down": "enderio:block/machine_bottom", + "east": "enderio:block/machine_side", + "north": "enderio:block/vat_front", + "particle": "enderio:block/vat_front", + "south": "enderio:block/vat_back", + "up": "enderio:block/vat_top", + "west": "enderio:block/machine_side" + } +} diff --git a/src/machines/resources/assets/enderio/textures/block/vat_back.png b/src/machines/resources/assets/enderio/textures/block/vat_back.png new file mode 100644 index 0000000000000000000000000000000000000000..a2a07ca868e18595c5d93b16ee81d5c6ae9a7e21 GIT binary patch literal 497 zcmVPx$t4TybR5*=&)3I(FF$~7>KPlbWhU3;nk)}Y?j@|MgeStiCwqz*cE;foJPVOX; z?BGL&0zQqxj}l0Il3%yCv0C&*IL!h?a5u)WaDR6Pz|Wf-&Y8Si^lUzSr0Y9WgxBK{ z^Wabqe7?M-S!2$qAgBsCcRcR?uwJg{x=hz~tS;7Uwp->*&MA>nV!7zKzWzo+kXixw zeg6Q!)#aD7CR;cnLTe3832%k~BJ$qCoXHX3Zd5yMMy;3`S%lTa8bp{gYVMTUh=5Wn zAp$^))3k|T&SYYl4+QDGbgYAMuG(CL6#lT>kcTC1oi0yHxuCEOiUnKLQ^eb>`z zV)wWsasmMN(=#Py&g5p!FbtGh*lsoqFGtKBkKk#4z})Fq>$4`;Qg|{WfG%guod9ZU z?Du;BK3!d%HTn4b%wo#<(E=602~gqdkM9t{@b(4~yszmml(CTe|8nl`SUBFC5D0g| z3;>Hj02RSJ_*)O;QYvq+uZ*LTHK8dHI5Px$$Vo&&R5*=&)4@&~F%ZV_|JdG5q6A8z0V+86#sl=ug%{x2xlk%pbt^TA00GI` zo|zsJaj2B_WhCn-YdroeH@CMw8MU|@RUJeyQ~EyhaCZm5x2r4mnKT}?92|b4X&ZtF z?{9CYIjgebWIm^AWyl0U2ti1x;dl3k>3BlZB$}pSGMjR6bi|NJDMn(9j7Ke(mls3? zDFuLE4?h7oo1gAAN!<_;YORDAv8o6lA|F>6GRYmxl%m^BF9lU4i7=T>L4+X_)Qnsz z?vP8tMF6P2oi^?anUG6CYej2Cg3xa^l$Px$bV)=(R5*=&(!oxXK@`RD|DBn(c0s63ql9WSE?w~=J^&BSj)f5v8!QkZl<)iI z-s7UBxM9xvH)l>VW8Y3s^=3Lj5mXnL5#e-C9p`6f0DL_;;Wbkx(+P*OIpfKQhx-ST z86INYU-O)nDMlhC<9f9MpdXyYV$Nth-WRk?DmhbfCL*}{{)16AjKu$Gnc@m8834o3 zBftPN<8c0#k_#frezWVWi;K+iy*2q)QXv5W*}&pRKt1d9&z{m4YgLHR#rcM zadmk?%al?wz)QP=kdQmapFU!iXqjZGfC~hYKw^})2k!pd@OOPf%cPVN5e|rCySH}7 za^~*#mi2l~%Oo?Hj3(6TEWdoF?*?{zU%qm~6!+k9v*GB&67MU?jBXfkXTKBcqeXP6x`R=_wdw;**&u4%3+EvN3Ipm$WjL8!gI`@;IOe+-)b(!`0HAK_=k0Yoy?mD2mau7T z19GC^vVHsLrt^=9G@~d#+ovoz`jn{1wMTxBAG1Ug^*}2dq_)@2M{1OABK=QtN~7)Fze=d?e1O&BQsDb#ht~KL~}7$TOS`!y56_)Q8HBWmNB33n*SSSQz4E{k%I zth@}7cuHS{1|QDQqAZ_e{U+C+xJ@>$_i))Lx0_m68Csx5AYwHja+iJY-Tl>X`q{Rd z7d)kmza3~Kj2pF7%d#TkWU@*!8-;S&S&?sKuyVovJrPx1NxGKtY}?%7co>K&#Z-2s zc;ri2%*I(7yA1JcJ0P?L1T4pMlsB4`ltlZfYiN;<)P`Rl@9Og5(vR4{us@XTt9puV zUtC)2O$$UdN-f^esbjc^I(ND>S&@yp;q1PDR3L4DA)7ou8ZD{I)zPI{= za7eqcSydIp&8^6#t!b0yuiz+Aw zt`sqP@AbJ4oaEPZ!Vs+phjR*EQI7!6N@~TvN-UO#pG}{&EIQr$%L9-65}Mdo9jcgd zvPijfsV!(Bo$Z)rSI`ktD?^#+LNB8Rg}p)BTa&Z`Zax?Lreqpc@jkb#T+V-Jy6*-a zrc>OunsNdgA(1tPu8{N7VAG5``_ZGjhM~ez0ClFo{2K+wc=PEmk{aSNq-Pu-W%4F= zR@_0j7Ehj+OfwQW??%D{=?V=cw+yfg1rJkll$$NV7w57=))m== zVY`>jmB1AnytPVvAr=nwsWEzkp{HDK3|Lg2@?P(A)Z6>3??`XR)HSbL3OZf7`vH|o zC3k&xP>Y={h5{VQ4*AoGp?r!CeByvLIv%g5r~e(WxOJHFfT8o)5^UKCJ93Z2R7}h; z1W8ODhM(}VdQBhy=0}OlgH#~gwzlVbcfU}YkQ<~AEI7N{&w@fr6fj7>NfD@GdrUW} zX9_cF@_=qW3LrtCm7QnwT(ZWc>Ih&JxuBYBipeTNX7jtR46?>xSfwk@+tL z!f7}*`hQCPcO7vCVQ$y#bA@3Br6V-!^BF0yZ}Oht*DVFQ-SP3RXNwG)#$IQk%`dRw z(-EgmjkIoW&{cu>VG3Q_*fGt~N|vtj=llQ1wYRtX@LdnT|FL6I&SaA0<9X!tMd4pq z=Un0|4_R*FO^d~iX|hl7m~ms!F*(Ob{!F#H8tqw$8AXGtjD8lnfh}4@qtPt1VNH7u zaGjdbZ9XWl166yh*8wgd?)z T;@j4*D(B~O*t>3T)aAbdooT0i literal 0 HcmV?d00001 From 038412f1931950d564b75994212169f83b913294 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Wed, 6 Mar 2024 01:12:30 +0530 Subject: [PATCH 02/14] Vat Datamap and Basic fluid Ingredient impl --- .../core/common/fluid/FluidIngredient.java | 151 ++++++++++++++++++ .../core/common/fluid/package-info.java | 4 + .../enderio/data_maps/item/vat_reagent.json | 14 ++ .../com/enderio/machines/EIOMachines.java | 3 +- .../machines/common/datamap/VatReagent.java | 25 +++ .../machines/common/datamap/package-info.java | 4 + .../machines/common/init/MachineDataMaps.java | 14 ++ .../data/datamaps/DataMapsProvider.java | 26 +++ .../machines/data/datamaps/package-info.java | 4 + 9 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 src/core/java/com/enderio/core/common/fluid/FluidIngredient.java create mode 100644 src/core/java/com/enderio/core/common/fluid/package-info.java create mode 100644 src/generated/resources/data/enderio/data_maps/item/vat_reagent.json create mode 100644 src/machines/java/com/enderio/machines/common/datamap/VatReagent.java create mode 100644 src/machines/java/com/enderio/machines/common/datamap/package-info.java create mode 100644 src/machines/java/com/enderio/machines/common/init/MachineDataMaps.java create mode 100644 src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java create mode 100644 src/machines/java/com/enderio/machines/data/datamaps/package-info.java diff --git a/src/core/java/com/enderio/core/common/fluid/FluidIngredient.java b/src/core/java/com/enderio/core/common/fluid/FluidIngredient.java new file mode 100644 index 0000000000..49a9ee6e4b --- /dev/null +++ b/src/core/java/com/enderio/core/common/fluid/FluidIngredient.java @@ -0,0 +1,151 @@ +package com.enderio.core.common.fluid; + +import com.google.common.collect.Lists; +import com.mojang.datafixers.util.Either; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.tags.TagKey; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.world.level.material.Fluid; + +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class FluidIngredient implements Predicate { + public static final FluidIngredient EMPTY = new FluidIngredient(Stream.empty()); + + private final Value[] values; + @Nullable private Fluid[] fluids; + + protected FluidIngredient(Stream stream) { + this.values = stream.toArray(Value[]::new); + } + + protected FluidIngredient(Value[] values) { + this.values = values; + } + + public Fluid[] getFluids() { + if (this.fluids == null) { + this.fluids = Arrays.stream(this.values).flatMap(value -> value.getFluids().stream()).distinct().toArray(Fluid[]::new); + } + + return this.fluids; + } + + @Override + public boolean test(@Nullable Fluid other) { + if (other == null) { + return false; + } else { + for (Fluid fluid : this.getFluids()) { + if (areFluidsEqual(fluid, other)) { + return true; + } + } + } + return false; + } + + protected boolean areFluidsEqual(Fluid left, Fluid right) { + return left.equals(right); + } + + public boolean isEmpty() { + return this.values.length == 0; + } + + public static FluidIngredient fromValues(Stream stream) { + FluidIngredient ingredient = new FluidIngredient(stream); + return ingredient.isEmpty() ? EMPTY : ingredient; + } + + public static FluidIngredient of() { + return EMPTY; + } + + public static FluidIngredient of(Fluid... fluids) { + return of(Arrays.stream(fluids)); + } + + public static FluidIngredient of(Stream fluids) { + return fromValues(fluids.map(FluidValue::new)); + } + + public static FluidIngredient of(TagKey tag) { + return fromValues(Stream.of(new TagValue(tag))); + } + + public record FluidValue(Fluid fluid, BiFunction comparator) implements Value { + public FluidValue(Fluid fluid) { + this(fluid, FluidValue::areFluidsEqual); + } + + static final Codec CODEC = RecordCodecBuilder.create(p_311727_ -> p_311727_ + .group(BuiltInRegistries.FLUID.byNameCodec().fieldOf("fluid").forGetter(FluidValue::fluid)) + .apply(p_311727_, FluidValue::new)); + + @Override + public boolean equals(Object other) { + if (other instanceof FluidValue otherFluid) { + return comparator().apply(fluid(), otherFluid.fluid()); + } + return false; + } + + @Override + public Collection getFluids() { + return Collections.singleton(this.fluid); + } + + private static boolean areFluidsEqual(Fluid left, Fluid right) { + return left.equals(right); + } + } + + public record TagValue(TagKey tag) implements Value { + static final Codec CODEC = RecordCodecBuilder.create( + p_301118_ -> p_301118_.group(TagKey.codec(Registries.FLUID).fieldOf("tag").forGetter(p_301154_ -> p_301154_.tag)).apply(p_301118_, TagValue::new)); + + @Override + public boolean equals(Object other) { + return other instanceof TagValue otherTag && otherTag.tag.location().equals(this.tag.location()); + } + + @Override + public Collection getFluids() { + List list = Lists.newArrayList(); + + for (Holder holder : BuiltInRegistries.FLUID.getTagOrEmpty(this.tag)) { + list.add(holder.value()); + } + + return list; + } + } + + protected interface Value { + Codec CODEC = ExtraCodecs + .xor(FluidValue.CODEC, TagValue.CODEC) + .xmap(p_300956_ -> p_300956_.map(p_300932_ -> p_300932_, p_301313_ -> p_301313_), p_301304_ -> { + if (p_301304_ instanceof TagValue fluidTag) { + return Either.right(fluidTag); + } else if (p_301304_ instanceof FluidValue fluidValue) { + return Either.left(fluidValue); + } else { + throw new UnsupportedOperationException("This is neither an fluid value nor a tag value."); + } + }); + + Collection getFluids(); + } +} diff --git a/src/core/java/com/enderio/core/common/fluid/package-info.java b/src/core/java/com/enderio/core/common/fluid/package-info.java new file mode 100644 index 0000000000..1dce7f0eb0 --- /dev/null +++ b/src/core/java/com/enderio/core/common/fluid/package-info.java @@ -0,0 +1,4 @@ +@javax.annotation.ParametersAreNonnullByDefault +@net.minecraft.MethodsReturnNonnullByDefault + +package com.enderio.core.common.fluid; diff --git a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json new file mode 100644 index 0000000000..51f8cc5d85 --- /dev/null +++ b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json @@ -0,0 +1,14 @@ +{ + "values": { + "#forge:crops": { + "#forge:crops": { + "modifier": 0.5 + } + }, + "minecraft:wheat": { + "#forge:crops": { + "modifier": 0.8 + } + } + } +} \ No newline at end of file diff --git a/src/machines/java/com/enderio/machines/EIOMachines.java b/src/machines/java/com/enderio/machines/EIOMachines.java index 886806d441..b10ac6a16f 100644 --- a/src/machines/java/com/enderio/machines/EIOMachines.java +++ b/src/machines/java/com/enderio/machines/EIOMachines.java @@ -20,6 +20,7 @@ import com.enderio.machines.common.tag.MachineTags; import com.enderio.machines.common.travel.AnchorTravelTarget; import com.enderio.machines.data.advancements.MachinesAdvancementGenerator; +import com.enderio.machines.data.datamaps.DataMapsProvider; import com.enderio.machines.data.recipes.AlloyRecipeProvider; import com.enderio.machines.data.recipes.EnchanterRecipeProvider; import com.enderio.machines.data.recipes.MachineRecipeProvider; @@ -35,7 +36,6 @@ import net.minecraft.data.DataGenerator; import net.minecraft.data.PackOutput; import net.minecraft.data.registries.VanillaRegistries; -import net.neoforged.bus.api.IEventBus; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.InterModComms; import net.neoforged.fml.ModLoadingContext; @@ -97,6 +97,7 @@ public static void gatherData(GatherDataEvent event) { provider.addSubProvider(event.includeServer(), new PaintingRecipeProvider(packOutput)); provider.addSubProvider(event.includeServer(), new SoulDataProvider(packOutput)); provider.addSubProvider(event.includeServer(), new MachineEntityTypeTagsProvider(packOutput, lookupProvider, event.getExistingFileHelper())); + provider.addSubProvider(event.includeServer(), new DataMapsProvider(packOutput, lookupProvider)); generator.addProvider(true, provider); provider.addSubProvider(event.includeServer(), new AdvancementProvider(packOutput, event.getLookupProvider(), event.getExistingFileHelper(), diff --git a/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java b/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java new file mode 100644 index 0000000000..eea049cd93 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java @@ -0,0 +1,25 @@ +package com.enderio.machines.common.datamap; + +import com.enderio.EnderIO; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.registries.Registries; +import net.minecraft.tags.TagKey; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.world.item.Item; +import net.neoforged.neoforge.registries.datamaps.AdvancedDataMapType; +import net.neoforged.neoforge.registries.datamaps.DataMapValueRemover; + +import java.util.Map; + +public class VatReagent { + + public static final AdvancedDataMapType, ReagentType>, DataMapValueRemover.Default, ReagentType>, Item>> DATA_MAP = AdvancedDataMapType + .builder(EnderIO.loc("vat_reagent"), Registries.ITEM, ExtraCodecs.strictUnboundedMap(TagKey.hashedCodec(Registries.ITEM), ReagentType.CODEC)) + .build(); + + public record ReagentType(double modifier) { + public static final Codec CODEC = RecordCodecBuilder.create( + in -> in.group(Codec.DOUBLE.fieldOf("modifier").forGetter(ReagentType::modifier)).apply(in, ReagentType::new)); + } +} diff --git a/src/machines/java/com/enderio/machines/common/datamap/package-info.java b/src/machines/java/com/enderio/machines/common/datamap/package-info.java new file mode 100644 index 0000000000..72c49f2a76 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/datamap/package-info.java @@ -0,0 +1,4 @@ +@javax.annotation.ParametersAreNonnullByDefault +@net.minecraft.MethodsReturnNonnullByDefault + +package com.enderio.machines.common.datamap; diff --git a/src/machines/java/com/enderio/machines/common/init/MachineDataMaps.java b/src/machines/java/com/enderio/machines/common/init/MachineDataMaps.java new file mode 100644 index 0000000000..5f852f7738 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/init/MachineDataMaps.java @@ -0,0 +1,14 @@ +package com.enderio.machines.common.init; + +import com.enderio.machines.common.datamap.VatReagent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.registries.datamaps.RegisterDataMapTypesEvent; + +@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) +public class MachineDataMaps { + @SubscribeEvent + public static void registerDataMap(RegisterDataMapTypesEvent event) { + event.register(VatReagent.DATA_MAP); + } +} diff --git a/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java b/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java new file mode 100644 index 0000000000..fa32312ccf --- /dev/null +++ b/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java @@ -0,0 +1,26 @@ +package com.enderio.machines.data.datamaps; + +import com.enderio.machines.common.datamap.VatReagent; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.minecraft.world.item.Items; +import net.neoforged.neoforge.common.Tags; +import net.neoforged.neoforge.common.data.DataMapProvider; + +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +public class DataMapsProvider extends DataMapProvider { + + public DataMapsProvider(PackOutput packOutput, CompletableFuture lookupProvider) { + super(packOutput, lookupProvider); + } + + @SuppressWarnings("deprecation") + @Override + protected void gather() { + builder(VatReagent.DATA_MAP) + .add(Tags.Items.CROPS, Map.of(Tags.Items.CROPS, new VatReagent.ReagentType(0.5)), false) + .add(Items.WHEAT.builtInRegistryHolder(), Map.of(Tags.Items.CROPS, new VatReagent.ReagentType(0.8)), false); + } +} diff --git a/src/machines/java/com/enderio/machines/data/datamaps/package-info.java b/src/machines/java/com/enderio/machines/data/datamaps/package-info.java new file mode 100644 index 0000000000..aeb447e845 --- /dev/null +++ b/src/machines/java/com/enderio/machines/data/datamaps/package-info.java @@ -0,0 +1,4 @@ +@javax.annotation.ParametersAreNonnullByDefault +@net.minecraft.MethodsReturnNonnullByDefault + +package com.enderio.machines.data.datamaps; From 6dbe11685ac1aa40192e955b46adff0dc1ef5647 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Wed, 6 Mar 2024 20:30:16 +0530 Subject: [PATCH 03/14] FluidIngredient and VatFermentingRecipe --- .../core/common/fluid/package-info.java | 4 - .../{fluid => recipes}/FluidIngredient.java | 63 +++++- .../machines/common/init/MachineRecipes.java | 4 +- .../common/recipe/VatFermentingRecipe.java | 192 ++++++++++++++++++ 4 files changed, 247 insertions(+), 16 deletions(-) delete mode 100644 src/core/java/com/enderio/core/common/fluid/package-info.java rename src/core/java/com/enderio/core/common/{fluid => recipes}/FluidIngredient.java (63%) create mode 100644 src/machines/java/com/enderio/machines/common/recipe/VatFermentingRecipe.java diff --git a/src/core/java/com/enderio/core/common/fluid/package-info.java b/src/core/java/com/enderio/core/common/fluid/package-info.java deleted file mode 100644 index 1dce7f0eb0..0000000000 --- a/src/core/java/com/enderio/core/common/fluid/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -@javax.annotation.ParametersAreNonnullByDefault -@net.minecraft.MethodsReturnNonnullByDefault - -package com.enderio.core.common.fluid; diff --git a/src/core/java/com/enderio/core/common/fluid/FluidIngredient.java b/src/core/java/com/enderio/core/common/recipes/FluidIngredient.java similarity index 63% rename from src/core/java/com/enderio/core/common/fluid/FluidIngredient.java rename to src/core/java/com/enderio/core/common/recipes/FluidIngredient.java index 49a9ee6e4b..26e60c72f0 100644 --- a/src/core/java/com/enderio/core/common/fluid/FluidIngredient.java +++ b/src/core/java/com/enderio/core/common/recipes/FluidIngredient.java @@ -1,12 +1,14 @@ -package com.enderio.core.common.fluid; +package com.enderio.core.common.recipes; import com.google.common.collect.Lists; import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.tags.TagKey; import net.minecraft.util.ExtraCodecs; import net.minecraft.world.level.material.Fluid; @@ -16,12 +18,30 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.stream.Stream; public class FluidIngredient implements Predicate { public static final FluidIngredient EMPTY = new FluidIngredient(Stream.empty()); + private static final Codec CODEC_LIST = Codec + .list(Value.CODEC) + .comapFlatMap(list -> list.isEmpty() ? + DataResult.error(() -> "Fluid array cannot be empty, at least one fluid must be defined") : + DataResult.success(list.toArray(new Value[0])), List::of); + + public static final Codec CODEC = ExtraCodecs + .either(CODEC_LIST, Value.CODEC) + .flatComapMap(either -> either.map(FluidIngredient::new, value -> new FluidIngredient(new Value[] { value })), fluidIngredient -> { + if (fluidIngredient.values.length == 1) { + return DataResult.success(Either.right(fluidIngredient.values[0])); + } else { + return fluidIngredient.values.length == 0 ? + DataResult.error(() -> "Fluid array cannot be empty, at least one fluid must be defined") : + DataResult.success(Either.left(fluidIngredient.values)); + } + }); private final Value[] values; @Nullable private Fluid[] fluids; @@ -85,14 +105,24 @@ public static FluidIngredient of(TagKey tag) { return fromValues(Stream.of(new TagValue(tag))); } + public final void toNetwork(FriendlyByteBuf pBuffer) { + BiConsumer writer = (buf, fluid) -> buf.writeId(BuiltInRegistries.FLUID, fluid); + pBuffer.writeCollection(Arrays.asList(this.getFluids()), writer::accept); + } + + public static FluidIngredient fromNetwork(FriendlyByteBuf buf) { + var size = buf.readVarInt(); + return new FluidIngredient(Stream.generate(() -> new FluidValue(buf.readById(BuiltInRegistries.FLUID))).limit(size)); + } + public record FluidValue(Fluid fluid, BiFunction comparator) implements Value { public FluidValue(Fluid fluid) { this(fluid, FluidValue::areFluidsEqual); } - static final Codec CODEC = RecordCodecBuilder.create(p_311727_ -> p_311727_ - .group(BuiltInRegistries.FLUID.byNameCodec().fieldOf("fluid").forGetter(FluidValue::fluid)) - .apply(p_311727_, FluidValue::new)); + static final Codec CODEC = RecordCodecBuilder.create(instance -> instance + .group(BuiltInRegistries.FLUID.byNameCodec().fieldOf("fluid_name").forGetter(FluidValue::fluid)) + .apply(instance, FluidValue::new)); @Override public boolean equals(Object other) { @@ -102,6 +132,11 @@ public boolean equals(Object other) { return false; } + @Override + public Codec getCodec() { + return CODEC; + } + @Override public Collection getFluids() { return Collections.singleton(this.fluid); @@ -113,14 +148,20 @@ private static boolean areFluidsEqual(Fluid left, Fluid right) { } public record TagValue(TagKey tag) implements Value { + static final Codec CODEC = RecordCodecBuilder.create( - p_301118_ -> p_301118_.group(TagKey.codec(Registries.FLUID).fieldOf("tag").forGetter(p_301154_ -> p_301154_.tag)).apply(p_301118_, TagValue::new)); + instance -> instance.group(TagKey.codec(Registries.FLUID).fieldOf("fluid_tag").forGetter(TagValue::tag)).apply(instance, TagValue::new)); @Override public boolean equals(Object other) { return other instanceof TagValue otherTag && otherTag.tag.location().equals(this.tag.location()); } + @Override + public Codec getCodec() { + return CODEC; + } + @Override public Collection getFluids() { List list = Lists.newArrayList(); @@ -133,19 +174,19 @@ public Collection getFluids() { } } - protected interface Value { + protected sealed interface Value { Codec CODEC = ExtraCodecs - .xor(FluidValue.CODEC, TagValue.CODEC) - .xmap(p_300956_ -> p_300956_.map(p_300932_ -> p_300932_, p_301313_ -> p_301313_), p_301304_ -> { - if (p_301304_ instanceof TagValue fluidTag) { - return Either.right(fluidTag); - } else if (p_301304_ instanceof FluidValue fluidValue) { + .xor(FluidValue.CODEC, TagValue.CODEC).xmap(either -> either.map(fluidValue -> fluidValue, tagValue -> tagValue), value -> { + if (value instanceof TagValue tagValue) { + return Either.right(tagValue); + } else if (value instanceof FluidValue fluidValue) { return Either.left(fluidValue); } else { throw new UnsupportedOperationException("This is neither an fluid value nor a tag value."); } }); + Codec getCodec(); Collection getFluids(); } } diff --git a/src/machines/java/com/enderio/machines/common/init/MachineRecipes.java b/src/machines/java/com/enderio/machines/common/init/MachineRecipes.java index 1e3ed37a2c..ff448326bf 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineRecipes.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineRecipes.java @@ -9,12 +9,12 @@ import com.enderio.machines.common.recipe.SlicingRecipe; import com.enderio.machines.common.recipe.SoulBindingRecipe; import com.enderio.machines.common.recipe.TankRecipe; +import com.enderio.machines.common.recipe.VatFermentingRecipe; import net.minecraft.core.registries.Registries; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.neoforged.bus.api.IEventBus; -import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; @@ -32,6 +32,8 @@ public class MachineRecipes { public static final RecipeTypeSerializerPair SOUL_BINDING = register("soul_binding", SoulBindingRecipe.Serializer::new); public static final RecipeTypeSerializerPair TANK = register("tank", TankRecipe.Serializer::new); public static final RecipeTypeSerializerPair PAINTING = register("painting", PaintingRecipe.Serializer::new); + public static final RecipeTypeSerializerPair VAT_FERMENTING = register("vat_fermenting", + VatFermentingRecipe.Serializer::new); private static > DeferredHolder, RecipeType> registerType(String name) { return RECIPE_TYPES.register(name, () -> RecipeType.simple(EnderIO.loc(name))); diff --git a/src/machines/java/com/enderio/machines/common/recipe/VatFermentingRecipe.java b/src/machines/java/com/enderio/machines/common/recipe/VatFermentingRecipe.java new file mode 100644 index 0000000000..caca1ff72c --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/recipe/VatFermentingRecipe.java @@ -0,0 +1,192 @@ +package com.enderio.machines.common.recipe; + +import com.enderio.core.common.recipes.FluidIngredient; +import com.enderio.core.common.recipes.OutputStack; +import com.enderio.machines.common.init.MachineRecipes; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.material.Fluid; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; +import net.neoforged.neoforge.items.IItemHandlerModifiable; +import net.neoforged.neoforge.items.wrapper.RecipeWrapper; + +import java.util.List; + +public class VatFermentingRecipe implements MachineRecipe { + + private final FluidIngredient inputFluid; + private final int inputFluidAmount; + private final TagKey leftReagent; + private final TagKey rightReagent; + private final int outputModifier; + private final Fluid outputFluid; + private final int ticks; + + public VatFermentingRecipe(FluidIngredient inputFluid, int inputFluidAmount, TagKey leftReagent, TagKey rightReagent, Fluid outputFluid, + int outputModifier, int ticks) { + this.inputFluid = inputFluid; + this.inputFluidAmount = inputFluidAmount; + this.leftReagent = leftReagent; + this.rightReagent = rightReagent; + this.outputModifier = outputModifier; + this.outputFluid = outputFluid; + this.ticks = ticks; + } + + @Override + public int getBaseEnergyCost() { + return 0; + } + + @Override + public List craft(Container container, RegistryAccess registryAccess) { + //Todo: get reagent modifiers + return List.of(OutputStack.of(new FluidStack(outputFluid, inputFluidAmount * outputModifier))); + } + + @Override + public List getResultStacks(RegistryAccess registryAccess) { + return List.of(OutputStack.EMPTY); + } + + @Override + public boolean matches(Container container, Level level) { + FluidStack inputTank = container.getInputTank().getFluid(); + if (!inputFluid.test(inputTank.getFluid()) || !(inputTank.getAmount() < inputFluidAmount)) { + return false; + } + if (!container.getItem(0).is(leftReagent)) { + return false; + } + if (!container.getItem(1).is(rightReagent)) { + return false; + } + + return true; + } + + public FluidIngredient getInputFluid() { + return inputFluid; + } + + public int getInputFluidAmount() { + return inputFluidAmount; + } + + public TagKey getLeftReagent() { + return leftReagent; + } + + public TagKey getRightReagent() { + return rightReagent; + } + + public int getOutputModifier() { + return outputModifier; + } + + public Fluid getOutputFluid() { + return outputFluid; + } + + public int getTicks() { + return ticks; + } + + @Override + public RecipeSerializer getSerializer() { + return MachineRecipes.VAT_FERMENTING.serializer().get(); + } + + @Override + public RecipeType getType() { + return MachineRecipes.VAT_FERMENTING.type().get(); + } + + public static class Container extends RecipeWrapper { + + private final FluidTank inputTank; + + private final FluidTank outputTank; + + public Container(IItemHandlerModifiable inv, FluidTank inputTank, FluidTank outputTank) { + super(inv); + this.inputTank = inputTank; + this.outputTank = outputTank; + } + + public FluidTank getInputTank() { + return inputTank; + } + + public FluidTank getOutputTank() { + return outputTank; + } + + } + + public static class Serializer implements RecipeSerializer { + + Codec CODEC = RecordCodecBuilder.create(instance -> instance + .group(FluidIngredient.CODEC.fieldOf("inputFluid").forGetter(VatFermentingRecipe::getInputFluid), + Codec.INT.fieldOf("inputFluidAmount").forGetter(VatFermentingRecipe::getInputFluidAmount), + TagKey.codec(Registries.ITEM).fieldOf("leftReagent").forGetter(VatFermentingRecipe::getLeftReagent), + TagKey.codec(Registries.ITEM).fieldOf("rightReagent").forGetter(VatFermentingRecipe::getRightReagent), + BuiltInRegistries.FLUID.byNameCodec().fieldOf("FluidName").forGetter(VatFermentingRecipe::getOutputFluid), + Codec.INT.fieldOf("outputModifier").forGetter(VatFermentingRecipe::getOutputModifier), + Codec.INT.fieldOf("ticks").forGetter(VatFermentingRecipe::getTicks)) + .apply(instance, VatFermentingRecipe::new)); + + @Override + public Codec codec() { + return CODEC; + } + + @Override + public VatFermentingRecipe fromNetwork(FriendlyByteBuf buffer) { + //TODO : NETWORK + // try { + // FluidStack inputFluid = FluidStack.readFromPacket(buffer); + // FluidStack outputFluid = FluidStack.readFromPacket(buffer); + // int baseModifier = buffer.readInt(); + // ResourceLocation leftReagent = buffer.readResourceLocation(); + // ResourceLocation rightReagent = buffer.readResourceLocation(); + // int ticks = buffer.readInt(); + // return new VatFermentingRecipe(inputFluid, outputFluid, baseModifier, leftReagent, rightReagent, ticks); + // } catch (Exception ex) { + // EnderIO.LOGGER.error("Error reading Vat recipe for packet.", ex); + // throw ex; + // } + return null; + } + + @Override + public void toNetwork(FriendlyByteBuf buffer, VatFermentingRecipe recipe) { + //TODO : NETWORK + // try { + // recipe.inputFluid.toNetwork(buffer); + // buffer.writeInt(recipe.inputFluidAmount); + // buffer.; + // buffer.ta(recipe.leftReagent); + // buffer.writeResourceLocation(recipe.rightReagent); + // buffer.writeId(BuiltInRegistries.FLUID, recipe.outputFluid); + // buffer.writeInt(recipe.outputModifier); + // buffer.writeInt(recipe.ticks); + // } catch (Exception ex) { + // EnderIO.LOGGER.error("Error reading Vat recipe for packet.", ex); + // throw ex; + // } + + } + } +} From a3a5a47a89767da696392d87763372b64ac8750a Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Thu, 7 Mar 2024 23:05:35 +0530 Subject: [PATCH 04/14] Finish recipe, add Datagen and Screen impl --- .../enderio/data_maps/item/vat_reagent.json | 8 +-- .../fermenting/fluid_hootch_still.json | 12 ++++ .../com/enderio/machines/EIOMachines.java | 2 + .../machines/client/gui/screen/VatScreen.java | 18 +++++- .../common/blockentity/VatBlockEntity.java | 14 +++++ .../machines/common/datamap/VatReagent.java | 13 ++--- .../machines/common/init/MachineRecipes.java | 6 +- .../common/io/fluid/MachineFluidHandler.java | 14 +++-- .../enderio/machines/common/menu/VatMenu.java | 4 ++ ...ntingRecipe.java => FermentingRecipe.java} | 54 +++++++++++------- .../data/datamaps/DataMapsProvider.java | 4 +- .../recipes/FermentingRecipeProvider.java | 33 +++++++++++ .../assets/enderio/textures/gui/vat.png | Bin 2547 -> 2148 bytes .../assets/enderio/textures/gui/vat.png | Bin 2148 -> 0 bytes 14 files changed, 137 insertions(+), 45 deletions(-) create mode 100644 src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json rename src/machines/java/com/enderio/machines/common/recipe/{VatFermentingRecipe.java => FermentingRecipe.java} (72%) create mode 100644 src/machines/java/com/enderio/machines/data/recipes/FermentingRecipeProvider.java delete mode 100644 src/main/resources/assets/enderio/textures/gui/vat.png diff --git a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json index 51f8cc5d85..8843e240cc 100644 --- a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json +++ b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json @@ -1,14 +1,10 @@ { "values": { "#forge:crops": { - "#forge:crops": { - "modifier": 0.5 - } + "#forge:crops": 0.5 }, "minecraft:wheat": { - "#forge:crops": { - "modifier": 0.8 - } + "#forge:crops": 0.8 } } } \ No newline at end of file diff --git a/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json b/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json new file mode 100644 index 0000000000..a5e1288580 --- /dev/null +++ b/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json @@ -0,0 +1,12 @@ +{ + "type": "enderio:vat_fermenting", + "input_amount": 100, + "input_fluid": { + "fluid_name": "minecraft:water" + }, + "left_reagent": "forge:seeds", + "output_fluid": "enderio:fluid_hootch_still", + "output_modifier": 0.25, + "right_reagent": "forge:crops", + "ticks": 20 +} \ No newline at end of file diff --git a/src/machines/java/com/enderio/machines/EIOMachines.java b/src/machines/java/com/enderio/machines/EIOMachines.java index b10ac6a16f..ffaa2fcf88 100644 --- a/src/machines/java/com/enderio/machines/EIOMachines.java +++ b/src/machines/java/com/enderio/machines/EIOMachines.java @@ -23,6 +23,7 @@ import com.enderio.machines.data.datamaps.DataMapsProvider; import com.enderio.machines.data.recipes.AlloyRecipeProvider; import com.enderio.machines.data.recipes.EnchanterRecipeProvider; +import com.enderio.machines.data.recipes.FermentingRecipeProvider; import com.enderio.machines.data.recipes.MachineRecipeProvider; import com.enderio.machines.data.recipes.PaintingRecipeProvider; import com.enderio.machines.data.recipes.SagMillRecipeProvider; @@ -95,6 +96,7 @@ public static void gatherData(GatherDataEvent event) { provider.addSubProvider(event.includeServer(), new SoulBindingRecipeProvider(packOutput)); provider.addSubProvider(event.includeServer(), new TankRecipeProvider(packOutput)); provider.addSubProvider(event.includeServer(), new PaintingRecipeProvider(packOutput)); + provider.addSubProvider(event.includeServer(), new FermentingRecipeProvider(packOutput)); provider.addSubProvider(event.includeServer(), new SoulDataProvider(packOutput)); provider.addSubProvider(event.includeServer(), new MachineEntityTypeTagsProvider(packOutput, lookupProvider, event.getExistingFileHelper())); provider.addSubProvider(event.includeServer(), new DataMapsProvider(packOutput, lookupProvider)); diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java index 1a58fb5b6e..0cd501e4cb 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -2,7 +2,11 @@ import com.enderio.EnderIO; import com.enderio.api.misc.Vector2i; +import com.enderio.base.common.lang.EIOLang; import com.enderio.core.client.gui.screen.EIOScreen; +import com.enderio.core.client.gui.widgets.EnumIconWidget; +import com.enderio.machines.client.gui.widget.FluidStackWidget; +import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; import com.enderio.machines.common.menu.VatMenu; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -13,7 +17,19 @@ public class VatScreen extends EIOScreen { private static final ResourceLocation VAT_BG = EnderIO.loc("textures/gui/vat.png"); public VatScreen(VatMenu pMenu, Inventory pPlayerInventory, Component pTitle) { - super(pMenu, pPlayerInventory, pTitle, true); + super(pMenu, pPlayerInventory, pTitle, false); + } + + @Override + protected void init() { + super.init(); + addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getInputTank, 30 + leftPos, 12 + topPos, 15, 47)); + addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getOutputTank, 132 + leftPos, 12 + topPos, 15, 47)); + + addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(), + control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE)); + + addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font)); } @Override diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java index 1249b045ff..933256ce7e 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -1,9 +1,11 @@ package com.enderio.machines.common.blockentity; +import com.enderio.core.common.network.slot.FluidStackNetworkDataSlot; import com.enderio.machines.common.attachment.IFluidTankUser; import com.enderio.machines.common.blockentity.base.MachineBlockEntity; import com.enderio.machines.common.init.MachineBlockEntities; import com.enderio.machines.common.io.fluid.MachineFluidHandler; +import com.enderio.machines.common.io.fluid.MachineFluidTank; import com.enderio.machines.common.io.fluid.MachineTankLayout; import com.enderio.machines.common.io.fluid.TankAccess; import com.enderio.machines.common.io.item.MachineInventoryLayout; @@ -31,6 +33,8 @@ public VatBlockEntity(BlockPos worldPosition, BlockState blockState) { super(MachineBlockEntities.VAT.get(), worldPosition, blockState); fluidHandler = createFluidHandler(); + addDataSlot(new FluidStackNetworkDataSlot(() -> INPUT_TANK.getFluid(this), f -> INPUT_TANK.setFluid(this, f))); + addDataSlot(new FluidStackNetworkDataSlot(() -> OUTPUT_TANK.getFluid(this), f -> OUTPUT_TANK.setFluid(this, f))); // craftingTaskHost = new CraftingMachineTaskHost<>(this, () -> true, MachineRecipes.VAT_FERMENTING.type().get(), // new VatFermentingRecipe.Container(getInventoryNN(), getFluidTankNN()), this::createTask); } @@ -91,6 +95,14 @@ protected void onContentsChanged(int slot) { }; } + public MachineFluidTank getInputTank() { + return INPUT_TANK.getTank(this); + } + + public MachineFluidTank getOutputTank() { + return OUTPUT_TANK.getTank(this); + } + // protected static class VatCraftingMachineTask extends CraftingMachineTask { // // public VatCraftingMachineTask(@NotNull Level level, MachineInventory inventory, VatFermentingRecipe.Container container, MultiSlotAccess outputSlots, @@ -127,12 +139,14 @@ protected void onContentsChanged(int slot) { @Override public void saveAdditional(CompoundTag pTag) { super.saveAdditional(pTag); + saveTank(pTag); // craftingTaskHost.save(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); + loadTank(pTag); // craftingTaskHost.load(pTag); } } diff --git a/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java b/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java index eea049cd93..410c9ec5d8 100644 --- a/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java +++ b/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java @@ -2,7 +2,6 @@ import com.enderio.EnderIO; import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.registries.Registries; import net.minecraft.tags.TagKey; import net.minecraft.util.ExtraCodecs; @@ -14,12 +13,12 @@ public class VatReagent { - public static final AdvancedDataMapType, ReagentType>, DataMapValueRemover.Default, ReagentType>, Item>> DATA_MAP = AdvancedDataMapType - .builder(EnderIO.loc("vat_reagent"), Registries.ITEM, ExtraCodecs.strictUnboundedMap(TagKey.hashedCodec(Registries.ITEM), ReagentType.CODEC)) + public static final AdvancedDataMapType, Double>, DataMapValueRemover.Default, Double>, Item>> DATA_MAP = AdvancedDataMapType + .builder(EnderIO.loc("vat_reagent"), Registries.ITEM, ExtraCodecs.strictUnboundedMap(TagKey.hashedCodec(Registries.ITEM), Codec.DOUBLE)) .build(); - public record ReagentType(double modifier) { - public static final Codec CODEC = RecordCodecBuilder.create( - in -> in.group(Codec.DOUBLE.fieldOf("modifier").forGetter(ReagentType::modifier)).apply(in, ReagentType::new)); - } + // public record ReagentType(double modifier) { + // public static final Codec CODEC = RecordCodecBuilder.create( + // in -> in.group(Codec.DOUBLE.fieldOf("modifier").forGetter(ReagentType::modifier)).apply(in, ReagentType::new)); + // } } diff --git a/src/machines/java/com/enderio/machines/common/init/MachineRecipes.java b/src/machines/java/com/enderio/machines/common/init/MachineRecipes.java index ff448326bf..5ac5dbe546 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineRecipes.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineRecipes.java @@ -4,12 +4,12 @@ import com.enderio.core.common.recipes.RecipeTypeSerializerPair; import com.enderio.machines.common.recipe.AlloySmeltingRecipe; import com.enderio.machines.common.recipe.EnchanterRecipe; +import com.enderio.machines.common.recipe.FermentingRecipe; import com.enderio.machines.common.recipe.PaintingRecipe; import com.enderio.machines.common.recipe.SagMillingRecipe; import com.enderio.machines.common.recipe.SlicingRecipe; import com.enderio.machines.common.recipe.SoulBindingRecipe; import com.enderio.machines.common.recipe.TankRecipe; -import com.enderio.machines.common.recipe.VatFermentingRecipe; import net.minecraft.core.registries.Registries; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; @@ -32,8 +32,8 @@ public class MachineRecipes { public static final RecipeTypeSerializerPair SOUL_BINDING = register("soul_binding", SoulBindingRecipe.Serializer::new); public static final RecipeTypeSerializerPair TANK = register("tank", TankRecipe.Serializer::new); public static final RecipeTypeSerializerPair PAINTING = register("painting", PaintingRecipe.Serializer::new); - public static final RecipeTypeSerializerPair VAT_FERMENTING = register("vat_fermenting", - VatFermentingRecipe.Serializer::new); + public static final RecipeTypeSerializerPair VAT_FERMENTING = register("vat_fermenting", + FermentingRecipe.Serializer::new); private static > DeferredHolder, RecipeType> registerType(String name) { return RECIPE_TYPES.register(name, () -> RecipeType.simple(EnderIO.loc(name))); diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java index 1ea899392b..03a733d0d5 100644 --- a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java +++ b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java @@ -193,13 +193,15 @@ public FluidStack drain(FluidStack resource, FluidAction action) { @Override public FluidStack drain(int maxDrain, FluidAction action) { for (int index = 0; index < getTanks(); index++) { - if (drain(index, maxDrain, FluidAction.SIMULATE) != FluidStack.EMPTY) { - FluidStack drained = drain(index, maxDrain, action); - if (!drained.isEmpty()) { - onContentsChanged(index); - changeListener.accept(index); + if (layout.canExtract(index)) { + if (drain(index, maxDrain, FluidAction.SIMULATE) != FluidStack.EMPTY) { + FluidStack drained = drain(index, maxDrain, action); + if (!drained.isEmpty()) { + onContentsChanged(index); + changeListener.accept(index); + } + return drained; } - return drained; } } diff --git a/src/machines/java/com/enderio/machines/common/menu/VatMenu.java b/src/machines/java/com/enderio/machines/common/menu/VatMenu.java index 5d88a53050..accebe9383 100644 --- a/src/machines/java/com/enderio/machines/common/menu/VatMenu.java +++ b/src/machines/java/com/enderio/machines/common/menu/VatMenu.java @@ -11,6 +11,10 @@ public class VatMenu extends MachineMenu { public VatMenu(@Nullable VatBlockEntity blockEntity, Inventory inventory, int pContainerId) { super(blockEntity, inventory, MachineMenus.VAT.get(), pContainerId); + if (blockEntity != null) { + addSlot(new MachineSlot(blockEntity.getInventory(), VatBlockEntity.REAGENTS.get(0), 56, 12)); + addSlot(new MachineSlot(blockEntity.getInventory(), VatBlockEntity.REAGENTS.get(1), 105, 12)); + } addInventorySlots(8, 84); } diff --git a/src/machines/java/com/enderio/machines/common/recipe/VatFermentingRecipe.java b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java similarity index 72% rename from src/machines/java/com/enderio/machines/common/recipe/VatFermentingRecipe.java rename to src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java index caca1ff72c..11bfdbc010 100644 --- a/src/machines/java/com/enderio/machines/common/recipe/VatFermentingRecipe.java +++ b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java @@ -2,6 +2,7 @@ import com.enderio.core.common.recipes.FluidIngredient; import com.enderio.core.common.recipes.OutputStack; +import com.enderio.machines.common.datamap.VatReagent; import com.enderio.machines.common.init.MachineRecipes; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; @@ -11,6 +12,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; @@ -22,18 +24,18 @@ import java.util.List; -public class VatFermentingRecipe implements MachineRecipe { +public class FermentingRecipe implements MachineRecipe { private final FluidIngredient inputFluid; private final int inputFluidAmount; private final TagKey leftReagent; private final TagKey rightReagent; - private final int outputModifier; + private final double outputModifier; private final Fluid outputFluid; private final int ticks; - public VatFermentingRecipe(FluidIngredient inputFluid, int inputFluidAmount, TagKey leftReagent, TagKey rightReagent, Fluid outputFluid, - int outputModifier, int ticks) { + public FermentingRecipe(FluidIngredient inputFluid, int inputFluidAmount, TagKey leftReagent, TagKey rightReagent, Fluid outputFluid, + double outputModifier, int ticks) { this.inputFluid = inputFluid; this.inputFluidAmount = inputFluidAmount; this.leftReagent = leftReagent; @@ -50,8 +52,12 @@ public int getBaseEnergyCost() { @Override public List craft(Container container, RegistryAccess registryAccess) { - //Todo: get reagent modifiers - return List.of(OutputStack.of(new FluidStack(outputFluid, inputFluidAmount * outputModifier))); + + double totalModifier = outputModifier; + totalModifier *= getReagentModifier(container.getItem(0), leftReagent); + totalModifier *= getReagentModifier(container.getItem(1), rightReagent); + + return List.of(OutputStack.of(new FluidStack(outputFluid, (int) (inputFluidAmount * totalModifier)))); } @Override @@ -75,6 +81,14 @@ public boolean matches(Container container, Level level) { return true; } + public double getReagentModifier(ItemStack stack, TagKey reagent) { + var map = stack.getItemHolder().getData(VatReagent.DATA_MAP); + if (map != null) { + return map.getOrDefault(reagent, 1D); + } + return 1; + } + public FluidIngredient getInputFluid() { return inputFluid; } @@ -91,7 +105,7 @@ public TagKey getRightReagent() { return rightReagent; } - public int getOutputModifier() { + public double getOutputModifier() { return outputModifier; } @@ -135,25 +149,25 @@ public FluidTank getOutputTank() { } - public static class Serializer implements RecipeSerializer { + public static class Serializer implements RecipeSerializer { - Codec CODEC = RecordCodecBuilder.create(instance -> instance - .group(FluidIngredient.CODEC.fieldOf("inputFluid").forGetter(VatFermentingRecipe::getInputFluid), - Codec.INT.fieldOf("inputFluidAmount").forGetter(VatFermentingRecipe::getInputFluidAmount), - TagKey.codec(Registries.ITEM).fieldOf("leftReagent").forGetter(VatFermentingRecipe::getLeftReagent), - TagKey.codec(Registries.ITEM).fieldOf("rightReagent").forGetter(VatFermentingRecipe::getRightReagent), - BuiltInRegistries.FLUID.byNameCodec().fieldOf("FluidName").forGetter(VatFermentingRecipe::getOutputFluid), - Codec.INT.fieldOf("outputModifier").forGetter(VatFermentingRecipe::getOutputModifier), - Codec.INT.fieldOf("ticks").forGetter(VatFermentingRecipe::getTicks)) - .apply(instance, VatFermentingRecipe::new)); + Codec CODEC = RecordCodecBuilder.create(instance -> instance + .group(FluidIngredient.CODEC.fieldOf("input_fluid").forGetter(FermentingRecipe::getInputFluid), + Codec.INT.fieldOf("input_amount").forGetter(FermentingRecipe::getInputFluidAmount), + TagKey.codec(Registries.ITEM).fieldOf("left_reagent").forGetter(FermentingRecipe::getLeftReagent), + TagKey.codec(Registries.ITEM).fieldOf("right_reagent").forGetter(FermentingRecipe::getRightReagent), + BuiltInRegistries.FLUID.byNameCodec().fieldOf("output_fluid").forGetter(FermentingRecipe::getOutputFluid), + Codec.DOUBLE.fieldOf("output_modifier").forGetter(FermentingRecipe::getOutputModifier), + Codec.INT.fieldOf("ticks").forGetter(FermentingRecipe::getTicks)) + .apply(instance, FermentingRecipe::new)); @Override - public Codec codec() { + public Codec codec() { return CODEC; } @Override - public VatFermentingRecipe fromNetwork(FriendlyByteBuf buffer) { + public FermentingRecipe fromNetwork(FriendlyByteBuf buffer) { //TODO : NETWORK // try { // FluidStack inputFluid = FluidStack.readFromPacket(buffer); @@ -171,7 +185,7 @@ public VatFermentingRecipe fromNetwork(FriendlyByteBuf buffer) { } @Override - public void toNetwork(FriendlyByteBuf buffer, VatFermentingRecipe recipe) { + public void toNetwork(FriendlyByteBuf buffer, FermentingRecipe recipe) { //TODO : NETWORK // try { // recipe.inputFluid.toNetwork(buffer); diff --git a/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java b/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java index fa32312ccf..c2b38bbb4d 100644 --- a/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java +++ b/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java @@ -20,7 +20,7 @@ public DataMapsProvider(PackOutput packOutput, CompletableFuture leftReagent, TagKey rightReagent, double outputModifier, + int ticks, RecipeOutput recipeOutput) { + recipeOutput.accept(EnderIO.loc("fermenting/" + BuiltInRegistries.FLUID.getKey(output).getPath()), + new FermentingRecipe(input, inputFluidAmount, leftReagent, rightReagent, output, outputModifier, ticks), null); + } +} diff --git a/src/machines/resources/assets/enderio/textures/gui/vat.png b/src/machines/resources/assets/enderio/textures/gui/vat.png index b860d8c4b0a5a4349ad57ab7c3ab151cf25b7bbd..459d4a4db2ae36b39cbaf35016b80a7499d64f1c 100644 GIT binary patch literal 2148 zcmbVNdoTKBcqeXP6x`R=_wdw;**&u4%3+EvN3Ipm$WjL8!gI`@;IOe+-)b(!`0HAK_=k0Yoy?mD2mau7T z19GC^vVHsLrt^=9G@~d#+ovoz`jn{1wMTxBAG1Ug^*}2dq_)@2M{1OABK=QtN~7)Fze=d?e1O&BQsDb#ht~KL~}7$TOS`!y56_)Q8HBWmNB33n*SSSQz4E{k%I zth@}7cuHS{1|QDQqAZ_e{U+C+xJ@>$_i))Lx0_m68Csx5AYwHja+iJY-Tl>X`q{Rd z7d)kmza3~Kj2pF7%d#TkWU@*!8-;S&S&?sKuyVovJrPx1NxGKtY}?%7co>K&#Z-2s zc;ri2%*I(7yA1JcJ0P?L1T4pMlsB4`ltlZfYiN;<)P`Rl@9Og5(vR4{us@XTt9puV zUtC)2O$$UdN-f^esbjc^I(ND>S&@yp;q1PDR3L4DA)7ou8ZD{I)zPI{= za7eqcSydIp&8^6#t!b0yuiz+Aw zt`sqP@AbJ4oaEPZ!Vs+phjR*EQI7!6N@~TvN-UO#pG}{&EIQr$%L9-65}Mdo9jcgd zvPijfsV!(Bo$Z)rSI`ktD?^#+LNB8Rg}p)BTa&Z`Zax?Lreqpc@jkb#T+V-Jy6*-a zrc>OunsNdgA(1tPu8{N7VAG5``_ZGjhM~ez0ClFo{2K+wc=PEmk{aSNq-Pu-W%4F= zR@_0j7Ehj+OfwQW??%D{=?V=cw+yfg1rJkll$$NV7w57=))m== zVY`>jmB1AnytPVvAr=nwsWEzkp{HDK3|Lg2@?P(A)Z6>3??`XR)HSbL3OZf7`vH|o zC3k&xP>Y={h5{VQ4*AoGp?r!CeByvLIv%g5r~e(WxOJHFfT8o)5^UKCJ93Z2R7}h; z1W8ODhM(}VdQBhy=0}OlgH#~gwzlVbcfU}YkQ<~AEI7N{&w@fr6fj7>NfD@GdrUW} zX9_cF@_=qW3LrtCm7QnwT(ZWc>Ih&JxuBYBipeTNX7jtR46?>xSfwk@+tL z!f7}*`hQCPcO7vCVQ$y#bA@3Br6V-!^BF0yZ}Oht*DVFQ-SP3RXNwG)#$IQk%`dRw z(-EgmjkIoW&{cu>VG3Q_*fGt~N|vtj=llQ1wYRtX@LdnT|FL6I&SaA0<9X!tMd4pq z=Un0|4_R*FO^d~iX|hl7m~ms!F*(Ob{!F#H8tqw$8AXGtjD8lnfh}4@qtPt1VNH7u zaGjdbZ9XWl166yh*8wgd?)z T;@j4*D(B~O*t>3T)aAbdooT0i literal 2547 zcmeHI`BT$J6yNWcgqT1mAcjjxR1A?T2y$pa0)awm#Bf<)3Z@9k6-X&ZK#{L#S`bu< zf?5tEpa|jx0vS;Jih>SmL923A3>B+594bOcVo0Oa`WN(vPThGsZ{M+>ee>D3vw0jp zA0oko001Dee7ynyfYeI}EYMJ^`1+6_wZd%k*x&)cg#%h|zrzBc0XXa+Z?)gq*_q8| z2L}g7MMXtNN5{m(#Ky+P#l^+P$0sBt@OZq$#Kfeeq_niO^z?LrK#-AK^_-4-hEDtx(?{p6?s_0{}V= z?g^RSw@-CDg(P z^}%gpE4;%EWt_g$3|qGbYTiDBRR5>DjcD{PB|j!AXhgL@noDKOmf)tQ zyffN|yI)%dqOP1y%>pp)rcr?8>v2z_!Dgo-HDq}4re$cEs`vvZ

A)rVSJ=9KMjAYBOrf`1cf#+Dy06b>9ezQrLHwY!*`Zi|@j)m!L1ZO4 zrhn>2Wp%ylrajHl|pq4@`#>&5p%6>`!ZW(~{z}Z(78h zqh*bI_g;dI{1LsO3JEYdbO#PjptwWQ)ja>6$Oc1+X;nq%C>@+pTU3nrbTU)W`!lBh zi7?&K5_R-(%U^?P^Rc3e&c&X{7?Mdkcno}#{KX7xIRUQ=z@MkA+=H7q``G5S2Ql94 zV!Y9#!#r6CdSglZd|wY@b}zY-CD=SsvTj$t=>EAdq&6GZhv@uS%gcGD*;mJWAF6^A zl#12`zuZ&a`@7sOj97lmRx-J$g}eJ|@nlH_Ziy3~p{&J(6dH6e+qSS#jkUP*H?*WC zgqJh!S(>gKbc^GitSWv!GkMah!8F$ z7u6!Qi8y_`2zM;|%}^uID(cvSaFo;752;03=Q-dtGr|_#aMv!z5tK4T#oKz|3K%PS z&a9w|oSCm|_UU?T?l%Mbv}XnMg}ufW_R75-%*H)f(N&k}14SXIE&(lcT?l(>k}_|F zpyFL825CUHbfcl2c*k;bR52p+$!JBM78vDw+5z8*C{xNbsTZUT)gteV1A}1 zmBUcCP3@3-r6+W>3~uI!ii>kO3=%wg?O3?HDR*?4D0HiZWKVV}V@!s3N%cr1HqY)C z=9(|!%T?3UQu2tD9y+j9q$kn8>+7m9uaGOB^^o1$m5Nuq-$ErAfz~S44x&r>yex7c zMRRUYxr{nS&ncyYSe7k!O3gb5bS)tg5TM`<*j^*Y3BIQ`fsCH^EpwMA4Y$z{_=A8a z`!&_M9|e7BF(@rzSp#W!nEvpPN5au!mJM(?vvedX;_z`m5Pgt>FHH;>&_6OZIeNX@ zoP;QBZSYeQl;+#r)gRU=r*aQylX zMO&^-qkSz_^62E!5!1m|?T^I)Ecf@jpY{WSZ@RPdCh7&mRqgDxk+=zwRy)O=A2IL? zSn=zw=QE~IvPsl#(-gM;xILW){A~=7QzQZ-NDE7;6T-R=JfYmU@b_|*YR+?U7STKBcqeXP6x`R=_wdw;**&u4%3+EvN3Ipm$WjL8!gI`@;IOe+-)b(!`0HAK_=k0Yoy?mD2mau7T z19GC^vVHsLrt^=9G@~d#+ovoz`jn{1wMTxBAG1Ug^*}2dq_)@2M{1OABK=QtN~7)Fze=d?e1O&BQsDb#ht~KL~}7$TOS`!y56_)Q8HBWmNB33n*SSSQz4E{k%I zth@}7cuHS{1|QDQqAZ_e{U+C+xJ@>$_i))Lx0_m68Csx5AYwHja+iJY-Tl>X`q{Rd z7d)kmza3~Kj2pF7%d#TkWU@*!8-;S&S&?sKuyVovJrPx1NxGKtY}?%7co>K&#Z-2s zc;ri2%*I(7yA1JcJ0P?L1T4pMlsB4`ltlZfYiN;<)P`Rl@9Og5(vR4{us@XTt9puV zUtC)2O$$UdN-f^esbjc^I(ND>S&@yp;q1PDR3L4DA)7ou8ZD{I)zPI{= za7eqcSydIp&8^6#t!b0yuiz+Aw zt`sqP@AbJ4oaEPZ!Vs+phjR*EQI7!6N@~TvN-UO#pG}{&EIQr$%L9-65}Mdo9jcgd zvPijfsV!(Bo$Z)rSI`ktD?^#+LNB8Rg}p)BTa&Z`Zax?Lreqpc@jkb#T+V-Jy6*-a zrc>OunsNdgA(1tPu8{N7VAG5``_ZGjhM~ez0ClFo{2K+wc=PEmk{aSNq-Pu-W%4F= zR@_0j7Ehj+OfwQW??%D{=?V=cw+yfg1rJkll$$NV7w57=))m== zVY`>jmB1AnytPVvAr=nwsWEzkp{HDK3|Lg2@?P(A)Z6>3??`XR)HSbL3OZf7`vH|o zC3k&xP>Y={h5{VQ4*AoGp?r!CeByvLIv%g5r~e(WxOJHFfT8o)5^UKCJ93Z2R7}h; z1W8ODhM(}VdQBhy=0}OlgH#~gwzlVbcfU}YkQ<~AEI7N{&w@fr6fj7>NfD@GdrUW} zX9_cF@_=qW3LrtCm7QnwT(ZWc>Ih&JxuBYBipeTNX7jtR46?>xSfwk@+tL z!f7}*`hQCPcO7vCVQ$y#bA@3Br6V-!^BF0yZ}Oht*DVFQ-SP3RXNwG)#$IQk%`dRw z(-EgmjkIoW&{cu>VG3Q_*fGt~N|vtj=llQ1wYRtX@LdnT|FL6I&SaA0<9X!tMd4pq z=Un0|4_R*FO^d~iX|hl7m~ms!F*(Ob{!F#H8tqw$8AXGtjD8lnfh}4@qtPt1VNH7u zaGjdbZ9XWl166yh*8wgd?)z T;@j4*D(B~O*t>3T)aAbdooT0i From b095a302181cea41b91b97315365faf4c078dad0 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Fri, 8 Mar 2024 14:06:17 +0530 Subject: [PATCH 05/14] add vat crafting --- .../enderio/data_maps/item/vat_reagent.json | 5 +- .../fermenting/fluid_hootch_still.json | 2 +- .../machines/client/gui/screen/VatScreen.java | 2 + .../common/blockentity/VatBlockEntity.java | 108 +++++++++++------- .../blockentity/task/CraftingMachineTask.java | 22 +++- .../machines/common/datamap/VatReagent.java | 9 +- .../common/recipe/FermentingRecipe.java | 22 ++-- .../data/datamaps/DataMapsProvider.java | 4 +- .../recipes/FermentingRecipeProvider.java | 2 +- 9 files changed, 105 insertions(+), 71 deletions(-) diff --git a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json index 8843e240cc..6952a732ef 100644 --- a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json +++ b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json @@ -1,10 +1,7 @@ { "values": { - "#forge:crops": { - "#forge:crops": 0.5 - }, "minecraft:wheat": { - "#forge:crops": 0.8 + "#forge:crops": 2.0 } } } \ No newline at end of file diff --git a/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json b/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json index a5e1288580..77589dc9ba 100644 --- a/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json +++ b/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json @@ -1,6 +1,6 @@ { "type": "enderio:vat_fermenting", - "input_amount": 100, + "input_amount": 1000, "input_fluid": { "fluid_name": "minecraft:water" }, diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java index 0cd501e4cb..30710254c4 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -5,6 +5,7 @@ import com.enderio.base.common.lang.EIOLang; import com.enderio.core.client.gui.screen.EIOScreen; import com.enderio.core.client.gui.widgets.EnumIconWidget; +import com.enderio.machines.client.gui.widget.ActivityWidget; import com.enderio.machines.client.gui.widget.FluidStackWidget; import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; import com.enderio.machines.common.menu.VatMenu; @@ -30,6 +31,7 @@ protected void init() { control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE)); addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font)); + addRenderableWidget(new ActivityWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16 * 4)); } @Override diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java index 933256ce7e..71de36d5d5 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -1,25 +1,38 @@ package com.enderio.machines.common.blockentity; import com.enderio.core.common.network.slot.FluidStackNetworkDataSlot; +import com.enderio.core.common.recipes.OutputStack; import com.enderio.machines.common.attachment.IFluidTankUser; import com.enderio.machines.common.blockentity.base.MachineBlockEntity; +import com.enderio.machines.common.blockentity.task.CraftingMachineTask; +import com.enderio.machines.common.blockentity.task.host.CraftingMachineTaskHost; import com.enderio.machines.common.init.MachineBlockEntities; +import com.enderio.machines.common.init.MachineRecipes; import com.enderio.machines.common.io.fluid.MachineFluidHandler; import com.enderio.machines.common.io.fluid.MachineFluidTank; import com.enderio.machines.common.io.fluid.MachineTankLayout; import com.enderio.machines.common.io.fluid.TankAccess; +import com.enderio.machines.common.io.item.MachineInventory; import com.enderio.machines.common.io.item.MachineInventoryLayout; import com.enderio.machines.common.io.item.MultiSlotAccess; import com.enderio.machines.common.menu.VatMenu; +import com.enderio.machines.common.recipe.FermentingRecipe; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + public class VatBlockEntity extends MachineBlockEntity implements IFluidTankUser { public static final int TANK_CAPACITY_COMMON = 8 * FluidType.BUCKET_VOLUME; @@ -27,7 +40,7 @@ public class VatBlockEntity extends MachineBlockEntity implements IFluidTankUser private static final TankAccess OUTPUT_TANK = new TankAccess(); public static final MultiSlotAccess REAGENTS = new MultiSlotAccess(); private final MachineFluidHandler fluidHandler; - // private final CraftingMachineTaskHost craftingTaskHost; + private final CraftingMachineTaskHost craftingTaskHost; public VatBlockEntity(BlockPos worldPosition, BlockState blockState) { super(MachineBlockEntities.VAT.get(), worldPosition, blockState); @@ -35,8 +48,8 @@ public VatBlockEntity(BlockPos worldPosition, BlockState blockState) { addDataSlot(new FluidStackNetworkDataSlot(() -> INPUT_TANK.getFluid(this), f -> INPUT_TANK.setFluid(this, f))); addDataSlot(new FluidStackNetworkDataSlot(() -> OUTPUT_TANK.getFluid(this), f -> OUTPUT_TANK.setFluid(this, f))); - // craftingTaskHost = new CraftingMachineTaskHost<>(this, () -> true, MachineRecipes.VAT_FERMENTING.type().get(), - // new VatFermentingRecipe.Container(getInventoryNN(), getFluidTankNN()), this::createTask); + craftingTaskHost = new CraftingMachineTaskHost<>(this, () -> true, MachineRecipes.VAT_FERMENTING.type().get(), + new FermentingRecipe.Container(getInventoryNN(), getInputTank()), this::createTask); } @Nullable @@ -50,25 +63,32 @@ public void serverTick() { super.serverTick(); if (canAct()) { - // craftingTaskHost.tick(); + craftingTaskHost.tick(); } } @Override public void onLoad() { super.onLoad(); - // craftingTaskHost.onLevelReady(); + craftingTaskHost.onLevelReady(); } - // protected VatBlockEntity.VatCraftingMachineTask createTask(Level level, VatFermentingRecipe.Container container, @Nullable VatFermentingRecipe recipe) { - // return new VatBlockEntity.VatCraftingMachineTask(level, getInventoryNN(), container, null, recipe); - // } + protected VatBlockEntity.VatCraftingMachineTask createTask(Level level, FermentingRecipe.Container container, + @Nullable RecipeHolder recipe) { + return new VatBlockEntity.VatCraftingMachineTask(level, getInventoryNN(), getFluidHandler(), container, recipe); + } @Override public @Nullable MachineInventoryLayout getInventoryLayout() { return MachineInventoryLayout.builder().inputSlot(2).slotAccess(REAGENTS).build(); } + @Override + protected void onInventoryContentsChanged(int slot) { + super.onInventoryContentsChanged(slot); + craftingTaskHost.newTaskAvailable(); + } + @Override public MachineTankLayout getTankLayout() { return MachineTankLayout @@ -89,7 +109,7 @@ public MachineFluidHandler createFluidHandler() { @Override protected void onContentsChanged(int slot) { super.onContentsChanged(slot); - // craftingTaskHost.newTaskAvailable(); + craftingTaskHost.newTaskAvailable(); setChanged(); } }; @@ -103,50 +123,52 @@ public MachineFluidTank getOutputTank() { return OUTPUT_TANK.getTank(this); } - // protected static class VatCraftingMachineTask extends CraftingMachineTask { - // - // public VatCraftingMachineTask(@NotNull Level level, MachineInventory inventory, VatFermentingRecipe.Container container, MultiSlotAccess outputSlots, - // @Nullable VatFermentingRecipe recipe) { - // super(level, inventory, container, outputSlots, recipe); - // } - // - // @Override - // protected void consumeInputs(VatFermentingRecipe recipe) { - // container.getItem(0).shrink(1); - // container.getItem(1).shrink(1); - // // TODO: Extract fluid from first tank - // // container.getTank().getFluidInTank(0).shrink(recipe.getInputFluid().getAmount()); - // } - // - // @Override - // protected boolean placeOutputs(List outputs, boolean simulate) { - // // TODO: Place the output fluid in the second tank - // return super.placeOutputs(outputs, simulate); - // } - // - // @Override - // protected int makeProgress(int remainingProgress) { - // return 1; - // } - // - // @Override - // protected int getProgressRequired(VatFermentingRecipe recipe) { - // return recipe.getTicks(); - // } - // - // } + protected static class VatCraftingMachineTask extends CraftingMachineTask { + + public VatCraftingMachineTask(@NotNull Level level, MachineInventory inventory, MachineFluidHandler fluidHandler, FermentingRecipe.Container container, + @Nullable RecipeHolder recipe) { + super(level, inventory, fluidHandler, container, recipe); + } + + @Override + protected void consumeInputs(FermentingRecipe recipe) { + REAGENTS.get(0).getItemStack(inventory).shrink(1); + REAGENTS.get(1).getItemStack(inventory).shrink(1); + + INPUT_TANK.getTank(fluidHandler).drain(recipe.getInputFluidAmount(), IFluidHandler.FluidAction.EXECUTE); + } + + @Override + protected boolean placeOutputs(List outputs, boolean simulate) { + var action = simulate ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE; + FluidStack output = outputs.get(0).getFluid(); + int filled = OUTPUT_TANK.getTank(fluidHandler).fill(output, action); + return filled == output.getAmount(); + } + + @Override + protected int makeProgress(int remainingProgress) { + return 1; + } + + @Override + protected int getProgressRequired(FermentingRecipe recipe) { + return recipe.getTicks(); + } + + } @Override public void saveAdditional(CompoundTag pTag) { super.saveAdditional(pTag); saveTank(pTag); - // craftingTaskHost.save(pTag); + craftingTaskHost.save(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); loadTank(pTag); - // craftingTaskHost.load(pTag); + craftingTaskHost.load(pTag); } } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/task/CraftingMachineTask.java b/src/machines/java/com/enderio/machines/common/blockentity/task/CraftingMachineTask.java index cd044069ee..f5b5e76c42 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/task/CraftingMachineTask.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/task/CraftingMachineTask.java @@ -2,6 +2,7 @@ import com.enderio.core.common.recipes.OutputStack; import com.enderio.machines.common.blockentity.MachineState; +import com.enderio.machines.common.io.fluid.MachineFluidHandler; import com.enderio.machines.common.io.item.MachineInventory; import com.enderio.machines.common.io.item.MultiSlotAccess; import com.enderio.machines.common.io.item.SingleSlotAccess; @@ -26,7 +27,9 @@ public abstract class CraftingMachineTask, C extends protected final Level level; protected final MachineInventory inventory; + @Nullable protected final MachineFluidHandler fluidHandler; protected final C container; + @Nullable protected final MultiSlotAccess outputSlots; @Nullable @@ -42,9 +45,21 @@ public abstract class CraftingMachineTask, C extends private boolean isComplete; - public CraftingMachineTask(@NotNull Level level, MachineInventory inventory, C container, MultiSlotAccess outputSlots, @Nullable RecipeHolder recipe) { + public CraftingMachineTask(@NotNull Level level, MachineInventory inventory, C container, @Nullable MultiSlotAccess outputSlots, + @Nullable RecipeHolder recipe) { + this(level, inventory, null, container, outputSlots, recipe); + } + + public CraftingMachineTask(@NotNull Level level, MachineInventory inventory, @Nullable MachineFluidHandler fluidHandler, C container, + @Nullable RecipeHolder recipe) { + this(level, inventory, fluidHandler, container, null, recipe); + } + + public CraftingMachineTask(@NotNull Level level, MachineInventory inventory, @Nullable MachineFluidHandler fluidHandler, C container, + @Nullable MultiSlotAccess outputSlots, @Nullable RecipeHolder recipe) { this.level = level; this.inventory = inventory; + this.fluidHandler = fluidHandler; this.container = container; this.outputSlots = outputSlots; this.recipe = recipe; @@ -158,6 +173,11 @@ public boolean isCompleted() { protected boolean placeOutputs(List outputs, boolean simulate) { // TODO: Handle fluids too. + //return early if there are no output slots + if (outputSlots == null) { + return false; + } + // See that we can add all the outputs for (OutputStack output : outputs) { ItemStack item = output.getItem(); diff --git a/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java b/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java index 410c9ec5d8..37150585dd 100644 --- a/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java +++ b/src/machines/java/com/enderio/machines/common/datamap/VatReagent.java @@ -12,13 +12,12 @@ import java.util.Map; public class VatReagent { + public static final ExtraCodecs.StrictUnboundedMapCodec, Double> CODEC = ExtraCodecs.strictUnboundedMap(TagKey.hashedCodec(Registries.ITEM), + Codec.DOUBLE); public static final AdvancedDataMapType, Double>, DataMapValueRemover.Default, Double>, Item>> DATA_MAP = AdvancedDataMapType - .builder(EnderIO.loc("vat_reagent"), Registries.ITEM, ExtraCodecs.strictUnboundedMap(TagKey.hashedCodec(Registries.ITEM), Codec.DOUBLE)) + .builder(EnderIO.loc("vat_reagent"), Registries.ITEM, CODEC) + .synced(CODEC, true) .build(); - // public record ReagentType(double modifier) { - // public static final Codec CODEC = RecordCodecBuilder.create( - // in -> in.group(Codec.DOUBLE.fieldOf("modifier").forGetter(ReagentType::modifier)).apply(in, ReagentType::new)); - // } } diff --git a/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java index 11bfdbc010..425c4f5069 100644 --- a/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java +++ b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java @@ -1,9 +1,11 @@ package com.enderio.machines.common.recipe; +import com.enderio.EnderIO; import com.enderio.core.common.recipes.FluidIngredient; import com.enderio.core.common.recipes.OutputStack; import com.enderio.machines.common.datamap.VatReagent; import com.enderio.machines.common.init.MachineRecipes; +import com.enderio.machines.common.io.fluid.MachineFluidTank; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.RegistryAccess; @@ -18,7 +20,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.material.Fluid; import net.neoforged.neoforge.fluids.FluidStack; -import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import net.neoforged.neoforge.items.IItemHandlerModifiable; import net.neoforged.neoforge.items.wrapper.RecipeWrapper; @@ -68,7 +69,7 @@ public List getResultStacks(RegistryAccess registryAccess) { @Override public boolean matches(Container container, Level level) { FluidStack inputTank = container.getInputTank().getFluid(); - if (!inputFluid.test(inputTank.getFluid()) || !(inputTank.getAmount() < inputFluidAmount)) { + if (!inputFluid.test(inputTank.getFluid()) || inputTank.getAmount() < inputFluidAmount) { return false; } if (!container.getItem(0).is(leftReagent)) { @@ -84,7 +85,9 @@ public boolean matches(Container container, Level level) { public double getReagentModifier(ItemStack stack, TagKey reagent) { var map = stack.getItemHolder().getData(VatReagent.DATA_MAP); if (map != null) { - return map.getOrDefault(reagent, 1D); + var a = map.getOrDefault(reagent, 1D); + EnderIO.LOGGER.info(reagent.location().getPath() + ": " + a); + return a; } return 1; } @@ -129,24 +132,17 @@ public RecipeType getType() { public static class Container extends RecipeWrapper { - private final FluidTank inputTank; + private final MachineFluidTank inputTank; - private final FluidTank outputTank; - - public Container(IItemHandlerModifiable inv, FluidTank inputTank, FluidTank outputTank) { + public Container(IItemHandlerModifiable inv, MachineFluidTank inputTank) { super(inv); this.inputTank = inputTank; - this.outputTank = outputTank; } - public FluidTank getInputTank() { + public MachineFluidTank getInputTank() { return inputTank; } - public FluidTank getOutputTank() { - return outputTank; - } - } public static class Serializer implements RecipeSerializer { diff --git a/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java b/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java index c2b38bbb4d..f40a774646 100644 --- a/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java +++ b/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java @@ -19,8 +19,6 @@ public DataMapsProvider(PackOutput packOutput, CompletableFuture leftReagent, TagKey rightReagent, double outputModifier, From 3480d3559de759f84a57eb35a0bf78a8f01ad426 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Sat, 9 Mar 2024 13:31:25 +0530 Subject: [PATCH 06/14] add vat progress and bucket interactions --- .../fermenting/fluid_hootch_still.json | 2 +- .../machines/client/gui/screen/VatScreen.java | 2 ++ .../common/blockentity/VatBlockEntity.java | 23 ++++++++++++++++++- .../io/fluid/IFluidItemInteractive.java | 4 ++-- .../common/io/fluid/MachineFluidHandler.java | 12 ++++++++-- .../machines/common/io/fluid/TankAccess.java | 16 +++++++++++++ .../machines/common/recipe/RecipeCaches.java | 9 ++++++-- .../recipes/FermentingRecipeProvider.java | 2 +- 8 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json b/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json index 77589dc9ba..ace9540117 100644 --- a/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json +++ b/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json @@ -8,5 +8,5 @@ "output_fluid": "enderio:fluid_hootch_still", "output_modifier": 0.25, "right_reagent": "forge:crops", - "ticks": 20 + "ticks": 100 } \ No newline at end of file diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java index 30710254c4..7de95571bb 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -7,6 +7,7 @@ import com.enderio.core.client.gui.widgets.EnumIconWidget; import com.enderio.machines.client.gui.widget.ActivityWidget; import com.enderio.machines.client.gui.widget.FluidStackWidget; +import com.enderio.machines.client.gui.widget.ProgressWidget; import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; import com.enderio.machines.common.menu.VatMenu; import net.minecraft.network.chat.Component; @@ -26,6 +27,7 @@ protected void init() { super.init(); addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getInputTank, 30 + leftPos, 12 + topPos, 15, 47)); addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getOutputTank, 132 + leftPos, 12 + topPos, 15, 47)); + addRenderableOnly(new ProgressWidget.BottomUp(this, () -> menu.getBlockEntity().getProgress(), getGuiLeft() + 82, getGuiTop() + 64, 14, 14, 176, 0)); addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(), control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE)); diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java index 71de36d5d5..6d64cb0b6c 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -8,6 +8,7 @@ import com.enderio.machines.common.blockentity.task.host.CraftingMachineTaskHost; import com.enderio.machines.common.init.MachineBlockEntities; import com.enderio.machines.common.init.MachineRecipes; +import com.enderio.machines.common.io.fluid.IFluidItemInteractive; import com.enderio.machines.common.io.fluid.MachineFluidHandler; import com.enderio.machines.common.io.fluid.MachineFluidTank; import com.enderio.machines.common.io.fluid.MachineTankLayout; @@ -19,12 +20,16 @@ import com.enderio.machines.common.recipe.FermentingRecipe; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.fluids.capability.IFluidHandler; @@ -33,7 +38,7 @@ import java.util.List; -public class VatBlockEntity extends MachineBlockEntity implements IFluidTankUser { +public class VatBlockEntity extends MachineBlockEntity implements IFluidTankUser, IFluidItemInteractive { public static final int TANK_CAPACITY_COMMON = 8 * FluidType.BUCKET_VOLUME; private static final TankAccess INPUT_TANK = new TankAccess(); @@ -73,6 +78,18 @@ public void onLoad() { craftingTaskHost.onLevelReady(); } + @Override + public InteractionResult onBlockEntityUsed(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + ItemStack stack = player.getItemInHand(hand); + if (!stack.isEmpty()) { + if (handleFluidItemInteraction(player, hand, stack, this, INPUT_TANK) || handleFluidItemInteraction(player, hand, stack, this, OUTPUT_TANK)) { + player.getInventory().setChanged(); + return InteractionResult.CONSUME; + } + } + return super.onBlockEntityUsed(state, level, pos, player, hand, hit); + } + protected VatBlockEntity.VatCraftingMachineTask createTask(Level level, FermentingRecipe.Container container, @Nullable RecipeHolder recipe) { return new VatBlockEntity.VatCraftingMachineTask(level, getInventoryNN(), getFluidHandler(), container, recipe); @@ -123,6 +140,10 @@ public MachineFluidTank getOutputTank() { return OUTPUT_TANK.getTank(this); } + public float getProgress() { + return craftingTaskHost.getProgress(); + } + protected static class VatCraftingMachineTask extends CraftingMachineTask { public VatCraftingMachineTask(@NotNull Level level, MachineInventory inventory, MachineFluidHandler fluidHandler, FermentingRecipe.Container container, diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/IFluidItemInteractive.java b/src/machines/java/com/enderio/machines/common/io/fluid/IFluidItemInteractive.java index 358e52766d..f90e37c60c 100644 --- a/src/machines/java/com/enderio/machines/common/io/fluid/IFluidItemInteractive.java +++ b/src/machines/java/com/enderio/machines/common/io/fluid/IFluidItemInteractive.java @@ -34,7 +34,7 @@ default boolean handleFluidItemInteraction(Player player, InteractionHand hand, fluidInItem = handler.drain(new FluidStack(tankAccess.getFluid(machine), Integer.MAX_VALUE), IFluidHandler.FluidAction.SIMULATE); } if (fluidInItem.isEmpty()) { - if (!tankAccess.isEmpty(machine)) { + if (!tankAccess.isEmpty(machine) && tankAccess.canExtract(machine)) { int filled = handler.fill(tankAccess.getFluid(machine), player.isCreative() ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE); ItemStack container = handler.getContainer(); @@ -60,7 +60,7 @@ default boolean handleFluidItemInteraction(Player player, InteractionHand hand, return true; } } - } else { + } else if (tankAccess.canInsert(machine)) { int filledAmount = tankAccess.fill(machine, fluidInItem, IFluidHandler.FluidAction.SIMULATE); if (filledAmount > 0) { boolean filled = false; diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java index 03a733d0d5..11ca6d1c34 100644 --- a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java +++ b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java @@ -82,6 +82,14 @@ public boolean isFluidValid(int tank, FluidStack stack) { return layout.isFluidValid(tank, stack); } + public boolean canInsert(int tank) { + return layout.canInsert(tank); + } + + public boolean canExtract(int tank) { + return layout.canExtract(tank); + } + @Nullable public IFluidHandler getForSide(@Nullable Direction side) { if (side == null) { @@ -144,7 +152,7 @@ public int fill(FluidStack resource, FluidAction action) { int totalFilled = 0; for (int index = 0; index < getTanks(); index++) { - if (!layout.canInsert(index)) + if (!canInsert(index)) continue; // Attempt to fill the tank @@ -193,7 +201,7 @@ public FluidStack drain(FluidStack resource, FluidAction action) { @Override public FluidStack drain(int maxDrain, FluidAction action) { for (int index = 0; index < getTanks(); index++) { - if (layout.canExtract(index)) { + if (canExtract(index)) { if (drain(index, maxDrain, FluidAction.SIMULATE) != FluidStack.EMPTY) { FluidStack drained = drain(index, maxDrain, action); if (!drained.isEmpty()) { diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/TankAccess.java b/src/machines/java/com/enderio/machines/common/io/fluid/TankAccess.java index 1190d43374..622370b077 100644 --- a/src/machines/java/com/enderio/machines/common/io/fluid/TankAccess.java +++ b/src/machines/java/com/enderio/machines/common/io/fluid/TankAccess.java @@ -64,6 +64,22 @@ public boolean isEmpty(MachineFluidHandler handler) { return getFluid(handler).isEmpty(); } + public boolean canInsert(IFluidTankUser machine) { + return canInsert(machine.getFluidHandler()); + } + + public boolean canInsert(MachineFluidHandler handler) { + return handler.canInsert(index); + } + + public boolean canExtract(IFluidTankUser machine) { + return canExtract(machine.getFluidHandler()); + } + + public boolean canExtract(MachineFluidHandler handler) { + return handler.canExtract(index); + } + public int fill(MachineFluidHandler handler, FluidStack stack, IFluidHandler.FluidAction action) { return handler.fill(index, stack, action); } diff --git a/src/machines/java/com/enderio/machines/common/recipe/RecipeCaches.java b/src/machines/java/com/enderio/machines/common/recipe/RecipeCaches.java index 4cdfc6ede4..6753b0a348 100644 --- a/src/machines/java/com/enderio/machines/common/recipe/RecipeCaches.java +++ b/src/machines/java/com/enderio/machines/common/recipe/RecipeCaches.java @@ -5,10 +5,10 @@ import net.minecraft.world.Container; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.SmeltingRecipe; -import net.neoforged.neoforge.client.event.RecipesUpdatedEvent; -import net.neoforged.neoforge.event.AddReloadListenerEvent; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.client.event.RecipesUpdatedEvent; +import net.neoforged.neoforge.event.AddReloadListenerEvent; import net.neoforged.neoforge.items.wrapper.RecipeWrapper; @@ -29,6 +29,9 @@ public class RecipeCaches { public static final RecipeInputCache SOUL_BINDING = new RecipeInputCache<>(MachineRecipes.SOUL_BINDING.type()); + public static final RecipeInputCache FERMENTING = new RecipeInputCache<>( + MachineRecipes.VAT_FERMENTING.type()); + @SubscribeEvent public static void registerReloadListener(AddReloadListenerEvent event) { ALLOY_SMELTING.markCacheDirty(); @@ -36,6 +39,7 @@ public static void registerReloadListener(AddReloadListenerEvent event) { PAINTING.markCacheDirty(); SAG_MILLING.markCacheDirty(); SOUL_BINDING.markCacheDirty(); + FERMENTING.markCacheDirty(); } @SubscribeEvent @@ -45,5 +49,6 @@ public static void onRecipesUpdated(RecipesUpdatedEvent event) { PAINTING.rebuildCache(event.getRecipeManager()); SAG_MILLING.rebuildCache(event.getRecipeManager()); SOUL_BINDING.rebuildCache(event.getRecipeManager()); + FERMENTING.rebuildCache(event.getRecipeManager()); } } diff --git a/src/machines/java/com/enderio/machines/data/recipes/FermentingRecipeProvider.java b/src/machines/java/com/enderio/machines/data/recipes/FermentingRecipeProvider.java index f22d3e7903..80d0952ce4 100644 --- a/src/machines/java/com/enderio/machines/data/recipes/FermentingRecipeProvider.java +++ b/src/machines/java/com/enderio/machines/data/recipes/FermentingRecipeProvider.java @@ -22,7 +22,7 @@ public FermentingRecipeProvider(PackOutput packOutput) { @Override protected void buildRecipes(RecipeOutput recipeOutput) { - build(EIOFluids.HOOTCH.getSource(), FluidIngredient.of(Fluids.WATER), 1000, Tags.Items.SEEDS, Tags.Items.CROPS, 0.25, 20, recipeOutput); + build(EIOFluids.HOOTCH.getSource(), FluidIngredient.of(Fluids.WATER), 1000, Tags.Items.SEEDS, Tags.Items.CROPS, 0.25, 100, recipeOutput); } protected void build(Fluid output, FluidIngredient input, int inputFluidAmount, TagKey leftReagent, TagKey rightReagent, double outputModifier, From c36d397aba975532f2dc0f8ee371e10785f1ae54 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Sat, 9 Mar 2024 20:59:59 +0530 Subject: [PATCH 07/14] add vat "fake" consume and fluid fermenting indicator --- .../machines/client/gui/screen/VatScreen.java | 84 +++++++++++++++++- .../gui/widget/FluidTransformWidget.java | 70 +++++++++++++++ .../common/blockentity/VatBlockEntity.java | 24 +++++ .../blockentity/task/CraftingMachineTask.java | 5 ++ .../common/io/fluid/MachineFluidTank.java | 2 - .../common/recipe/FermentingRecipe.java | 62 ++++++------- .../common/recipe/SagMillingRecipe.java | 2 +- .../textures/gui/sprites/vat_cover.png | Bin 0 -> 253 bytes 8 files changed, 213 insertions(+), 36 deletions(-) create mode 100644 src/machines/java/com/enderio/machines/client/gui/widget/FluidTransformWidget.java create mode 100644 src/main/resources/assets/enderio/textures/gui/sprites/vat_cover.png diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java index 7de95571bb..aacf70a067 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -7,16 +7,30 @@ import com.enderio.core.client.gui.widgets.EnumIconWidget; import com.enderio.machines.client.gui.widget.ActivityWidget; import com.enderio.machines.client.gui.widget.FluidStackWidget; +import com.enderio.machines.client.gui.widget.FluidTransformWidget; import com.enderio.machines.client.gui.widget.ProgressWidget; import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; +import com.enderio.machines.common.io.fluid.MachineFluidTank; import com.enderio.machines.common.menu.VatMenu; +import com.enderio.machines.common.recipe.FermentingRecipe; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.level.material.Fluid; +import net.neoforged.neoforge.fluids.FluidStack; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; public class VatScreen extends EIOScreen { private static final ResourceLocation VAT_BG = EnderIO.loc("textures/gui/vat.png"); + private static final ResourceLocation VAT_COVER = EnderIO.loc("vat_cover"); + private FermentingRecipe recipeCache; + private ResourceLocation recipeId; public VatScreen(VatMenu pMenu, Inventory pPlayerInventory, Component pTitle) { super(pMenu, pPlayerInventory, pTitle, false); @@ -25,9 +39,14 @@ public VatScreen(VatMenu pMenu, Inventory pPlayerInventory, Component pTitle) { @Override protected void init() { super.init(); - addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getInputTank, 30 + leftPos, 12 + topPos, 15, 47)); + updateRecipeCache(); + addRenderableOnly(new FluidStackWidget(this, this::wrappedInputTank, 30 + leftPos, 12 + topPos, 15, 47)); addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getOutputTank, 132 + leftPos, 12 + topPos, 15, 47)); - addRenderableOnly(new ProgressWidget.BottomUp(this, () -> menu.getBlockEntity().getProgress(), getGuiLeft() + 82, getGuiTop() + 64, 14, 14, 176, 0)); + + addRenderableOnly( + new FluidTransformWidget(this::isCrafting, this::getInputFluid, this::getOutputFluid, this::getProgress, 76 + leftPos, 34 + topPos, 26, 28)); + + addRenderableOnly(new ProgressWidget.BottomUp(this, this::getProgress, 82 + leftPos, 64 + topPos, 14, 14, 176, 0)); addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 6 - 16, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(), control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE)); @@ -36,6 +55,14 @@ protected void init() { addRenderableWidget(new ActivityWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16 * 4)); } + @Override + public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { + super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); + updateRecipeCache(); + + guiGraphics.blitSprite(VAT_COVER, 76 + leftPos, 34 + topPos, 26, 28); + } + @Override public ResourceLocation getBackgroundImage() { return VAT_BG; @@ -45,4 +72,57 @@ public ResourceLocation getBackgroundImage() { protected Vector2i getBackgroundImageSize() { return new Vector2i(176, 166); } + + private void updateRecipeCache() { + if (recipeId != getMenu().getBlockEntity().getRecipeId()) { + recipeId = getMenu().getBlockEntity().getRecipeId(); + Optional> optional = Minecraft.getInstance().level.getRecipeManager().byKey(recipeId); + if (optional.isPresent() && optional.get().value() instanceof FermentingRecipe recipe) { + recipeCache = recipe; + } + } + } + + private boolean isCrafting() { + return getMenu().getBlockEntity().getCraftingHost().getProgress() > 0 && recipeCache != null; + } + + private Fluid getInputFluid() { + return getMenu().getBlockEntity().getInputTank().getFluid().getFluid(); + } + + private Fluid getOutputFluid() { + return recipeCache.getOutputFluid(); + } + + private float getProgress() { + return menu.getBlockEntity().getProgress(); + } + + /** + * Wraps the essential parts of the input tank. Remove the amount of fluid in client screen to fake the effect of consumption of fluid. + */ + private MachineFluidTank wrappedInputTank() { + MachineFluidTank tank = getMenu().getBlockEntity().getInputTank(); + return new MachineFluidTank(0, null) { + @Override + public @NotNull FluidStack getFluid() { + return tank.getFluid(); + } + + @Override + public int getFluidAmount() { + int reduced = 0; + if (isCrafting()) { + reduced = recipeCache.getInputFluidAmount(); + } + return tank.getFluidAmount() - reduced; + } + + @Override + public int getCapacity() { + return tank.getCapacity(); + } + }; + } } diff --git a/src/machines/java/com/enderio/machines/client/gui/widget/FluidTransformWidget.java b/src/machines/java/com/enderio/machines/client/gui/widget/FluidTransformWidget.java new file mode 100644 index 0000000000..8d155fd5d0 --- /dev/null +++ b/src/machines/java/com/enderio/machines/client/gui/widget/FluidTransformWidget.java @@ -0,0 +1,70 @@ +package com.enderio.machines.client.gui.widget; + +import com.enderio.core.client.gui.widgets.EIOWidget; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.renderer.texture.AbstractTexture; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.FastColor; +import net.minecraft.world.level.material.Fluid; +import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; + +import java.util.function.Supplier; + +public class FluidTransformWidget extends EIOWidget { + private final Supplier isVisible; + private final Supplier first; + private final Supplier second; + private final Supplier progress; + + public FluidTransformWidget(Supplier isVisible, Supplier first, Supplier second, Supplier progress, int x, int y, int width, + int height) { + super(x, y, width, height); + this.isVisible = isVisible; + this.first = first; + this.second = second; + this.progress = progress; + } + + @Override + protected void renderWidget(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTick) { + RenderSystem.defaultBlendFunc(); + RenderSystem.enableDepthTest(); + + if (isVisible.get()) { + renderFluid(guiGraphics, first.get(), 1 - progress.get()); + renderFluid(guiGraphics, second.get(), progress.get()); + } + + RenderSystem.disableDepthTest(); + } + + @Override + protected void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput) {} + + public void renderFluid(GuiGraphics guiGraphics, Fluid fluid, float progress) { + Minecraft minecraft = Minecraft.getInstance(); + IClientFluidTypeExtensions props = IClientFluidTypeExtensions.of(fluid); + ResourceLocation loc = props.getStillTexture(); + + AbstractTexture texture = minecraft.getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS); + if (texture instanceof TextureAtlas atlas) { + TextureAtlasSprite sprite = atlas.getSprite(loc); + + int color = props.getTintColor(); + RenderSystem.setShaderColor(FastColor.ARGB32.red(color) / 255.0F, FastColor.ARGB32.green(color) / 255.0F, FastColor.ARGB32.blue(color) / 255.0F, + FastColor.ARGB32.alpha(color) * progress / 255.0F); + RenderSystem.enableBlend(); + + int atlasWidth = (int) (sprite.contents().width() / (sprite.getU1() - sprite.getU0())); + int atlasHeight = (int) (sprite.contents().height() / (sprite.getV1() - sprite.getV0())); + guiGraphics.blit(TextureAtlas.LOCATION_BLOCKS, x, y, width, height, sprite.getU0() * atlasWidth, sprite.getV0() * atlasHeight, + sprite.contents().width(), sprite.contents().height(), atlasWidth, atlasHeight); + RenderSystem.setShaderColor(1, 1, 1, 1); + } + } +} diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java index 6d64cb0b6c..e9e2d9869b 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -1,6 +1,8 @@ package com.enderio.machines.common.blockentity; +import com.enderio.EnderIO; import com.enderio.core.common.network.slot.FluidStackNetworkDataSlot; +import com.enderio.core.common.network.slot.ResourceLocationNetworkDataSlot; import com.enderio.core.common.recipes.OutputStack; import com.enderio.machines.common.attachment.IFluidTankUser; import com.enderio.machines.common.blockentity.base.MachineBlockEntity; @@ -20,6 +22,7 @@ import com.enderio.machines.common.recipe.FermentingRecipe; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Inventory; @@ -46,6 +49,8 @@ public class VatBlockEntity extends MachineBlockEntity implements IFluidTankUser public static final MultiSlotAccess REAGENTS = new MultiSlotAccess(); private final MachineFluidHandler fluidHandler; private final CraftingMachineTaskHost craftingTaskHost; + private ResourceLocation recipeId; + private static final ResourceLocation EMPTY = EnderIO.loc(""); public VatBlockEntity(BlockPos worldPosition, BlockState blockState) { super(MachineBlockEntities.VAT.get(), worldPosition, blockState); @@ -53,6 +58,9 @@ public VatBlockEntity(BlockPos worldPosition, BlockState blockState) { addDataSlot(new FluidStackNetworkDataSlot(() -> INPUT_TANK.getFluid(this), f -> INPUT_TANK.setFluid(this, f))); addDataSlot(new FluidStackNetworkDataSlot(() -> OUTPUT_TANK.getFluid(this), f -> OUTPUT_TANK.setFluid(this, f))); + + addDataSlot(new ResourceLocationNetworkDataSlot(() -> getRecipeId(), id -> recipeId = id)); + craftingTaskHost = new CraftingMachineTaskHost<>(this, () -> true, MachineRecipes.VAT_FERMENTING.type().get(), new FermentingRecipe.Container(getInventoryNN(), getInputTank()), this::createTask); } @@ -144,6 +152,22 @@ public float getProgress() { return craftingTaskHost.getProgress(); } + public ResourceLocation getRecipeId() { + if (level.isClientSide) { + return recipeId; + } + + if (craftingTaskHost.getCurrentTask() != null) { + ResourceLocation id = craftingTaskHost.getCurrentTask().getRecipeId(); + return id != null ? id : EMPTY; + } + return EMPTY; + } + + public CraftingMachineTaskHost getCraftingHost() { + return craftingTaskHost; + } + protected static class VatCraftingMachineTask extends CraftingMachineTask { public VatCraftingMachineTask(@NotNull Level level, MachineInventory inventory, MachineFluidHandler fluidHandler, FermentingRecipe.Container container, diff --git a/src/machines/java/com/enderio/machines/common/blockentity/task/CraftingMachineTask.java b/src/machines/java/com/enderio/machines/common/blockentity/task/CraftingMachineTask.java index f5b5e76c42..9fe2260d3b 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/task/CraftingMachineTask.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/task/CraftingMachineTask.java @@ -77,6 +77,11 @@ public R getRecipe() { return recipe.value(); } + @Nullable + public ResourceLocation getRecipeId() { + return recipe.id(); + } + // region Abstract Implementation protected abstract void consumeInputs(R recipe); diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidTank.java b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidTank.java index 69a3d9108b..e0347f3064 100644 --- a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidTank.java +++ b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidTank.java @@ -1,7 +1,5 @@ package com.enderio.machines.common.io.fluid; -import net.minecraft.nbt.CompoundTag; -import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.IFluidTank; import net.neoforged.neoforge.fluids.capability.IFluidHandler; diff --git a/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java index 425c4f5069..dddf567862 100644 --- a/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java +++ b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java @@ -12,6 +12,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.tags.ItemTags; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -22,8 +23,10 @@ import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.items.IItemHandlerModifiable; import net.neoforged.neoforge.items.wrapper.RecipeWrapper; +import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.Objects; public class FermentingRecipe implements MachineRecipe { @@ -85,9 +88,7 @@ public boolean matches(Container container, Level level) { public double getReagentModifier(ItemStack stack, TagKey reagent) { var map = stack.getItemHolder().getData(VatReagent.DATA_MAP); if (map != null) { - var a = map.getOrDefault(reagent, 1D); - EnderIO.LOGGER.info(reagent.location().getPath() + ": " + a); - return a; + return map.getOrDefault(reagent, 1D); } return 1; } @@ -163,39 +164,38 @@ public Codec codec() { } @Override + @Nullable public FermentingRecipe fromNetwork(FriendlyByteBuf buffer) { - //TODO : NETWORK - // try { - // FluidStack inputFluid = FluidStack.readFromPacket(buffer); - // FluidStack outputFluid = FluidStack.readFromPacket(buffer); - // int baseModifier = buffer.readInt(); - // ResourceLocation leftReagent = buffer.readResourceLocation(); - // ResourceLocation rightReagent = buffer.readResourceLocation(); - // int ticks = buffer.readInt(); - // return new VatFermentingRecipe(inputFluid, outputFluid, baseModifier, leftReagent, rightReagent, ticks); - // } catch (Exception ex) { - // EnderIO.LOGGER.error("Error reading Vat recipe for packet.", ex); - // throw ex; - // } - return null; + try { + FluidIngredient inputFluid = FluidIngredient.fromNetwork(buffer); + int inputFluidAmount = buffer.readInt(); + TagKey left = ItemTags.create(buffer.readResourceLocation()); + TagKey right = ItemTags.create(buffer.readResourceLocation()); + Fluid fluid = Objects.requireNonNull(buffer.readById(BuiltInRegistries.FLUID)); + double outputModifier = buffer.readDouble(); + int ticks = buffer.readInt(); + + return new FermentingRecipe(inputFluid, inputFluidAmount, left, right, fluid, outputModifier, ticks); + } catch (Exception ex) { + EnderIO.LOGGER.error("Error reading fermenting recipe to packet.", ex); + return null; + } } @Override public void toNetwork(FriendlyByteBuf buffer, FermentingRecipe recipe) { - //TODO : NETWORK - // try { - // recipe.inputFluid.toNetwork(buffer); - // buffer.writeInt(recipe.inputFluidAmount); - // buffer.; - // buffer.ta(recipe.leftReagent); - // buffer.writeResourceLocation(recipe.rightReagent); - // buffer.writeId(BuiltInRegistries.FLUID, recipe.outputFluid); - // buffer.writeInt(recipe.outputModifier); - // buffer.writeInt(recipe.ticks); - // } catch (Exception ex) { - // EnderIO.LOGGER.error("Error reading Vat recipe for packet.", ex); - // throw ex; - // } + try { + recipe.inputFluid.toNetwork(buffer); + buffer.writeInt(recipe.inputFluidAmount); + buffer.writeResourceLocation(recipe.leftReagent.location()); + buffer.writeResourceLocation(recipe.rightReagent.location()); + buffer.writeId(BuiltInRegistries.FLUID, recipe.outputFluid); + buffer.writeDouble(recipe.outputModifier); + buffer.writeInt(recipe.ticks); + } catch (Exception ex) { + EnderIO.LOGGER.error("Error writing fermenting recipe to packet.", ex); + throw ex; + } } } diff --git a/src/machines/java/com/enderio/machines/common/recipe/SagMillingRecipe.java b/src/machines/java/com/enderio/machines/common/recipe/SagMillingRecipe.java index 7511362eb7..60c839ee5f 100644 --- a/src/machines/java/com/enderio/machines/common/recipe/SagMillingRecipe.java +++ b/src/machines/java/com/enderio/machines/common/recipe/SagMillingRecipe.java @@ -372,7 +372,7 @@ public void toNetwork(FriendlyByteBuf buffer, SagMillingRecipe recipe) { buffer.writeBoolean(item.optional); } } catch (Exception ex) { - EnderIO.LOGGER.error("Error writing allow smelting recipe to packet.", ex); + EnderIO.LOGGER.error("Error writing sag milling recipe to packet.", ex); throw ex; } } diff --git a/src/main/resources/assets/enderio/textures/gui/sprites/vat_cover.png b/src/main/resources/assets/enderio/textures/gui/sprites/vat_cover.png new file mode 100644 index 0000000000000000000000000000000000000000..e3dc441923c5016a43e535adf7c8ccb838c9490b GIT binary patch literal 253 zcmVPx#w@E}nR7i>KmP-nRFc3tmW$vUNt54FmYVlMx3n7>f4&$V=ka;T!p&wNV5^;B; zfvTqOecuHD=6TNcw${z8H4f4escIVXEhM>ZTeUvj8Fqz;$hxkdMZcuEqI;sDqE>yG zD5|zf)RQt*5=ExTMA3wb&hmiX09csYtT=QAR+L&$tZ3Ma!~`(2VAP>u%%j zjI56&-TkP}%tFrU{33eZ86{Eg`pSo7mdMP&PL$#|AvmTSfcDx?00000NkvXXu0mjf Dt5j~F literal 0 HcmV?d00001 From 1bc373cea85388f46bd9471f2a8e9c6ead991e0b Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Mon, 25 Mar 2024 23:56:11 +0530 Subject: [PATCH 08/14] add reagent datagen --- .../enderio/data_maps/item/vat_reagent.json | 2 +- .../com/enderio/machines/EIOMachines.java | 4 +- .../machines/client/gui/screen/VatScreen.java | 2 +- .../data/datamaps/DataMapsProvider.java | 24 ----- .../data/reagentdata/ReagentDataProvider.java | 101 ++++++++++++++++++ .../package-info.java | 2 +- 6 files changed, 106 insertions(+), 29 deletions(-) delete mode 100644 src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java create mode 100644 src/machines/java/com/enderio/machines/data/reagentdata/ReagentDataProvider.java rename src/machines/java/com/enderio/machines/data/{datamaps => reagentdata}/package-info.java (66%) diff --git a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json index 6952a732ef..92d3a83ee6 100644 --- a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json +++ b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json @@ -1,7 +1,7 @@ { "values": { "minecraft:wheat": { - "#forge:crops": 2.0 + "#forge:crops": 3.0 } } } \ No newline at end of file diff --git a/src/machines/java/com/enderio/machines/EIOMachines.java b/src/machines/java/com/enderio/machines/EIOMachines.java index ffaa2fcf88..d9ad762eb7 100644 --- a/src/machines/java/com/enderio/machines/EIOMachines.java +++ b/src/machines/java/com/enderio/machines/EIOMachines.java @@ -20,7 +20,7 @@ import com.enderio.machines.common.tag.MachineTags; import com.enderio.machines.common.travel.AnchorTravelTarget; import com.enderio.machines.data.advancements.MachinesAdvancementGenerator; -import com.enderio.machines.data.datamaps.DataMapsProvider; +import com.enderio.machines.data.reagentdata.ReagentDataProvider; import com.enderio.machines.data.recipes.AlloyRecipeProvider; import com.enderio.machines.data.recipes.EnchanterRecipeProvider; import com.enderio.machines.data.recipes.FermentingRecipeProvider; @@ -99,7 +99,7 @@ public static void gatherData(GatherDataEvent event) { provider.addSubProvider(event.includeServer(), new FermentingRecipeProvider(packOutput)); provider.addSubProvider(event.includeServer(), new SoulDataProvider(packOutput)); provider.addSubProvider(event.includeServer(), new MachineEntityTypeTagsProvider(packOutput, lookupProvider, event.getExistingFileHelper())); - provider.addSubProvider(event.includeServer(), new DataMapsProvider(packOutput, lookupProvider)); + provider.addSubProvider(event.includeServer(), new ReagentDataProvider(packOutput, lookupProvider, event.getExistingFileHelper())); generator.addProvider(true, provider); provider.addSubProvider(event.includeServer(), new AdvancementProvider(packOutput, event.getLookupProvider(), event.getExistingFileHelper(), diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java index aacf70a067..4d17998d47 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -57,8 +57,8 @@ protected void init() { @Override public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { - super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); updateRecipeCache(); + super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); guiGraphics.blitSprite(VAT_COVER, 76 + leftPos, 34 + topPos, 26, 28); } diff --git a/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java b/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java deleted file mode 100644 index f40a774646..0000000000 --- a/src/machines/java/com/enderio/machines/data/datamaps/DataMapsProvider.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.enderio.machines.data.datamaps; - -import com.enderio.machines.common.datamap.VatReagent; -import net.minecraft.core.HolderLookup; -import net.minecraft.data.PackOutput; -import net.minecraft.world.item.Items; -import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.data.DataMapProvider; - -import java.util.Map; -import java.util.concurrent.CompletableFuture; - -public class DataMapsProvider extends DataMapProvider { - - public DataMapsProvider(PackOutput packOutput, CompletableFuture lookupProvider) { - super(packOutput, lookupProvider); - } - - @SuppressWarnings("deprecation") - @Override - protected void gather() { - builder(VatReagent.DATA_MAP).add(Items.WHEAT.builtInRegistryHolder(), Map.of(Tags.Items.CROPS, 2D), false); - } -} diff --git a/src/machines/java/com/enderio/machines/data/reagentdata/ReagentDataProvider.java b/src/machines/java/com/enderio/machines/data/reagentdata/ReagentDataProvider.java new file mode 100644 index 0000000000..d5938c4c73 --- /dev/null +++ b/src/machines/java/com/enderio/machines/data/reagentdata/ReagentDataProvider.java @@ -0,0 +1,101 @@ +package com.enderio.machines.data.reagentdata; + +import com.enderio.EnderIO; +import com.enderio.machines.common.datamap.VatReagent; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.CachedOutput; +import net.minecraft.data.DataProvider; +import net.minecraft.data.PackOutput; +import net.minecraft.data.tags.IntrinsicHolderTagsProvider; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.neoforged.neoforge.common.Tags; +import net.neoforged.neoforge.common.data.DataMapProvider; +import net.neoforged.neoforge.common.data.ExistingFileHelper; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +public class ReagentDataProvider implements DataProvider { + + private final VatTagsProvider tagsProvider; + private final VatDatamapProvider datamapProvider; + + public ReagentDataProvider(PackOutput packOutput, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper) { + tagsProvider = new VatTagsProvider(packOutput, lookupProvider, existingFileHelper); + datamapProvider = new VatDatamapProvider(packOutput, lookupProvider); + } + + @Override + public CompletableFuture run(CachedOutput pOutput) { + gather(); + List> list = new ArrayList<>(); + list.add(tagsProvider.run(pOutput)); + list.add(datamapProvider.run(pOutput)); + return CompletableFuture.allOf(list.toArray(CompletableFuture[]::new)); + } + + protected void gather() { + addReagentData(Items.WHEAT, Tags.Items.CROPS, 3D); + } + + public void addReagentData(Item item, TagKey tag, double value) { + tagsProvider.addItemTag(tag, item); + datamapProvider.addData(tag, item, value); + } + + @Override + public String getName() { + return "ReagentData"; + } + + private static class VatTagsProvider extends IntrinsicHolderTagsProvider { + private final Map, List> tagsMap = new HashMap<>(); + + public VatTagsProvider(PackOutput packOutput, CompletableFuture provider, @Nullable ExistingFileHelper existingFileHelper) { + super(packOutput, Registries.ITEM, provider, item -> item.builtInRegistryHolder().key(), EnderIO.MODID, existingFileHelper); + } + + public void addItemTag(TagKey tag, Item item) { + var list = tagsMap.computeIfAbsent(tag, it -> new ArrayList<>()); + list.add(item); + } + + @Override + protected void addTags(HolderLookup.Provider pProvider) { + tagsMap.forEach((key, value) -> { + var tag = this.tag(key); + value.forEach(tag::add); + }); + } + } + + private static class VatDatamapProvider extends DataMapProvider { + private final Map, Map> data = new HashMap<>(); + + protected VatDatamapProvider(PackOutput packOutput, CompletableFuture lookupProvider) { + super(packOutput, lookupProvider); + } + + public void addData(TagKey tag, Item item, double value) { + var map = data.computeIfAbsent(tag, it -> new HashMap<>()); + map.put(item, value); + } + + @Override + protected void gather() { + var builder = builder(VatReagent.DATA_MAP); + data.forEach((tag, map) -> { + map.forEach(((item, value) -> { + builder.add(item.builtInRegistryHolder(), Map.of(tag, value), false); + })); + }); + } + } +} diff --git a/src/machines/java/com/enderio/machines/data/datamaps/package-info.java b/src/machines/java/com/enderio/machines/data/reagentdata/package-info.java similarity index 66% rename from src/machines/java/com/enderio/machines/data/datamaps/package-info.java rename to src/machines/java/com/enderio/machines/data/reagentdata/package-info.java index aeb447e845..e22d36810c 100644 --- a/src/machines/java/com/enderio/machines/data/datamaps/package-info.java +++ b/src/machines/java/com/enderio/machines/data/reagentdata/package-info.java @@ -1,4 +1,4 @@ @javax.annotation.ParametersAreNonnullByDefault @net.minecraft.MethodsReturnNonnullByDefault -package com.enderio.machines.data.datamaps; +package com.enderio.machines.data.reagentdata; From 6bfc65f63e35cd36b0828b935dc3279f46f5e0d6 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Tue, 11 Jun 2024 23:35:55 +0530 Subject: [PATCH 09/14] general cleanup --- .../resources/data/c/tags/items/seeds.json | 5 ++ .../enderio/data_maps/item/vat_reagent.json | 3 +- .../fermenting/fluid_hootch_still.json | 4 +- .../machines/client/gui/screen/VatScreen.java | 4 +- ...ormWidget.java => FermentationWidget.java} | 14 +++--- .../common/blockentity/VatBlockEntity.java | 14 +++--- .../common/io/fluid/MachineFluidHandler.java | 3 +- .../common/recipe/FermentingRecipe.java | 29 +++++------- .../data/reagentdata/ReagentDataProvider.java | 47 +++++++++---------- 9 files changed, 61 insertions(+), 62 deletions(-) create mode 100644 src/generated/resources/data/c/tags/items/seeds.json rename src/machines/java/com/enderio/machines/client/gui/widget/{FluidTransformWidget.java => FermentationWidget.java} (87%) diff --git a/src/generated/resources/data/c/tags/items/seeds.json b/src/generated/resources/data/c/tags/items/seeds.json new file mode 100644 index 0000000000..498cb445f6 --- /dev/null +++ b/src/generated/resources/data/c/tags/items/seeds.json @@ -0,0 +1,5 @@ +{ + "values": [ + "minecraft:wheat" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json index f8aa97a115..4fea5d770f 100644 --- a/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json +++ b/src/generated/resources/data/enderio/data_maps/item/vat_reagent.json @@ -1,7 +1,8 @@ { "values": { "minecraft:wheat": { - "#c:crops": 3.0 + "#c:crops": 3.0, + "#c:seeds": 2.0 } } } \ No newline at end of file diff --git a/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json b/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json index 5c4d9ce3bd..b088d8032d 100644 --- a/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json +++ b/src/generated/resources/data/enderio/recipes/fermenting/fluid_hootch_still.json @@ -1,11 +1,11 @@ { "type": "enderio:vat_fermenting", - "input_fluid": { + "input": { "amount": 1000, "tag": "minecraft:water" }, "left_reagent": "c:seeds", - "output_fluid": { + "output": { "amount": 250, "id": "enderio:fluid_hootch_still" }, diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java index c8a003f1a9..3419c1af01 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -6,8 +6,8 @@ import com.enderio.core.client.gui.screen.EIOScreen; import com.enderio.core.client.gui.widgets.EnumIconWidget; import com.enderio.machines.client.gui.widget.ActivityWidget; +import com.enderio.machines.client.gui.widget.FermentationWidget; import com.enderio.machines.client.gui.widget.FluidStackWidget; -import com.enderio.machines.client.gui.widget.FluidTransformWidget; import com.enderio.machines.client.gui.widget.ProgressWidget; import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; import com.enderio.machines.common.io.fluid.MachineFluidTank; @@ -43,7 +43,7 @@ protected void init() { addRenderableOnly(new FluidStackWidget(this, getMenu().getBlockEntity()::getOutputTank, 132 + leftPos, 12 + topPos, 15, 47)); addRenderableOnly( - new FluidTransformWidget(this::isCrafting, this::inputFluidStack, this::outputFluidStack, this::getProgress, 76 + leftPos, 34 + topPos, 26, 28)); + new FermentationWidget(this::isCrafting, this::inputFluidStack, this::outputFluidStack, this::getProgress, 76 + leftPos, 34 + topPos, 26, 28)); addRenderableOnly(new ProgressWidget.BottomUp(this, this::getProgress, 82 + leftPos, 64 + topPos, 14, 14, 176, 0)); diff --git a/src/machines/java/com/enderio/machines/client/gui/widget/FluidTransformWidget.java b/src/machines/java/com/enderio/machines/client/gui/widget/FermentationWidget.java similarity index 87% rename from src/machines/java/com/enderio/machines/client/gui/widget/FluidTransformWidget.java rename to src/machines/java/com/enderio/machines/client/gui/widget/FermentationWidget.java index 29b53fd40e..8c80e53ef3 100644 --- a/src/machines/java/com/enderio/machines/client/gui/widget/FluidTransformWidget.java +++ b/src/machines/java/com/enderio/machines/client/gui/widget/FermentationWidget.java @@ -15,17 +15,17 @@ import java.util.function.Supplier; -public class FluidTransformWidget extends EIOWidget { - private final Supplier isVisible; +public class FermentationWidget extends EIOWidget { + private final Supplier shouldShow; private final Supplier first; private final Supplier second; private final Supplier progress; - public FluidTransformWidget(Supplier isVisible, Supplier first, Supplier second, Supplier progress, int x, int y, + public FermentationWidget(Supplier shouldShow, Supplier first, Supplier second, Supplier progress, int x, int y, int width, int height) { super(x, y, width, height); - this.isVisible = isVisible; + this.shouldShow = shouldShow; this.first = first; this.second = second; this.progress = progress; @@ -36,7 +36,7 @@ protected void renderWidget(GuiGraphics guiGraphics, int pMouseX, int pMouseY, f RenderSystem.defaultBlendFunc(); RenderSystem.enableDepthTest(); - if (isVisible.get()) { + if (shouldShow.get()) { renderFluid(guiGraphics, first.get(), 1 - progress.get()); renderFluid(guiGraphics, second.get(), progress.get()); } @@ -47,7 +47,7 @@ protected void renderWidget(GuiGraphics guiGraphics, int pMouseX, int pMouseY, f @Override protected void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput) {} - public void renderFluid(GuiGraphics guiGraphics, FluidStack fluid, float progress) { + public void renderFluid(GuiGraphics guiGraphics, FluidStack fluid, float opacity) { Minecraft minecraft = Minecraft.getInstance(); IClientFluidTypeExtensions props = IClientFluidTypeExtensions.of(fluid.getFluid()); ResourceLocation loc = props.getStillTexture(); @@ -58,7 +58,7 @@ public void renderFluid(GuiGraphics guiGraphics, FluidStack fluid, float progres int color = props.getTintColor(); RenderSystem.setShaderColor(FastColor.ARGB32.red(color) / 255.0F, FastColor.ARGB32.green(color) / 255.0F, FastColor.ARGB32.blue(color) / 255.0F, - FastColor.ARGB32.alpha(color) * progress / 255.0F); + FastColor.ARGB32.alpha(color) * opacity / 255.0F); RenderSystem.enableBlend(); int atlasWidth = (int) (sprite.contents().width() / (sprite.getU1() - sprite.getU0())); diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java index b98157241e..8f8bc9145f 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -43,14 +43,16 @@ public class VatBlockEntity extends MachineBlockEntity implements FluidTankUser, FluidItemInteractive { - public static final int TANK_CAPACITY_COMMON = 8 * FluidType.BUCKET_VOLUME; + public static final int TANK_CAPACITY = 8 * FluidType.BUCKET_VOLUME; private static final TankAccess INPUT_TANK = new TankAccess(); private static final TankAccess OUTPUT_TANK = new TankAccess(); public static final MultiSlotAccess REAGENTS = new MultiSlotAccess(); + private static final ResourceLocation EMPTY = EnderIO.loc(""); + private final MachineFluidHandler fluidHandler; private final CraftingMachineTaskHost craftingTaskHost; + private ResourceLocation recipeId; - private static final ResourceLocation EMPTY = EnderIO.loc(""); public VatBlockEntity(BlockPos worldPosition, BlockState blockState) { super(MachineBlockEntities.VAT.get(), worldPosition, blockState); @@ -119,8 +121,8 @@ protected void onInventoryContentsChanged(int slot) { public MachineTankLayout getTankLayout() { return MachineTankLayout .builder() - .tank(INPUT_TANK, TANK_CAPACITY_COMMON, true, false, (stack) -> true) - .tank(OUTPUT_TANK, TANK_CAPACITY_COMMON, false, true, (stack) -> true) + .tank(INPUT_TANK, TANK_CAPACITY, true, false, (stack) -> true) + .tank(OUTPUT_TANK, TANK_CAPACITY, false, true, (stack) -> true) .build(); } @@ -154,7 +156,7 @@ public float getProgress() { } public ResourceLocation getRecipeId() { - if (level.isClientSide) { + if (level.isClientSide()) { return recipeId; } @@ -198,7 +200,7 @@ protected boolean placeOutputs(List outputs, boolean simulate) { @Override protected int makeProgress(int remainingProgress) { - return 1; + return 1; // do nothing. VAT doesn't consume power } @Override diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java index e84155102d..b925b9e642 100644 --- a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java +++ b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java @@ -166,8 +166,9 @@ public int fill(FluidStack resource, FluidAction action) { int totalFilled = 0; for (int index = 0; index < getTanks(); index++) { - if (!canInsert(index)) + if (!canInsert(index)) { continue; + } // Attempt to fill the tank int filled = fill(index, resourceLeft, action); diff --git a/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java index a90d7b83b9..c3c6adad51 100644 --- a/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java +++ b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java @@ -38,16 +38,15 @@ public int getBaseEnergyCost() { @Override public List craft(Container container, RegistryAccess registryAccess) { - double totalModifier = 1; - totalModifier *= getReagentModifier(container.getItem(0), leftReagent); - totalModifier *= getReagentModifier(container.getItem(1), rightReagent); + double modifier = getModifier(container.getItem(0), leftReagent); + modifier *= getModifier(container.getItem(1), rightReagent); - return List.of(OutputStack.of(new FluidStack(output.getFluid(), (int) (output.getAmount() * totalModifier)))); + return List.of(OutputStack.of(new FluidStack(output.getFluid(), (int) (output.getAmount() * modifier)))); } @Override public List getResultStacks(RegistryAccess registryAccess) { - return List.of(OutputStack.EMPTY); + return List.of(OutputStack.of(output().copy())); } @Override @@ -56,17 +55,11 @@ public boolean matches(Container container, Level level) { if (!input.test(inputTank) || inputTank.getAmount() < input.amount()) { return false; } - if (!container.getItem(0).is(leftReagent)) { - return false; - } - if (!container.getItem(1).is(rightReagent)) { - return false; - } - return true; + return container.getItem(0).is(leftReagent) && container.getItem(1).is(rightReagent); } - public double getReagentModifier(ItemStack stack, TagKey reagent) { + public double getModifier(ItemStack stack, TagKey reagent) { var map = stack.getItemHolder().getData(VatReagent.DATA_MAP); if (map != null) { return map.getOrDefault(reagent, 1D); @@ -100,18 +93,18 @@ public MachineFluidTank getInputTank() { } public static class Serializer implements RecipeSerializer { - private static final StreamCodec> ItemTagStreamCodec = ResourceLocation.STREAM_CODEC.map( + private static final StreamCodec> ITEM_TAG_STREAM_CODEC = ResourceLocation.STREAM_CODEC.map( loc -> TagKey.create(Registries.ITEM, loc), TagKey::location); - MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance - .group(SizedFluidIngredient.FLAT_CODEC.fieldOf("input_fluid").forGetter(FermentingRecipe::input), + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec( + instance -> instance.group(SizedFluidIngredient.FLAT_CODEC.fieldOf("input").forGetter(FermentingRecipe::input), TagKey.codec(Registries.ITEM).fieldOf("left_reagent").forGetter(FermentingRecipe::leftReagent), TagKey.codec(Registries.ITEM).fieldOf("right_reagent").forGetter(FermentingRecipe::rightReagent), - FluidStack.CODEC.fieldOf("output_fluid").forGetter(FermentingRecipe::output), Codec.INT.fieldOf("ticks").forGetter(FermentingRecipe::ticks)) + FluidStack.CODEC.fieldOf("output").forGetter(FermentingRecipe::output), Codec.INT.fieldOf("ticks").forGetter(FermentingRecipe::ticks)) .apply(instance, FermentingRecipe::new)); public static final StreamCodec STREAM_CODEC = StreamCodec.composite(SizedFluidIngredient.STREAM_CODEC, - FermentingRecipe::input, ItemTagStreamCodec, FermentingRecipe::leftReagent, ItemTagStreamCodec, FermentingRecipe::rightReagent, + FermentingRecipe::input, ITEM_TAG_STREAM_CODEC, FermentingRecipe::leftReagent, ITEM_TAG_STREAM_CODEC, FermentingRecipe::rightReagent, FluidStack.STREAM_CODEC, FermentingRecipe::output, ByteBufCodecs.INT, FermentingRecipe::ticks, FermentingRecipe::new); @Override diff --git a/src/machines/java/com/enderio/machines/data/reagentdata/ReagentDataProvider.java b/src/machines/java/com/enderio/machines/data/reagentdata/ReagentDataProvider.java index d5938c4c73..3b2b18a3d4 100644 --- a/src/machines/java/com/enderio/machines/data/reagentdata/ReagentDataProvider.java +++ b/src/machines/java/com/enderio/machines/data/reagentdata/ReagentDataProvider.java @@ -24,12 +24,17 @@ public class ReagentDataProvider implements DataProvider { - private final VatTagsProvider tagsProvider; - private final VatDatamapProvider datamapProvider; + private final TagsProvider tagsProvider; + private final DataProvider dataProvider; public ReagentDataProvider(PackOutput packOutput, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper) { - tagsProvider = new VatTagsProvider(packOutput, lookupProvider, existingFileHelper); - datamapProvider = new VatDatamapProvider(packOutput, lookupProvider); + tagsProvider = new TagsProvider(packOutput, lookupProvider, existingFileHelper); + dataProvider = new DataProvider(packOutput, lookupProvider); + } + + protected void gather() { + addReagent(Items.WHEAT, Tags.Items.CROPS, 3D); + addReagent(Items.WHEAT, Tags.Items.SEEDS, 2D); } @Override @@ -37,34 +42,29 @@ public CompletableFuture run(CachedOutput pOutput) { gather(); List> list = new ArrayList<>(); list.add(tagsProvider.run(pOutput)); - list.add(datamapProvider.run(pOutput)); + list.add(dataProvider.run(pOutput)); return CompletableFuture.allOf(list.toArray(CompletableFuture[]::new)); } - protected void gather() { - addReagentData(Items.WHEAT, Tags.Items.CROPS, 3D); - } - - public void addReagentData(Item item, TagKey tag, double value) { + public void addReagent(Item item, TagKey tag, double value) { tagsProvider.addItemTag(tag, item); - datamapProvider.addData(tag, item, value); + dataProvider.addData(tag, item, value); } @Override public String getName() { - return "ReagentData"; + return "Fermenting Reagent Datamaps"; } - private static class VatTagsProvider extends IntrinsicHolderTagsProvider { + private static class TagsProvider extends IntrinsicHolderTagsProvider { private final Map, List> tagsMap = new HashMap<>(); - public VatTagsProvider(PackOutput packOutput, CompletableFuture provider, @Nullable ExistingFileHelper existingFileHelper) { + protected TagsProvider(PackOutput packOutput, CompletableFuture provider, @Nullable ExistingFileHelper existingFileHelper) { super(packOutput, Registries.ITEM, provider, item -> item.builtInRegistryHolder().key(), EnderIO.MODID, existingFileHelper); } public void addItemTag(TagKey tag, Item item) { - var list = tagsMap.computeIfAbsent(tag, it -> new ArrayList<>()); - list.add(item); + tagsMap.computeIfAbsent(tag, it -> new ArrayList<>()).add(item); } @Override @@ -76,25 +76,22 @@ protected void addTags(HolderLookup.Provider pProvider) { } } - private static class VatDatamapProvider extends DataMapProvider { - private final Map, Map> data = new HashMap<>(); + private static class DataProvider extends DataMapProvider { + private final Map, Double>> data = new HashMap<>(); - protected VatDatamapProvider(PackOutput packOutput, CompletableFuture lookupProvider) { + protected DataProvider(PackOutput packOutput, CompletableFuture lookupProvider) { super(packOutput, lookupProvider); } public void addData(TagKey tag, Item item, double value) { - var map = data.computeIfAbsent(tag, it -> new HashMap<>()); - map.put(item, value); + data.computeIfAbsent(item, it -> new HashMap<>()).put(tag, value); } @Override protected void gather() { var builder = builder(VatReagent.DATA_MAP); - data.forEach((tag, map) -> { - map.forEach(((item, value) -> { - builder.add(item.builtInRegistryHolder(), Map.of(tag, value), false); - })); + data.forEach((item, map) -> { + builder.add(item.builtInRegistryHolder(), map, false); }); } } From 541a886b84c8c1d8666e671d7cae80f98a05cf41 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Wed, 12 Jun 2024 01:58:21 +0530 Subject: [PATCH 10/14] small porting bugfixes --- .../machines/common/blockentity/FluidTankBlockEntity.java | 2 +- .../enderio/machines/common/blockentity/VatBlockEntity.java | 2 +- .../machines/common/io/fluid/MachineFluidHandler.java | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/machines/java/com/enderio/machines/common/blockentity/FluidTankBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/FluidTankBlockEntity.java index 1b5948846d..aeaa2a36dc 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/FluidTankBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/FluidTankBlockEntity.java @@ -238,7 +238,7 @@ public ItemInteractionResult onBlockEntityUsed(BlockState state, Level level, Bl ItemStack stack = player.getItemInHand(hand); if (!stack.isEmpty() && handleFluidItemInteraction(player, hand, stack, this, TANK)) { player.getInventory().setChanged(); - return ItemInteractionResult.CONSUME; + return ItemInteractionResult.sidedSuccess(level.isClientSide()); } return super.onBlockEntityUsed(state, level, pos, player, hand, hit); } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java index 8f8bc9145f..a04e470cd3 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -95,7 +95,7 @@ public ItemInteractionResult onBlockEntityUsed(BlockState state, Level level, Bl if (!stack.isEmpty()) { if (handleFluidItemInteraction(player, hand, stack, this, INPUT_TANK) || handleFluidItemInteraction(player, hand, stack, this, OUTPUT_TANK)) { player.getInventory().setChanged(); - return ItemInteractionResult.CONSUME; + return ItemInteractionResult.sidedSuccess(level.isClientSide()); } } return super.onBlockEntityUsed(state, level, pos, player, hand, hit); diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java index b925b9e642..825cfe2b30 100644 --- a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java +++ b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java @@ -253,8 +253,7 @@ public CompoundTag serializeNBT(HolderLookup.Provider lookupProvider) { for (int i = 0; i < getTanks(); i++) { CompoundTag tankTag = new CompoundTag(); tankTag.putInt(TANK_INDEX, i); - tankTag.put(TANK_CONTENTS, stacks.get(i).save(lookupProvider)); - + tankTag.put(TANK_CONTENTS, stacks.get(i).saveOptional(lookupProvider)); nbtTagList.add(tankTag); } CompoundTag nbt = new CompoundTag(); @@ -268,7 +267,7 @@ public void deserializeNBT(HolderLookup.Provider lookupProvider, CompoundTag nbt for (int i = 0; i < tagList.size(); i++) { CompoundTag tankTag = tagList.getCompound(i); int index = tankTag.getInt(TANK_INDEX); - stacks.set(index, FluidStack.parseOptional(lookupProvider, tankTag)); + stacks.set(index, FluidStack.parseOptional(lookupProvider, tankTag.getCompound(TANK_CONTENTS))); } } From a02725dfe23938711c7c90232410f9178a8ba2ed Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Wed, 12 Jun 2024 23:33:33 +0530 Subject: [PATCH 11/14] fix fluid io bug --- .../blockentity/base/MachineBlockEntity.java | 4 +-- .../common/init/MachineBlockEntities.java | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/machines/java/com/enderio/machines/common/blockentity/base/MachineBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/base/MachineBlockEntity.java index 0255eba9f4..1b620d4365 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/base/MachineBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/base/MachineBlockEntity.java @@ -1,6 +1,5 @@ package com.enderio.machines.common.blockentity.base; -import com.enderio.api.UseOnly; import com.enderio.api.capability.SideConfig; import com.enderio.api.io.IOConfigurable; import com.enderio.api.io.IOMode; @@ -39,7 +38,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; -import net.neoforged.fml.LogicalSide; import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.capabilities.ICapabilityProvider; import net.neoforged.neoforge.client.model.data.ModelData; @@ -410,7 +408,7 @@ private void moveFluids(Direction side) { return; } - TransferUtil.distributeFluids(getIOConfig().getMode(side), selfHandler, otherHandler); + TransferUtil.distributeFluids(getIOMode(side), selfHandler, otherHandler); } // endregion diff --git a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java index b861d0ec8c..9460c9fd1e 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java @@ -55,13 +55,14 @@ public class MachineBlockEntities { public static final RegiliteBlockEntity FLUID_TANK = register("fluid_tank", FluidTankBlockEntity.Standard::new, MachineBlocks.FLUID_TANK) .setRenderer(() -> FluidTankBER::new) - .apply(MachineBlockEntities::machineBlockEntityCapabilities).addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); - + .apply(MachineBlockEntities::machineBlockEntityCapabilities) + .apply(MachineBlockEntities::fluidHandlerCapability); public static final RegiliteBlockEntity PRESSURIZED_FLUID_TANK = register("pressurized_fluid_tank", FluidTankBlockEntity.Enhanced::new, MachineBlocks.PRESSURIZED_FLUID_TANK) .setRenderer(() -> FluidTankBER::new) - .apply(MachineBlockEntities::machineBlockEntityCapabilities).addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); + .apply(MachineBlockEntities::machineBlockEntityCapabilities) + .apply(MachineBlockEntities::fluidHandlerCapability); public static final RegiliteBlockEntity ENCHANTER = register("enchanter", EnchanterBlockEntity::new, MachineBlocks.ENCHANTER); @@ -100,7 +101,8 @@ public class MachineBlockEntities { public static final RegiliteBlockEntity XP_VACUUM = register("xp_vacuum", XPVacuumBlockEntity::new, MachineBlocks.XP_VACUUM) - .apply(MachineBlockEntities::machineBlockEntityCapabilities).addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); + .apply(MachineBlockEntities::machineBlockEntityCapabilities) + .apply(MachineBlockEntities::fluidHandlerCapability); public static final RegiliteBlockEntity TRAVEL_ANCHOR = register("travel_anchor", TravelAnchorBlockEntity::new, MachineBlocks.TRAVEL_ANCHOR) @@ -116,12 +118,12 @@ public class MachineBlockEntities { public static final RegiliteBlockEntity DRAIN = register("drain", DrainBlockEntity::new, MachineBlocks.DRAIN) .apply(MachineBlockEntities::poweredMachineBlockEntityCapabilities) - .addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); + .apply(MachineBlockEntities::fluidHandlerCapability); public static final RegiliteBlockEntity SOUL_BINDER = register("soul_binder", SoulBinderBlockEntity::new, MachineBlocks.SOUL_BINDER) .apply(MachineBlockEntities::poweredMachineBlockEntityCapabilities) - .addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); + .apply(MachineBlockEntities::fluidHandlerCapability); public static final RegiliteBlockEntity WIRED_CHARGER = register("wired_charger", WiredChargerBlockEntity::new, MachineBlocks.WIRED_CHARGER) @@ -166,15 +168,17 @@ public class MachineBlockEntities { public static final RegiliteBlockEntity SOUL_ENGINE = register("soul_engine", SoulEngineBlockEntity::new, MachineBlocks.SOUL_ENGINE) .apply(MachineBlockEntities::poweredMachineBlockEntityCapabilities) - .addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); + .apply(MachineBlockEntities::fluidHandlerCapability); public static final RegiliteBlockEntity XP_OBELISK = register("xp_obelisk", XPObeliskBlockEntity::new, MachineBlocks.XP_OBELISK) .setRenderer(() -> XPObeliskBER::new) - .apply(MachineBlockEntities::machineBlockEntityCapabilities).addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); + .apply(MachineBlockEntities::machineBlockEntityCapabilities) + .apply(MachineBlockEntities::fluidHandlerCapability); public static final RegiliteBlockEntity VAT = register("vat", VatBlockEntity::new, MachineBlocks.VAT) - .apply(MachineBlockEntities::machineBlockEntityCapabilities).addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); + .apply(MachineBlockEntities::machineBlockEntityCapabilities) + .apply(MachineBlockEntities::fluidHandlerCapability); @SafeVarargs private static RegiliteBlockEntity register(String name, BlockEntityType.BlockEntitySupplier beFactory, @@ -193,6 +197,10 @@ private static void poweredMachineBlockEntityCapabilities(RegiliteBlockEntity blockEntity) { + blockEntity.addCapability(Capabilities.FluidHandler.BLOCK, FluidTankUser.FLUID_HANDLER_PROVIDER); + } + public static void register(IEventBus bus) { BLOCK_ENTITY_REGISTRY.register(bus); } From f6890eada17094515f2c90576169c060e4646101 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Sun, 16 Jun 2024 23:16:40 +0530 Subject: [PATCH 12/14] active states and fix another fluid IO bug --- .../common/blockentity/VatBlockEntity.java | 5 +++++ .../common/io/fluid/MachineFluidHandler.java | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java index a04e470cd3..c016e4c9a8 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -81,6 +81,11 @@ public void serverTick() { if (canAct()) { craftingTaskHost.tick(); } + updateMachineState(MachineState.ACTIVE, isActive()); + } + + protected boolean isActive() { + return canAct() && craftingTaskHost.hasTask(); } @Override diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java index 825cfe2b30..f3cc6df07b 100644 --- a/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java +++ b/src/machines/java/com/enderio/machines/common/io/fluid/MachineFluidHandler.java @@ -214,13 +214,15 @@ public FluidStack drain(int tank, FluidStack resource, IFluidHandler.FluidAction @Override public FluidStack drain(FluidStack resource, FluidAction action) { for (int index = 0; index < getTanks(); index++) { - if (drain(index, resource, FluidAction.SIMULATE) != FluidStack.EMPTY) { - FluidStack drained = drain(index, resource, action); - if (!drained.isEmpty()) { - onContentsChanged(index); - changeListener.accept(index); + if (canExtract(index)) { + if (drain(index, resource, FluidAction.SIMULATE) != FluidStack.EMPTY) { + FluidStack drained = drain(index, resource, action); + if (!drained.isEmpty()) { + onContentsChanged(index); + changeListener.accept(index); + } + return drained; } - return drained; } } From 5814699adf9f4961c30ea6032486e3bd361524c7 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Mon, 17 Jun 2024 01:35:23 +0530 Subject: [PATCH 13/14] add reagent modifier indicators and buttons to manipulate tanks --- .../machines/client/gui/screen/VatScreen.java | 35 +++++++++++++++++- .../common/blockentity/VatBlockEntity.java | 28 +++++++++++++- .../machines/common/init/MachineNetwork.java | 5 +++ .../common/network/MachinePayloadHandler.java | 17 +++++++++ .../common/network/VatDumpTankPacket.java | 19 ++++++++++ .../common/network/VatMoveTankPacket.java | 19 ++++++++++ .../common/recipe/FermentingRecipe.java | 2 +- .../gui/sprites/buttons/move_fluid.png | Bin 0 -> 274 bytes .../gui/sprites/buttons/void_fluid.png | Bin 0 -> 332 bytes 9 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 src/machines/java/com/enderio/machines/common/network/VatDumpTankPacket.java create mode 100644 src/machines/java/com/enderio/machines/common/network/VatMoveTankPacket.java create mode 100644 src/main/resources/assets/enderio/textures/gui/sprites/buttons/move_fluid.png create mode 100644 src/main/resources/assets/enderio/textures/gui/sprites/buttons/void_fluid.png diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java index 3419c1af01..15dbd8de51 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -4,6 +4,7 @@ import com.enderio.api.misc.Vector2i; import com.enderio.base.common.lang.EIOLang; import com.enderio.core.client.gui.screen.EIOScreen; +import com.enderio.core.client.gui.widgets.EIOImageButton; import com.enderio.core.client.gui.widgets.EnumIconWidget; import com.enderio.machines.client.gui.widget.ActivityWidget; import com.enderio.machines.client.gui.widget.FermentationWidget; @@ -15,9 +16,11 @@ import com.enderio.machines.common.recipe.FermentingRecipe; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.WidgetSprites; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeHolder; import net.neoforged.neoforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; @@ -28,6 +31,9 @@ public class VatScreen extends EIOScreen { private static final ResourceLocation VAT_BG = EnderIO.loc("textures/gui/vat.png"); private static final ResourceLocation VAT_COVER = EnderIO.loc("vat_cover"); + public static final ResourceLocation MOVE_FLUID = EnderIO.loc("buttons/move_fluid"); + public static final ResourceLocation VOID_FLUID = EnderIO.loc("buttons/void_fluid"); + private FermentingRecipe recipeCache; private ResourceLocation recipeId; @@ -52,6 +58,12 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 24, 16, 16, menu, this::addRenderableWidget, font)); addRenderableWidget(new ActivityWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16 * 4)); + + addRenderableWidget(new EIOImageButton(this, leftPos + 29, topPos + 62, 16, 16, new WidgetSprites(MOVE_FLUID, MOVE_FLUID), + press -> menu.getBlockEntity().moveFluidToOutputTank())); + + addRenderableWidget(new EIOImageButton(this, leftPos + 131, topPos + 62, 16, 16, new WidgetSprites(VOID_FLUID, VOID_FLUID), + press -> menu.getBlockEntity().dumpOutputTank())); } @Override @@ -60,6 +72,7 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); guiGraphics.blitSprite(VAT_COVER, 76 + leftPos, 34 + topPos, 26, 28); + drawModifierStrings(guiGraphics); } @Override @@ -115,7 +128,7 @@ public int getFluidAmount() { if (isCrafting()) { reduced = recipeCache.input().amount(); } - return tank.getFluidAmount() - reduced; + return Math.max(tank.getFluidAmount() - reduced, 0); } @Override @@ -124,4 +137,24 @@ public int getCapacity() { } }; } + + private void drawModifierStrings(GuiGraphics guiGraphics) { + if (!isCrafting()) { + return; + } + // left modifier + ItemStack item = getMenu().getSlot(0).getItem(); + double modifier = FermentingRecipe.getModifier(item, recipeCache.leftReagent()); + String text = "x" + modifier; + int x = getGuiLeft() + 63 - minecraft.font.width(text) / 2; + guiGraphics.drawString(minecraft.font, text, x, getGuiTop() + 32, 4210752, false); + + // right modifier + item = getMenu().getSlot(1).getItem(); + modifier = FermentingRecipe.getModifier(item, recipeCache.rightReagent()); + text = "x" + modifier; + x = getGuiLeft() + 113 - minecraft.font.width(text) / 2; + guiGraphics.drawString(minecraft.font, text, x, getGuiTop() + 32, 4210752, false); + + } } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java index c016e4c9a8..da8af67c61 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/VatBlockEntity.java @@ -18,6 +18,8 @@ import com.enderio.machines.common.io.item.MachineInventoryLayout; import com.enderio.machines.common.io.item.MultiSlotAccess; import com.enderio.machines.common.menu.VatMenu; +import com.enderio.machines.common.network.VatDumpTankPacket; +import com.enderio.machines.common.network.VatMoveTankPacket; import com.enderio.machines.common.recipe.FermentingRecipe; import net.minecraft.core.BlockPos; import net.minecraft.core.HolderLookup; @@ -36,6 +38,7 @@ import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.network.PacketDistributor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,6 +54,8 @@ public class VatBlockEntity extends MachineBlockEntity implements FluidTankUser, private final MachineFluidHandler fluidHandler; private final CraftingMachineTaskHost craftingTaskHost; + private final NetworkDataSlot inputTankDataSlot; + private final NetworkDataSlot outputTankDataSlot; private ResourceLocation recipeId; @@ -59,8 +64,8 @@ public VatBlockEntity(BlockPos worldPosition, BlockState blockState) { fluidHandler = createFluidHandler(); // Sync fluid_stacks and active recipe. - addDataSlot(NetworkDataSlot.FLUID_STACK.create(() -> INPUT_TANK.getFluid(this), stack -> INPUT_TANK.setFluid(this, stack))); - addDataSlot(NetworkDataSlot.FLUID_STACK.create(() -> OUTPUT_TANK.getFluid(this), stack -> OUTPUT_TANK.setFluid(this, stack))); + inputTankDataSlot = addDataSlot(NetworkDataSlot.FLUID_STACK.create(() -> INPUT_TANK.getFluid(this), stack -> INPUT_TANK.setFluid(this, stack))); + outputTankDataSlot = addDataSlot(NetworkDataSlot.FLUID_STACK.create(() -> OUTPUT_TANK.getFluid(this), stack -> OUTPUT_TANK.setFluid(this, stack))); addDataSlot(NetworkDataSlot.RESOURCE_LOCATION.create(this::getRecipeId, this::setRecipeId)); @@ -180,6 +185,25 @@ public CraftingMachineTaskHost get return craftingTaskHost; } + public void moveFluidToOutputTank() { + if (level != null && level.isClientSide()) { + PacketDistributor.sendToServer(new VatMoveTankPacket(getBlockPos())); + } else { + if (OUTPUT_TANK.isEmpty(this) && !INPUT_TANK.isEmpty(this)) { + OUTPUT_TANK.setFluid(this, INPUT_TANK.getFluid(this)); + INPUT_TANK.setFluid(this, FluidStack.EMPTY); + } + } + } + + public void dumpOutputTank() { + if (level != null && level.isClientSide()) { + PacketDistributor.sendToServer(new VatDumpTankPacket(getBlockPos())); + } else { + OUTPUT_TANK.setFluid(this, FluidStack.EMPTY); + } + } + protected static class VatCraftingMachineTask extends CraftingMachineTask { public VatCraftingMachineTask(@NotNull Level level, MachineInventory inventory, MachineFluidHandler fluidHandler, FermentingRecipe.Container container, diff --git a/src/machines/java/com/enderio/machines/common/init/MachineNetwork.java b/src/machines/java/com/enderio/machines/common/init/MachineNetwork.java index 6c9ab72f0c..451d9f9155 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineNetwork.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineNetwork.java @@ -5,6 +5,8 @@ import com.enderio.machines.common.network.PoweredSpawnerSoulPacket; import com.enderio.machines.common.network.SoulEngineSoulPacket; import com.enderio.machines.common.network.UpdateCrafterTemplatePacket; +import com.enderio.machines.common.network.VatDumpTankPacket; +import com.enderio.machines.common.network.VatMoveTankPacket; import com.enderio.machines.common.souldata.EngineSoul; import com.enderio.machines.common.souldata.SpawnerSoul; import net.neoforged.bus.api.SubscribeEvent; @@ -34,5 +36,8 @@ public static void register(final RegisterPayloadHandlersEvent event) { registrar.playToServer(UpdateCrafterTemplatePacket.TYPE, UpdateCrafterTemplatePacket.STREAM_CODEC, MachinePayloadHandler.Server.getInstance()::updateCrafterTemplate); + + registrar.playToServer(VatMoveTankPacket.TYPE, VatMoveTankPacket.STREAM_CODEC, MachinePayloadHandler.Server.getInstance()::vatMoveTank); + registrar.playToServer(VatDumpTankPacket.TYPE, VatDumpTankPacket.STREAM_CODEC, MachinePayloadHandler.Server.getInstance()::vatDumpTank); } } diff --git a/src/machines/java/com/enderio/machines/common/network/MachinePayloadHandler.java b/src/machines/java/com/enderio/machines/common/network/MachinePayloadHandler.java index 87454a6e8c..c65d192b98 100644 --- a/src/machines/java/com/enderio/machines/common/network/MachinePayloadHandler.java +++ b/src/machines/java/com/enderio/machines/common/network/MachinePayloadHandler.java @@ -1,5 +1,6 @@ package com.enderio.machines.common.network; +import com.enderio.machines.common.blockentity.VatBlockEntity; import com.enderio.machines.common.menu.CrafterMenu; import com.enderio.machines.common.souldata.EngineSoul; import com.enderio.machines.common.souldata.SpawnerSoul; @@ -38,5 +39,21 @@ public void updateCrafterTemplate(UpdateCrafterTemplatePacket packet, IPayloadCo } }); } + + public void vatMoveTank(VatMoveTankPacket packet, IPayloadContext context) { + context.enqueueWork(() -> { + if (context.player().level().getBlockEntity(packet.pos()) instanceof VatBlockEntity vatBlockEntity) { + vatBlockEntity.moveFluidToOutputTank(); + } + }); + } + + public void vatDumpTank(VatDumpTankPacket packet, IPayloadContext context) { + context.enqueueWork(() -> { + if (context.player().level().getBlockEntity(packet.pos()) instanceof VatBlockEntity vatBlockEntity) { + vatBlockEntity.dumpOutputTank(); + } + }); + } } } diff --git a/src/machines/java/com/enderio/machines/common/network/VatDumpTankPacket.java b/src/machines/java/com/enderio/machines/common/network/VatDumpTankPacket.java new file mode 100644 index 0000000000..72808450a5 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/network/VatDumpTankPacket.java @@ -0,0 +1,19 @@ +package com.enderio.machines.common.network; + +import com.enderio.EnderIO; +import io.netty.buffer.ByteBuf; +import net.minecraft.core.BlockPos; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; + +public record VatDumpTankPacket(BlockPos pos) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(EnderIO.loc("vat_dump_tank")); + + public static StreamCodec STREAM_CODEC = StreamCodec.composite(BlockPos.STREAM_CODEC, VatDumpTankPacket::pos, + VatDumpTankPacket::new); + + @Override + public Type type() { + return TYPE; + } +} diff --git a/src/machines/java/com/enderio/machines/common/network/VatMoveTankPacket.java b/src/machines/java/com/enderio/machines/common/network/VatMoveTankPacket.java new file mode 100644 index 0000000000..f45221c583 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/network/VatMoveTankPacket.java @@ -0,0 +1,19 @@ +package com.enderio.machines.common.network; + +import com.enderio.EnderIO; +import io.netty.buffer.ByteBuf; +import net.minecraft.core.BlockPos; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; + +public record VatMoveTankPacket(BlockPos pos) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(EnderIO.loc("vat_move_tank")); + + public static StreamCodec STREAM_CODEC = StreamCodec.composite(BlockPos.STREAM_CODEC, VatMoveTankPacket::pos, + VatMoveTankPacket::new); + + @Override + public Type type() { + return TYPE; + } +} diff --git a/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java index c3c6adad51..f2dc1f83a1 100644 --- a/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java +++ b/src/machines/java/com/enderio/machines/common/recipe/FermentingRecipe.java @@ -59,7 +59,7 @@ public boolean matches(Container container, Level level) { return container.getItem(0).is(leftReagent) && container.getItem(1).is(rightReagent); } - public double getModifier(ItemStack stack, TagKey reagent) { + public static double getModifier(ItemStack stack, TagKey reagent) { var map = stack.getItemHolder().getData(VatReagent.DATA_MAP); if (map != null) { return map.getOrDefault(reagent, 1D); diff --git a/src/main/resources/assets/enderio/textures/gui/sprites/buttons/move_fluid.png b/src/main/resources/assets/enderio/textures/gui/sprites/buttons/move_fluid.png new file mode 100644 index 0000000000000000000000000000000000000000..e6847e790bf2c647bb7856a4994691b2a5ef2bd6 GIT binary patch literal 274 zcmV+t0qy>YP)Px#%t=H+R5*?8ki7|mP!vXw!3>~9DharOjbwm~AWo3Z0Wykp8bPpd1Pe2FW z6^Esx=Xn6wwoMQOSeC^&j?{Inow_{XfX*>ZQ!P=J<>u;=pC`ifNU5u;GGO}Ax_M{f Y3v$>=VY>vk`2YX_07*qoM6N<$f*kyGxBvhE literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/enderio/textures/gui/sprites/buttons/void_fluid.png b/src/main/resources/assets/enderio/textures/gui/sprites/buttons/void_fluid.png new file mode 100644 index 0000000000000000000000000000000000000000..c7dfc6557e3dbd0be3f547faa40a95a0533b1fd6 GIT binary patch literal 332 zcmV-S0ki&zP)Px$21!IgR5*>rlCNvSKorM6*9;10HZxI(n2C)G6bkzv;wH;PHk~v54>D7z8PpVN zr(z2G3r5A6P&Js1n<;}8Dvp~NDM@$7CI^*L7`&tzHV?9>SW7%i6v z$jf-_OY;K&ZrAHyAr#se-Ft8 eYUDfR)9VW+32VoKrHXF=0000 literal 0 HcmV?d00001 From c469b7f68c04484b87493a49877a89e4f9222a33 Mon Sep 17 00:00:00 2001 From: Darshan Phaldesai Date: Wed, 26 Jun 2024 13:19:46 +0530 Subject: [PATCH 14/14] address pr comments - add tooltips --- .../client/gui/widgets/EIOImageButton.java | 21 +++++++++++++++---- .../resources/assets/enderio/lang/en_us.json | 2 ++ .../machines/client/gui/screen/VatScreen.java | 7 ++++--- .../machines/common/lang/MachineLang.java | 2 ++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/core/java/com/enderio/core/client/gui/widgets/EIOImageButton.java b/src/core/java/com/enderio/core/client/gui/widgets/EIOImageButton.java index 257b17519c..87cd2b5a03 100644 --- a/src/core/java/com/enderio/core/client/gui/widgets/EIOImageButton.java +++ b/src/core/java/com/enderio/core/client/gui/widgets/EIOImageButton.java @@ -5,21 +5,34 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.ImageButton; import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.network.chat.Component; + +import javax.annotation.Nullable; // Wrapper for ImageButton to draw background. // Can be removed after GUI redesign if no longer required. public class EIOImageButton extends ImageButton { - private final EIOScreen addedOn; + private final EIOScreen screen; + @Nullable private final Component message; - public EIOImageButton(EIOScreen addedOn, int x, int y, int width, int height, WidgetSprites sprites, OnPress onPress) { + public EIOImageButton(EIOScreen screen, int x, int y, int width, int height, WidgetSprites sprites, OnPress onPress, @Nullable Component message) { super(x, y, width, height, sprites, onPress); - this.addedOn = addedOn; + this.screen = screen; + this.message = message; + } + + public EIOImageButton(EIOScreen screen, int x, int y, int width, int height, WidgetSprites sprites, OnPress onPress) { + this(screen, x, y, width, height, sprites, onPress, null); } @Override public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { - addedOn.renderSimpleArea(guiGraphics, new Vector2i(getX(), getY()), new Vector2i(getX() + getWidth(), getY() + getHeight())); + screen.renderSimpleArea(guiGraphics, new Vector2i(getX(), getY()), new Vector2i(getX() + getWidth(), getY() + getHeight())); super.renderWidget(guiGraphics, mouseX, mouseY, partialTick); + + if (this.isHovered() && message != null) { + guiGraphics.renderTooltip(screen.getMinecraft().font, message, mouseX, mouseY); + } } } diff --git a/src/generated/resources/assets/enderio/lang/en_us.json b/src/generated/resources/assets/enderio/lang/en_us.json index d619551ae5..cc157ccf07 100644 --- a/src/generated/resources/assets/enderio/lang/en_us.json +++ b/src/generated/resources/assets/enderio/lang/en_us.json @@ -237,12 +237,14 @@ "gui.enderio.alloy_smelter.mode_alloy": "Alloys Only", "gui.enderio.alloy_smelter.mode_furnace": "Furnace Only", "gui.enderio.blocked_redstone": "The machine is blocked by redstone", + "gui.enderio.button.dump_tank": "Void tank contents", "gui.enderio.button.retrieve_10_level": "Retrieve 10 levels of XP", "gui.enderio.button.retrieve_1_level": "Retrieve 1 level of XP", "gui.enderio.button.retrieve_all_level": "Retrieve all levels of XP", "gui.enderio.button.store_10_level": "Store 10 levels of XP", "gui.enderio.button.store_1_level": "Store 1 level of XP", "gui.enderio.button.store_all_level": "Store all levels of XP", + "gui.enderio.button.transfer_tank": "Transfer tank contents", "gui.enderio.cancel": "Cancel", "gui.enderio.category.alloy_smelting": "Alloy Smelting", "gui.enderio.category.enchanter": "Enchanting", diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java index 15dbd8de51..2caeeb87a9 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/VatScreen.java @@ -12,6 +12,7 @@ import com.enderio.machines.client.gui.widget.ProgressWidget; import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; import com.enderio.machines.common.io.fluid.MachineFluidTank; +import com.enderio.machines.common.lang.MachineLang; import com.enderio.machines.common.menu.VatMenu; import com.enderio.machines.common.recipe.FermentingRecipe; import net.minecraft.client.Minecraft; @@ -60,10 +61,10 @@ protected void init() { addRenderableWidget(new ActivityWidget(this, menu.getBlockEntity()::getMachineStates, leftPos + imageWidth - 6 - 16, topPos + 16 * 4)); addRenderableWidget(new EIOImageButton(this, leftPos + 29, topPos + 62, 16, 16, new WidgetSprites(MOVE_FLUID, MOVE_FLUID), - press -> menu.getBlockEntity().moveFluidToOutputTank())); + press -> menu.getBlockEntity().moveFluidToOutputTank(), MachineLang.TRANSFER_TANK)); addRenderableWidget(new EIOImageButton(this, leftPos + 131, topPos + 62, 16, 16, new WidgetSprites(VOID_FLUID, VOID_FLUID), - press -> menu.getBlockEntity().dumpOutputTank())); + press -> menu.getBlockEntity().dumpOutputTank(), MachineLang.DUMP_TANK)); } @Override @@ -96,7 +97,7 @@ private void updateRecipeCache() { } private boolean isCrafting() { - return getMenu().getBlockEntity().getCraftingHost().getProgress() > 0 && recipeCache != null; + return recipeCache != null && getMenu().getBlockEntity().getCraftingHost().getProgress() > 0; } private FluidStack inputFluidStack() { diff --git a/src/machines/java/com/enderio/machines/common/lang/MachineLang.java b/src/machines/java/com/enderio/machines/common/lang/MachineLang.java index 09cdc59ee4..8ad510ec33 100644 --- a/src/machines/java/com/enderio/machines/common/lang/MachineLang.java +++ b/src/machines/java/com/enderio/machines/common/lang/MachineLang.java @@ -65,6 +65,8 @@ public class MachineLang { public static final Component STORE_1 = addTranslation("gui", EnderIO.loc("button.store_1_level"), "Store 1 level of XP"); public static final Component STORE_10 = addTranslation("gui", EnderIO.loc("button.store_10_level"), "Store 10 levels of XP"); public static final Component STORE_ALL = addTranslation("gui", EnderIO.loc("button.store_all_level"), "Store all levels of XP"); + public static final Component TRANSFER_TANK = addTranslation("gui", EnderIO.loc("button.transfer_tank"), "Transfer tank contents"); + public static final Component DUMP_TANK = addTranslation("gui", EnderIO.loc("button.dump_tank"), "Void tank contents"); // TODO: NEO-PORT: Common lang base class? private static MutableComponent addTranslation(String prefix, ResourceLocation id, String translation) {