From 6a93c3fd460e0ad0e2e2d94f3c6914a2524b4002 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 24 Jul 2019 19:06:21 +0100 Subject: [PATCH] more misc fluid work, gonna leave most of this untill we have an offical or new api --- .../java/techreborn/TechRebornClient.java | 4 +- .../techreborn/api/ISubItemRetriever.java | 75 -------- .../java/techreborn/api/TechRebornAPI.java | 2 - .../FluidReplicatorRecipe.java | 2 +- .../recipes/IndustrialGrinderRecipe.java | 4 +- .../recipes/IndustrialSawmillRecipe.java | 4 +- .../BaseFluidGeneratorBlockEntity.java | 8 +- .../FluidReplicatorBlockEntity.java | 5 +- .../IndustrialGrinderBlockEntity.java | 6 +- .../IndustrialSawmillBlockEntity.java | 5 +- .../machine/tier3/QuantumTankBlockEntity.java | 19 +- .../client/gui/GuiDieselGenerator.java | 2 +- .../client/gui/GuiFluidReplicator.java | 2 +- .../techreborn/client/gui/GuiGasTurbine.java | 2 +- .../client/gui/GuiIndustrialGrinder.java | 2 +- .../client/gui/GuiIndustrialSawmill.java | 2 +- .../client/gui/GuiPlasmaGenerator.java | 2 +- .../techreborn/client/gui/GuiQuantumTank.java | 2 +- .../client/gui/GuiSemifluidGenerator.java | 2 +- .../client/gui/GuiThermalGenerator.java | 2 +- ...dModel.java => DynamicCellBakedModel.java} | 23 ++- .../techreborn/init/SubItemRetriever.java | 170 ------------------ .../recipes/DistillationTowerRecipes.java | 5 +- .../init/recipes/FusionReactorRecipes.java | 17 +- .../init/recipes/RecipeMethods.java | 7 +- src/main/java/techreborn/items/ItemCells.java | 65 ------- .../techreborn/items/ItemDynamicCell.java | 47 +++-- .../java/techreborn/utils/FluidUtils.java | 65 +++++-- 28 files changed, 147 insertions(+), 404 deletions(-) delete mode 100644 src/main/java/techreborn/api/ISubItemRetriever.java rename src/main/java/techreborn/client/render/{DyamicCellBakedModel.java => DynamicCellBakedModel.java} (86%) delete mode 100644 src/main/java/techreborn/init/SubItemRetriever.java delete mode 100644 src/main/java/techreborn/items/ItemCells.java diff --git a/src/main/java/techreborn/TechRebornClient.java b/src/main/java/techreborn/TechRebornClient.java index 5a3e6e56e..5c9bf177a 100644 --- a/src/main/java/techreborn/TechRebornClient.java +++ b/src/main/java/techreborn/TechRebornClient.java @@ -10,7 +10,7 @@ import net.minecraft.client.render.model.UnbakedModel; import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.SpriteAtlasTexture; import net.minecraft.util.Identifier; -import techreborn.client.render.DyamicCellBakedModel; +import techreborn.client.render.DynamicCellBakedModel; import javax.annotation.Nullable; import java.util.Collection; @@ -46,7 +46,7 @@ public class TechRebornClient implements ClientModInitializer { @Nullable @Override public BakedModel bake(ModelLoader modelLoader, Function function, ModelBakeSettings modelBakeSettings) { - return new DyamicCellBakedModel(); + return new DynamicCellBakedModel(); } }; }); diff --git a/src/main/java/techreborn/api/ISubItemRetriever.java b/src/main/java/techreborn/api/ISubItemRetriever.java deleted file mode 100644 index 0b916c20b..000000000 --- a/src/main/java/techreborn/api/ISubItemRetriever.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2018 TechReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package techreborn.api; - -import net.minecraft.item.ItemStack; - -public interface ISubItemRetriever { - - ItemStack getCellByName(String name); - - ItemStack getCellByName(String name, int count); - - ItemStack getDustByName(String name); - - ItemStack getDustByName(String name, int count); - - ItemStack getSmallDustByName(String name); - - ItemStack getSmallDustByName(String name, int count); - - ItemStack getGemByName(String name); - - ItemStack getGemByName(String name, int count); - - ItemStack getIngotByName(String name); - - ItemStack getIngotByName(String name, int count); - - ItemStack getNuggetByName(String name); - - ItemStack getNuggetByName(String name, int count); - - ItemStack getPartByName(String name); - - ItemStack getPartByName(String name, int count); - - ItemStack getPlateByName(String name); - - ItemStack getPlateByName(String name, int count); - - ItemStack getUpgradeByName(String name); - - ItemStack getUpgradeByName(String name, int count); - - ItemStack getOreByName(String name); - - ItemStack getOreByName(String name, int count); - - ItemStack getStorageBlockByName(String name); - - ItemStack getStorageBlockByName(String name, int count); - -} diff --git a/src/main/java/techreborn/api/TechRebornAPI.java b/src/main/java/techreborn/api/TechRebornAPI.java index 994a811a8..73f67161b 100644 --- a/src/main/java/techreborn/api/TechRebornAPI.java +++ b/src/main/java/techreborn/api/TechRebornAPI.java @@ -35,8 +35,6 @@ public final class TechRebornAPI { */ public static IRecipeCompact recipeCompact; - public static ISubItemRetriever subItemRetriever; - public static IC2Helper ic2Helper; /** diff --git a/src/main/java/techreborn/api/fluidreplicator/FluidReplicatorRecipe.java b/src/main/java/techreborn/api/fluidreplicator/FluidReplicatorRecipe.java index 04b4a125d..7690c5e84 100644 --- a/src/main/java/techreborn/api/fluidreplicator/FluidReplicatorRecipe.java +++ b/src/main/java/techreborn/api/fluidreplicator/FluidReplicatorRecipe.java @@ -117,7 +117,7 @@ public class FluidReplicatorRecipe implements Cloneable { if (!FluidUtils.fluidEquals(fluid, output)) { return false; } - final Fluid tankFluid = blockEntity.tank.getFluidType(); + final Fluid tankFluid = blockEntity.tank.getFluid(); if (tankFluid != null && !FluidUtils.fluidEquals(tankFluid, fluid)) { return false; } diff --git a/src/main/java/techreborn/api/recipe/recipes/IndustrialGrinderRecipe.java b/src/main/java/techreborn/api/recipe/recipes/IndustrialGrinderRecipe.java index b61b93b9e..9e0e83597 100644 --- a/src/main/java/techreborn/api/recipe/recipes/IndustrialGrinderRecipe.java +++ b/src/main/java/techreborn/api/recipe/recipes/IndustrialGrinderRecipe.java @@ -47,7 +47,7 @@ public class IndustrialGrinderRecipe extends RebornRecipe { return false; } final FluidInstance recipeFluid = fluidStack; - final FluidInstance tankFluid = blockEntity.tank.getFluid(); + final FluidInstance tankFluid = blockEntity.tank.getFluidInstance(); if (fluidStack == null) { return true; } @@ -66,7 +66,7 @@ public class IndustrialGrinderRecipe extends RebornRecipe { public boolean onCraft(final BlockEntity be) { IndustrialGrinderBlockEntity blockEntity = (IndustrialGrinderBlockEntity) be; final FluidInstance recipeFluid = fluidStack; - final FluidInstance tankFluid = blockEntity.tank.getFluid(); + final FluidInstance tankFluid = blockEntity.tank.getFluidInstance(); if (fluidStack == null) { return true; } diff --git a/src/main/java/techreborn/api/recipe/recipes/IndustrialSawmillRecipe.java b/src/main/java/techreborn/api/recipe/recipes/IndustrialSawmillRecipe.java index 01940c8dc..2fc870be2 100644 --- a/src/main/java/techreborn/api/recipe/recipes/IndustrialSawmillRecipe.java +++ b/src/main/java/techreborn/api/recipe/recipes/IndustrialSawmillRecipe.java @@ -47,7 +47,7 @@ public class IndustrialSawmillRecipe extends RebornRecipe { return false; } final FluidInstance recipeFluid = fluidStack; - final FluidInstance tankFluid = blockEntity.tank.getFluid(); + final FluidInstance tankFluid = blockEntity.tank.getFluidInstance(); if (fluidStack == null) { return true; } @@ -66,7 +66,7 @@ public class IndustrialSawmillRecipe extends RebornRecipe { public boolean onCraft(BlockEntity be) { IndustrialSawmillBlockEntity blockEntity = (IndustrialSawmillBlockEntity) be; final FluidInstance recipeFluid = fluidStack; - final FluidInstance tankFluid = blockEntity.tank.getFluid(); + final FluidInstance tankFluid = blockEntity.tank.getFluidInstance(); if (fluidStack == null) { return true; } diff --git a/src/main/java/techreborn/blockentity/generator/BaseFluidGeneratorBlockEntity.java b/src/main/java/techreborn/blockentity/generator/BaseFluidGeneratorBlockEntity.java index 0c3292427..24ccd8359 100644 --- a/src/main/java/techreborn/blockentity/generator/BaseFluidGeneratorBlockEntity.java +++ b/src/main/java/techreborn/blockentity/generator/BaseFluidGeneratorBlockEntity.java @@ -82,17 +82,15 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn if (ticksSinceLastChange >= 10) { if (!inventory.getInvStack(0).isEmpty()) { FluidUtils.drainContainers(tank, inventory, 0, 1); - FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType()); + FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid()); } - tank.setBlockEntity(this); - tank.compareAndUpdate(); ticksSinceLastChange = 0; } if (tank.getFluidAmount() > 0) { - if (currentRecipe == null || !FluidUtils.fluidEquals(currentRecipe.getFluid(), tank.getFluidType())) - currentRecipe = getRecipes().getRecipeForFluid(tank.getFluidType()).orElse(null); + if (currentRecipe == null || !FluidUtils.fluidEquals(currentRecipe.getFluid(), tank.getFluid())) + currentRecipe = getRecipes().getRecipeForFluid(tank.getFluid()).orElse(null); if (currentRecipe != null) { final Integer euPerBucket = currentRecipe.getEnergyPerMb() * 1000; diff --git a/src/main/java/techreborn/blockentity/machine/multiblock/FluidReplicatorBlockEntity.java b/src/main/java/techreborn/blockentity/machine/multiblock/FluidReplicatorBlockEntity.java index 8dbd89d92..13039da5d 100644 --- a/src/main/java/techreborn/blockentity/machine/multiblock/FluidReplicatorBlockEntity.java +++ b/src/main/java/techreborn/blockentity/machine/multiblock/FluidReplicatorBlockEntity.java @@ -92,7 +92,7 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem // Check cells input slot 2 time per second if (!world.isClient && ticksSinceLastChange >= 10) { if (!inventory.getInvStack(1).isEmpty()) { - FluidUtils.fillContainers(tank, inventory, 1, 2, tank.getFluidType()); + FluidUtils.fillContainers(tank, inventory, 1, 2, tank.getFluid()); } ticksSinceLastChange = 0; } @@ -101,7 +101,6 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem super.tick(); } - tank.compareAndUpdate(); } @Override @@ -144,7 +143,7 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem public BuiltContainer createContainer(int syncID, PlayerEntity player) { return new ContainerBuilder("fluidreplicator").player(player.inventory).inventory().hotbar().addInventory() .blockEntity(this).fluidSlot(1, 124, 35).filterSlot(0, 55, 45, stack -> stack.isItemEqualIgnoreDamage(TRContent.Parts.UU_MATTER.getStack())) - .outputSlot(2, 124, 55).energySlot(3, 8, 72).syncEnergyValue().syncCrafterValue().addInventory() + .outputSlot(2, 124, 55).energySlot(3, 8, 72).sync(tank).syncEnergyValue().syncCrafterValue().addInventory() .create(this, syncID); } } diff --git a/src/main/java/techreborn/blockentity/machine/multiblock/IndustrialGrinderBlockEntity.java b/src/main/java/techreborn/blockentity/machine/multiblock/IndustrialGrinderBlockEntity.java index b6c30905b..c60f80333 100644 --- a/src/main/java/techreborn/blockentity/machine/multiblock/IndustrialGrinderBlockEntity.java +++ b/src/main/java/techreborn/blockentity/machine/multiblock/IndustrialGrinderBlockEntity.java @@ -108,7 +108,7 @@ public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity impl if (!world.isClient && ticksSinceLastChange >= 10) { if (!inventory.getInvStack(1).isEmpty()) { FluidUtils.drainContainers(tank, inventory, 1, 6); - FluidUtils.fillContainers(tank, inventory, 1, 6, tank.getFluidType()); + FluidUtils.fillContainers(tank, inventory, 1, 6, tank.getFluid()); } ticksSinceLastChange = 0; } @@ -116,8 +116,6 @@ public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity impl if (!world.isClient && getMultiBlock()) { super.tick(); } - - tank.compareAndUpdate(); } @Override @@ -147,7 +145,7 @@ public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity impl return new ContainerBuilder("industrialgrinder").player(player.inventory).inventory().hotbar().addInventory() .blockEntity(this).fluidSlot(1, 34, 35).slot(0, 84, 43).outputSlot(2, 126, 18).outputSlot(3, 126, 36) .outputSlot(4, 126, 54).outputSlot(5, 126, 72).outputSlot(6, 34, 55).energySlot(7, 8, 72) - .syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID); + .sync(tank).syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID); } } \ No newline at end of file diff --git a/src/main/java/techreborn/blockentity/machine/multiblock/IndustrialSawmillBlockEntity.java b/src/main/java/techreborn/blockentity/machine/multiblock/IndustrialSawmillBlockEntity.java index b41c15b38..4adbed186 100644 --- a/src/main/java/techreborn/blockentity/machine/multiblock/IndustrialSawmillBlockEntity.java +++ b/src/main/java/techreborn/blockentity/machine/multiblock/IndustrialSawmillBlockEntity.java @@ -98,7 +98,7 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl if (!world.isClient && ticksSinceLastChange >= 10) { if (!inventory.getInvStack(1).isEmpty()) { FluidUtils.drainContainers(tank, inventory, 1, 5); - FluidUtils.fillContainers(tank, inventory, 1, 5, tank.getFluidType()); + FluidUtils.fillContainers(tank, inventory, 1, 5, tank.getFluidInstance().getFluid()); } ticksSinceLastChange = 0; } @@ -107,7 +107,6 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl super.tick(); } - tank.compareAndUpdate(); } // TilePowerAcceptor @@ -147,7 +146,7 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl public BuiltContainer createContainer(int syncID, final PlayerEntity player) { return new ContainerBuilder("industrialsawmill").player(player.inventory).inventory().hotbar().addInventory() .blockEntity(this).fluidSlot(1, 34, 35).slot(0, 84, 43).outputSlot(2, 126, 25).outputSlot(3, 126, 43) - .outputSlot(4, 126, 61).outputSlot(5, 34, 55).energySlot(6, 8, 72).syncEnergyValue().syncCrafterValue() + .outputSlot(4, 126, 61).outputSlot(5, 34, 55).energySlot(6, 8, 72).sync(tank).syncEnergyValue().syncCrafterValue() .addInventory().create(this, syncID); } diff --git a/src/main/java/techreborn/blockentity/machine/tier3/QuantumTankBlockEntity.java b/src/main/java/techreborn/blockentity/machine/tier3/QuantumTankBlockEntity.java index 3df58f2ed..4511aad08 100644 --- a/src/main/java/techreborn/blockentity/machine/tier3/QuantumTankBlockEntity.java +++ b/src/main/java/techreborn/blockentity/machine/tier3/QuantumTankBlockEntity.java @@ -44,6 +44,7 @@ import reborncore.common.util.Tank; import techreborn.TechReborn; import techreborn.init.TRContent; import techreborn.init.TRBlockEntities; +import techreborn.utils.FluidUtils; import javax.annotation.Nullable; import java.util.List; @@ -89,14 +90,12 @@ public class QuantumTankBlockEntity extends MachineBaseBlockEntity public void tick() { super.tick(); if (!world.isClient) { -// TODO: Fix in 1.13 -// if (FluidUtils.drainContainers(tank, inventory, 0, 1) -// || FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType())) { -// this.syncWithAll(); -// } + if (FluidUtils.drainContainers(tank, inventory, 0, 1) + || FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid())) { + this.syncWithAll(); + } } - tank.compareAndUpdate(); } @Override @@ -133,8 +132,8 @@ public class QuantumTankBlockEntity extends MachineBaseBlockEntity @Override public void addInfo(final List info, final boolean isReal, boolean hasData) { if (isReal | hasData) { - if (this.tank.getFluid() != null) { - info.add(new LiteralText(this.tank.getFluidAmount() + " of " + this.tank.getFluidType())); + if (!this.tank.getFluidInstance().isEmpty()) { + info.add(new LiteralText(this.tank.getFluidAmount() + " of " + this.tank.getFluid())); } else { info.add(new LiteralText("Empty")); } @@ -146,8 +145,8 @@ public class QuantumTankBlockEntity extends MachineBaseBlockEntity @Override public BuiltContainer createContainer(int syncID, final PlayerEntity player) { return new ContainerBuilder("quantumtank").player(player.inventory).inventory().hotbar() - .addInventory().blockEntity(this).fluidSlot(0, 80, 17).outputSlot(1, 80, 53).addInventory() - .create(this, syncID); + .addInventory().blockEntity(this).fluidSlot(0, 80, 17).outputSlot(1, 80, 53) + .sync(tank).addInventory().create(this, syncID); } @Nullable diff --git a/src/main/java/techreborn/client/gui/GuiDieselGenerator.java b/src/main/java/techreborn/client/gui/GuiDieselGenerator.java index 65711cd0c..4e3cc0c08 100644 --- a/src/main/java/techreborn/client/gui/GuiDieselGenerator.java +++ b/src/main/java/techreborn/client/gui/GuiDieselGenerator.java @@ -58,7 +58,7 @@ public class GuiDieselGenerator extends GuiBase { builder.drawProgressBar(this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawMultiEnergyBar(this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); - builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluid(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); + builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); } diff --git a/src/main/java/techreborn/client/gui/GuiFluidReplicator.java b/src/main/java/techreborn/client/gui/GuiFluidReplicator.java index 798f7744f..fe41b2861 100644 --- a/src/main/java/techreborn/client/gui/GuiFluidReplicator.java +++ b/src/main/java/techreborn/client/gui/GuiFluidReplicator.java @@ -86,7 +86,7 @@ public class GuiFluidReplicator extends GuiBase { super.drawForeground(mouseX, mouseY); final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND; - builder.drawTank(this, 99, 25, mouseX, mouseY, blockEntity.tank.getFluid(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); + builder.drawTank(this, 99, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); builder.drawProgressBar(this, blockEntity.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); if (blockEntity.getMultiBlock()) { addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); diff --git a/src/main/java/techreborn/client/gui/GuiGasTurbine.java b/src/main/java/techreborn/client/gui/GuiGasTurbine.java index 08cbd79cb..e7829617d 100644 --- a/src/main/java/techreborn/client/gui/GuiGasTurbine.java +++ b/src/main/java/techreborn/client/gui/GuiGasTurbine.java @@ -55,7 +55,7 @@ public class GuiGasTurbine extends GuiBase { builder.drawProgressBar(this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawMultiEnergyBar(this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); - builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluid(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); + builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); } } diff --git a/src/main/java/techreborn/client/gui/GuiIndustrialGrinder.java b/src/main/java/techreborn/client/gui/GuiIndustrialGrinder.java index e5aded128..f701b6311 100644 --- a/src/main/java/techreborn/client/gui/GuiIndustrialGrinder.java +++ b/src/main/java/techreborn/client/gui/GuiIndustrialGrinder.java @@ -85,7 +85,7 @@ public class GuiIndustrialGrinder extends GuiBase { final Layer layer = Layer.FOREGROUND; builder.drawProgressBar(this, blockEntity.getProgressScaled(100), 100, 105, 47, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); - builder.drawTank(this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluid(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); + builder.drawTank(this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); if (blockEntity.getMultiBlock()) { addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); } else { diff --git a/src/main/java/techreborn/client/gui/GuiIndustrialSawmill.java b/src/main/java/techreborn/client/gui/GuiIndustrialSawmill.java index b702db745..8b186acae 100644 --- a/src/main/java/techreborn/client/gui/GuiIndustrialSawmill.java +++ b/src/main/java/techreborn/client/gui/GuiIndustrialSawmill.java @@ -84,7 +84,7 @@ public class GuiIndustrialSawmill extends GuiBase { final Layer layer = Layer.FOREGROUND; builder.drawProgressBar(this, blockEntity.getProgressScaled(100), 100, 105, 47, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); - builder.drawTank(this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluid(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); + builder.drawTank(this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); if (blockEntity.getMutliBlock()) { addHologramButton(6, 4, 212, layer).clickHandler(this::onClick); } else { diff --git a/src/main/java/techreborn/client/gui/GuiPlasmaGenerator.java b/src/main/java/techreborn/client/gui/GuiPlasmaGenerator.java index 5f5334c98..acc77124d 100644 --- a/src/main/java/techreborn/client/gui/GuiPlasmaGenerator.java +++ b/src/main/java/techreborn/client/gui/GuiPlasmaGenerator.java @@ -67,7 +67,7 @@ public class GuiPlasmaGenerator extends GuiBase { builder.drawProgressBar(this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawMultiEnergyBar(this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); - builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluid(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); + builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); } diff --git a/src/main/java/techreborn/client/gui/GuiQuantumTank.java b/src/main/java/techreborn/client/gui/GuiQuantumTank.java index 81c68c0fa..06ba57843 100644 --- a/src/main/java/techreborn/client/gui/GuiQuantumTank.java +++ b/src/main/java/techreborn/client/gui/GuiQuantumTank.java @@ -53,7 +53,7 @@ public class GuiQuantumTank extends GuiBase { protected void drawForeground(final int mouseX, final int mouseY) { super.drawForeground(mouseX, mouseY); - FluidInstance fluid = quantumTank.tank.getFluid(); + FluidInstance fluid = quantumTank.tank.getFluidInstance(); if(fluid != null){ font.draw( "Fluid Type:", 10, 20, 4210752); font.draw(FluidUtil.getFluidName(fluid) + "", 10, 30, 4210752); diff --git a/src/main/java/techreborn/client/gui/GuiSemifluidGenerator.java b/src/main/java/techreborn/client/gui/GuiSemifluidGenerator.java index 25f5c03c3..febea7111 100644 --- a/src/main/java/techreborn/client/gui/GuiSemifluidGenerator.java +++ b/src/main/java/techreborn/client/gui/GuiSemifluidGenerator.java @@ -55,7 +55,7 @@ public class GuiSemifluidGenerator extends GuiBase { builder.drawProgressBar(this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawMultiEnergyBar(this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); - builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluid(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); + builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); } } diff --git a/src/main/java/techreborn/client/gui/GuiThermalGenerator.java b/src/main/java/techreborn/client/gui/GuiThermalGenerator.java index 15359ab13..e91b87c3a 100644 --- a/src/main/java/techreborn/client/gui/GuiThermalGenerator.java +++ b/src/main/java/techreborn/client/gui/GuiThermalGenerator.java @@ -55,7 +55,7 @@ public class GuiThermalGenerator extends GuiBase { builder.drawProgressBar(this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); builder.drawMultiEnergyBar(this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); - builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluid(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); + builder.drawTank(this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer); } } diff --git a/src/main/java/techreborn/client/render/DyamicCellBakedModel.java b/src/main/java/techreborn/client/render/DynamicCellBakedModel.java similarity index 86% rename from src/main/java/techreborn/client/render/DyamicCellBakedModel.java rename to src/main/java/techreborn/client/render/DynamicCellBakedModel.java index 75c134203..4f507a860 100644 --- a/src/main/java/techreborn/client/render/DyamicCellBakedModel.java +++ b/src/main/java/techreborn/client/render/DynamicCellBakedModel.java @@ -1,5 +1,6 @@ package techreborn.client.render; +import io.github.prospector.silk.fluid.FluidInstance; import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler; import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; import net.fabricmc.fabric.api.renderer.v1.Renderer; @@ -20,6 +21,7 @@ import net.minecraft.client.render.model.json.ModelTransformation; import net.minecraft.client.texture.Sprite; import net.minecraft.entity.LivingEntity; import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -27,6 +29,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.registry.Registry; import net.minecraft.world.ExtendedBlockView; import net.minecraft.world.World; +import reborncore.common.fluid.container.GenericFluidContainer; import javax.annotation.Nullable; import java.util.Collections; @@ -34,11 +37,11 @@ import java.util.List; import java.util.Random; import java.util.function.Supplier; -public class DyamicCellBakedModel implements BakedModel, FabricBakedModel { +public class DynamicCellBakedModel implements BakedModel, FabricBakedModel { Sprite base; - public DyamicCellBakedModel() { + public DynamicCellBakedModel() { base = MinecraftClient.getInstance().getSpriteAtlas().getSprite(new Identifier("techreborn:item/cell_base")); } @@ -49,12 +52,14 @@ public class DyamicCellBakedModel implements BakedModel, FabricBakedModel { @Override public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { - - Fluid fluid = null; - if(stack.hasTag() && stack.getTag().containsKey("fluid")){ - fluid = Registry.FLUID.get(new Identifier(stack.getTag().getString("fluid"))); + GenericFluidContainer fluidContainer = GenericFluidContainer.fromStack(stack); + Fluid fluid = Fluids.EMPTY; + if(fluidContainer != null){ + FluidInstance fluidInstance = fluidContainer.getFluidInstance(stack); + if(!fluidInstance.isEmpty()){ + fluid = fluidContainer.getFluidInstance(stack).getFluid(); + } } - context.meshConsumer().accept(getMesh(fluid)); } @@ -77,7 +82,7 @@ public class DyamicCellBakedModel implements BakedModel, FabricBakedModel { .spriteColor(0, -1, -1, -1, -1) .spriteBake(0, base, MutableQuadView.BAKE_LOCK_UV).emit(); - if(fluid != null){ + if(fluid != Fluids.EMPTY){ FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid); if(fluidRenderHandler != null){ Sprite fluidSprite = fluidRenderHandler.getFluidSprites(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState())[0]; @@ -129,7 +134,7 @@ public class DyamicCellBakedModel implements BakedModel, FabricBakedModel { @Override public BakedModel apply(BakedModel bakedModel, ItemStack itemStack, World world, LivingEntity livingEntity) { - return DyamicCellBakedModel.this; + return DynamicCellBakedModel.this; } } diff --git a/src/main/java/techreborn/init/SubItemRetriever.java b/src/main/java/techreborn/init/SubItemRetriever.java deleted file mode 100644 index a7bfc8656..000000000 --- a/src/main/java/techreborn/init/SubItemRetriever.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2018 TechReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package techreborn.init; - -import net.minecraft.item.ItemStack; -import techreborn.api.ISubItemRetriever; -import techreborn.items.ItemCells; -/** - * Created by Mark on 03/04/2016. - */ -public class SubItemRetriever implements ISubItemRetriever { - @Override - public ItemStack getCellByName(String name) { - return ItemCells.getCellByName(name); - } - - @Override - public ItemStack getCellByName(String name, int count) { - return ItemCells.getCellByName(name, count); - } - - @Override - public ItemStack getDustByName(String name) { -// return ItemDusts.getDustByName(name); - return null; - } - - @Override - public ItemStack getDustByName(String name, int count) { -// return ItemDusts.getDustByName(name, count); - return null; - } - - @Override - public ItemStack getSmallDustByName(String name) { -// return ItemDustsSmall.getSmallDustByName(name); - return null; - } - - @Override - public ItemStack getSmallDustByName(String name, int count) { -// return ItemDustsSmall.getSmallDustByName(name, count); - return null; - } - - @Override - public ItemStack getGemByName(String name) { - // TODO: Fix recipe - //return ItemGems.getGemByName(name); - return null; - } - - @Override - public ItemStack getGemByName(String name, int count) { - // TODO: Fix recipe - //return ItemGems.getGemByName(name, count); - return null; - } - - @Override - public ItemStack getIngotByName(String name) { - //return ItemIngots.getIngotByName(name); - return null; - } - - @Override - public ItemStack getIngotByName(String name, int count) { - //return ItemIngots.getIngotByName(name, count); - return null; - } - - - @Override - public ItemStack getNuggetByName(String name) { -// TODO: fix recipe -// return ItemNuggets.getNuggetByName(name); - return null; - } - - @Override - public ItemStack getNuggetByName(String name, int count) { -// TODO: fix recipe -// return ItemNuggets.getNuggetByName(name, count); - return null; - } - - @Override - public ItemStack getPartByName(String name) { -// return ItemParts.getPartByName(name); - return null; - } - - @Override - public ItemStack getPartByName(String name, int count) { -// return ItemParts.getPartByName(name, count); - return null; - } - - @Override - public ItemStack getPlateByName(String name) { -// TODO: fix recipe -// return ItemPlates.getPlateByName(name); - return null; - } - - @Override - public ItemStack getPlateByName(String name, int count) { -// TODO: fix recipe -// return ItemPlates.getPlateByName(name, count); - return null; - } - - @Override - public ItemStack getUpgradeByName(String name) { -// return ItemUpgrades.getUpgradeByName(name); - return null; - } - - @Override - public ItemStack getUpgradeByName(String name, int count) { -// return ItemUpgrades.getUpgradeByName(name, count); - return null; - } - - @Override - public ItemStack getOreByName(String name) { -// return BlockOre.getOreByName(name); - return null; - } - - @Override - public ItemStack getOreByName(String name, int count) { -// return BlockOre.getOreByName(name, count); - return null; - } - - @Override - public ItemStack getStorageBlockByName(String name) { -// return BlockStorage.getStorageBlockByName(name); - return null; - } - - @Override - public ItemStack getStorageBlockByName(String name, int count) { -// return BlockStorage.getStorageBlockByName(name, count); - return null; - } -} diff --git a/src/main/java/techreborn/init/recipes/DistillationTowerRecipes.java b/src/main/java/techreborn/init/recipes/DistillationTowerRecipes.java index 3b7c267ec..dcdbbe255 100644 --- a/src/main/java/techreborn/init/recipes/DistillationTowerRecipes.java +++ b/src/main/java/techreborn/init/recipes/DistillationTowerRecipes.java @@ -25,8 +25,9 @@ package techreborn.init.recipes; import net.minecraft.item.ItemStack; +import techreborn.init.ModFluids; import techreborn.items.ItemDynamicCell; -import techreborn.items.ItemCells; + import java.security.InvalidParameterException; @@ -37,7 +38,7 @@ import java.security.InvalidParameterException; public class DistillationTowerRecipes extends RecipeMethods { public static void init() { - register(ItemCells.getCellByName("oil", 16), 1400, 13, getMaterial("diesel", 16, Type.CELL), getMaterial("sulfuricAcid", 16, Type.CELL), getMaterial("glyceryl", Type.CELL)); + register(ItemDynamicCell.getCellWithFluid(ModFluids.OIL.getFluid(), 16), 1400, 13, getMaterial("diesel", 16, Type.CELL), getMaterial("sulfuricAcid", 16, Type.CELL), getMaterial("glyceryl", Type.CELL)); } static void register(ItemStack input, int ticks, int euPerTick, boolean oreDict, ItemStack... outputs) { diff --git a/src/main/java/techreborn/init/recipes/FusionReactorRecipes.java b/src/main/java/techreborn/init/recipes/FusionReactorRecipes.java index 82a23210e..22339cd67 100644 --- a/src/main/java/techreborn/init/recipes/FusionReactorRecipes.java +++ b/src/main/java/techreborn/init/recipes/FusionReactorRecipes.java @@ -24,23 +24,18 @@ package techreborn.init.recipes; -import techreborn.api.reactor.FusionReactorRecipe; -import techreborn.api.reactor.FusionReactorRecipeHelper; -import techreborn.init.TRContent; -import techreborn.items.ItemCells; - /** * @author drcrazy * */ public class FusionReactorRecipes extends RecipeMethods { public static void init() { - FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("helium3"), - ItemCells.getCellByName("deuterium"), ItemCells.getCellByName("heliumplasma"), 40000000, 32768, 1024)); - FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("tritium"), - ItemCells.getCellByName("deuterium"), ItemCells.getCellByName("helium3"), 60000000, 16384, 2048)); - FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), - ItemCells.getCellByName("Berylium"), TRContent.Dusts.PLATINUM.getStack(), 80000000, -2048, 1024)); +// FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("helium3"), +// ItemCells.getCellByName("deuterium"), ItemCells.getCellByName("heliumplasma"), 40000000, 32768, 1024)); +// FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("tritium"), +// ItemCells.getCellByName("deuterium"), ItemCells.getCellByName("helium3"), 60000000, 16384, 2048)); +// FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), +// ItemCells.getCellByName("Berylium"), TRContent.Dusts.PLATINUM.getStack(), 80000000, -2048, 1024)); // TODO: Fix recipe // FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), // ItemCells.getCellByName("lithium"), BlockOre.getOreByName("iridium"), 90000000, -2048, 1024)); diff --git a/src/main/java/techreborn/init/recipes/RecipeMethods.java b/src/main/java/techreborn/init/recipes/RecipeMethods.java index f52199e98..58ba9c183 100644 --- a/src/main/java/techreborn/init/recipes/RecipeMethods.java +++ b/src/main/java/techreborn/init/recipes/RecipeMethods.java @@ -29,7 +29,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.recipe.Ingredient; import reborncore.common.util.StringUtils; -import techreborn.items.ItemCells; /** * Created by Prospector @@ -50,8 +49,8 @@ public abstract class RecipeMethods { // } else if (type == Type.NUGGET) { // return ItemNuggets.getNuggetByName(name, count); // } else - if (type == Type.CELL) { - return ItemCells.getCellByName(name, count); +// if (type == Type.CELL) { +// return ItemCells.getCellByName(name, count); // } else if (type == Type.PART) { // return ItemParts.getPartByName(name, count); // } else if (type == Type.CABLE) { @@ -64,7 +63,7 @@ public abstract class RecipeMethods { // return ItemUpgrades.getUpgradeByName(name, count); // } else if (type == Type.ORE) { // return BlockOre.getOreByName(name, count); - } +// } return ItemStack.EMPTY; } diff --git a/src/main/java/techreborn/items/ItemCells.java b/src/main/java/techreborn/items/ItemCells.java deleted file mode 100644 index 2c67369e9..000000000 --- a/src/main/java/techreborn/items/ItemCells.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2018 TechReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package techreborn.items; - -import net.minecraft.item.ItemStack; -import org.apache.commons.lang3.Validate; -import net.minecraft.fluid.Fluid; -import techreborn.utils.FluidUtils; - -public class ItemCells { - public static ItemStack getCellByName(String name, int count) { - if (name.equalsIgnoreCase("empty") || name.equalsIgnoreCase("cell")) { - return ItemDynamicCell.getEmptyCell(count).copy(); - } - Fluid fluid = FluidUtils.getFluid("fluid" + name.toLowerCase()); - if (fluid == null) { - fluid = FluidUtils.getFluid(name.toLowerCase()); - if (fluid == null) { - fluid = FluidUtils.getFluid(name.toLowerCase()); - } - } - Validate.notNull(fluid, "The fluid " + name + " could not be found"); - return ItemDynamicCell.getCellWithFluid(fluid, count); - } - - public static ItemStack getCellByName(String name) { - return getCellByName(name, 1); - } - - public static boolean isCellEqual(ItemStack stack1, ItemStack stack2){ - if(stack1 == null || stack2 == null){ - return false; - } - if(stack1.isEmpty() || stack2.isEmpty()){ - return false; - } - if(stack1.getTag() == null || stack2.getTag() == null){ - return false; - } - return stack1.getTag().equals(stack2.getTag()); - } - -} diff --git a/src/main/java/techreborn/items/ItemDynamicCell.java b/src/main/java/techreborn/items/ItemDynamicCell.java index bed0a8e20..df4fa400a 100644 --- a/src/main/java/techreborn/items/ItemDynamicCell.java +++ b/src/main/java/techreborn/items/ItemDynamicCell.java @@ -24,17 +24,17 @@ package techreborn.items; +import io.github.prospector.silk.fluid.FluidInstance; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.DefaultedList; -import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.apache.commons.lang3.Validate; -import net.minecraft.fluid.Fluid; +import reborncore.common.fluid.container.GenericFluidContainer; import reborncore.common.util.ItemNBTHelper; import techreborn.TechReborn; import techreborn.init.TRContent; @@ -43,12 +43,12 @@ import techreborn.utils.FluidUtils; /** * Created by modmuss50 on 17/05/2016. */ -public class ItemDynamicCell extends Item { +public class ItemDynamicCell extends Item implements GenericFluidContainer { public static final int CAPACITY = 1000; public ItemDynamicCell() { - super(new Item.Settings().group(TechReborn.ITEMGROUP)); + super(new Item.Settings().maxCount(1).group(TechReborn.ITEMGROUP)); } @Override @@ -66,8 +66,6 @@ public class ItemDynamicCell extends Item { } } - - @Override public void appendStacks(ItemGroup tab, DefaultedList subItems) { if (!isIn(tab)) { @@ -81,22 +79,18 @@ public class ItemDynamicCell extends Item { // @Override // public String getTranslationKey(ItemStack stack) { -// FluidStack fluidStack = getFluidHandler(stack).getFluid(); +// FluidStack fluidStack = getFluidHandler(stack).getFluidInstance(); // if (fluidStack == null) // return super.getTranslationKey(stack); // return StringUtils.t("item.techreborn.cell.fluid.name").replaceAll("\\$fluid\\$", fluidStack.getLocalizedName()); // } -// -// @Override -// public ICapabilityProvider initCapabilities(ItemStack stack, CompoundTag nbt) { -// return getFluidHandler(stack); -// } -// public static ItemStack getCellWithFluid(Fluid fluid, int stackSize) { Validate.notNull(fluid); ItemStack stack = new ItemStack(TRContent.CELL); - ItemNBTHelper.getNBT(stack).putString("fluid", Registry.FLUID.getId(fluid).toString()); + GenericFluidContainer fluidContainer = GenericFluidContainer.fromStack(stack); + Validate.notNull(fluidContainer); + fluidContainer.setFluid(stack, new FluidInstance(fluid, fluidContainer.getCapacity(stack))); stack.setCount(stackSize); return stack; } @@ -110,4 +104,27 @@ public class ItemDynamicCell extends Item { } + @Override + public void setFluid(ItemStack type, FluidInstance instance) { + Validate.notNull(type, "ItemStack cannot be null!"); + CompoundTag compoundTag = new CompoundTag(); + instance.toTag(compoundTag); + ItemNBTHelper.getNBT(type).put("fluid", compoundTag); + } + + @Override + public FluidInstance getFluidInstance(ItemStack type) { + Validate.notNull(type, "ItemStack cannot be null!"); + if(ItemNBTHelper.getNBT(type).containsKey("fluid")){ + CompoundTag compoundTag = ItemNBTHelper.getNBT(type).getCompound("fluid"); + return new FluidInstance(compoundTag); + } + return new FluidInstance(); + } + + @Override + public int getCapacity(ItemStack type) { + Validate.notNull(type, "ItemStack cannot be null!"); + return CAPACITY; + } } diff --git a/src/main/java/techreborn/utils/FluidUtils.java b/src/main/java/techreborn/utils/FluidUtils.java index 722bcf767..aac73e1cb 100644 --- a/src/main/java/techreborn/utils/FluidUtils.java +++ b/src/main/java/techreborn/utils/FluidUtils.java @@ -26,11 +26,18 @@ package techreborn.utils; import io.github.prospector.silk.fluid.FluidInstance; import net.minecraft.block.Block; +import net.minecraft.block.FluidBlock; +import net.minecraft.fluid.Fluids; +import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; +import net.minecraft.util.math.Direction; import net.minecraft.util.registry.Registry; +import reborncore.common.fluid.container.GenericFluidContainer; +import reborncore.common.util.ItemUtils; import reborncore.common.util.RebornInventory; import reborncore.common.util.Tank; import net.minecraft.fluid.Fluid; +import reborncore.mixin.extensions.FluidBlockExtensions; import java.util.Collections; import java.util.List; @@ -38,24 +45,62 @@ import java.util.stream.Collectors; public class FluidUtils { - public static Fluid fluidFromBlock(Block bLock){ - throw new UnsupportedOperationException("needs coding"); + public static Fluid fluidFromBlock(Block block){ + if(block instanceof FluidBlockExtensions){ + return ((FluidBlockExtensions) block).getFluid(); + } + return Fluids.EMPTY; } public static List getAllFluids() { return Registry.FLUID.stream().collect(Collectors.toList()); } - public static Fluid getFluid(String name){ - return null; + public static boolean drainContainers(GenericFluidContainer target, Inventory inventory, int inputSlot, int outputSlot) { + ItemStack inputStack = inventory.getInvStack(inputSlot); + ItemStack outputStack = inventory.getInvStack(outputSlot); + + if (inputStack.isEmpty()) return false; + + if(inputStack.getCount() > 1){ + System.out.println("TODO make this support more than 1 item"); + return false; + } + + if (outputStack.getCount() >= outputStack.getMaxCount()) return false; + + GenericFluidContainer source = GenericFluidContainer.fromStack(inputStack); + if(source == null || source.getFluidInstance(inputStack).isEmpty()){ + return false; + } + + Fluid fluidType = source.getFluidInstance(inputStack).getFluid(); + FluidInstance contained = target.getFluidInstance(null); + + if(!contained.isEmpty()){ + //Check that the fluid we are trying to insert into is the same + if(contained.getFluid() != fluidType){ + return false; + } + } + + int transferAmount = 10; + + if(source.canExtractFluid(inputStack, fluidType, transferAmount) && target.canInsertFluid(null, fluidType, transferAmount)){ + target.insertFluid(null, fluidType, transferAmount); + source.extractFluid(inputStack, fluidType, transferAmount); + if(source.getCurrentFluidAmount(inputStack) < 1){ + inventory.setInvStack(outputSlot, inputStack); + inventory.setInvStack(inputSlot, ItemStack.EMPTY); + } + return true; + } + + return false; } - public static void drainContainers(Tank tank, RebornInventory inventory, int i, int i1) { - - } - - public static void fillContainers(Tank tank, RebornInventory inventory, int i, int i1, Fluid fluidType) { - + public static boolean fillContainers(GenericFluidContainer source, Inventory inventory, int inputSlot, int outputSlot, Fluid fluidToFill) { + return false; } public static boolean fluidEquals(Fluid fluid, Fluid fluid1) {