From 7362572749ac4c11f0e91d2dbc90889c8746cc3b Mon Sep 17 00:00:00 2001 From: deirn Date: Sun, 4 Feb 2024 16:27:46 +0700 Subject: [PATCH] ie: add multiblock storage, ie: fix furnace progress inverted --- .../module/ie/MeganeImmersiveEngineering.java | 14 +++++-- .../module/ie/provider/FurnaceProvider.java | 4 +- .../module/ie/provider/ProcessProvider.java | 42 +++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/provider/ProcessProvider.java diff --git a/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/MeganeImmersiveEngineering.java b/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/MeganeImmersiveEngineering.java index 4e436be..bb1b522 100644 --- a/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/MeganeImmersiveEngineering.java +++ b/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/MeganeImmersiveEngineering.java @@ -9,9 +9,11 @@ import blusunrize.immersiveengineering.common.blocks.multiblocks.logic.AssemblerLogic; import blusunrize.immersiveengineering.common.blocks.multiblocks.logic.BlastFurnaceLogic; import blusunrize.immersiveengineering.common.blocks.multiblocks.logic.CokeOvenLogic; +import blusunrize.immersiveengineering.common.blocks.multiblocks.logic.DieselGeneratorLogic; import blusunrize.immersiveengineering.common.blocks.multiblocks.logic.MetalPressLogic; import blusunrize.immersiveengineering.common.blocks.multiblocks.logic.SheetmetalTankLogic; import blusunrize.immersiveengineering.common.blocks.multiblocks.logic.SiloLogic; +import blusunrize.immersiveengineering.common.blocks.multiblocks.process.ProcessContext; import blusunrize.immersiveengineering.common.util.inventory.IIEInventory; import lol.bai.megane.module.ie.provider.AssemblerProvider; import lol.bai.megane.module.ie.provider.CokeOvenProvider; @@ -19,6 +21,7 @@ import lol.bai.megane.module.ie.provider.IEInventoryProvider; import lol.bai.megane.module.ie.provider.MetalPressProvider; import lol.bai.megane.module.ie.provider.MultiblockProvider; +import lol.bai.megane.module.ie.provider.ProcessProvider; import lol.bai.megane.module.ie.provider.SheetmetalTankProvider; import lol.bai.megane.module.ie.provider.SiloProvider; import mcp.mobius.waila.api.IRegistrar; @@ -36,22 +39,25 @@ public class MeganeImmersiveEngineering implements IWailaPlugin { @Override public void register(IRegistrar registrar) { EnergyData.describe("immersiveengineering").unit("IF"); + + var multiblockProvider = new MultiblockProvider(); + registrar.addComponent(multiblockProvider, TooltipPosition.BODY, IMultiblockBE.class); + registrar.addBlockData(multiblockProvider, IMultiblockBE.class, 100); + registrar.addBlockData(EnergyData.newInfiniteProvider(), CapacitorCreativeBlockEntity.class, 900); registrar.addBlockData(new BlockingDataProvider<>(EnergyData.class), DynamoBlockEntity.class, 900); registrar.addBlockData(new BlockingDataProvider<>(EnergyData.class), ThermoelectricGenBlockEntity.class, 900); + MultiblockProvider.addData(new BlockingDataProvider<>(EnergyData.class), DieselGeneratorLogic.State.class); registrar.addBlockData(new IEInventoryProvider(), IIEInventory.class); - var multiblockProvider = new MultiblockProvider(); - registrar.addComponent(multiblockProvider, TooltipPosition.BODY, IMultiblockBE.class); - registrar.addBlockData(multiblockProvider, IMultiblockBE.class); - MultiblockProvider.addData(new CokeOvenProvider(), CokeOvenLogic.State.class); MultiblockProvider.addData(new FurnaceProvider<>(BlastFurnaceLogic.State::getStateView), BlastFurnaceLogic.State.class); MultiblockProvider.addData(new FurnaceProvider<>(AdvBlastFurnaceLogic.State::getStateView), AdvBlastFurnaceLogic.State.class); MultiblockProvider.addData(new FurnaceProvider<>(AlloySmelterLogic.State::getStateView), AlloySmelterLogic.State.class); MultiblockProvider.addData(new SiloProvider(), SiloLogic.State.class); MultiblockProvider.addData(new SheetmetalTankProvider(), SheetmetalTankLogic.State.class); + MultiblockProvider.addData(new ProcessProvider<>(), ProcessContext.class); registrar.addFeatureConfig(CONFIG_SHOW_METAL_PRESS_MOLD, true); MultiblockProvider.addBody(new MetalPressProvider(), MetalPressLogic.State.class); diff --git a/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/provider/FurnaceProvider.java b/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/provider/FurnaceProvider.java index 4a5e961..870800a 100644 --- a/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/provider/FurnaceProvider.java +++ b/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/provider/FurnaceProvider.java @@ -38,9 +38,9 @@ public void appendData(IDataWriter data, IServerAccessor> acces var stateView = (FurnaceHandler.StateView & AccessFurnaceHandlerStateView) containerDataFunction.apply(state); var processStep = (float) FurnaceHandler.StateView.getProcess(stateView); var processMax = (float) FurnaceHandler.StateView.getMaxProcess(stateView); - if (processStep == 0) return; + if (processMax == 0) return; - var ratio = processStep / processMax; + var ratio = (processMax - processStep) / processMax; var progressData = ProgressData.ratio(ratio) .itemGetter(inventory::getStackInSlot); diff --git a/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/provider/ProcessProvider.java b/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/provider/ProcessProvider.java new file mode 100644 index 0000000..1725f60 --- /dev/null +++ b/modules/forge/immersive-engineering/src/main/java/lol/bai/megane/module/ie/provider/ProcessProvider.java @@ -0,0 +1,42 @@ +package lol.bai.megane.module.ie.provider; + +import blusunrize.immersiveengineering.api.multiblocks.blocks.logic.IMultiblockBE; +import blusunrize.immersiveengineering.api.multiblocks.blocks.logic.IMultiblockState; +import blusunrize.immersiveengineering.common.blocks.multiblocks.process.ProcessContext; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.data.FluidData; +import mcp.mobius.waila.api.data.ItemData; +import mcp.mobius.waila.api.forge.ForgeFluidData; +import net.minecraftforge.fluids.IFluidTank; + +public class ProcessProvider> implements IDataProvider> { + + @Override + public void appendData(IDataWriter data, IServerAccessor> accessor, IPluginConfig config) { + var state = accessor.getTarget().getHelper().getState(); + if (state == null) return; + + data.add(ItemData.class, res -> { + var inventory = state.getInventory(); + if (inventory.getSlots() == 0) return; + + res.add(ItemData.of(config) + .getter(inventory::getStackInSlot, inventory.getSlots())); + }); + + data.add(FluidData.class, res -> { + var tanks = state.getInternalTanks(); + if (tanks.length == 0) return; + + var fluidData = ForgeFluidData.of(tanks.length); + for (IFluidTank tank : tanks) { + fluidData.add(tank.getFluid(), tank.getCapacity()); + } + res.add(fluidData); + }); + } + +}