From a78751024090b13b4cc7c5516c5b7331af258485 Mon Sep 17 00:00:00 2001 From: Lex Date: Wed, 28 Oct 2020 22:00:07 +0700 Subject: [PATCH] start test change fluid save ID to name --- .../container/ContainerFluidInterface.java | 37 ++++++++----------- .../packet/part/PacketFluidInterface.java | 24 ++++++------ 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/main/scala/extracells/container/ContainerFluidInterface.java b/src/main/scala/extracells/container/ContainerFluidInterface.java index f4f2aa8..1b300cb 100644 --- a/src/main/scala/extracells/container/ContainerFluidInterface.java +++ b/src/main/scala/extracells/container/ContainerFluidInterface.java @@ -71,6 +71,14 @@ private int getFluidID(ForgeDirection side) { return fluid.getID(); } + private String getFluidName(ForgeDirection side) { + Fluid fluid = this.fluidInterface.getFilter(side); + if (fluid == null) { + return ""; + } + return fluid.getName(); + } + @Override public void onContainerClosed(EntityPlayer player) { super.onContainerClosed(player); @@ -139,27 +147,14 @@ public ItemStack transferStackInSlot(EntityPlayer player, int slotnumber) { @Override public void updateContainer() { - new PacketFluidInterface(new FluidStack[] { - this.fluidInterface.getFluidTank( - ForgeDirection.getOrientation(0)).getFluid(), - this.fluidInterface.getFluidTank( - ForgeDirection.getOrientation(1)).getFluid(), - this.fluidInterface.getFluidTank( - ForgeDirection.getOrientation(2)).getFluid(), - this.fluidInterface.getFluidTank( - ForgeDirection.getOrientation(3)).getFluid(), - this.fluidInterface.getFluidTank( - ForgeDirection.getOrientation(4)).getFluid(), - this.fluidInterface.getFluidTank( - ForgeDirection.getOrientation(5)).getFluid() }, - new Integer[] { getFluidID(ForgeDirection.getOrientation(0)), - getFluidID(ForgeDirection.getOrientation(1)), - getFluidID(ForgeDirection.getOrientation(2)), - getFluidID(ForgeDirection.getOrientation(3)), - getFluidID(ForgeDirection.getOrientation(4)), - getFluidID(ForgeDirection.getOrientation(5)) }, - this.player).sendPacketToPlayer(this.player); - + FluidStack[] fluidStacks = new FluidStack[6]; + String[] fluidNames = new String[6]; + for (int i = 0; i < 6; i++) { + ForgeDirection location = ForgeDirection.getOrientation(i); + fluidStacks[i] = fluidInterface.getFluidTank(location).getFluid(); + fluidNames[i] = getFluidName(location); + } + new PacketFluidInterface(fluidStacks, fluidNames, this.player).sendPacketToPlayer(this.player); } } diff --git a/src/main/scala/extracells/network/packet/part/PacketFluidInterface.java b/src/main/scala/extracells/network/packet/part/PacketFluidInterface.java index 4d922c3..16e576d 100644 --- a/src/main/scala/extracells/network/packet/part/PacketFluidInterface.java +++ b/src/main/scala/extracells/network/packet/part/PacketFluidInterface.java @@ -17,13 +17,13 @@ public class PacketFluidInterface extends AbstractPacket { FluidStack[] tank; - Integer[] filter; + String[] filter; int fluidID; int filterSlot; public PacketFluidInterface() {} - public PacketFluidInterface(FluidStack[] _tank, Integer[] _filter, + public PacketFluidInterface(FluidStack[] _tank, String[] _filter, EntityPlayer _player) { super(_player); this.mode = 0; @@ -73,10 +73,11 @@ private void mode0() { container.fluidInterface.setFluidTank( ForgeDirection.getOrientation(i), this.tank[i]); } - for (int i = 0; i < this.filter.length; i++) { - if (gui.filter[i] != null) + for (int i = 0; i < filter.length; i++) { + if (gui.filter[i] != null) { gui.filter[i].setFluid(FluidRegistry - .getFluid(this.filter[i])); + .getFluid(filter[i])); + } } } } @@ -95,12 +96,13 @@ public void readData(ByteBuf in) { else this.tank[i] = null; } - this.filter = new Integer[tag.getInteger("lengthFilter")]; + this.filter = new String[tag.getInteger("lengthFilter")]; for (int i = 0; i < this.filter.length; i++) { - if (tag.hasKey("filter#" + i)) - this.filter[i] = tag.getInteger("filter#" + i); - else - this.filter[i] = -1; + if (tag.hasKey("filter#" + i)) { + this.filter[i] = tag.getString("filter#" + i); + } else { + this.filter[i] = ""; + } } break; case 1: @@ -127,7 +129,7 @@ public void writeData(ByteBuf out) { tag.setInteger("lengthFilter", this.filter.length); for (int i = 0; i < this.filter.length; i++) { if (this.filter[i] != null) { - tag.setInteger("filter#" + i, this.filter[i]); + tag.setString("filter#" + i, this.filter[i]); } } ByteBufUtils.writeTag(out, tag);