diff --git a/src/main/java/mekanism/client/gui/GuiFluidicPlenisher.java b/src/main/java/mekanism/client/gui/GuiFluidicPlenisher.java index dc5709db0..17c13be02 100644 --- a/src/main/java/mekanism/client/gui/GuiFluidicPlenisher.java +++ b/src/main/java/mekanism/client/gui/GuiFluidicPlenisher.java @@ -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); } diff --git a/src/main/java/mekanism/common/inventory/container/ContainerFluidicPlenisher.java b/src/main/java/mekanism/common/inventory/container/ContainerFluidicPlenisher.java index 7dba30c8b..4306c04a1 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerFluidicPlenisher.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerFluidicPlenisher.java @@ -82,7 +82,7 @@ public class ContainerFluidicPlenisher extends Container } } } - else if(FluidContainerRegistry.isEmptyContainer(slotStack)) + else if(FluidContainerRegistry.isFilledContainer(slotStack)) { if(slotID != 0) { diff --git a/src/main/java/mekanism/common/item/ItemBlockMachine.java b/src/main/java/mekanism/common/item/ItemBlockMachine.java index a0b8415f1..66e13a298 100644 --- a/src/main/java/mekanism/common/item/ItemBlockMachine.java +++ b/src/main/java/mekanism/common/item/ItemBlockMachine.java @@ -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; diff --git a/src/main/java/mekanism/common/tile/TileEntityFluidicPlenisher.java b/src/main/java/mekanism/common/tile/TileEntityFluidicPlenisher.java index 60fc4f2d1..0c2f52c1d 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFluidicPlenisher.java +++ b/src/main/java/mekanism/common/tile/TileEntityFluidicPlenisher.java @@ -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 activeNodes = new HashSet(); + public Set usedNodes = new HashSet(); + + public boolean finishedCalc = false; public FluidTank fluidTank = new FluidTank(10000); + private static EnumSet dirs = EnumSet.complementOf(EnumSet.of(ForgeDirection.UP, ForgeDirection.UNKNOWN)); + private static int MAX_NODES = 4000; + public TileEntityFluidicPlenisher() { super("FluidicPlenisher", MachineType.FLUIDIC_PLENISHER.baseEnergy); @@ -96,20 +106,106 @@ 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 toRemove = new HashSet(); + + 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 public void handlePacketData(ByteBuf dataStream) { super.handlePacketData(dataStream); + + finishedCalc = dataStream.readBoolean(); if(dataStream.readInt() == 1) { @@ -126,6 +222,8 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen public ArrayList getNetworkedData(ArrayList data) { super.getNetworkedData(data); + + data.add(finishedCalc); if(fluidTank.getFluid() != null) { @@ -149,22 +247,72 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen public void writeToNBT(NBTTagCompound nbtTags) { 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 public void readFromNBT(NBTTagCompound nbtTags) { 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; diff --git a/src/main/java/mekanism/common/util/MekanismUtils.java b/src/main/java/mekanism/common/util/MekanismUtils.java index 5b7ab45fa..d5154c2f3 100644 --- a/src/main/java/mekanism/common/util/MekanismUtils.java +++ b/src/main/java/mekanism/common/util/MekanismUtils.java @@ -816,6 +816,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. diff --git a/src/main/resources/assets/mekanism/lang/en_US.lang b/src/main/resources/assets/mekanism/lang/en_US.lang index 27774b029..fa57b82a8 100644 --- a/src/main/resources/assets/mekanism/lang/en_US.lang +++ b/src/main/resources/assets/mekanism/lang/en_US.lang @@ -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