From 62261a5b8f7ff7233a9e3696c1dd7c31ff541d2f Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Wed, 24 Dec 2014 07:10:06 -0800 Subject: [PATCH] TankManager.tankCanDrainFluid() should take the fluid type into account (oops) --- .../forestry/core/fluids/FluidHelper.java | 33 +- .../java/forestry/core/fluids/Fluids.java | 511 +++++++++--------- .../forestry/core/fluids/TankManager.java | 72 +-- 3 files changed, 309 insertions(+), 307 deletions(-) diff --git a/src/main/java/forestry/core/fluids/FluidHelper.java b/src/main/java/forestry/core/fluids/FluidHelper.java index 952966deb..663a3e7bd 100644 --- a/src/main/java/forestry/core/fluids/FluidHelper.java +++ b/src/main/java/forestry/core/fluids/FluidHelper.java @@ -166,16 +166,14 @@ public final class FluidHelper { ItemStack emptyItem = getEmptyContainer(input); - if (output != null && emptyItem != null) { + if (output != null && emptyItem != null) if (outputSlot == inputSlot) { if (input.stackSize > 1) return false; - } else if (!StackUtils.isIdenticalItem(output, emptyItem)) { + } else if (!StackUtils.isIdenticalItem(output, emptyItem)) return false; - } else if (output.stackSize + emptyItem.stackSize > output.getMaxStackSize()) { + else if (output.stackSize + emptyItem.stackSize > output.getMaxStackSize()) return false; - } - } fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true); @@ -185,11 +183,10 @@ public final class FluidHelper { return true; } - if (output == null) { + if (output == null) inv.setInventorySlotContents(outputSlot, emptyItem); - } else { + else output.stackSize++; - } } inv.decrStackSize(inputSlot, 1); return true; @@ -207,7 +204,7 @@ public final class FluidHelper { Item item = stack.getItem(); if (item instanceof IFluidContainerItem) { - IFluidContainerItem containerItem = (IFluidContainerItem)item; + IFluidContainerItem containerItem = (IFluidContainerItem) item; FluidStack fluidStack = containerItem.getFluid(stack); return fluidStack != null && fluidStack.amount > 0; } @@ -218,7 +215,7 @@ public final class FluidHelper { public static boolean isFillableContainer(ItemStack empty, FluidStack liquid) { Item item = empty.getItem(); if (item instanceof IFluidContainerItem) { - IFluidContainerItem containerItem = (IFluidContainerItem)item; + IFluidContainerItem containerItem = (IFluidContainerItem) item; return containerItem.fill(empty, liquid, false) > 0; } @@ -237,7 +234,7 @@ public final class FluidHelper { Item item = empty.getItem(); if (item instanceof IFluidContainerItem) { - IFluidContainerItem containerItem = (IFluidContainerItem)item; + IFluidContainerItem containerItem = (IFluidContainerItem) item; FluidStack fluid = containerItem.getFluid(empty); return fluid == null || fluid.amount == 0; } @@ -252,7 +249,7 @@ public final class FluidHelper { return item.getContainerItem(container); } - + public static ItemStack getFullyDrainedContainer(ItemStack container) { return container.getItem().getContainerItem(container); } @@ -312,12 +309,6 @@ public final class FluidHelper { return containsFluidStack(stack, new FluidStack(fluid, 1)); } - public static boolean isFluidEqual(FluidStack L1, FluidStack L2) { - if (L1 == null || L2 == null) - return false; - return L1.isFluidEqual(L2); - } - public static FluidStack drainBlock(World world, int x, int y, int z, boolean doDrain) { return drainBlock(world.getBlock(x, y, z), world, x, y, z, doDrain); } @@ -364,10 +355,4 @@ public final class FluidHelper { return FluidRegistry.LAVA; return null; } - - public static boolean areEqual(Fluid fluid, FluidStack fluidStack) { - if (fluidStack != null && fluid == fluidStack.getFluid()) - return true; - return fluid == null && fluidStack == null; - } } diff --git a/src/main/java/forestry/core/fluids/Fluids.java b/src/main/java/forestry/core/fluids/Fluids.java index 0c6d9c2c3..d4c178690 100644 --- a/src/main/java/forestry/core/fluids/Fluids.java +++ b/src/main/java/forestry/core/fluids/Fluids.java @@ -33,285 +33,285 @@ import static forestry.core.items.ItemLiquidContainer.EnumContainerType; public enum Fluids { ETHANOL(new Color(255, 111, 0), 790, 1000) { - @Override - public String getTag() { - return "bioethanol"; - } + @Override + public String getTag() { + return "bioethanol"; + } - @Override - public Block makeBlock() { - return new BlockForestryFluid(this, 300, true); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this, 300, true); + } - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case BUCKET: - return ForestryItem.bucketEthanol; - case CAN: - return ForestryItem.canEthanol; - case CAPSULE: - return ForestryItem.waxCapsuleEthanol; - case REFRACTORY: - return ForestryItem.refractoryEthanol; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketEthanol; + case CAN: + return ForestryItem.canEthanol; + case CAPSULE: + return ForestryItem.waxCapsuleEthanol; + case REFRACTORY: + return ForestryItem.refractoryEthanol; + default: + return null; + } + } + }, BIOMASS(new Color(100, 132, 41), 400, 6560) { - @Override - public Block makeBlock() { - return new BlockForestryFluid(this, 100, true); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this, 100, true); + } - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case BUCKET: - return ForestryItem.bucketBiomass; - case CAN: - return ForestryItem.canBiomass; - case CAPSULE: - return ForestryItem.waxCapsuleBiomass; - case REFRACTORY: - return ForestryItem.refractoryBiomass; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketBiomass; + case CAN: + return ForestryItem.canBiomass; + case CAPSULE: + return ForestryItem.waxCapsuleBiomass; + case REFRACTORY: + return ForestryItem.refractoryBiomass; + default: + return null; + } + } + }, GLASS(new Color(164, 164, 164), 2400, 10000) { - @Override - public int getTemperature() { - return 1200; - } + @Override + public int getTemperature() { + return 1200; + } - @Override - public Block makeBlock() { - return new BlockForestryFluid(this, 0, true); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this, 0, true); + } - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case BUCKET: - return ForestryItem.bucketGlass; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketGlass; + default: + return null; + } + } + }, HONEY(new Color(255, 196, 35), 1420, 73600) { - @Override - public String getTag() { - return "for.honey"; - } + @Override + public String getTag() { + return "for.honey"; + } - @Override - public Block makeBlock() { - return new BlockForestryFluid(this); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case BUCKET: - return ForestryItem.bucketHoney; - case CAN: - return ForestryItem.canHoney; - case CAPSULE: - return ForestryItem.waxCapsuleHoney; - case REFRACTORY: - return ForestryItem.refractoryHoney; - default: - return null; - } - } + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketHoney; + case CAN: + return ForestryItem.canHoney; + case CAPSULE: + return ForestryItem.waxCapsuleHoney; + case REFRACTORY: + return ForestryItem.refractoryHoney; + default: + return null; + } + } - @Override - public void setProperties(ItemLiquidContainer liquidContainer) { - if (liquidContainer.getType() != EnumContainerType.BUCKET) - liquidContainer.setDrink(Defaults.FOOD_HONEY_HEAL, Defaults.FOOD_HONEY_SATURATION); - } - }, + @Override + public void setProperties(ItemLiquidContainer liquidContainer) { + if (liquidContainer.getType() != EnumContainerType.BUCKET) + liquidContainer.setDrink(Defaults.FOOD_HONEY_HEAL, Defaults.FOOD_HONEY_SATURATION); + } + }, LEGACY_HONEY { - @Override - public String getTag() { - return "honey"; - } - }, + @Override + public String getTag() { + return "honey"; + } + }, ICE(new Color(175, 242, 255), 920, 1000) { - @Override - public int getTemperature() { - return 265; - } + @Override + public int getTemperature() { + return 265; + } - @Override - public Block makeBlock() { - return new BlockForestryFluid(this); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case BUCKET: - return ForestryItem.bucketIce; - case CAN: - return ForestryItem.canIce; - case CAPSULE: - return ForestryItem.waxCapsuleIce; - case REFRACTORY: - return ForestryItem.refractoryIce; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketIce; + case CAN: + return ForestryItem.canIce; + case CAPSULE: + return ForestryItem.waxCapsuleIce; + case REFRACTORY: + return ForestryItem.refractoryIce; + default: + return null; + } + } + }, JUICE(new Color(168, 201, 114)) { - @Override - public Block makeBlock() { - return new BlockForestryFluid(this); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case BUCKET: - return ForestryItem.bucketJuice; - case CAN: - return ForestryItem.canJuice; - case CAPSULE: - return ForestryItem.waxCapsuleJuice; - case REFRACTORY: - return ForestryItem.refractoryJuice; - default: - return null; - } - } + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketJuice; + case CAN: + return ForestryItem.canJuice; + case CAPSULE: + return ForestryItem.waxCapsuleJuice; + case REFRACTORY: + return ForestryItem.refractoryJuice; + default: + return null; + } + } - @Override - public void setProperties(ItemLiquidContainer liquidContainer) { - if (liquidContainer.getType() != EnumContainerType.BUCKET) - liquidContainer.setDrink(Defaults.FOOD_JUICE_HEAL, Defaults.FOOD_JUICE_SATURATION); - } - }, + @Override + public void setProperties(ItemLiquidContainer liquidContainer) { + if (liquidContainer.getType() != EnumContainerType.BUCKET) + liquidContainer.setDrink(Defaults.FOOD_JUICE_HEAL, Defaults.FOOD_JUICE_SATURATION); + } + }, MILK(new Color(255, 255, 255), 1030, 3000) { - @Override - public Block makeBlock() { - return new BlockForestryFluid(this); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } - @Override - public List getOtherContainers() { - return Arrays.asList( - new ItemStack(Items.milk_bucket) - ); - } - }, + @Override + public List getOtherContainers() { + return Arrays.asList( + new ItemStack(Items.milk_bucket) + ); + } + }, SEEDOIL(new Color(255, 255, 168), 885, 5000) { - @Override - public Block makeBlock() { - return new BlockForestryFluid(this, 2, true); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this, 2, true); + } - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case BUCKET: - return ForestryItem.bucketSeedoil; - case CAN: - return ForestryItem.canSeedOil; - case CAPSULE: - return ForestryItem.waxCapsuleSeedOil; - case REFRACTORY: - return ForestryItem.refractorySeedOil; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketSeedoil; + case CAN: + return ForestryItem.canSeedOil; + case CAPSULE: + return ForestryItem.waxCapsuleSeedOil; + case REFRACTORY: + return ForestryItem.refractorySeedOil; + default: + return null; + } + } + }, SHORT_MEAD(new Color(239, 154, 56), 1000, 1200) { - @Override - public String getTag() { - return "short.mead"; - } + @Override + public String getTag() { + return "short.mead"; + } - @Override - public Block makeBlock() { - return new BlockForestryFluid(this); - } + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case BUCKET: - return ForestryItem.bucketShortMead; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketShortMead; + default: + return null; + } + } + }, // Vanilla WATER(new Color(0x2432ec)) { - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case CAN: - return ForestryItem.canWater; - case CAPSULE: - return ForestryItem.waxCapsuleWater; - case REFRACTORY: - return ForestryItem.refractoryWater; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case CAN: + return ForestryItem.canWater; + case CAPSULE: + return ForestryItem.waxCapsuleWater; + case REFRACTORY: + return ForestryItem.refractoryWater; + default: + return null; + } + } + }, LAVA(new Color(0xfd461f)) { - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case CAN: - return ForestryItem.canLava; - case REFRACTORY: - return ForestryItem.refractoryLava; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case CAN: + return ForestryItem.canLava; + case REFRACTORY: + return ForestryItem.refractoryLava; + default: + return null; + } + } + }, // BuildCraft FUEL(new Color(0xffff00)) { - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case CAN: - return ForestryItem.canFuel; - case CAPSULE: - return ForestryItem.waxCapsuleFuel; - case REFRACTORY: - return ForestryItem.refractoryFuel; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case CAN: + return ForestryItem.canFuel; + case CAPSULE: + return ForestryItem.waxCapsuleFuel; + case REFRACTORY: + return ForestryItem.refractoryFuel; + default: + return null; + } + } + }, OIL(new Color(0x404040)) { - @Override - public ForestryItem getContainerForType(EnumContainerType type) { - switch (type) { - case CAN: - return ForestryItem.canOil; - case CAPSULE: - return ForestryItem.waxCapsuleOil; - case REFRACTORY: - return ForestryItem.refractoryOil; - default: - return null; - } - } - }, + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case CAN: + return ForestryItem.canOil; + case CAPSULE: + return ForestryItem.waxCapsuleOil; + case REFRACTORY: + return ForestryItem.refractoryOil; + default: + return null; + } + } + }, // Railcraft CREOSOTE, STEAM, // Thermal Expansion @@ -383,8 +383,21 @@ public enum Fluids { return containerStack != null && FluidHelper.containsFluid(containerStack, getFluid()); } - /** FluidBlock and Container registration */ + public static boolean areEqual(Fluid fluid, FluidStack fluidStack) { + if (fluidStack != null && fluid == fluidStack.getFluid()) + return true; + return fluid == null && fluidStack == null; + } + public static boolean areEqual(FluidStack a, FluidStack b) { + if (a == b) + return true; + if (a == null || b == null) + return false; + return a.isFluidEqual(b); + } + + /** FluidBlock and Container registration */ /** * Add the filled containers for this fluid. * They will be automatically created and registered. diff --git a/src/main/java/forestry/core/fluids/TankManager.java b/src/main/java/forestry/core/fluids/TankManager.java index 85b348684..9510e8508 100644 --- a/src/main/java/forestry/core/fluids/TankManager.java +++ b/src/main/java/forestry/core/fluids/TankManager.java @@ -68,12 +68,8 @@ public class TankManager extends ForwardingList implements IFluidH } @Override - public boolean addAll(Collection collection) { - boolean changed = false; - for (StandardTank tank : collection) - changed |= add(tank); - - return changed; + public final boolean addAll(Collection collection) { + return standardAddAll(collection); } @Override @@ -114,8 +110,9 @@ public class TankManager extends ForwardingList implements IFluidH } public void writePacketData(DataOutputStream data) throws IOException { - for (int i = 0; i < tanks.size(); i++) + for (int i = 0; i < tanks.size(); i++) { writePacketData(data, i); + } } public void writePacketData(DataOutputStream data, int tankIndex) throws IOException { @@ -132,8 +129,9 @@ public class TankManager extends ForwardingList implements IFluidH } public void readPacketData(DataInputStream data) throws IOException { - for (int i = 0; i < tanks.size(); i++) + for (int i = 0; i < tanks.size(); i++) { readPacketData(data, i); + } } public void readPacketData(DataInputStream data, int tankIndex) throws IOException { @@ -149,8 +147,9 @@ public class TankManager extends ForwardingList implements IFluidH } public void initGuiData(Container container, ICrafting player) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { initGuiData(container, player, tank.getTankIndex()); + } } public void initGuiData(Container container, ICrafting player, int tankIndex) { @@ -166,12 +165,13 @@ public class TankManager extends ForwardingList implements IFluidH player.sendProgressBarUpdate(container, tankIndex * NETWORK_DATA, fluidId); PacketGuiInteger packet = new PacketGuiInteger(container.windowId, tankIndex * NETWORK_DATA + 1, fluidAmount); - Proxies.net.sendToPlayer(packet, (EntityPlayerMP)player); + Proxies.net.sendToPlayer(packet, (EntityPlayerMP) player); } public void updateGuiData(Container container, List crafters) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { updateGuiData(container, crafters, tank.getTankIndex()); + } } public void updateGuiData(Container container, List crafters, int tankIndex) { @@ -226,16 +226,16 @@ public class TankManager extends ForwardingList implements IFluidH int color = tank.colorCache; boolean newLiquid = false; switch (messageId % NETWORK_DATA) { - case 0: - fluidId = data; - newLiquid = true; - break; - case 1: - amount = data; - break; - case 2: - color = data; - break; + case 0: + fluidId = data; + newLiquid = true; + break; + case 1: + amount = data; + break; + case 2: + color = data; + break; } if (newLiquid) { fluidStack = new FluidStack(fluidId, 0); @@ -247,9 +247,10 @@ public class TankManager extends ForwardingList implements IFluidH @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { if (tankAcceptsFluid(tank, resource)) return fill(tank.getTankIndex(), resource, doFill); + } return FakeTank.INSTANCE.fill(resource, doFill); } @@ -267,9 +268,10 @@ public class TankManager extends ForwardingList implements IFluidH @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { if (tankCanDrain(tank)) return drain(tank.getTankIndex(), maxDrain, doDrain); + } return FakeTank.INSTANCE.drain(maxDrain, doDrain); } @@ -285,9 +287,10 @@ public class TankManager extends ForwardingList implements IFluidH } public FluidStack drain(FluidStack resource, boolean doDrain) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { if (tankCanDrainFluid(tank, resource)) return tank.drain(resource.amount, doDrain); + } return null; } @@ -309,8 +312,9 @@ public class TankManager extends ForwardingList implements IFluidH @Override public FluidTankInfo[] getTankInfo(ForgeDirection direction) { FluidTankInfo[] info = new FluidTankInfo[size()]; - for (int i = 0; i < size(); i++) + for (int i = 0; i < size(); i++) { info[i] = get(i).getInfo(); + } return info; } @@ -347,9 +351,10 @@ public class TankManager extends ForwardingList implements IFluidH } public boolean accepts(Fluid fluid) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { if (tank.accepts(fluid)) return true; + } return false; } @@ -359,22 +364,21 @@ public class TankManager extends ForwardingList implements IFluidH return false; if (!tank.canBeFilledExternally()) return false; - if (tank.fill(fluidStack, false) > 0) - return true; - return false; + return tank.fill(fluidStack, false) > 0; } private boolean tankCanDrain(StandardTank tank) { if (!tank.canBeDrainedExternally()) return false; FluidStack drained = tank.drain(1, false); - if (drained != null && drained.amount > 0) - return true; - return false; + return drained != null && drained.amount > 0; } private boolean tankCanDrainFluid(StandardTank tank, FluidStack fluidStack) { - return fluidStack != null && tankCanDrain(tank); + if (fluidStack == null) + return false; + if (!Fluids.areEqual(tank.getFluidType(), fluidStack)) + return false; + return tankCanDrain(tank); } - }