diff --git a/src/tconstruct/TConstruct.java b/src/tconstruct/TConstruct.java index 258b5e08a10..d249b8386cc 100644 --- a/src/tconstruct/TConstruct.java +++ b/src/tconstruct/TConstruct.java @@ -48,7 +48,7 @@ * @dependencies: IC2 API, MFR API */ -@Mod(modid = "TConstruct", name = "TConstruct", version = "1.6.X_1.4.7", dependencies = "required-after:Forge@[8.9,)") +@Mod(modid = "TConstruct", name = "TConstruct", version = "1.6.X_1.5.0d", dependencies = "required-after:Forge@[8.9,)") @NetworkMod(serverSideRequired = false, clientSideRequired = true, channels = { "TConstruct" }, packetHandler = tconstruct.util.network.TPacketHandler.class) public class TConstruct { diff --git a/src/tconstruct/blocks/SmelteryBlock.java b/src/tconstruct/blocks/SmelteryBlock.java index 738de17a650..6bdc50567e0 100644 --- a/src/tconstruct/blocks/SmelteryBlock.java +++ b/src/tconstruct/blocks/SmelteryBlock.java @@ -40,11 +40,11 @@ public SmelteryBlock(int id) /* Rendering */ - @Override + /*@Override public int getRenderType () { return SmelteryRender.smelteryModel; - } + }*/ @Override public String[] getTextureNames () @@ -216,7 +216,7 @@ public TileEntity createTileEntity (World world, int metadata) switch (metadata) { case 0: - return new SmelteryLogic(); + return new AdaptiveSmelteryLogic(); case 1: return new SmelteryDrainLogic(); case 3: @@ -225,7 +225,7 @@ public TileEntity createTileEntity (World world, int metadata) return new MultiServantLogic(); } - @Override + /*@Override public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack stack) { super.onBlockPlacedBy(world, x, y, z, entityliving, stack); @@ -243,7 +243,7 @@ public void onBlockPlacedElsewhere (World world, int x, int y, int z, EntityLivi public void breakBlock (World world, int x, int y, int z, int par5, int par6) //Don't drop inventory { world.removeBlockTileEntity(x, y, z); - } + }*/ @Override public void getSubBlocks (int id, CreativeTabs tab, List list) diff --git a/src/tconstruct/blocks/TankAirBlock.java b/src/tconstruct/blocks/TankAirBlock.java index 472db131afe..07886351ad7 100644 --- a/src/tconstruct/blocks/TankAirBlock.java +++ b/src/tconstruct/blocks/TankAirBlock.java @@ -1,10 +1,14 @@ package tconstruct.blocks; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import tconstruct.blocks.logic.TankAirLogic; +import tconstruct.client.block.TankAirRender; public class TankAirBlock extends BlockContainer { @@ -19,4 +23,28 @@ public TileEntity createNewTileEntity (World world) { return new TankAirLogic(); } + + @Override + public int getRenderType () + { + return TankAirRender.model; + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IconRegister par1IconRegister) + { + + } + + @Override + public boolean isOpaqueCube () + { + return false; + } + + @Override + public boolean renderAsNormalBlock () + { + return false; + } } diff --git a/src/tconstruct/blocks/component/SmelteryComponent.java b/src/tconstruct/blocks/component/SmelteryComponent.java index 0a3bb0b50e7..b26f94eeca0 100644 --- a/src/tconstruct/blocks/component/SmelteryComponent.java +++ b/src/tconstruct/blocks/component/SmelteryComponent.java @@ -3,14 +3,14 @@ import java.util.ArrayList; import net.minecraft.block.Block; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; +import tconstruct.blocks.logic.AdaptiveSmelteryLogic; import tconstruct.library.component.LogicComponent; import tconstruct.library.component.MultiFluidTank; import tconstruct.library.crafting.Smeltery; @@ -18,7 +18,7 @@ public class SmelteryComponent extends LogicComponent { - final IInventory master; + final AdaptiveSmelteryLogic master; final SmelteryScan structure; final MultiFluidTank multitank; int maxTemp; @@ -33,7 +33,7 @@ public class SmelteryComponent extends LogicComponent CoordTuple activeLavaTank; - public SmelteryComponent(IInventory inventory, SmelteryScan structure, MultiFluidTank multitank, int maxTemp) + public SmelteryComponent(AdaptiveSmelteryLogic inventory, SmelteryScan structure, MultiFluidTank multitank, int maxTemp) { master = inventory; this.structure = structure; @@ -74,6 +74,16 @@ public void adjustSize (int size, boolean forceAdjust) } } + public void updateTemperatures () + { + inUse = true; + for (int i = 0; i < meltingTemps.length; i++) + { + meltingTemps[i] = Smeltery.instance.getLiquifyTemperature(master.getStackInSlot(i)); + System.out.println("New temp: " + meltingTemps[i]); + } + } + public void heatItems () { if (fuelTicks > 0) @@ -84,7 +94,7 @@ public void heatItems () fuelTicks--; if (fuelTicks <= 0) break; - + ItemStack slot = master.getStackInSlot(i); if (meltingTemps[i] > 20 && slot != null) { @@ -109,10 +119,10 @@ else if (activeTemps[i] >= meltingTemps[i] && !world.isRemote) multitank.addFluidToTank(liquid, true); } master.onInventoryChanged(); + master.setUpdateFluids(); } } } - } else @@ -178,7 +188,7 @@ void updateFuelGague () if (newliquid != null && newliquid.getFluid().getBlockID() == Block.lavaStill.blockID && newliquid.amount > 0) { foundTank = true; - activeLavaTank = possibleTank; + setActiveLavaTank(possibleTank); iter = structure.lavaTanks.size(); FluidTankInfo[] info = ((IFluidHandler) tankContainer).getTankInfo(ForgeDirection.DOWN); @@ -204,6 +214,11 @@ void updateFuelGague () } } + public void setActiveLavaTank (CoordTuple coord) + { + activeLavaTank = coord; + } + private int drainFuelAmount () { int amount = activeTemps.length / 3; @@ -231,4 +246,22 @@ public int getMeltingPointForSlot (int slot) { return meltingTemps[slot]; } + + /* NBT */ + public void readNetworkNBT (NBTTagCompound tags) + { + activeTemps = tags.getIntArray("Temperature"); + meltingTemps = tags.getIntArray("Melting"); + int[] tank = tags.getIntArray("LavaTank"); + if (tank != null) + activeLavaTank = new CoordTuple(tank[0], tank[1], tank[2]); + } + + public void writeNetworkNBT (NBTTagCompound tags) + { + tags.setIntArray("Temperature", activeTemps); + tags.setIntArray("Melting", meltingTemps); + if (activeLavaTank != null) + tags.setIntArray("LavaTank", new int[] { activeLavaTank.x, activeLavaTank.y, activeLavaTank.z }); + } } diff --git a/src/tconstruct/blocks/component/SmelteryScan.java b/src/tconstruct/blocks/component/SmelteryScan.java index 88c41d6482a..ae57e9e3261 100644 --- a/src/tconstruct/blocks/component/SmelteryScan.java +++ b/src/tconstruct/blocks/component/SmelteryScan.java @@ -1,6 +1,7 @@ package tconstruct.blocks.component; import java.util.ArrayList; +import java.util.Iterator; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; @@ -24,7 +25,7 @@ public void checkValidStructure () lavaTanks.clear(); super.checkValidStructure(); } - + @Override protected boolean checkServant (int x, int y, int z) { @@ -46,24 +47,38 @@ protected boolean checkServant (int x, int y, int z) return false; } - + protected void finalizeStructure () { super.finalizeStructure(); - for (CoordTuple coord : airCoords) + if (lavaTanks.size() < 1) + completeStructure = false; + else { - world.setBlock(coord.x, coord.y, coord.z, TContent.tankAir.blockID); - IServantLogic servant = (IServantLogic) world.getBlockTileEntity(coord.x, coord.y, coord.z); - servant.verifyMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord); + for (CoordTuple coord : airCoords) + { + world.setBlock(coord.x, coord.y, coord.z, TContent.tankAir.blockID); + IServantLogic servant = (IServantLogic) world.getBlockTileEntity(coord.x, coord.y, coord.z); + servant.verifyMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord); + } } } - - /*protected void addAirBlock (int x, int y, int z) + + @Override + public void cleanup () { - super.addAirBlock(x, y, z); - world.setBlock(x, y, z, Block.glass.blockID); - }*/ - + super.cleanup(); + Iterator i = airCoords.iterator(); + while (i.hasNext()) + { + CoordTuple coord = (CoordTuple) i.next(); + TileEntity te = world.getBlockTileEntity(coord.x, coord.y, coord.z); + if (te != null && te instanceof IServantLogic) + { + ((IServantLogic) te).invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord); + } + } + } /*public void cleanup() { System.out.println("Structure cleanup activated. Air blocks: "+airCoords.size()); diff --git a/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java b/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java index c72ca7e172a..4ebdb56c7ec 100644 --- a/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java +++ b/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java @@ -1,7 +1,10 @@ package tconstruct.blocks.logic; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.InventoryPlayer; @@ -11,13 +14,16 @@ import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet132TileEntityData; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; import tconstruct.TConstruct; import tconstruct.blocks.component.SmelteryComponent; import tconstruct.blocks.component.SmelteryScan; import tconstruct.common.TContent; +import tconstruct.inventory.AdaptiveSmelteryContainer; import tconstruct.library.blocks.AdaptiveInventoryLogic; import tconstruct.library.component.IComponentHolder; import tconstruct.library.component.LogicComponent; @@ -30,6 +36,7 @@ public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IActiveLogic, IMasterLogic, IComponentHolder { byte direction; + boolean updateFluids = false; SmelteryScan structure = new SmelteryScan(this, TContent.smeltery, TContent.lavaTank); MultiFluidTank multitank = new MultiFluidTank(); SmelteryComponent smeltery = new SmelteryComponent(this, structure, multitank, 800); @@ -42,9 +49,16 @@ public void updateEntity () if (tick % 4 == 0) smeltery.heatItems(); - if (tick % 20 == 0 && structure.isComplete()) + if (tick % 20 == 0) { - smeltery.update(); + if (structure.isComplete()) + smeltery.update(); + + if (updateFluids) + { + distributeFluids(); + updateFluids = false; + } } if (tick >= 60) @@ -61,6 +75,11 @@ public void updateEntity () } } + public void setUpdateFluids () + { + updateFluids = true; + } + @Override public List getComponents () { @@ -70,7 +89,7 @@ public List getComponents () ret.add(smeltery); return ret; } - + /* Structure */ @Override @@ -84,7 +103,7 @@ public void setWorldObj (World world) @Override public void notifyChange (IServantLogic servant, int x, int y, int z) { - + //Re-check structure here } @Override @@ -96,12 +115,13 @@ public void placeBlock (EntityLivingBase entity, ItemStack itemstack) validateSmeltery(); } } - - void validateSmeltery() + + void validateSmeltery () { adjustInventory(structure.getAirSize(), true); smeltery.adjustSize(structure.getAirSize(), true); - multitank.setCapacity(structure.getAirSize() * (TConstruct.ingotLiquidValue * 18)); + multitank.setCapacity(structure.getAirSize() * (TConstruct.ingotLiquidValue * 18)); + smeltery.setActiveLavaTank(structure.lavaTanks.get(0)); } @Override @@ -109,7 +129,7 @@ public void removeBlock () { structure.cleanup(); } - + /* Direction */ @Override @@ -165,15 +185,15 @@ public void setActive (boolean flag) { } - + /* Inventory */ - + @Override public int getInventoryStackLimit () { return 1; } - + @Override public void setInventorySlotContents (int slot, ItemStack itemstack) { @@ -181,10 +201,10 @@ public void setInventorySlotContents (int slot, ItemStack itemstack) if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); - updateAirBlocks(slot, itemstack); } + updateWorldBlock(slot, itemstack); } - + @Override public ItemStack decrStackSize (int slot, int quantity) { @@ -194,6 +214,7 @@ public ItemStack decrStackSize (int slot, int quantity) { ItemStack stack = inventory[slot]; inventory[slot] = null; + updateWorldBlock(slot, inventory[slot]); return stack; } ItemStack split = inventory[slot].splitStack(quantity); @@ -202,24 +223,196 @@ public ItemStack decrStackSize (int slot, int quantity) inventory[slot] = null; } - updateAirBlocks(slot, inventory[slot]); + updateWorldBlock(slot, inventory[slot]); return split; } else { return null; } + } + + @Override + public void onInventoryChanged () + { + smeltery.updateTemperatures(); + super.onInventoryChanged(); } - void updateAirBlocks (int slot, ItemStack itemstack) + void updateWorldBlock (int slot, ItemStack itemstack) { - //CoordTuple coord = structure.airCoords.; + CoordTuple air = structure.getAirByIndex(slot); + if (air != null) + { + TileEntity te = worldObj.getBlockTileEntity(air.x, air.y, air.z); + if (te != null && te instanceof TankAirLogic) + { + ((TankAirLogic) te).setInventorySlotContents(0, itemstack); + } + } } + static final int pixelLayer = 162; + + //Do the Monster Mash~ + public void distributeFluids () + { + //Calculate liquids in each block + int size = structure.getAirLayerSize(); + HashMap blocks = new HashMap(); + + for (FluidStack fluid : multitank.fluidlist) + { + //Base calculations per liquid + LiquidData data = new LiquidData(fluid.amount, size); + int baseY = structure.airCoords.get(0).y; + int layerSize = structure.getAirLayerSize(); + + //Calculate where to distribute liquids + for (int i = 0; i < structure.airCoords.size(); i++) + { + LiquidDataInstance instance; + CoordTuple coord = structure.airCoords.get(i); + int height = 16 * (baseY - coord.y); + int position = i % layerSize; + + if (!blocks.containsKey(coord)) + { + instance = new LiquidDataInstance(); + blocks.put(coord, instance); + } + else + { + instance = blocks.get(coord); + } + + if (instance.openLayers() > 0) + { + if (position > data.blocksWithExtra) + { + //Calculate open layers + int open = data.layers - height + 1; + if (open > instance.openLayers()) + open = instance.openLayers(); + + //Copy fluid + FluidStack newFluid = fluid.copy(); + newFluid.amount = pixelLayer * open; + instance.addFluid(open, newFluid); + + //Subtract from total + data.totalAmount -= newFluid.amount; + if (data.totalAmount < 0) + continue; + } + else if (position == data.blocksWithExtra && data.leftovers > 0) + { + //Calculate open layers + int open = data.layers - height + 1; + boolean full = false; + if (open > instance.openLayers()) + { + open = instance.openLayers(); + full = true; + } + + //Copy fluid + FluidStack newFluid = fluid.copy(); + newFluid.amount = pixelLayer * open; + if (!full) + newFluid.amount += data.leftovers; + instance.addFluid(open, newFluid); + + //Subtract from total + data.totalAmount -= newFluid.amount; + if (data.totalAmount < 0) + continue; + } + else + { + //Calculate open layers + int open = data.layers - height; + if (open > instance.openLayers()) + open = instance.openLayers(); + + //Copy fluid + FluidStack newFluid = fluid.copy(); + newFluid.amount = pixelLayer * open; + instance.addFluid(open, newFluid); + + //Subtract from total + data.totalAmount -= newFluid.amount; + if (data.totalAmount < 0) + continue; + } + } + } + } + + //Distribute liquids to each block + Iterator iter = blocks.entrySet().iterator(); + while (iter.hasNext()) + { + Map.Entry pairs = (Map.Entry) iter.next(); + CoordTuple coord = (CoordTuple) pairs.getKey(); + TileEntity te = worldObj.getBlockTileEntity(coord.x, coord.y, coord.z); + if (te instanceof TankAirLogic) + { + ((TankAirLogic) te).overrideFluids(((LiquidDataInstance) pairs.getValue()).fluids); + } + } + } + + class LiquidData + { + public int totalAmount; + public int layers; + public int leftovers; + public int blocksWithExtra; + + LiquidData(int amount, int blocks) + { + totalAmount = amount; + int layerAmount = pixelLayer * blocks; + layers = amount / layerAmount; + leftovers = amount % pixelLayer; + blocksWithExtra = (amount % layerAmount) / pixelLayer; + } + } + + class LiquidDataInstance + { + public ArrayList fluids = new ArrayList(); + int layers = 0; + + public int openLayers () + { + return 16 - layers; + } + + public void addFluid (int l, FluidStack fluid) + { + layers += l; + fluids.add(fluid); + } + } + + /* Gui */ + @Override public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z) { - return null; + return new AdaptiveSmelteryContainer(inventoryplayer, this); + } + + public int getTempForSlot (int slot) + { + return smeltery.activeTemps[slot]; + } + + public int getMeltingPointForSlot (int slot) + { + return smeltery.meltingTemps[slot]; } @Override @@ -227,8 +420,8 @@ public String getDefaultName () { return "crafters.Smeltery"; } - - /* Network */ + + /* NBT */ @Override public void readFromNBT (NBTTagCompound tags) @@ -244,6 +437,8 @@ public void readFromNBT (NBTTagCompound tags) public void readNetworkNBT (NBTTagCompound tags) { direction = tags.getByte("Direction"); + inventory = new ItemStack[tags.getInteger("InvSize")]; + System.out.println("Inventory size: " + inventory.length); structure.readNetworkNBT(tags); multitank.readNetworkNBT(tags); @@ -264,6 +459,7 @@ public void writeToNBT (NBTTagCompound tags) public void writeNetworkNBT (NBTTagCompound tags) { tags.setByte("Direction", direction); + tags.setInteger("InvSize", inventory.length); structure.writeNetworkNBT(tags); multitank.writeNetworkNBT(tags); diff --git a/src/tconstruct/blocks/logic/TankAirLogic.java b/src/tconstruct/blocks/logic/TankAirLogic.java index ec4e8831622..be17f519a31 100644 --- a/src/tconstruct/blocks/logic/TankAirLogic.java +++ b/src/tconstruct/blocks/logic/TankAirLogic.java @@ -1,9 +1,17 @@ package tconstruct.blocks.logic; import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.INetworkManager; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; import tconstruct.TConstruct; @@ -13,7 +21,7 @@ import tconstruct.library.util.IMasterLogic; import tconstruct.library.util.IServantLogic; -public class TankAirLogic extends InventoryLogic implements IServantLogic +public class TankAirLogic extends InventoryLogic implements IServantLogic, ISidedInventory { TankAirComponent multitank = new TankAirComponent(TConstruct.ingotLiquidValue * 18); CoordTuple master; @@ -26,6 +34,34 @@ public TankAirLogic() public void overrideFluids(ArrayList fluids) { multitank.overrideFluids(fluids); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + public boolean hasItem() + { + return inventory[0] != null; + } + + public boolean hasFluids() + { + return multitank.fluidlist.size() > 0; + } + + public List getFluids () + { + return multitank.fluidlist; + } + + @Override + public void setInventorySlotContents (int slot, ItemStack itemstack) + { + inventory[slot] = itemstack; + if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + { + itemstack.stackSize = getInventoryStackLimit(); + worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, itemstack == null ? 0 : itemstack.getItemDamage(), 3); + //worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } } @Override @@ -73,4 +109,79 @@ public void invalidateMaster (IMasterLogic master, World world, int xMaster, int { world.setBlockToAir(xCoord, yCoord, zCoord); } + + @Override + public int[] getAccessibleSlotsFromSide (int var1) + { + return new int[0]; + } + + @Override + public boolean canInsertItem (int i, ItemStack itemstack, int j) + { + return false; + } + + @Override + public boolean canExtractItem (int i, ItemStack itemstack, int j) + { + return false; + } + + @Override + public boolean canUpdate() + { + return false; + } + + //Keep TE regardless of metadata + public boolean shouldRefresh(int oldID, int newID, int oldMeta, int newMeta, World world, int x, int y, int z) + { + return oldID != newID; + } + + /* NBT */ + + @Override + public void readFromNBT (NBTTagCompound tags) + { + super.superReadFromNBT(tags); + readNetworkNBT(tags); + multitank.readFromNBT(tags); + } + + public void readNetworkNBT (NBTTagCompound tags) + { + multitank.readNetworkNBT(tags); + super.readInventoryFromNBT(tags); + } + + @Override + public void writeToNBT (NBTTagCompound tags) + { + super.superWriteToNBT(tags); + writeNetworkNBT(tags); + multitank.writeToNBT(tags); + } + + public void writeNetworkNBT (NBTTagCompound tags) + { + multitank.writeNetworkNBT(tags); + super.writeInventoryToNBT(tags); + } + + @Override + public void onDataPacket (INetworkManager net, Packet132TileEntityData packet) + { + readNetworkNBT(packet.data); + worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); + } + + @Override + public Packet getDescriptionPacket () + { + NBTTagCompound tag = new NBTTagCompound(); + writeNetworkNBT(tag); + return new Packet132TileEntityData(xCoord, yCoord, zCoord, 1, tag); + } } diff --git a/src/tconstruct/client/TProxyClient.java b/src/tconstruct/client/TProxyClient.java index 34f5023edab..8a1f39c6c94 100644 --- a/src/tconstruct/client/TProxyClient.java +++ b/src/tconstruct/client/TProxyClient.java @@ -65,7 +65,7 @@ public Object getClientGuiElement (int ID, EntityPlayer player, World world, int if (ID == frypanGuiID) return new FrypanGui(player.inventory, (FrypanLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); if (ID == smelteryGuiID) - return new SmelteryGui(player.inventory, (SmelteryLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); + return new AdaptiveSmelteryGui(player.inventory, (AdaptiveSmelteryLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); if (ID == stencilTableID) return new StencilTableGui(player.inventory, (StencilTableLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); if (ID == toolForgeID) @@ -197,8 +197,8 @@ public void registerRenderer () RenderingRegistry.registerBlockHandler(new TableRender()); RenderingRegistry.registerBlockHandler(new TableForgeRender()); RenderingRegistry.registerBlockHandler(new FrypanRender()); - RenderingRegistry.registerBlockHandler(new SmelteryRender()); RenderingRegistry.registerBlockHandler(new TankRender()); + RenderingRegistry.registerBlockHandler(new TankAirRender()); RenderingRegistry.registerBlockHandler(new SearedRender()); RenderingRegistry.registerBlockHandler(new OreberryRender()); RenderingRegistry.registerBlockHandler(new BarricadeRender()); diff --git a/src/tconstruct/client/block/TankAirRender.java b/src/tconstruct/client/block/TankAirRender.java index 5941f2d1adb..a4a4f36e73e 100644 --- a/src/tconstruct/client/block/TankAirRender.java +++ b/src/tconstruct/client/block/TankAirRender.java @@ -2,23 +2,20 @@ import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; import net.minecraft.world.IBlockAccess; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; - -import org.lwjgl.opengl.GL11; - -import tconstruct.blocks.logic.LavaTankLogic; -import tconstruct.client.TProxyClient; - +import tconstruct.TConstruct; +import tconstruct.blocks.logic.TankAirLogic; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.RenderingRegistry; public class TankAirRender implements ISimpleBlockRenderingHandler { public static int model = RenderingRegistry.getNextAvailableRenderId(); + private static final double capacity = TConstruct.ingotLiquidValue * 18; @Override public void renderInventoryBlock (Block block, int metadata, int modelID, RenderBlocks renderer) @@ -31,33 +28,43 @@ public boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, Block { if (modelID == model) { - //Liquid - LavaTankLogic logic = (LavaTankLogic) world.getBlockTileEntity(x, y, z); - if (logic.containsFluid()) + TankAirLogic logic = (TankAirLogic) world.getBlockTileEntity(x, y, z); + if (logic.hasItem()) { - FluidStack liquid = logic.tank.getFluid(); - renderer.setRenderBounds(0.001, 0.001, 0.001, 0.999, logic.getFluidAmountScaled(), 0.999); - Fluid fluid = liquid.getFluid(); - if (fluid.canBePlacedInWorld()) - BlockSkinRenderHelper.renderMetadataBlock(Block.blocksList[fluid.getBlockID()], 0, x, y, z, renderer, world); - else - BlockSkinRenderHelper.renderLiquidBlock(fluid.getStillIcon(), fluid.getFlowingIcon(), x, y, z, renderer, world); - - renderer.setRenderBounds(00, 0.001, 0.001, 0.999, logic.getFluidAmountScaled(), 0.999); + ItemStack item = logic.getStackInSlot(0); + if (item.getItem() instanceof ItemBlock) + { + Block inv = Block.blocksList[item.itemID]; + renderer.renderBlockByRenderType(inv, x, y, z); + } } - - //Block - int meta = world.getBlockMetadata(x, y, z); - if (meta == 0 && world.getBlockId(x, y + 1, z) == 0) + else if (logic.hasFluids()) { - renderer.setRenderBounds(0.1875, 0, 0.1875, 0.8125, 0.125, 0.8125); - renderer.renderStandardBlock(block, x, y + 1, z); + int base = 0; + for (FluidStack fluidstack : logic.getFluids()) + { + Fluid fluid = fluidstack.getFluid(); + renderer.setRenderBounds(0.0, getBaseAmount(base), 0.0, 1.0, getHeightAmount(base, fluidstack.amount), 1.0); + if (fluid.canBePlacedInWorld()) + BlockSkinRenderHelper.renderMetadataBlock(Block.blocksList[fluid.getBlockID()], 0, x, y, z, renderer, world); + else + BlockSkinRenderHelper.renderLiquidBlock(fluid.getStillIcon(), fluid.getFlowingIcon(), x, y, z, renderer, world); + base += fluidstack.amount; + } } - renderer.setRenderBounds(0, 0, 0, 1, 1, 1); - renderer.renderStandardBlock(block, x, y, z); } return true; } + + private double getBaseAmount (int base) + { + return base / capacity; + } + + private double getHeightAmount (int base, int amount) + { + return (base + amount) / capacity; + } @Override public boolean shouldRender3DInInventory () diff --git a/src/tconstruct/client/gui/AdaptiveSmelteryGui.java b/src/tconstruct/client/gui/AdaptiveSmelteryGui.java new file mode 100644 index 00000000000..ec647cbadcb --- /dev/null +++ b/src/tconstruct/client/gui/AdaptiveSmelteryGui.java @@ -0,0 +1,490 @@ +package tconstruct.client.gui; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.network.packet.Packet250CustomPayload; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Icon; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import tconstruct.blocks.logic.AdaptiveSmelteryLogic; +import tconstruct.inventory.ActiveContainer; +import tconstruct.inventory.SmelteryContainer; +import cpw.mods.fml.common.network.PacketDispatcher; + +public class AdaptiveSmelteryGui extends NewContainerGui +{ + public AdaptiveSmelteryLogic logic; + String username; + boolean isScrolling = false; + boolean wasClicking; + float currentScroll = 0.0F; + int slotPos = 0; + int prevSlotPos = 0; + + public AdaptiveSmelteryGui(InventoryPlayer inventoryplayer, AdaptiveSmelteryLogic smeltery, World world, int x, int y, int z) + { + super((ActiveContainer) smeltery.getGuiContainer(inventoryplayer, world, x, y, z)); + logic = smeltery; + username = inventoryplayer.player.username; + xSize = 248; + //smeltery.updateFuelDisplay(); + } + + public void drawScreen (int mouseX, int mouseY, float par3) + { + super.drawScreen(mouseX, mouseY, par3); + updateScrollbar(mouseX, mouseY, par3); + } + + protected void updateScrollbar (int mouseX, int mouseY, float par3) + { + if (logic.getSizeInventory() > 24) + { + boolean mouseDown = Mouse.isButtonDown(0); + int lefto = this.guiLeft; + int topo = this.guiTop; + int xScroll = lefto + 67; + int yScroll = topo + 8; + int scrollWidth = xScroll + 14; + int scrollHeight = yScroll + 144; + + if (!this.wasClicking && mouseDown && mouseX >= xScroll && mouseY >= yScroll && mouseX < scrollWidth && mouseY < scrollHeight) + { + this.isScrolling = true; + } + + if (!mouseDown) + { + this.isScrolling = false; + } + + if (wasClicking && !isScrolling && slotPos != prevSlotPos) + { + prevSlotPos = slotPos; + } + + this.wasClicking = mouseDown; + + if (this.isScrolling) + { + this.currentScroll = ((float) (mouseY - yScroll) - 7.5F) / ((float) (scrollHeight - yScroll) - 15.0F); + + if (this.currentScroll < 0.0F) + { + this.currentScroll = 0.0F; + } + + if (this.currentScroll > 1.0F) + { + this.currentScroll = 1.0F; + } + + int s = ((SmelteryContainer) this.container).scrollTo(this.currentScroll); + if (s != -1) + slotPos = s; + } + } + } + + protected void drawGuiContainerForegroundLayer (int mouseX, int mouseY) + { + fontRenderer.drawString(StatCollector.translateToLocal("crafters.Smeltery"), 86, 5, 0x404040); + fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 90, (ySize - 96) + 2, 0x404040); + + int base = 0; + int cornerX = (width - xSize) / 2 + 36; + int cornerY = (height - ySize) / 2; + + /*for (FluidStack liquid : logic.moltenMetal) + { + int basePos = 54; + int initialLiquidSize = 0; + int liquidSize = 0;//liquid.amount * 52 / liquidLayers; + if (logic.getCapacity() > 0) + { + int total = logic.getTotalLiquid(); + int liquidLayers = (total / 20000 + 1) * 20000; + if (liquidLayers > 0) + { + liquidSize = liquid.amount * 52 / liquidLayers; + if (liquidSize == 0) + liquidSize = 1; + base += liquidSize; + } + } + + int leftX = cornerX + basePos; + int topY = (cornerY + 68) - base; + int sizeX = 52; + int sizeY = liquidSize; + if (mouseX >= leftX && mouseX <= leftX + sizeX && mouseY >= topY && mouseY < topY + sizeY) + { + drawFluidStackTooltip(liquid, mouseX - cornerX + 36, mouseY - cornerY); + + } + } + if (logic.fuelGague > 0) + { + int leftX = cornerX + 117; + int topY = (cornerY + 68) - logic.getScaledFuelGague(52); + int sizeX = 12; + int sizeY = logic.getScaledFuelGague(52); + if (mouseX >= leftX && mouseX <= leftX + sizeX && mouseY >= topY && mouseY < topY + sizeY) + { + drawFluidStackTooltip(new FluidStack(-37, logic.fuelAmount), mouseX - cornerX + 36, mouseY - cornerY); + } + }*/ + } + + private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/smeltery.png"); + private static final ResourceLocation backgroundSide = new ResourceLocation("tinker", "textures/gui/smelteryside.png"); + private static final ResourceLocation terrain = new ResourceLocation("terrain.png"); + + protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(background); + int cornerX = (width - xSize) / 2 + 36; + int cornerY = (height - ySize) / 2; + drawTexturedModalRect(cornerX + 46, cornerY, 0, 0, 176, ySize); + + //Fuel - Lava + /*this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + if (logic.fuelGague > 0) + { + Icon lavaIcon = Block.lavaStill.getIcon(0, 0); + int fuel = logic.getScaledFuelGague(52); + int count = 0; + while (fuel > 0) + { + int size = fuel >= 16 ? 16 : fuel; + fuel -= size; + drawLiquidRect(cornerX + 117, (cornerY + 68) - size - 16 * count, lavaIcon, 12, size); + count++; + } + }*/ + + //Liquids - molten metal + /*int base = 0; + for (FluidStack liquid : logic.moltenMetal) + { + Icon renderIndex = liquid.getFluid().getStillIcon(); + int basePos = 54; + if (logic.getCapacity() > 0) + { + int total = logic.getTotalLiquid(); + int liquidLayers = (total / 20000 + 1) * 20000; + if (liquidLayers > 0) + { + int liquidSize = liquid.amount * 52 / liquidLayers; + if (liquidSize == 0) + liquidSize = 1; + while (liquidSize > 0) + { + int size = liquidSize >= 16 ? 16 : liquidSize; + drawLiquidRect(cornerX + basePos, (cornerY + 68) - size - base, renderIndex, 16, size); + drawLiquidRect(cornerX + basePos + 16, (cornerY + 68) - size - base, renderIndex, 16, size); + drawLiquidRect(cornerX + basePos + 32, (cornerY + 68) - size - base, renderIndex, 16, size); + drawLiquidRect(cornerX + basePos + 48, (cornerY + 68) - size - base, renderIndex, 4, size); + liquidSize -= size; + base += size; + } + } + } + }*/ + + //Liquid gague + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + this.mc.getTextureManager().bindTexture(background); + drawTexturedModalRect(cornerX + 54, cornerY + 16, 176, 76, 52, 52); + + //Side inventory + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(backgroundSide); + //if (logic.layers > 0) + { + /*if (logic.layers == 1) + { + drawTexturedModalRect(cornerX - 46, cornerY, 0, 0, 98, 43); + drawTexturedModalRect(cornerX - 46, cornerY + 43, 0, 133, 98, 25); + } + else if (logic.layers == 2) + { + drawTexturedModalRect(cornerX - 46, cornerY, 0, 0, 98, 61); + drawTexturedModalRect(cornerX - 46, cornerY + 61, 0, 97, 98, 61); + } + else*/ + { + drawTexturedModalRect(cornerX - 46, cornerY, 0, 0, 98, ySize - 8); + } + drawTexturedModalRect(cornerX + 32, (int) (cornerY + 8 + 127 * currentScroll), 98, 0, 12, 15); + } + + //Temperature + int slotSize = logic.getSizeInventory(); + if (slotSize > 24) + slotSize = 24; + for (int iter = 0; iter < slotSize; iter++) + { + int slotTemp = logic.getTempForSlot(iter + slotPos * 3) - 20; + int maxTemp = logic.getMeltingPointForSlot(iter + slotPos * 3) - 20; + if (slotTemp > 0 && maxTemp > 0) + { + int size = 16 * slotTemp / maxTemp + 1; + drawTexturedModalRect(cornerX - 38 + (iter % 3 * 22), cornerY + 8 + (iter / 3 * 18) + 16 - size, 98, 15 + 16 - size, 5, size); + } + } + } + + protected void drawFluidStackTooltip (FluidStack par1ItemStack, int par2, int par3) + { + this.zLevel = 100; + List list = getLiquidTooltip(par1ItemStack, this.mc.gameSettings.advancedItemTooltips); + + for (int k = 0; k < list.size(); ++k) + { + list.set(k, EnumChatFormatting.GRAY + (String) list.get(k)); + } + + this.drawToolTip(list, par2, par3); + this.zLevel = 0; + } + + public List getLiquidTooltip (FluidStack liquid, boolean par2) + { + ArrayList list = new ArrayList(); + if (liquid.fluidID == -37) + { + list.add("\u00A7fFuel"); + int mB = liquid.amount; + if (mB > 0) + list.add("mB: " + mB); + } + else + { + String name = StatCollector.translateToLocal(FluidRegistry.getFluidName(liquid)); + list.add("\u00A7f" + name); + if (name.equals("liquified emerald")) + { + float emeralds = liquid.amount / 320f; + list.add("Emeralds: " + emeralds); + } + else if (name.contains("Molten")) + { + int ingots = liquid.amount / 144; + if (ingots > 0) + list.add("Ingots: " + ingots); + int mB = liquid.amount % 144; + if (mB > 0) + { + if (mB % 72 == 0) + list.add("Chunks: " + liquid.amount % 144 / 72); + else if (mB % 16 == 0) + list.add("Nuggets: " + liquid.amount % 144 / 16); + else + list.add("mB: " + mB); + } + } + else if (name.equals("Seared Stone")) + { + int ingots = liquid.amount / 144; + if (ingots > 0) + list.add("Blocks: " + ingots); + int mB = liquid.amount % 144; + if (mB > 0) + { + list.add("mB: " + mB); + } + } + else if (name.equals("Molten Glass")) + { + int ingots = liquid.amount / 1000; + if (ingots > 0) + list.add("Blocks: " + ingots); + int mB = liquid.amount % 144; + if (mB > 0) + { + list.add("mB: " + mB); + } + } + else + { + int mB = liquid.amount; + list.add("mB: " + mB); + } + } + return list; + } + + protected void drawToolTip (List par1List, int par2, int par3) + { + if (!par1List.isEmpty()) + { + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + int k = 0; + Iterator iterator = par1List.iterator(); + + while (iterator.hasNext()) + { + String s = (String) iterator.next(); + int l = this.fontRenderer.getStringWidth(s); + + if (l > k) + { + k = l; + } + } + + int i1 = par2 + 12; + int j1 = par3 - 12; + int k1 = 8; + + if (par1List.size() > 1) + { + k1 += 2 + (par1List.size() - 1) * 10; + } + + if (i1 + k > this.width) + { + i1 -= 28 + k; + } + + if (j1 + k1 + 6 > this.height) + { + j1 = this.height - k1 - 6; + } + + this.zLevel = 300.0F; + itemRenderer.zLevel = 300.0F; + int l1 = -267386864; + this.drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1); + this.drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1); + this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1); + this.drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1); + this.drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1); + int i2 = 1347420415; + int j2 = (i2 & 16711422) >> 1 | i2 & -16777216; + this.drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2); + this.drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2); + this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2); + this.drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2); + + for (int k2 = 0; k2 < par1List.size(); ++k2) + { + String s1 = (String) par1List.get(k2); + this.fontRenderer.drawStringWithShadow(s1, i1, j1, -1); + + if (k2 == 0) + { + j1 += 2; + } + + j1 += 10; + } + + this.zLevel = 0.0F; + itemRenderer.zLevel = 0.0F; + } + } + + public void drawLiquidRect (int startU, int startV, Icon par3Icon, int endU, int endV) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV((double) (startU + 0), (double) (startV + endV), (double) this.zLevel, (double) par3Icon.getMinU(), (double) par3Icon.getMaxV());//Bottom left + tessellator.addVertexWithUV((double) (startU + endU), (double) (startV + endV), (double) this.zLevel, (double) par3Icon.getMaxU(), (double) par3Icon.getMaxV());//Bottom right + tessellator.addVertexWithUV((double) (startU + endU), (double) (startV + 0), (double) this.zLevel, (double) par3Icon.getMaxU(), (double) par3Icon.getMinV());//Top right + tessellator.addVertexWithUV((double) (startU + 0), (double) (startV + 0), (double) this.zLevel, (double) par3Icon.getMinU(), (double) par3Icon.getMinV()); //Top left + tessellator.draw(); + } + + /*@Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) + { + super.mouseClicked(mouseX, mouseY, mouseButton); + + int base = 0; + int cornerX = (width - xSize) / 2 + 36; + int cornerY = (height - ySize) / 2; + int fluidToBeBroughtUp = -1; + + for (FluidStack liquid : logic.moltenMetal) + { + int basePos = 54; + int initialLiquidSize = 0; + int liquidSize = 0;//liquid.amount * 52 / liquidLayers; + if (logic.getCapacity() > 0) + { + int total = logic.getTotalLiquid(); + int liquidLayers = (total / 20000 + 1) * 20000; + if (liquidLayers > 0) + { + liquidSize = liquid.amount * 52 / liquidLayers; + if (liquidSize == 0) + liquidSize = 1; + base += liquidSize; + } + } + + int leftX = cornerX + basePos; + int topY = (cornerY + 68) - base; + int sizeX = 52; + int sizeY = liquidSize; + if (mouseX >= leftX && mouseX <= leftX + sizeX && mouseY >= topY && mouseY < topY + sizeY) + { + fluidToBeBroughtUp = liquid.fluidID; + + Packet250CustomPayload packet = new Packet250CustomPayload(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + + try + { + dos.write(11); + + dos.writeInt(logic.worldObj.provider.dimensionId); + dos.writeInt(logic.xCoord); + dos.writeInt(logic.yCoord); + dos.writeInt(logic.zCoord); + + dos.writeBoolean(this.isShiftKeyDown()); + + dos.writeInt(fluidToBeBroughtUp); + } + catch (Exception e) + { + e.printStackTrace(); + } + + packet.channel = "TConstruct"; + packet.data = bos.toByteArray(); + packet.length = bos.size(); + + PacketDispatcher.sendPacketToServer(packet); + } + } + }*/ +} diff --git a/src/tconstruct/common/TContent.java b/src/tconstruct/common/TContent.java index 79894a438f7..c197ad7ae5b 100644 --- a/src/tconstruct/common/TContent.java +++ b/src/tconstruct/common/TContent.java @@ -383,8 +383,7 @@ void registerBlocks () //Smeltery smeltery = new SmelteryBlock(PHConstruct.smeltery).setUnlocalizedName("Smeltery"); GameRegistry.registerBlock(smeltery, SmelteryItemBlock.class, "Smeltery"); - GameRegistry.registerTileEntity(SmelteryLogic.class, "TConstruct.Smeltery"); - //GameRegistry.registerTileEntity(AdaptiveSmelteryLogic.class, "TConstruct.Smeltery"); + GameRegistry.registerTileEntity(AdaptiveSmelteryLogic.class, "TConstruct.Smeltery"); GameRegistry.registerTileEntity(SmelteryDrainLogic.class, "TConstruct.SmelteryDrain"); GameRegistry.registerTileEntity(MultiServantLogic.class, "TConstruct.Servants"); diff --git a/src/tconstruct/inventory/AdaptiveSmelteryContainer.java b/src/tconstruct/inventory/AdaptiveSmelteryContainer.java new file mode 100644 index 00000000000..b5c08fb0499 --- /dev/null +++ b/src/tconstruct/inventory/AdaptiveSmelteryContainer.java @@ -0,0 +1,266 @@ +package tconstruct.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import tconstruct.blocks.logic.AdaptiveSmelteryLogic; + +public class AdaptiveSmelteryContainer extends ActiveContainer +{ + public AdaptiveSmelteryLogic logic; + public InventoryPlayer playerInv; + public int fuel = 0; + int slotRow; + + public AdaptiveSmelteryContainer(InventoryPlayer inventoryplayer, AdaptiveSmelteryLogic smeltery) + { + logic = smeltery; + playerInv = inventoryplayer; + slotRow = 0; + + /* Smeltery inventory */ + + int height = smeltery.getSizeInventory() / 3; + for (int y = 0; y < height; y++) + { + for (int x = 0; x < 3; x++) + { + this.addDualSlotToContainer(new ActiveSlot(smeltery, x + y * 3, 2 + x * 22, 8 + y * 18, y < 8)); + } + } + int leftovers = smeltery.getSizeInventory() % 3; + for (int x = 0; x < leftovers; x++) + { + this.addDualSlotToContainer(new ActiveSlot(smeltery, x + height * 3, 2 + x * 22, 8 + height * 18, height < 8)); + } + + /* Player inventory */ + for (int column = 0; column < 3; column++) + { + for (int row = 0; row < 9; row++) + { + this.addSlotToContainer(new Slot(inventoryplayer, row + column * 9 + 9, 90 + row * 18, 84 + column * 18)); + } + } + + for (int column = 0; column < 9; column++) + { + this.addSlotToContainer(new Slot(inventoryplayer, column, 90 + column * 18, 142)); + } + } + + public int updateRows (int invRow) + { + if (invRow != slotRow) + { + slotRow = invRow; + //System.out.println(invRow); + int basePos = invRow * 3; + for (int iter = 0; iter < activeInventorySlots.size(); iter++) + { + ActiveSlot slot = (ActiveSlot) activeInventorySlots.get(iter); + if (slot.activeSlotNumber >= basePos && slot.activeSlotNumber < basePos + 24) + { + slot.setActive(true); + } + else + { + slot.setActive(false); + } + int xPos = (iter - basePos) % 3; + int yPos = (iter - basePos) / 3; + slot.xDisplayPosition = 2 + 22 * xPos; + slot.yDisplayPosition = 8 + 18 * yPos; + } + return slotRow; + } + return -1; + } + + public int scrollTo (float scrollPos) + { + float total = (logic.getSizeInventory() - 24) / 3; + int rowPos = (int) (total * scrollPos); + return updateRows(rowPos); + } + + public void updateProgressBar (int id, int value) + { + + } + + @Override + public boolean canInteractWith (EntityPlayer entityplayer) + { + return logic.isUseableByPlayer(entityplayer); + } + + @Override + public ItemStack transferStackInSlot (EntityPlayer player, int slotID) + { + ItemStack stack = null; + Slot slot = (Slot) this.inventorySlots.get(slotID); + + if (slot != null && slot.getHasStack()) + { + ItemStack slotStack = slot.getStack(); + stack = slotStack.copy(); + + if (slotID < logic.getSizeInventory()) + { + if (!this.mergeItemStack(slotStack, logic.getSizeInventory(), this.inventorySlots.size(), true)) + { + return null; + } + } + else if (!this.mergeItemStack(slotStack, 0, logic.getSizeInventory(), false)) + { + return null; + } + + if (slotStack.stackSize == 0) + { + slot.putStack((ItemStack) null); + } + else + { + slot.onSlotChanged(); + } + } + + return stack; + } + + @Override + protected boolean mergeItemStack (ItemStack inputStack, int startSlot, int endSlot, boolean flag) + { + //System.out.println("Merge"); + boolean merged = false; + int slotPos = startSlot; + + if (flag) + { + slotPos = endSlot - 1; + } + + Slot slot; + ItemStack slotStack; + + /*if (inputStack.isStackable() && startSlot >= logic.getSizeInventory()) + { + System.out.println("Rawr!"); + while (inputStack.stackSize > 0 && (!flag && slotPos < endSlot || flag && slotPos >= startSlot)) + { + slot = (Slot) this.inventorySlots.get(slotPos); + slotStack = slot.getStack(); + + if (slotStack != null && ItemStack.areItemStacksEqual(inputStack, slotStack) && !inputStack.getHasSubtypes()) + { + int totalSize = slotStack.stackSize + inputStack.stackSize; + + if (totalSize <= inputStack.getMaxStackSize()) + { + inputStack.stackSize = 0; + slotStack.stackSize = totalSize; + slot.onSlotChanged(); + merged = true; + } + else if (slotStack.stackSize < inputStack.getMaxStackSize()) + { + inputStack.stackSize -= inputStack.getMaxStackSize() - slotStack.stackSize; + slotStack.stackSize = inputStack.getMaxStackSize(); + slot.onSlotChanged(); + merged = true; + } + } + + if (flag) + { + --slotPos; + } + else + { + ++slotPos; + } + } + }*/ + + if (inputStack.isStackable() && startSlot >= logic.getSizeInventory()) + { + while (inputStack.stackSize > 0 && (!flag && slotPos < endSlot || flag && slotPos >= startSlot)) + { + slot = (Slot) this.inventorySlots.get(slotPos); + slotStack = slot.getStack(); + + if (slotStack != null && slotStack.itemID == inputStack.itemID && (!inputStack.getHasSubtypes() || inputStack.getItemDamage() == slotStack.getItemDamage()) + && ItemStack.areItemStackTagsEqual(inputStack, slotStack)) + { + int l = slotStack.stackSize + inputStack.stackSize; + + if (l <= inputStack.getMaxStackSize()) + { + inputStack.stackSize = 0; + slotStack.stackSize = l; + slot.onSlotChanged(); + merged = true; + } + else if (slotStack.stackSize < inputStack.getMaxStackSize()) + { + inputStack.stackSize -= inputStack.getMaxStackSize() - slotStack.stackSize; + slotStack.stackSize = inputStack.getMaxStackSize(); + slot.onSlotChanged(); + merged = true; + } + } + + if (flag) + { + --slotPos; + } + else + { + ++slotPos; + } + } + } + + if (inputStack.stackSize > 0) + { + if (flag) + { + slotPos = endSlot - 1; + } + else + { + slotPos = startSlot; + } + + while (!flag && slotPos < endSlot || flag && slotPos >= startSlot) + { + slot = (Slot) this.inventorySlots.get(slotPos); + slotStack = slot.getStack(); + + if (slotStack == null) + { + slot.putStack(inputStack.copy()); + slot.onSlotChanged(); + inputStack.stackSize -= 1; + merged = true; + break; + } + + if (flag) + { + --slotPos; + } + else + { + ++slotPos; + } + } + } + + return merged; + } +} diff --git a/src/tconstruct/library/blocks/InventoryLogic.java b/src/tconstruct/library/blocks/InventoryLogic.java index c022194520e..e1eb9672f09 100644 --- a/src/tconstruct/library/blocks/InventoryLogic.java +++ b/src/tconstruct/library/blocks/InventoryLogic.java @@ -107,6 +107,12 @@ public boolean isUseableByPlayer (EntityPlayer entityplayer) /* NBT */ @Override public void readFromNBT (NBTTagCompound tags) + { + super.readFromNBT(tags); + readInventoryFromNBT(tags); + } + + public void readInventoryFromNBT (NBTTagCompound tags) { super.readFromNBT(tags); this.invName = tags.getString("InvName"); @@ -127,6 +133,11 @@ public void readFromNBT (NBTTagCompound tags) public void writeToNBT (NBTTagCompound tags) { super.writeToNBT(tags); + writeInventoryToNBT(tags); + } + + public void writeInventoryToNBT (NBTTagCompound tags) + { if (invName != null) tags.setString("InvName", invName); NBTTagList nbttaglist = new NBTTagList(); @@ -143,7 +154,18 @@ public void writeToNBT (NBTTagCompound tags) tags.setTag("Items", nbttaglist); } - + + //Added for blocks that need to sync inventory + public void superReadFromNBT (NBTTagCompound tags) + { + super.readFromNBT(tags); + } + + public void superWriteToNBT (NBTTagCompound tags) + { + super.writeToNBT(tags); + } + /* Default implementations of hardly used methods */ public ItemStack getStackInSlotOnClosing (int slot) { diff --git a/src/tconstruct/library/component/MultiFluidTank.java b/src/tconstruct/library/component/MultiFluidTank.java index 8de66893a7c..db86694a5a3 100644 --- a/src/tconstruct/library/component/MultiFluidTank.java +++ b/src/tconstruct/library/component/MultiFluidTank.java @@ -168,9 +168,11 @@ public FluidTankInfo[] getMultiTankInfo () info[fluidlist.size()] = new FluidTankInfo(null, maxLiquid - currentLiquid); return info; } + + /* Sync liquids */ @Override - public void readFromNBT (NBTTagCompound tags) + public void readNetworkNBT (NBTTagCompound tags) { NBTTagList liquidTag = tags.getTagList("Liquids"); fluidlist.clear(); @@ -184,7 +186,7 @@ public void readFromNBT (NBTTagCompound tags) } @Override - public void writeToNBT (NBTTagCompound tags) + public void writeNetworkNBT (NBTTagCompound tags) { NBTTagList taglist = new NBTTagList(); for (FluidStack liquid : fluidlist) diff --git a/src/tconstruct/library/component/TankLayerScan.java b/src/tconstruct/library/component/TankLayerScan.java index da3ecb719dd..ce156bb5267 100644 --- a/src/tconstruct/library/component/TankLayerScan.java +++ b/src/tconstruct/library/component/TankLayerScan.java @@ -30,12 +30,12 @@ public class TankLayerScan extends LogicComponent protected HashSet layerBlockCoords = new HashSet(); protected HashSet layerAirCoords = new HashSet(); - protected ArrayList blockCoords = new ArrayList(); - protected ArrayList airCoords = new ArrayList(); + public ArrayList blockCoords = new ArrayList(); + public ArrayList airCoords = new ArrayList(); protected ArrayList validAirCoords = new ArrayList(); protected CoordTuple returnStone; - private boolean debug = true; + private boolean debug = false; public TankLayerScan(TileEntity te, Block... ids) { @@ -140,15 +140,6 @@ public void checkValidStructure () } } } - - if (completeStructure) - { - - } - else - { - - } } protected void finalizeStructure () @@ -161,11 +152,24 @@ public boolean isComplete () return completeStructure; } + public int getAirLayerSize () + { + return layerAirCoords.size(); + } + public int getAirSize () { return airBlocks; } + public CoordTuple getAirByIndex (int index) + { + if (index >= airCoords.size() || index < 0) + return null; + + return airCoords.get(index); + } + private byte getDirection () { if (master instanceof IFacingLogic) @@ -400,9 +404,7 @@ public void cleanup () TileEntity te = world.getBlockTileEntity(coord.x, coord.y, coord.z); if (te != null && te instanceof IServantLogic) { - IServantLogic servant = (IServantLogic) te; - if (servant != null) - servant.invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord); + ((IServantLogic) te).invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord); } } } @@ -448,7 +450,7 @@ public void readFromNBT (NBTTagCompound tags) airCoords.add(new CoordTuple(coord[0], coord[1], coord[2])); } } - + super.readFromNBT(tags); } @@ -480,12 +482,12 @@ public void writeToNBT (NBTTagCompound tags) air.appendTag(new NBTTagIntArray("coord", new int[] { coord.x, coord.y, coord.z })); } tags.setTag("Air", air); - + super.writeToNBT(tags); } - + public void writeNetworkNBT (NBTTagCompound tags) { - tags.setBoolean("Complete", completeStructure); + tags.setBoolean("Complete", completeStructure); } }