Iteration #2 of salination plants, they have a more defined shape now but the algorithm seems very costly so it only does it when configurated. Still work to do.
This commit is contained in:
parent
6fa8cebb3a
commit
a1cc44bb90
5 changed files with 262 additions and 32 deletions
|
@ -305,9 +305,9 @@ public class BlockBasic extends Block
|
|||
{
|
||||
entityplayer.openGui(Mekanism.instance, 33, world, x, y, z);
|
||||
TileEntitySalinationController controller = (TileEntitySalinationController)new Coord4D(x, y, z).getTileEntity(world);
|
||||
entityplayer.sendChatToPlayer(ChatMessageComponent.createFromText("Water Level: " + controller.waterTank.getFluidAmount()));
|
||||
entityplayer.sendChatToPlayer(ChatMessageComponent.createFromText("Brine Level: " + controller.brineTank.getFluidAmount()));
|
||||
entityplayer.sendChatToPlayer(ChatMessageComponent.createFromText("Can operate: " + controller.canOperate()));
|
||||
//entityplayer.sendChatToPlayer(ChatMessageComponent.createFromText("Water Level: " + controller.waterTank.getFluidAmount()));
|
||||
//entityplayer.sendChatToPlayer(ChatMessageComponent.createFromText("Brine Level: " + controller.brineTank.getFluidAmount()));
|
||||
//entityplayer.sendChatToPlayer(ChatMessageComponent.createFromText("Can operate: " + controller.canOperate()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,30 +1,39 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import java.rmi.registry.Registry;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.common.IConfigurable;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.generators.common.tile.TileEntityAdvancedSolarGenerator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
public class TileEntitySalinationController extends TileEntityContainerBlock
|
||||
public class TileEntitySalinationController extends TileEntitySalinationTank implements IConfigurable
|
||||
{
|
||||
public static int MAX_WATER = 100000;
|
||||
public static int MAX_BRINE = 1000;
|
||||
|
||||
public FluidTank waterTank = new FluidTank(MAX_WATER);
|
||||
|
||||
public FluidTank brineTank = new FluidTank(MAX_BRINE);
|
||||
|
||||
public Set<TileEntitySalinationTank> tankParts = new HashSet<TileEntitySalinationTank>();
|
||||
public TileEntityAdvancedSolarGenerator[] solars = new TileEntityAdvancedSolarGenerator[4];
|
||||
|
||||
public boolean temperatureSet = false;
|
||||
public double partialWater = 0;
|
||||
public double partialBrine = 0;
|
||||
public float temperature = 0;
|
||||
public int height = 0;
|
||||
public boolean structured = false;
|
||||
|
||||
public boolean isLeftOnFace;
|
||||
|
||||
public TileEntitySalinationController()
|
||||
{
|
||||
|
@ -34,12 +43,11 @@ public class TileEntitySalinationController extends TileEntityContainerBlock
|
|||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
buildStructure();
|
||||
setTemperature();
|
||||
|
||||
if(canOperate())
|
||||
{
|
||||
partialWater += temperature;
|
||||
partialWater += temperature * (height + 7)/8;
|
||||
if(partialWater >= 1)
|
||||
{
|
||||
int waterInt = (int)Math.floor(partialWater);
|
||||
|
@ -58,18 +66,23 @@ public class TileEntitySalinationController extends TileEntityContainerBlock
|
|||
|
||||
public boolean canOperate()
|
||||
{
|
||||
if(waterTank.getFluid() == null || !waterTank.getFluid().containsFluid(FluidRegistry.getFluidStack("water", 100)))
|
||||
if(!structured || height < 1 || waterTank.getFluid() == null || !waterTank.getFluid().containsFluid(FluidRegistry.getFluidStack("water", 100)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity backTile = Coord4D.get(this).getFromSide(ForgeDirection.getOrientation(facing).getOpposite()).getTileEntity(worldObj);
|
||||
if(backTile instanceof TileEntityAdvancedSolarGenerator)
|
||||
boolean solarsActive = true;
|
||||
|
||||
for(TileEntityAdvancedSolarGenerator solarPanel : solars)
|
||||
{
|
||||
TileEntityAdvancedSolarGenerator heater = (TileEntityAdvancedSolarGenerator)backTile;
|
||||
return heater.seesSun;
|
||||
if(solarPanel == null || solarPanel.isInvalid())
|
||||
{
|
||||
clearStructure();
|
||||
return false;
|
||||
}
|
||||
solarsActive &= solarPanel.seesSun;
|
||||
}
|
||||
return false;
|
||||
return solarsActive;
|
||||
}
|
||||
|
||||
public void setTemperature()
|
||||
|
@ -81,17 +94,200 @@ public class TileEntitySalinationController extends TileEntityContainerBlock
|
|||
}
|
||||
}
|
||||
|
||||
public void buildStructure()
|
||||
public boolean buildStructure()
|
||||
{
|
||||
TileEntity leftTile = Coord4D.get(this).getFromSide(MekanismUtils.getLeft(facing)).getTileEntity(worldObj);
|
||||
TileEntity rightTile = Coord4D.get(this).getFromSide(MekanismUtils.getRight(facing)).getTileEntity(worldObj);
|
||||
if(leftTile instanceof TileEntitySalinationValve)
|
||||
ForgeDirection right = MekanismUtils.getRight(facing);
|
||||
|
||||
height = 0;
|
||||
if(!findBottomLayer()) { return false; }
|
||||
Coord4D startPoint = Coord4D.get(this).getFromSide(right);
|
||||
startPoint = isLeftOnFace ? startPoint : startPoint.getFromSide(right);
|
||||
|
||||
while(findMiddleLayer(startPoint))
|
||||
{
|
||||
((TileEntitySalinationValve)leftTile).master = this;
|
||||
startPoint = startPoint.getFromSide(ForgeDirection.UP);
|
||||
height++;
|
||||
}
|
||||
if(rightTile instanceof TileEntitySalinationValve)
|
||||
|
||||
structured = findTopLayer(startPoint);
|
||||
height = structured ? height + 1 : 0;
|
||||
return structured;
|
||||
}
|
||||
|
||||
public boolean findTopLayer(Coord4D current)
|
||||
{
|
||||
ForgeDirection left = MekanismUtils.getLeft(facing);
|
||||
ForgeDirection right = MekanismUtils.getRight(facing);
|
||||
ForgeDirection back = MekanismUtils.getBack(facing);
|
||||
ForgeDirection front = ForgeDirection.getOrientation(facing);
|
||||
|
||||
for(int i = 1; i <= 2; i++)
|
||||
{
|
||||
((TileEntitySalinationValve)rightTile).master = this;
|
||||
current = current.getFromSide(back);
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
}
|
||||
|
||||
current = current.getFromSide(back);
|
||||
TileEntity solar = current.getTileEntity(worldObj);
|
||||
if(!addSolarPanel(solar, 0)) { return false; }
|
||||
|
||||
for(int i = 1; i <= 2; i++)
|
||||
{
|
||||
current = current.getFromSide(left);
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
}
|
||||
|
||||
current = current.getFromSide(left);
|
||||
solar = current.getTileEntity(worldObj);
|
||||
if(!addSolarPanel(solar, 1)) { return false; }
|
||||
|
||||
for(int i = 1; i <= 2; i++)
|
||||
{
|
||||
current = current.getFromSide(front);
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
}
|
||||
|
||||
current = current.getFromSide(front);
|
||||
solar = current.getTileEntity(worldObj);
|
||||
if(!addSolarPanel(solar, 2)) { return false; }
|
||||
|
||||
for(int i = 1; i <= 2; i++)
|
||||
{
|
||||
current = current.getFromSide(right);
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
}
|
||||
|
||||
current = current.getFromSide(right);
|
||||
solar = current.getTileEntity(worldObj);
|
||||
if(!addSolarPanel(solar, 3)) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean findMiddleLayer(Coord4D current)
|
||||
{
|
||||
ForgeDirection left = MekanismUtils.getLeft(facing);
|
||||
ForgeDirection right = MekanismUtils.getRight(facing);
|
||||
ForgeDirection back = MekanismUtils.getBack(facing);
|
||||
ForgeDirection front = ForgeDirection.getOrientation(facing);
|
||||
|
||||
for(int i = 1; i <= 3; i++)
|
||||
{
|
||||
current = current.getFromSide(back);
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
}
|
||||
|
||||
for(int i = 1; i <= 3; i++)
|
||||
{
|
||||
current = current.getFromSide(left);
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
}
|
||||
|
||||
for(int i = 1; i <= 3; i++)
|
||||
{
|
||||
current = current.getFromSide(front);
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
}
|
||||
|
||||
for(int i = 1; i <= 3; i++)
|
||||
{
|
||||
current = current.getFromSide(right);
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean findBottomLayer()
|
||||
{
|
||||
Coord4D baseBlock = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);
|
||||
|
||||
ForgeDirection left = MekanismUtils.getLeft(facing);
|
||||
ForgeDirection right = MekanismUtils.getRight(facing);
|
||||
|
||||
if(!findBottomRow(baseBlock)) { return false; };
|
||||
if(!findBottomRow(baseBlock.getFromSide(left))) { return false; };
|
||||
if(!findBottomRow(baseBlock.getFromSide(right))) { return false; };
|
||||
|
||||
boolean twoLeft = findBottomRow(baseBlock.getFromSide(left).getFromSide(left));
|
||||
boolean twoRight = findBottomRow(baseBlock.getFromSide(right).getFromSide(right));
|
||||
|
||||
if(twoLeft == twoRight) { return false; }
|
||||
|
||||
isLeftOnFace = twoLeft;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean findBottomRow(Coord4D start)
|
||||
{
|
||||
ForgeDirection back = MekanismUtils.getBack(facing);
|
||||
Coord4D current = start;
|
||||
|
||||
for(int i = 1; i <= 4; i++)
|
||||
{
|
||||
TileEntity tile = current.getTileEntity(worldObj);
|
||||
if(!addTankPart(tile)) { return false; }
|
||||
current = current.getFromSide(back);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean addTankPart(TileEntity tile)
|
||||
{
|
||||
if(tile instanceof TileEntitySalinationTank)
|
||||
{
|
||||
((TileEntitySalinationTank)tile).addToStructure(this);
|
||||
tankParts.add((TileEntitySalinationTank)tile);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addSolarPanel(TileEntity tile, int i)
|
||||
{
|
||||
if(tile instanceof TileEntityAdvancedSolarGenerator)
|
||||
{
|
||||
solars[i] = (TileEntityAdvancedSolarGenerator)tile;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSneakRightClick(EntityPlayer player, int side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onRightClick(EntityPlayer player, int side)
|
||||
{
|
||||
structured = buildStructure();
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText("Height: " + height + ", Structured: " + structured));
|
||||
System.out.println(solars[0] + " " + solars[1] + " " + solars[2] + " " + solars[3]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearStructure()
|
||||
{
|
||||
for(TileEntitySalinationTank tankPart : tankParts)
|
||||
{
|
||||
tankPart.controllerGone();
|
||||
}
|
||||
tankParts.clear();
|
||||
solars = new TileEntityAdvancedSolarGenerator[]{null, null, null, null};
|
||||
}
|
||||
}
|
||||
|
|
34
common/mekanism/common/tile/TileEntitySalinationTank.java
Normal file
34
common/mekanism/common/tile/TileEntitySalinationTank.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class TileEntitySalinationTank extends TileEntityContainerBlock
|
||||
{
|
||||
TileEntitySalinationController master;
|
||||
|
||||
public TileEntitySalinationTank()
|
||||
{
|
||||
super("SalinationTank");
|
||||
inventory = new ItemStack[0];
|
||||
|
||||
}
|
||||
|
||||
public TileEntitySalinationTank(String fullName)
|
||||
{
|
||||
super(fullName);
|
||||
inventory = new ItemStack[0];
|
||||
}
|
||||
|
||||
public void onUpdate() {};
|
||||
|
||||
public void addToStructure(TileEntitySalinationController controller)
|
||||
{
|
||||
master = controller;
|
||||
}
|
||||
|
||||
public void controllerGone()
|
||||
{
|
||||
master = null;
|
||||
}
|
||||
}
|
|
@ -7,15 +7,8 @@ import net.minecraftforge.fluids.FluidStack;
|
|||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class TileEntitySalinationValve extends TileEntityContainerBlock implements IFluidHandler
|
||||
public class TileEntitySalinationValve extends TileEntitySalinationTank implements IFluidHandler
|
||||
{
|
||||
public TileEntitySalinationController master;
|
||||
|
||||
public TileEntitySalinationValve()
|
||||
{
|
||||
super("SalinationController");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
|
@ -61,7 +54,4 @@ public class TileEntitySalinationValve extends TileEntityContainerBlock implemen
|
|||
}
|
||||
return new FluidTankInfo[] {new FluidTankInfo(master.waterTank), new FluidTankInfo(master.brineTank)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {}
|
||||
}
|
||||
|
|
|
@ -444,6 +444,16 @@ public final class MekanismUtils
|
|||
{
|
||||
return getLeft(orientation).getOpposite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opposite side of a certain orientation.
|
||||
* @param orientation
|
||||
* @return opposite side
|
||||
*/
|
||||
public static ForgeDirection getBack(int orientation)
|
||||
{
|
||||
return ForgeDirection.getOrientation(orientation).getOpposite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a specified ItemStack is stored in the Ore Dictionary with the specified name.
|
||||
|
|
Loading…
Reference in a new issue