Skip to content

Commit

Permalink
start test change fluid save ID to name
Browse files Browse the repository at this point in the history
  • Loading branch information
aagrishankov committed Oct 28, 2020
1 parent 66ce5b4 commit a787510
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
37 changes: 16 additions & 21 deletions src/main/scala/extracells/container/ContainerFluidInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]));
}
}
}
}
Expand All @@ -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:
Expand All @@ -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);
Expand Down

0 comments on commit a787510

Please sign in to comment.