From 8c6c348daf904c08658450b398b11cb516aa934d Mon Sep 17 00:00:00 2001 From: tartaric_acid Date: Sun, 24 Dec 2023 16:48:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E6=B7=BB=E5=8A=A0=E5=82=A8?= =?UTF-8?q?=E7=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backpack/TankBackpackContainerScreen.java | 1 + .../entity/backpack/TankBackpack.java | 2 +- .../backpack/data/FurnaceBackpackData.java | 4 --- .../backpack/data/TankBackpackData.java | 27 ++++++++++++++---- .../backpack/TankBackpackContainer.java | 23 +++++++++++++-- .../textures/gui/maid_tank.png | Bin 15890 -> 16363 bytes 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/maid/backpack/TankBackpackContainerScreen.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/maid/backpack/TankBackpackContainerScreen.java index 16d52e7d7..f12d73516 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/maid/backpack/TankBackpackContainerScreen.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/gui/entity/maid/backpack/TankBackpackContainerScreen.java @@ -28,5 +28,6 @@ protected void renderBg(GuiGraphics graphics, float partialTicks, int x, int y) RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderTexture(0, BACKPACK); graphics.blit(BACKPACK, leftPos + 85, topPos + 36, 0, 0, 165, 128); + graphics.drawString(font, this.menu.getFluidCount() + " mB", leftPos + 145, topPos + 130, 0x000000, false); } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/TankBackpack.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/TankBackpack.java index 41c929c3e..227f6b3ff 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/TankBackpack.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/TankBackpack.java @@ -60,7 +60,7 @@ public boolean hasBackpackData() { @Nullable @Override public IBackpackData getBackpackData(EntityMaid maid) { - return new TankBackpackData(); + return new TankBackpackData(maid); } @Override diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/data/FurnaceBackpackData.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/data/FurnaceBackpackData.java index f31c0958d..9179a50e1 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/data/FurnaceBackpackData.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/data/FurnaceBackpackData.java @@ -154,13 +154,9 @@ public void setItem(int index, ItemStack stack) { ItemStack slotItem = this.getItem(index); boolean isSameItem = !stack.isEmpty() && ItemStack.isSameItemSameTags(slotItem, stack); super.setItem(index, stack); - if (stack.getCount() > this.getMaxStackSize()) { - stack.setCount(this.getMaxStackSize()); - } if (index == 0 && !isSameItem) { this.cookingTotalTime = getTotalCookTime(this.level); this.cookingProgress = 0; - this.setChanged(); } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/data/TankBackpackData.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/data/TankBackpackData.java index b0b1a171a..801ec2b3a 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/data/TankBackpackData.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/backpack/data/TankBackpackData.java @@ -7,19 +7,22 @@ import net.minecraft.world.SimpleContainer; import net.minecraft.world.inventory.ContainerData; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidActionResult; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.templates.FluidTank; +import net.minecraftforge.items.ItemHandlerHelper; +import net.minecraftforge.items.wrapper.CombinedInvWrapper; public class TankBackpackData extends SimpleContainer implements IBackpackData { public static final int CAPACITY = 10 * FluidType.BUCKET_VOLUME; - private static final int INPUT_INDEX = 0; - private static final int OUTPUT_INDEX = 1; + private final EntityMaid maid; private final FluidTank tank = new FluidTank(CAPACITY); private final ContainerData dataAccess = new ContainerData() { public int get(int index) { if (index == 0) { - TankBackpackData.this.tank.getFluidAmount(); + return TankBackpackData.this.tank.getFluidAmount(); } return 0; } @@ -38,13 +41,27 @@ public int getCount() { } }; - public TankBackpackData() { - super(2); + public TankBackpackData(EntityMaid maid) { + super(1); + this.maid = maid; } @Override public void setItem(int index, ItemStack stack) { super.setItem(index, stack); + CombinedInvWrapper availableInv = this.maid.getAvailableInv(false); + FluidActionResult fluidActionResult = FluidUtil.tryFillContainerAndStow(stack, tank, availableInv, Integer.MAX_VALUE, null, true); + if (!fluidActionResult.isSuccess()) { + fluidActionResult = FluidUtil.tryEmptyContainerAndStow(stack, tank, availableInv, Integer.MAX_VALUE, null, true); + } + if (fluidActionResult.isSuccess()) { + ItemStack result = fluidActionResult.getResult(); + ItemStack remainder = ItemHandlerHelper.insertItemStacked(availableInv, result, false); + if (!remainder.isEmpty()) { + this.maid.spawnAtLocation(remainder); + } + this.getItem(0).shrink(result.getCount()); + } } @Override diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/inventory/container/backpack/TankBackpackContainer.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/inventory/container/backpack/TankBackpackContainer.java index 78d21e0ec..554f74588 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/inventory/container/backpack/TankBackpackContainer.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/inventory/container/backpack/TankBackpackContainer.java @@ -2,11 +2,14 @@ import com.github.tartaricacid.touhoulittlemaid.entity.backpack.data.TankBackpackData; import com.github.tartaricacid.touhoulittlemaid.inventory.container.MaidMainContainer; +import net.minecraft.world.Container; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.ContainerData; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.extensions.IForgeMenuType; +import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; @@ -20,11 +23,10 @@ public TankBackpackContainer(int id, Inventory inventory, int entityId) { if (this.getMaid().getBackpackData() instanceof TankBackpackData) { tankData = (TankBackpackData) this.getMaid().getBackpackData(); } else { - tankData = new TankBackpackData(); + tankData = new TankBackpackData(this.getMaid()); } this.data = tankData.getDataAccess(); - this.addSlot(new Slot(tankData, 0, 161, 101)); - this.addSlot(new Slot(tankData, 1, 161, 141)); + this.addSlot(new TankInputSlot(tankData, 0, 161, 101)); this.addDataSlots(this.data); } @@ -42,4 +44,19 @@ protected void addBackpackInv(Inventory inventory) { public int getTankPercent() { return this.data.get(0) / TankBackpackData.CAPACITY; } + + public int getFluidCount() { + return this.data.get(0); + } + + public static class TankInputSlot extends Slot { + public TankInputSlot(Container pContainer, int pSlot, int pX, int pY) { + super(pContainer, pSlot, pX, pY); + } + + @Override + public boolean mayPlace(ItemStack stack) { + return FluidUtil.getFluidHandler(stack).isPresent(); + } + } } diff --git a/src/main/resources/assets/touhou_little_maid/textures/gui/maid_tank.png b/src/main/resources/assets/touhou_little_maid/textures/gui/maid_tank.png index 8ebb71365e468072af63f082f12579e6ac6460ee..ec04f34ff78ed4b876fccf22072a0f29ea30ce39 100644 GIT binary patch delta 1622 zcmb_adrVVj6hHU2h4PT61C$~aR&n9c)&hM1r7%HY8IVaNI5&C7!)-jI;Fv@2MW%Dh zHabg010r=LIAlZ~E({S1RvbkKxFH1CD7f!d*+}+>BUy9Od(QX$&iS41 zch2d;NkSpQ#kU$I1vGQtIKIC`Ad>L-$~Icy+7PE#y)59R2t?v!zIW0NfzW$Ll5di? zNR-0&7N+u2`Dr3CUnoer+(9qLl|zg$nmp;S(#=HrpR$x6nFOq5`_bg6($d7-DJ3H* zD?Rmql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