Fluidic Plenisher work - just about done!
This commit is contained in:
parent
90da466ca1
commit
fba83a3634
6 changed files with 185 additions and 6 deletions
|
@ -5,6 +5,7 @@ import mekanism.client.gui.GuiSlot.SlotOverlay;
|
|||
import mekanism.client.gui.GuiSlot.SlotType;
|
||||
import mekanism.common.inventory.container.ContainerFluidicPlenisher;
|
||||
import mekanism.common.tile.TileEntityFluidicPlenisher;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
@ -48,7 +49,8 @@ public class GuiFluidicPlenisher extends GuiMekanism
|
|||
fontRendererObj.drawString(tileEntity.getInventoryName(), 45, 6, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 94) + 2, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.getEnergyDisplay(tileEntity.getEnergy()), 51, 26, 0x00CD00);
|
||||
fontRendererObj.drawString(tileEntity.fluidTank.getFluid() != null ? tileEntity.fluidTank.getFluid().getFluid().getName() + ": " + tileEntity.fluidTank.getFluid().amount : MekanismUtils.localize("gui.noFluid"), 51, 35, 0x00CD00);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.finished") + ": " + LangUtils.transYesNo(tileEntity.finishedCalc), 51, 35, 0x00CD00);
|
||||
fontRendererObj.drawString(tileEntity.fluidTank.getFluid() != null ? tileEntity.fluidTank.getFluid().getFluid().getName() + ": " + tileEntity.fluidTank.getFluid().amount : MekanismUtils.localize("gui.noFluid"), 51, 44, 0x00CD00);
|
||||
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class ContainerFluidicPlenisher extends Container
|
|||
}
|
||||
}
|
||||
}
|
||||
else if(FluidContainerRegistry.isEmptyContainer(slotStack))
|
||||
else if(FluidContainerRegistry.isFilledContainer(slotStack))
|
||||
{
|
||||
if(slotID != 0)
|
||||
{
|
||||
|
|
|
@ -572,7 +572,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
|
|||
|
||||
public boolean tryPlaceContainedLiquid(World world, ItemStack itemstack, int x, int y, int z)
|
||||
{
|
||||
if(getFluidStack(itemstack) == null)
|
||||
if(getFluidStack(itemstack) == null || !getFluidStack(itemstack).getFluid().canBePlacedInWorld())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -600,7 +600,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
|
|||
world.func_147480_a(x, y, z, true);
|
||||
}
|
||||
|
||||
world.setBlock(x, y, z, getFluidStack(itemstack).getFluid().getBlock(), 0, 3);
|
||||
world.setBlock(x, y, z, MekanismUtils.getFlowingBlock(getFluidStack(itemstack).getFluid()), 0, 3);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -11,6 +11,7 @@ import mekanism.api.Coord4D;
|
|||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.IConfigurable;
|
||||
import mekanism.common.ISustainedTank;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.block.BlockMachine.MachineType;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
@ -18,10 +19,13 @@ import mekanism.common.util.PipeUtils;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
@ -30,9 +34,15 @@ import net.minecraftforge.fluids.IFluidHandler;
|
|||
public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implements IConfigurable, IFluidHandler, ISustainedTank
|
||||
{
|
||||
public Set<Coord4D> activeNodes = new HashSet<Coord4D>();
|
||||
public Set<Coord4D> usedNodes = new HashSet<Coord4D>();
|
||||
|
||||
public boolean finishedCalc = false;
|
||||
|
||||
public FluidTank fluidTank = new FluidTank(10000);
|
||||
|
||||
private static EnumSet<ForgeDirection> dirs = EnumSet.complementOf(EnumSet.of(ForgeDirection.UP, ForgeDirection.UNKNOWN));
|
||||
private static int MAX_NODES = 4000;
|
||||
|
||||
public TileEntityFluidicPlenisher()
|
||||
{
|
||||
super("FluidicPlenisher", MachineType.FLUIDIC_PLENISHER.baseEnergy);
|
||||
|
@ -96,14 +106,98 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
|
|||
}
|
||||
}
|
||||
|
||||
if(g)
|
||||
doPlenish();
|
||||
if(getEnergy() >= Mekanism.fluidicPlenisherUsage && worldObj.getWorldTime() % 10 == 0 && fluidTank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME && !finishedCalc)
|
||||
{
|
||||
if(fluidTank.getFluid().getFluid().canBePlacedInWorld())
|
||||
{
|
||||
doPlenish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doPlenish()
|
||||
{
|
||||
if(usedNodes.size() >= MAX_NODES)
|
||||
{
|
||||
finishedCalc = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(activeNodes.isEmpty())
|
||||
{
|
||||
if(usedNodes.isEmpty())
|
||||
{
|
||||
Coord4D below = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);
|
||||
|
||||
if(!canReplace(below))
|
||||
{
|
||||
finishedCalc = true;
|
||||
return;
|
||||
}
|
||||
|
||||
activeNodes.add(below);
|
||||
}
|
||||
else {
|
||||
finishedCalc = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Set<Coord4D> toRemove = new HashSet<Coord4D>();
|
||||
|
||||
for(Coord4D coord : activeNodes)
|
||||
{
|
||||
if(coord.exists(worldObj) && canReplace(coord))
|
||||
{
|
||||
worldObj.setBlock(coord.xCoord, coord.yCoord, coord.zCoord, MekanismUtils.getFlowingBlock(fluidTank.getFluid().getFluid()), 0, 3);
|
||||
|
||||
setEnergy(getEnergy() - Mekanism.fluidicPlenisherUsage);
|
||||
fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
|
||||
|
||||
for(ForgeDirection dir : dirs)
|
||||
{
|
||||
Coord4D sideCoord = coord.getFromSide(dir);
|
||||
|
||||
if(coord.exists(worldObj) && canReplace(coord))
|
||||
{
|
||||
activeNodes.add(sideCoord);
|
||||
}
|
||||
}
|
||||
|
||||
toRemove.add(coord);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
toRemove.add(coord);
|
||||
}
|
||||
}
|
||||
|
||||
for(Coord4D coord : toRemove)
|
||||
{
|
||||
activeNodes.remove(coord);
|
||||
usedNodes.add(coord);
|
||||
}
|
||||
}
|
||||
|
||||
public int getActiveY()
|
||||
{
|
||||
return yCoord-1;
|
||||
}
|
||||
|
||||
public boolean canReplace(Coord4D coord)
|
||||
{
|
||||
if(usedNodes.contains(coord))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(coord.isAirBlock(worldObj) || MekanismUtils.isDeadFluid(worldObj, coord.xCoord, coord.yCoord, coord.zCoord))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return coord.getBlock(worldObj).isReplaceable(worldObj, coord.xCoord, coord.yCoord, coord.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,6 +205,8 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
|
|||
{
|
||||
super.handlePacketData(dataStream);
|
||||
|
||||
finishedCalc = dataStream.readBoolean();
|
||||
|
||||
if(dataStream.readInt() == 1)
|
||||
{
|
||||
fluidTank.setFluid(new FluidStack(dataStream.readInt(), dataStream.readInt()));
|
||||
|
@ -127,6 +223,8 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
|
|||
{
|
||||
super.getNetworkedData(data);
|
||||
|
||||
data.add(finishedCalc);
|
||||
|
||||
if(fluidTank.getFluid() != null)
|
||||
{
|
||||
data.add(1);
|
||||
|
@ -150,10 +248,38 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
|
|||
{
|
||||
super.writeToNBT(nbtTags);
|
||||
|
||||
nbtTags.setBoolean("finishedCalc", finishedCalc);
|
||||
|
||||
if(fluidTank.getFluid() != null)
|
||||
{
|
||||
nbtTags.setTag("fluidTank", fluidTank.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
NBTTagList activeList = new NBTTagList();
|
||||
|
||||
for(Coord4D wrapper : activeNodes)
|
||||
{
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
wrapper.write(tagCompound);
|
||||
activeList.appendTag(tagCompound);
|
||||
}
|
||||
|
||||
if(activeList.tagCount() != 0)
|
||||
{
|
||||
nbtTags.setTag("activeNodes", activeList);
|
||||
}
|
||||
|
||||
NBTTagList usedList = new NBTTagList();
|
||||
|
||||
for(Coord4D obj : usedNodes)
|
||||
{
|
||||
activeList.appendTag(obj.write(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
if(activeList.tagCount() != 0)
|
||||
{
|
||||
nbtTags.setTag("usedNodes", usedList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -161,10 +287,32 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
|
|||
{
|
||||
super.readFromNBT(nbtTags);
|
||||
|
||||
finishedCalc = nbtTags.getBoolean("finishedCalc");
|
||||
|
||||
if(nbtTags.hasKey("fluidTank"))
|
||||
{
|
||||
fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank"));
|
||||
}
|
||||
|
||||
if(nbtTags.hasKey("activeNodes"))
|
||||
{
|
||||
NBTTagList tagList = nbtTags.getTagList("activeNodes", NBT.TAG_COMPOUND);
|
||||
|
||||
for(int i = 0; i < tagList.tagCount(); i++)
|
||||
{
|
||||
activeNodes.add(Coord4D.read((NBTTagCompound)tagList.getCompoundTagAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
if(nbtTags.hasKey("usedNodes"))
|
||||
{
|
||||
NBTTagList tagList = nbtTags.getTagList("usedNodes", NBT.TAG_COMPOUND);
|
||||
|
||||
for(int i = 0; i < tagList.tagCount(); i++)
|
||||
{
|
||||
usedNodes.add(Coord4D.read((NBTTagCompound)tagList.getCompoundTagAt(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -301,6 +449,10 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
|
|||
@Override
|
||||
public boolean onSneakRightClick(EntityPlayer player, int side)
|
||||
{
|
||||
activeNodes.clear();
|
||||
usedNodes.clear();
|
||||
finishedCalc = false;
|
||||
|
||||
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + MekanismUtils.localize("tooltip.configurator.plenisherReset")));
|
||||
|
||||
return true;
|
||||
|
|
|
@ -817,6 +817,30 @@ public final class MekanismUtils
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the flowing block type from a Forge-based fluid. Incorporates the MC system of fliuds as well.
|
||||
* @param fluid - the fluid type
|
||||
* @return the block corresponding to the given fluid
|
||||
*/
|
||||
public static Block getFlowingBlock(Fluid fluid)
|
||||
{
|
||||
if(fluid == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if(fluid == FluidRegistry.WATER)
|
||||
{
|
||||
return Blocks.flowing_water;
|
||||
}
|
||||
else if(fluid == FluidRegistry.LAVA)
|
||||
{
|
||||
return Blocks.flowing_lava;
|
||||
}
|
||||
else {
|
||||
return fluid.getBlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FML doesn't really do GUIs the way it's supposed to -- opens Electric Chest GUI on client and server.
|
||||
* Call this method server-side only!
|
||||
|
|
|
@ -321,6 +321,7 @@ gui.dumping=Dumping
|
|||
gui.modID=Mod ID
|
||||
gui.key=Key
|
||||
gui.id=ID
|
||||
gui.finished=Finished
|
||||
|
||||
gui.chemicalInfuser.short=C. Infuser
|
||||
gui.chemicalDissolutionChamber.short=C. Dissolution Chamber
|
||||
|
|
Loading…
Reference in a new issue