Fixed Solar Evaporation Plant memory leaks

This commit is contained in:
aidancbrady 2016-01-13 10:53:16 -05:00
parent a8efb3b0de
commit e950c645e7
3 changed files with 56 additions and 20 deletions

View file

@ -4,14 +4,14 @@ import java.util.HashSet;
import java.util.Set;
import mekanism.api.Coord4D;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntitySolarEvaporationBlock extends TileEntityContainerBlock
{
public TileEntitySolarEvaporationController master;
public Coord4D master;
public boolean attempted;
@ -40,7 +40,7 @@ public class TileEntitySolarEvaporationBlock extends TileEntityContainerBlock
attempted = false;
}
public void addToStructure(TileEntitySolarEvaporationController controller)
public void addToStructure(Coord4D controller)
{
master = controller;
}
@ -57,7 +57,12 @@ public class TileEntitySolarEvaporationBlock extends TileEntityContainerBlock
if(master != null)
{
master.refresh();
TileEntitySolarEvaporationController tile = getController();
if(tile != null)
{
((TileEntitySolarEvaporationController)tile).refresh();
}
}
}
@ -68,9 +73,11 @@ public class TileEntitySolarEvaporationBlock extends TileEntityContainerBlock
if(!worldObj.isRemote)
{
if(master != null)
TileEntitySolarEvaporationController tile = getController();
if(tile != null)
{
master.refresh();
((TileEntitySolarEvaporationController)tile).refresh();
}
else {
updateController();
@ -91,6 +98,21 @@ public class TileEntitySolarEvaporationBlock extends TileEntityContainerBlock
}
}
public TileEntitySolarEvaporationController getController()
{
if(master != null)
{
TileEntity tile = master.getTileEntity(worldObj);
if(tile instanceof TileEntitySolarEvaporationController)
{
return (TileEntitySolarEvaporationController)tile;
}
}
return null;
}
public class ControllerFinder
{
public TileEntitySolarEvaporationController found;

View file

@ -43,7 +43,7 @@ public class TileEntitySolarEvaporationController extends TileEntitySolarEvapora
public FluidTank inputTank = new FluidTank(0);
public FluidTank outputTank = new FluidTank(MAX_OUTPUT);
public Set<TileEntitySolarEvaporationBlock> tankParts = new HashSet<TileEntitySolarEvaporationBlock>();
public Set<Coord4D> tankParts = new HashSet<Coord4D>();
public ISalinationSolar[] solars = new ISalinationSolar[4];
public boolean temperatureSet = false;
@ -547,8 +547,8 @@ public class TileEntitySolarEvaporationController extends TileEntitySolarEvapora
{
if(tile != this)
{
((TileEntitySolarEvaporationBlock)tile).addToStructure(this);
tankParts.add((TileEntitySolarEvaporationBlock)tile);
((TileEntitySolarEvaporationBlock)tile).addToStructure(Coord4D.get(this));
tankParts.add(Coord4D.get(tile));
}
return true;
@ -730,9 +730,14 @@ public class TileEntitySolarEvaporationController extends TileEntitySolarEvapora
public void clearStructure()
{
for(TileEntitySolarEvaporationBlock tankPart : tankParts)
for(Coord4D tankPart : tankParts)
{
tankPart.controllerGone();
TileEntity tile = tankPart.getTileEntity(worldObj);
if(tile instanceof TileEntitySolarEvaporationBlock)
{
((TileEntitySolarEvaporationBlock)tile).controllerGone();
}
}
tankParts.clear();

View file

@ -39,15 +39,18 @@ public class TileEntitySolarEvaporationValve extends TileEntitySolarEvaporationB
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
return master == null ? 0 : master.inputTank.fill(resource, doFill);
TileEntitySolarEvaporationController controller = getController();
return controller == null ? 0 : controller.inputTank.fill(resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
if(master != null && (resource == null || resource.isFluidEqual(master.outputTank.getFluid())))
TileEntitySolarEvaporationController controller = getController();
if(controller != null && (resource == null || resource.isFluidEqual(controller.outputTank.getFluid())))
{
return master.outputTank.drain(resource.amount, doDrain);
return controller.outputTank.drain(resource.amount, doDrain);
}
return null;
@ -56,9 +59,11 @@ public class TileEntitySolarEvaporationValve extends TileEntitySolarEvaporationB
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
if(master != null)
TileEntitySolarEvaporationController controller = getController();
if(controller != null)
{
return master.outputTank.drain(maxDrain, doDrain);
return controller.outputTank.drain(maxDrain, doDrain);
}
return null;
@ -67,23 +72,27 @@ public class TileEntitySolarEvaporationValve extends TileEntitySolarEvaporationB
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return master != null && master.hasRecipe(fluid);
TileEntitySolarEvaporationController controller = getController();
return controller != null && controller.hasRecipe(fluid);
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return master != null && master.outputTank.getFluidAmount() > 0;
TileEntitySolarEvaporationController controller = getController();
return controller != null && controller.outputTank.getFluidAmount() > 0;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
if(master == null)
TileEntitySolarEvaporationController controller = getController();
if(controller == null)
{
return PipeUtils.EMPTY;
}
return new FluidTankInfo[] {new FluidTankInfo(master.inputTank), new FluidTankInfo(master.outputTank)};
return new FluidTankInfo[] {new FluidTankInfo(controller.inputTank), new FluidTankInfo(controller.outputTank)};
}
}