Skip to content

Commit

Permalink
Refactored Tank Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryLoenwind committed May 5, 2015
1 parent 23a8a8b commit 8ecc703
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 197 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package crazypants.enderio.machine.generator.zombie;

import crazypants.enderio.tool.SmartTank;

public interface IHasNutrientTank {

NutrientTank getNutrientTank();
SmartTank getNutrientTank();

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import crazypants.enderio.machine.generator.AbstractGeneratorEntity;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.power.PowerDistributor;
import crazypants.enderio.tool.SmartTank;
import crazypants.util.BlockCoord;
import crazypants.util.FluidUtil;
import crazypants.util.ITankAccess;
Expand All @@ -26,7 +27,7 @@ public class TileZombieGenerator extends AbstractGeneratorEntity implements IFlu

private static int IO_MB_TICK = 250;

final NutrientTank fuelTank = new NutrientTank(FluidContainerRegistry.BUCKET_VOLUME * 2);
final SmartTank fuelTank = new SmartTank(EnderIO.fluidNutrientDistillation, FluidContainerRegistry.BUCKET_VOLUME * 2);

int outputPerTick = Config.zombieGeneratorRfPerTick;
int tickPerBucketOfFuel = Config.zombieGeneratorTicksPerBucketFuel;
Expand Down Expand Up @@ -274,7 +275,7 @@ public void setTanksDirty() {
}

@Override
public NutrientTank getNutrientTank() {
public SmartTank getNutrientTank() {
return fuelTank;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
import crazypants.enderio.gui.TextFieldEIO;
import crazypants.enderio.gui.TooltipAddera;
import crazypants.enderio.gui.VScrollbarEIO;
import crazypants.enderio.machine.generator.zombie.NutrientTank;
import crazypants.enderio.machine.gui.GuiMachineBase;
import crazypants.enderio.machine.invpanel.client.DatabaseView;
import crazypants.enderio.machine.invpanel.client.ICraftingHelper;
import crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient;
import crazypants.enderio.machine.invpanel.client.ItemEntry;
import crazypants.enderio.machine.invpanel.client.SortOrder;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.tool.SmartTank;
import crazypants.gui.GhostSlot;
import crazypants.gui.GuiToolTip;
import crazypants.render.RenderUtil;
Expand Down Expand Up @@ -198,7 +198,7 @@ protected void drawGuiContainerBackgroundLayer(float par1, int mouseX, int mouse
fr.drawString(headerInventory, sx + 38, sy + 120, headerColor);

TileInventoryPanel te = getTileEntity();
NutrientTank fuelTank = te.fuelTank;
SmartTank fuelTank = te.fuelTank;
if(fuelTank.getFluidAmount() > 0) {
RenderUtil.renderGuiTank(fuelTank.getFluid(), fuelTank.getCapacity(), fuelTank.getFluidAmount(), sx + 12, sy + 132, zLevel, 16, 47);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.conduit.TileConduitBundle;
import crazypants.enderio.conduit.item.FilterRegister;
Expand All @@ -20,12 +21,12 @@
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.machine.generator.zombie.IHasNutrientTank;
import crazypants.enderio.machine.generator.zombie.NutrientTank;
import crazypants.enderio.machine.generator.zombie.PacketNutrientTank;
import crazypants.enderio.machine.invpanel.client.ClientDatabaseManager;
import crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient;
import crazypants.enderio.machine.invpanel.server.InventoryDatabaseServer;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.tool.SmartTank;
import crazypants.util.ITankAccess;

public class TileInventoryPanel extends AbstractMachineEntity implements IFluidHandler, ITankAccess, IHasNutrientTank {
Expand All @@ -35,7 +36,7 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
public static final int SLOT_VIEW_FILTER = 10;
public static final int SLOT_RETURN_START = 11;

protected final NutrientTank fuelTank;
protected final SmartTank fuelTank;
protected boolean tanksDirty;

private InventoryDatabaseServer dbServer;
Expand All @@ -48,7 +49,7 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH

public TileInventoryPanel() {
super(new SlotDefinition(0, 8, 11, 20, 21, 20));
this.fuelTank = new NutrientTank(2000);
this.fuelTank = new SmartTank(EnderIO.fluidNutrientDistillation, 2000);
}

public InventoryDatabaseServer getDatabaseServer() {
Expand Down Expand Up @@ -294,7 +295,7 @@ public void setTanksDirty() {
}

@Override
public NutrientTank getNutrientTank() {
public SmartTank getNutrientTank() {
return fuelTank;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.machine.generator.zombie.IHasNutrientTank;
import crazypants.enderio.machine.generator.zombie.NutrientTank;
import crazypants.enderio.machine.generator.zombie.PacketNutrientTank;
import crazypants.enderio.machine.wireless.WirelessChargedLocation;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.tool.SmartTank;
import crazypants.enderio.xp.ExperienceContainer;
import crazypants.enderio.xp.IHaveExperience;
import crazypants.enderio.xp.PacketExperianceContainer;
Expand All @@ -63,7 +63,7 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle

protected WirelessChargedLocation chargedLocation;

final NutrientTank fuelTank = new NutrientTank(FluidContainerRegistry.BUCKET_VOLUME * 2);
final SmartTank fuelTank = new SmartTank(EnderIO.fluidNutrientDistillation, FluidContainerRegistry.BUCKET_VOLUME * 2);

int lastFluidLevelUpdate;

Expand Down Expand Up @@ -569,7 +569,7 @@ public void setTanksDirty() {
}

@Override
public NutrientTank getNutrientTank() {
public SmartTank getNutrientTank() {
return fuelTank;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidRegistry;

import org.lwjgl.opengl.GL11;

Expand Down Expand Up @@ -170,7 +171,7 @@ private ResourceLocation getLiquidSheet() {

private IIcon getLiquidTexture() {
if(tex == null) {
tex = ReservoirTank.WATER.getFluid().getStillIcon();
tex = FluidRegistry.WATER.getStillIcon();
}
return tex;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraftforge.fluids.IFluidHandler;
import crazypants.enderio.EnderIO;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.tool.SmartTank;
import crazypants.render.BoundingBox;
import crazypants.util.BlockCoord;
import crazypants.util.ITankAccess;
Expand Down Expand Up @@ -66,9 +67,9 @@ public boolean isTop(ForgeDirection side) {
// Position within multiblock
Pos pos = Pos.UNKNOWN;

ReservoirTank tank = new ReservoirTank(BUCKET_VOLUME);
SmartTank tank = new SmartTank(FluidRegistry.WATER, BUCKET_VOLUME);

ReservoirTank regenTank = null;
SmartTank regenTank = null;

boolean autoEject;

Expand Down Expand Up @@ -105,8 +106,8 @@ public void doUpdate() {
if(autoEject && neighboursDirty) {
doUpdateTankNeighbours();
}
if(autoEject && tankNeighbours != null && !tankNeighbours.isEmpty() && tank.getAmount() > 0) {
int ejectable = tank.getAmount();
if(autoEject && tankNeighbours != null && !tankNeighbours.isEmpty() && tank.getFluidAmount() > 0) {
int ejectable = tank.getFluidAmount();
int amountPerNeighbour = ejectable / tankNeighbours.size();
FluidStack source = WATER_BUCKET.copy();
int used = 0;
Expand Down Expand Up @@ -256,13 +257,14 @@ public void readCustomNBT(NBTTagCompound nbtRoot) {
if(liquid != null) {
tank.setFluid(liquid);
} else {
tank.setAmount(0);
tank.setFluidAmount(0);
}

if(regenLiquid == null) {
regenTank = null;
} else {
regenTank = new ReservoirTank(regenLiquid, BUCKET_VOLUME * 2);
regenTank = new SmartTank(FluidRegistry.WATER, BUCKET_VOLUME * 2);
regenTank.setFluidAmount(regenLiquid.amount);
}

boolean wasMulti = isMultiblock();
Expand Down Expand Up @@ -416,19 +418,19 @@ private void setMultiblock(BlockCoord[] mb) {

if(isMaster()) {

regenTank = new ReservoirTank(BUCKET_VOLUME * 2);
regenTank = new SmartTank(FluidRegistry.WATER, BUCKET_VOLUME * 2);
tank.setCapacity(BUCKET_VOLUME * 2);
for (BlockCoord bc : multiblock) {
TileReservoir res = getReservoir(bc);
if(res != null) {
FluidStack drained = res.doDrain(ForgeDirection.UNKNOWN, regenTank.getAvailableSpace(), true);
if(drained != null) {
regenTank.addAmount(drained.amount);
regenTank.addFluidAmount(drained.amount);
}
// incase regen tank is full, add to normal tank
drained = res.doDrain(ForgeDirection.UNKNOWN, tank.getAvailableSpace(), true);
if(drained != null) {
tank.addAmount(drained.amount);
tank.addFluidAmount(drained.amount);
}
}
}
Expand Down Expand Up @@ -681,10 +683,10 @@ public FluidTank[] getOutputTanks() {
@Override
public void setTanksDirty() {
if (isMaster() && regenTank != null && tank != null) {
if (!regenTank.isFull() && tank.getAmount() > 0) {
int toMove = Math.min(tank.getAmount(), regenTank.getCapacity() - regenTank.getAmount());
regenTank.setAmount(regenTank.getAmount() + toMove);
tank.setAmount(tank.getAmount() - toMove);
if (!regenTank.isFull() && tank.getFluidAmount() > 0) {
int toMove = Math.min(tank.getFluidAmount(), regenTank.getCapacity() - regenTank.getFluidAmount());
regenTank.setFluidAmount(regenTank.getFluidAmount() + toMove);
tank.setFluidAmount(tank.getFluidAmount() - toMove);
}
}
tankDirty = true;
Expand Down
Loading

0 comments on commit 8ecc703

Please sign in to comment.