diff --git a/resources/assets/tinker/textures/gui/slotButton.png b/resources/assets/tinker/textures/gui/slotButton.png new file mode 100644 index 00000000000..4cdd631f16f Binary files /dev/null and b/resources/assets/tinker/textures/gui/slotButton.png differ diff --git a/src/tconstruct/blocks/RedstoneMachine.java b/src/tconstruct/blocks/RedstoneMachine.java index d6f5784349b..695445426f5 100644 --- a/src/tconstruct/blocks/RedstoneMachine.java +++ b/src/tconstruct/blocks/RedstoneMachine.java @@ -35,10 +35,10 @@ public RedstoneMachine(int id) @Override public int getLightValue (IBlockAccess world, int x, int y, int z) { - if (world.getBlockMetadata(x, y, z) == 0) + if (world.getBlockMetadata(x, y, z) == 0 || world.getBlockMetadata(x, y, z) == 2) { TileEntity logic = world.getBlockTileEntity(x, y, z); - + if (logic != null && logic instanceof DrawbridgeLogic) { if (((DrawbridgeLogic) logic).getStackInSlot(1) != null) @@ -48,6 +48,16 @@ public int getLightValue (IBlockAccess world, int x, int y, int z) return lightValue[stack.itemID]; } } + + if (logic != null && logic instanceof AdvancedDrawbridgeLogic) + { + if (((AdvancedDrawbridgeLogic) logic).camoInventory.getCamoStack() != null) + { + ItemStack stack = ((AdvancedDrawbridgeLogic) logic).camoInventory.getCamoStack(); + if (stack.itemID < 4096 && Block.blocksList[stack.itemID] != null) + return lightValue[stack.itemID]; + } + } } return super.getLightValue(world, x, y, z); } @@ -80,8 +90,8 @@ public TileEntity createTileEntity (World world, int metadata) return new DrawbridgeLogic(); case 1: return new FirestarterLogic(); -// case 2: -// return new AdvancedDrawbridgeLogic(); + case 2: + return new AdvancedDrawbridgeLogic(); default: return null; } @@ -95,6 +105,8 @@ public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplay { case 0: return TConstruct.proxy.drawbridgeID; + case 2: + return TConstruct.proxy.advDrawbridgeID; } return null; } @@ -168,6 +180,26 @@ public Icon getBlockTexture (IBlockAccess world, int x, int y, int z, int side) return icons[getTextureIndex(side)]; } } + + if (meta == 2) + { + AdvancedDrawbridgeLogic drawbridge = (AdvancedDrawbridgeLogic) logic; + ItemStack stack = drawbridge.camoInventory.getCamoStack(); + if (stack != null && stack.itemID < 4096) + { + Block block = Block.blocksList[stack.itemID]; + if (block != null && block.renderAsNormalBlock()) + return block.getIcon(side, stack.getItemDamage()); + } + if (side == direction) + { + return icons[getTextureIndex(side) + 3]; + } + else + { + return icons[getTextureIndex(side)]; + } + } if (meta == 1) { diff --git a/src/tconstruct/blocks/logic/AdvancedDrawbridgeLogic.java b/src/tconstruct/blocks/logic/AdvancedDrawbridgeLogic.java index cabf96d8b25..72fb4085412 100644 --- a/src/tconstruct/blocks/logic/AdvancedDrawbridgeLogic.java +++ b/src/tconstruct/blocks/logic/AdvancedDrawbridgeLogic.java @@ -1,446 +1,530 @@ -//package tconstruct.blocks.logic; -// -//import java.util.ArrayList; -//import net.minecraft.block.Block; -//import net.minecraft.entity.EntityLivingBase; -//import net.minecraft.entity.player.*; -//import net.minecraft.inventory.Container; -//import net.minecraft.item.ItemStack; -//import net.minecraft.nbt.NBTTagCompound; -//import net.minecraft.network.INetworkManager; -//import net.minecraft.network.packet.*; -//import net.minecraft.util.MathHelper; -//import net.minecraft.world.World; -//import net.minecraftforge.common.ForgeDirection; -//import tconstruct.inventory.AdvancedDrawbridgeContainer; -//import tconstruct.library.TConstructRegistry; -//import tconstruct.library.blocks.*; -//import tconstruct.library.util.*; -//import tconstruct.util.player.FakePlayerLogic; -// -//public class AdvancedDrawbridgeLogic extends ExpandableInventoryLogic implements IFacingLogic, IActiveLogic, IDrawbridgeLogicBase { -// boolean active; -// boolean working; -// int ticks; -// public int selSlot = 0; -// byte extension; -// byte direction; -// byte placementDirection = 4; -// FakePlayerLogic fakePlayer; -// -// ArrayList bufferStacks = new ArrayList(); -// -// @Override -// public void setWorldObj(World par1World) { -// this.worldObj = par1World; -// fakePlayer = new FakePlayerLogic(worldObj, "Player.Drawbridge", this); -// } -// -// @Override -// public boolean getActive() { -// return active; -// } -// -// @Override -// public void setActive(boolean flag) { -// active = flag; -// working = true; -// } -// -// @Override -// public byte getRenderDirection() { -// return direction; -// } -// -// @Override -// public ForgeDirection getForgeDirection() { -// return ForgeDirection.VALID_DIRECTIONS[direction]; -// } -// -// @Override -// public void setDirection(int side) { -// } -// -// public boolean canDropInventorySlot(int slot) { -// return false; -// } -// -// @Override -// public void setDirection(float yaw, float pitch, EntityLivingBase player) { -// if (pitch > 45) { -// direction = 1; -// } else if (pitch < -45) { -// direction = 0; -// } else { -// int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3; -// switch (facing) { -// case 0: -// direction = 2; -// break; -// -// case 1: -// direction = 5; -// break; -// -// case 2: -// direction = 3; -// break; -// -// case 3: -// direction = 4; -// break; -// } -// } -// } -// -// /* -// * 0 = Up 1 = Right 2 = Down 3 = Left 4 = Center, neutral -// */ -// public void setPlacementDirection(byte keycode) { -// if (keycode == 4) { -// fakePlayer.rotationYaw = 0; -// fakePlayer.rotationPitch = 0; -// } else if (this.direction == 0 || this.direction == 1) { -// switch (keycode) { -// case 0: -// fakePlayer.rotationYaw = 0; -// break; -// case 1: -// fakePlayer.rotationYaw = 90; -// break; -// case 2: -// fakePlayer.rotationYaw = 180; -// break; -// case 3: -// fakePlayer.rotationYaw = 270; -// break; -// } -// -// if (this.direction == 0) -// fakePlayer.rotationPitch = -90; -// else -// fakePlayer.rotationPitch = 90; -// } else { -// if (keycode == 0) // Forward -// { -// fakePlayer.rotationYaw = mapDirection() * 90; -// -// if (keycode == 0) -// fakePlayer.rotationPitch = 90; -// else -// fakePlayer.rotationPitch = -90; -// } else if (keycode == 2) // Backward -// { -// int face = mapDirection() + 2; -// if (face > 3) -// face -= 4; -// fakePlayer.rotationYaw = face * 90; -// -// if (keycode == 0) -// fakePlayer.rotationPitch = 90; -// else -// fakePlayer.rotationPitch = -90; -// } else { -// fakePlayer.rotationPitch = 0; -// -// int facing = mapDirection(); -// if (keycode == 1) -// facing += 1; -// else -// facing -= 1; -// -// if (facing >= 4) -// facing = 0; -// if (facing < 0) -// facing = 3; -// -// fakePlayer.rotationYaw = facing * 90; -// } -// } -// placementDirection = keycode; -// } -// -// int mapDirection() { -// if (this.direction == 2) // North -// return 0; -// if (this.direction == 5) // East -// return 1; -// if (this.direction == 3) // South -// return 2; -// -// return 3; // West -// } -// -// public byte getPlacementDirection() { -// return placementDirection; -// } -// -// @Override -// public Container getGuiContainer(InventoryPlayer inventoryplayer, World world, int x, int y, int z) { -// return new AdvancedDrawbridgeContainer(inventoryplayer, this); -// } -// -// @Override -// protected String getDefaultName() { -// return "tinker.drawbridge"; -// } -// -// @Override -// public void setInventorySlotContents(int slot, ItemStack itemstack) { -// super.setInventorySlotContents(slot, itemstack); -// if (slot == 1) -// worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); -// } -// -// @Override -// public ItemStack decrStackSize(int slot, int quantity) { -// ItemStack stack = super.decrStackSize(slot, quantity); -// if (slot == 1) -// worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); -// return stack; -// } -// -// public void updateEntity() { -// if (working) { -// ticks++; -// if (ticks == 5) { -// ticks = 0; -// if (active) // Placement -// { -// if (inventory[0] != null && inventory[0].stackSize > 0 && extension < 15) { -// extension++; -// int xPos = xCoord; -// int yPos = yCoord; -// int zPos = zCoord; -// -// switch (direction) { -// case 0: -// yPos -= extension; -// break; -// case 1: -// yPos += extension; -// break; -// case 2: -// zPos -= extension; -// break; -// case 3: -// zPos += extension; -// break; -// case 4: -// xPos -= extension; -// break; -// case 5: -// xPos += extension; -// break; -// } -// -// Block block = Block.blocksList[worldObj.getBlockId(xPos, yPos, zPos)]; -// if (block == null || block.isAirBlock(worldObj, xPos, yPos, zPos) || block.isBlockReplaceable(worldObj, xPos, yPos, zPos)) { -// // tryExtend(worldObj, xPos, yPos, zPos, direction); -// int blockToItem = TConstructRegistry.blockToItemMapping[bufferStack.itemID]; -// if (blockToItem == 0) { -// if (inventory[0].itemID >= 4096 || Block.blocksList[inventory[0].itemID] == null) -// return; -// Block placeBlock = Block.blocksList[bufferStack.itemID]; -// placeBlockAt(bufferStack, fakePlayer, worldObj, xPos, yPos, zPos, direction, 0, 0, 0, bufferStack.getItemDamage(), placeBlock); -// } else { -// Block placeBlock = Block.blocksList[blockToItem]; -// placeBlockAt(bufferStack, fakePlayer, worldObj, xPos, yPos, zPos, direction, 0, 0, 0, bufferStack.getItemDamage(), placeBlock); -// } -// worldObj.playSoundEffect((double) xPos + 0.5D, (double) yPos + 0.5D, (double) zPos + 0.5D, "tile.piston.out", 0.25F, worldObj.rand.nextFloat() * 0.25F + 0.6F); -// decrStackSize(0, 1); -// } else { -// extension--; -// working = false; -// } -// } -// -// else { -// working = false; -// } -// } else -// // Retraction -// { -// if ((inventory[0] == null || inventory[0].stackSize < inventory[0].getMaxStackSize()) && extension > 0) { -// int xPos = xCoord; -// int yPos = yCoord; -// int zPos = zCoord; -// -// switch (direction) { -// case 0: -// yPos -= extension; -// break; -// case 1: -// yPos += extension; -// break; -// case 2: -// zPos -= extension; -// break; -// case 3: -// zPos += extension; -// break; -// case 4: -// xPos -= extension; -// break; -// case 5: -// xPos += extension; -// break; -// } -// -// Block block = Block.blocksList[worldObj.getBlockId(xPos, yPos, zPos)]; -// if (block != null) { -// int meta = worldObj.getBlockMetadata(xPos, yPos, zPos); -// if (bufferStack != null && validBlock(block) && validMetadata(block.blockID, meta)) { -// worldObj.playSoundEffect((double) xPos + 0.5D, (double) yPos + 0.5D, (double) zPos + 0.5D, "tile.piston.in", 0.25F, worldObj.rand.nextFloat() * 0.15F + 0.6F); -// if (worldObj.setBlock(xPos, yPos, zPos, 0)) -// if (inventory[0] == null) { -// inventory[0] = bufferStack.copy(); -// } else { -// inventory[0].stackSize++; -// } -// } else { -// working = false; -// } -// } -// extension--; -// } else { -// working = false; -// } -// } -// } -// } -// } -// -// /** -// * Called to actually place the block, after the location is determined and -// * all permission checks have been made. Copied from ItemBlock -// * -// * @param stack -// * The item stack that was used to place the block. This can be -// * changed inside the method. -// * @param player -// * The player who is placing the block. Can be null if the block -// * is not being placed by a player. -// * @param side -// * The side the player (or machine) right-clicked on. -// */ -// public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata, Block block) { -// if (!world.setBlock(x, y, z, block.blockID, metadata, 3)) { -// return false; -// } -// -// if (world.getBlockId(x, y, z) == block.blockID) { -// block.onBlockPlacedBy(world, x, y, z, player, stack); -// block.onPostBlockPlaced(world, x, y, z, metadata); -// } -// -// return true; -// } -// -// boolean validBlock(Block block) { -// int type = TConstructRegistry.interchangableBlockMapping[block.blockID]; -// if (type != 0) { -// if (type == bufferStack.itemID) -// return true; -// } -// int blockToItem = TConstructRegistry.blockToItemMapping[block.blockID]; -// if (blockToItem != 0) { -// if (blockToItem == bufferStack.itemID) -// return true; -// } -// return block.blockID == bufferStack.itemID; -// } -// -// boolean validMetadata(int blockID, int metadata) { -// int type = TConstructRegistry.drawbridgeState[blockID]; -// if (type == 0) { -// return metadata == bufferStack.getItemDamage(); -// } -// if (type == 1) { -// return true; -// } -// if (type == 2) { -// return false; -// } -// if (type == 3) { -// return true; // TODO: rotational metadata, probably not needed -// // anymore -// } -// if (type == 4) { -// return true; -// } -// if (type == 5) { -// return metadata == bufferStack.getItemDamage(); -// } -// return false; -// } -// -// @Override -// public void readFromNBT(NBTTagCompound tags) { -// super.readFromNBT(tags); -// active = tags.getBoolean("Active"); -// working = tags.getBoolean("Working"); -// extension = tags.getByte("Extension"); -// -// NBTTagCompound bufferInv = (NBTTagCompound) tags.getTag("BufferInv"); -// if (bufferInv != null) { -// bufferStack = ItemStack.loadItemStackFromNBT(bufferInv); -// } -// -// readCustomNBT(tags); -// } -// -// @Override -// public void writeToNBT(NBTTagCompound tags) { -// super.writeToNBT(tags); -// tags.setBoolean("Active", active); -// tags.setBoolean("Working", working); -// tags.setByte("Extension", extension); -// -// if (bufferStack != null) { -// NBTTagCompound bufferInv = new NBTTagCompound(); -// bufferStack.writeToNBT(bufferInv); -// tags.setTag("BufferInv", bufferInv); -// } -// -// writeCustomNBT(tags); -// } -// -// public void readCustomNBT(NBTTagCompound tags) { -// direction = tags.getByte("Direction"); -// placementDirection = tags.getByte("Placement"); -// } -// -// public void writeCustomNBT(NBTTagCompound tags) { -// tags.setByte("Direction", direction); -// tags.setByte("Placement", placementDirection); -// } -// -// /* Packets */ -// @Override -// public Packet getDescriptionPacket() { -// NBTTagCompound tag = new NBTTagCompound(); -// writeToNBT(tag); -// return new Packet132TileEntityData(xCoord, yCoord, zCoord, 1, tag); -// } -// -// @Override -// public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) { -// readFromNBT(packet.data); -// worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); -// } -// -// public boolean hasExtended() { -// return extension != 0; -// } -// -// @Override -// public void onInventoryChanged() { -// super.onInventoryChanged(); -// if (getStackInSlot(0) != null) { -// bufferStack = getStackInSlot(0).copy(); -// bufferStack.stackSize = 1; -// } -// this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); -// } -//} +package tconstruct.blocks.logic; + +import net.minecraft.inventory.InventoryBasic; + +import net.minecraft.nbt.NBTTagList; + +import java.util.ArrayList; +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.*; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.INetworkManager; +import net.minecraft.network.packet.*; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; +import tconstruct.inventory.AdvancedDrawbridgeContainer; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.blocks.*; +import tconstruct.library.util.*; +import tconstruct.util.player.FakePlayerLogic; + +public class AdvancedDrawbridgeLogic extends ExpandableInventoryLogic implements IFacingLogic, IActiveLogic, IDrawbridgeLogicBase { + boolean active; + boolean working; + int ticks; + public int selSlot = 0; + byte extension; + byte direction; + byte placementDirection = 4; + FakePlayerLogic fakePlayer; + + ArrayList bufferStacks = new ArrayList(); + + public InvCamo camoInventory = new InvCamo(); + + @Override + public void setWorldObj(World par1World) { + this.worldObj = par1World; + fakePlayer = new FakePlayerLogic(worldObj, "Player.Drawbridge", this); + } + + @Override + public boolean getActive() { + return active; + } + + @Override + public void setActive(boolean flag) { + active = flag; + working = true; + } + + @Override + public byte getRenderDirection() { + return direction; + } + + @Override + public ForgeDirection getForgeDirection() { + return ForgeDirection.VALID_DIRECTIONS[direction]; + } + + @Override + public void setDirection(int side) { + } + + public boolean canDropInventorySlot(int slot) { + return false; + } + + @Override + public void setDirection(float yaw, float pitch, EntityLivingBase player) { + if (pitch > 45) { + direction = 1; + } else if (pitch < -45) { + direction = 0; + } else { + int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3; + switch (facing) { + case 0: + direction = 2; + break; + + case 1: + direction = 5; + break; + + case 2: + direction = 3; + break; + + case 3: + direction = 4; + break; + } + } + } + + /* + * 0 = Up 1 = Right 2 = Down 3 = Left 4 = Center, neutral + */ + public void setPlacementDirection(byte keycode) { + if (keycode == 4) { + fakePlayer.rotationYaw = 0; + fakePlayer.rotationPitch = 0; + } else if (this.direction == 0 || this.direction == 1) { + switch (keycode) { + case 0: + fakePlayer.rotationYaw = 0; + break; + case 1: + fakePlayer.rotationYaw = 90; + break; + case 2: + fakePlayer.rotationYaw = 180; + break; + case 3: + fakePlayer.rotationYaw = 270; + break; + } + + if (this.direction == 0) + fakePlayer.rotationPitch = -90; + else + fakePlayer.rotationPitch = 90; + } else { + if (keycode == 0) // Forward + { + fakePlayer.rotationYaw = mapDirection() * 90; + + if (keycode == 0) + fakePlayer.rotationPitch = 90; + else + fakePlayer.rotationPitch = -90; + } else if (keycode == 2) // Backward + { + int face = mapDirection() + 2; + if (face > 3) + face -= 4; + fakePlayer.rotationYaw = face * 90; + + if (keycode == 0) + fakePlayer.rotationPitch = 90; + else + fakePlayer.rotationPitch = -90; + } else { + fakePlayer.rotationPitch = 0; + + int facing = mapDirection(); + if (keycode == 1) + facing += 1; + else + facing -= 1; + + if (facing >= 4) + facing = 0; + if (facing < 0) + facing = 3; + + fakePlayer.rotationYaw = facing * 90; + } + } + placementDirection = keycode; + } + + int mapDirection() { + if (this.direction == 2) // North + return 0; + if (this.direction == 5) // East + return 1; + if (this.direction == 3) // South + return 2; + + return 3; // West + } + + public byte getPlacementDirection() { + return placementDirection; + } + + public ItemStack getStackInBufferSlot(int slot) { + return slot < bufferStacks.size() ? bufferStacks.get(slot) : null; + } + + public void setBufferSlotContents(int slot, ItemStack itemstack) { + if (slot < bufferStacks.size()) { + bufferStacks.set(slot, itemstack); + } else if (slot == bufferStacks.size()) { + bufferStacks.add(itemstack); + } else if (slot < getMaxSize()) { + bufferStacks.ensureCapacity(slot); + bufferStacks.set(slot, itemstack); + } else { + return; + } + if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { + itemstack.stackSize = getInventoryStackLimit(); + } + } + + @Override + public Container getGuiContainer(InventoryPlayer inventoryplayer, World world, int x, int y, int z) { + return new AdvancedDrawbridgeContainer(inventoryplayer, this); + } + + @Override + protected String getDefaultName() { + return "tinker.drawbridge"; + } + + @Override + public ItemStack decrStackSize(int slot, int quantity) { + ItemStack stack = super.decrStackSize(slot, quantity); + if (slot == 1) + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + return stack; + } + + public void updateEntity() { + if (working) { + ticks++; + if (ticks == 5) { + ticks = 0; + if (active) // Placement + { + if (getStackInSlot(extension) != null && getStackInSlot(extension).stackSize > 0 && extension < 15) { + extension++; + int xPos = xCoord; + int yPos = yCoord; + int zPos = zCoord; + + switch (direction) { + case 0: + yPos -= extension; + break; + case 1: + yPos += extension; + break; + case 2: + zPos -= extension; + break; + case 3: + zPos += extension; + break; + case 4: + xPos -= extension; + break; + case 5: + xPos += extension; + break; + } + + Block block = Block.blocksList[worldObj.getBlockId(xPos, yPos, zPos)]; + if (block == null || block.isAirBlock(worldObj, xPos, yPos, zPos) || block.isBlockReplaceable(worldObj, xPos, yPos, zPos)) { + // tryExtend(worldObj, xPos, yPos, zPos, direction); + int blockToItem = TConstructRegistry.blockToItemMapping[getStackInBufferSlot(extension).itemID]; + if (blockToItem == 0) { + if (getStackInSlot(extension).itemID >= 4096 || Block.blocksList[getStackInSlot(extension).itemID] == null) + return; + Block placeBlock = Block.blocksList[getStackInBufferSlot(extension).itemID]; + placeBlockAt(getStackInBufferSlot(extension), fakePlayer, worldObj, xPos, yPos, zPos, direction, 0, 0, 0, getStackInBufferSlot(extension).getItemDamage(), placeBlock); + } else { + Block placeBlock = Block.blocksList[blockToItem]; + placeBlockAt(getStackInBufferSlot(extension), fakePlayer, worldObj, xPos, yPos, zPos, direction, 0, 0, 0, getStackInBufferSlot(extension).getItemDamage(), placeBlock); + } + worldObj.playSoundEffect((double) xPos + 0.5D, (double) yPos + 0.5D, (double) zPos + 0.5D, "tile.piston.out", 0.25F, worldObj.rand.nextFloat() * 0.25F + 0.6F); + decrStackSize(0, 1); + } else { + extension--; + working = false; + } + } else { + working = false; + } + } else + // Retraction + { + if ((getStackInSlot(extension) == null || getStackInSlot(extension).stackSize < getStackInSlot(extension).getMaxStackSize()) && extension > 0) { + int xPos = xCoord; + int yPos = yCoord; + int zPos = zCoord; + + switch (direction) { + case 0: + yPos -= extension; + break; + case 1: + yPos += extension; + break; + case 2: + zPos -= extension; + break; + case 3: + zPos += extension; + break; + case 4: + xPos -= extension; + break; + case 5: + xPos += extension; + break; + } + + Block block = Block.blocksList[worldObj.getBlockId(xPos, yPos, zPos)]; + if (block != null) { + int meta = worldObj.getBlockMetadata(xPos, yPos, zPos); + if (getStackInBufferSlot(extension) != null && validBlock(extension, block) && validMetadata(extension, block.blockID, meta)) { + worldObj.playSoundEffect((double) xPos + 0.5D, (double) yPos + 0.5D, (double) zPos + 0.5D, "tile.piston.in", 0.25F, worldObj.rand.nextFloat() * 0.15F + 0.6F); + if (worldObj.setBlock(xPos, yPos, zPos, 0)) + if (getStackInSlot(extension) == null) { + setInventorySlotContents(extension, getStackInBufferSlot(extension).copy()); + } else { + getStackInSlot(extension).stackSize++; + } + } else { + working = false; + } + } + extension--; + } else { + working = false; + } + } + } + } + } + + /** + * Called to actually place the block, after the location is determined and + * all permission checks have been made. Copied from ItemBlock + * + * @param stack + * The item stack that was used to place the block. This can be + * changed inside the method. + * @param player + * The player who is placing the block. Can be null if the block + * is not being placed by a player. + * @param side + * The side the player (or machine) right-clicked on. + */ + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata, Block block) { + if (!world.setBlock(x, y, z, block.blockID, metadata, 3)) { + return false; + } + + if (world.getBlockId(x, y, z) == block.blockID) { + block.onBlockPlacedBy(world, x, y, z, player, stack); + block.onPostBlockPlaced(world, x, y, z, metadata); + } + + return true; + } + + boolean validBlock(int slot, Block block) { + int type = TConstructRegistry.interchangableBlockMapping[block.blockID]; + if (type != 0) { + if (type == getStackInBufferSlot(slot).itemID) + return true; + } + int blockToItem = TConstructRegistry.blockToItemMapping[block.blockID]; + if (blockToItem != 0) { + if (blockToItem == getStackInBufferSlot(slot).itemID) + return true; + } + return block.blockID == getStackInBufferSlot(slot).itemID; + } + + boolean validMetadata(int slot, int blockID, int metadata) { + int type = TConstructRegistry.drawbridgeState[blockID]; + if (type == 0) { + return metadata == getStackInBufferSlot(slot).getItemDamage(); + } + if (type == 1) { + return true; + } + if (type == 2) { + return false; + } + if (type == 3) { + return true; // TODO: rotational metadata, probably not needed + // anymore + } + if (type == 4) { + return true; + } + if (type == 5) { + return metadata == getStackInBufferSlot(slot).getItemDamage(); + } + return false; + } + + @Override + public void readFromNBT(NBTTagCompound tags) { + super.readFromNBT(tags); + active = tags.getBoolean("Active"); + working = tags.getBoolean("Working"); + extension = tags.getByte("Extension"); + + NBTTagCompound camoTag = (NBTTagCompound) tags.getTag("Camo"); + if (camoTag != null) { + camoInventory.setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(camoTag)); + } + + readBufferFromNBT(tags); + + readCustomNBT(tags); + } + + @Override + public void writeToNBT(NBTTagCompound tags) { + super.writeToNBT(tags); + tags.setBoolean("Active", active); + tags.setBoolean("Working", working); + tags.setByte("Extension", extension); + + if (camoInventory.getStackInSlot(0) != null) { + NBTTagCompound camoTag = new NBTTagCompound(); + camoInventory.getStackInSlot(0).writeToNBT(camoTag); + tags.setTag("Camo", camoTag); + } + + writeBufferToNBT(tags); + + writeCustomNBT(tags); + } + + public void readBufferFromNBT(NBTTagCompound tags) { + NBTTagList nbttaglist = tags.getTagList("Buffer"); + bufferStacks = new ArrayList(); + bufferStacks.ensureCapacity(nbttaglist.tagCount() > getMaxSize() ? getMaxSize() : nbttaglist.tagCount()); + for (int iter = 0; iter < nbttaglist.tagCount(); iter++) { + NBTTagCompound tagList = (NBTTagCompound) nbttaglist.tagAt(iter); + byte slotID = tagList.getByte("Slot"); + if (slotID >= 0 && slotID < bufferStacks.size()) { + setBufferSlotContents(slotID, ItemStack.loadItemStackFromNBT(tagList)); + } + } + } + + public void writeBufferToNBT(NBTTagCompound tags) { + NBTTagList nbttaglist = new NBTTagList(); + for (int iter = 0; iter < bufferStacks.size(); iter++) { + if (getStackInBufferSlot(iter) != null) { + NBTTagCompound tagList = new NBTTagCompound(); + tagList.setByte("Slot", (byte) iter); + getStackInBufferSlot(iter).writeToNBT(tagList); + nbttaglist.appendTag(tagList); + } + } + + tags.setTag("Buffer", nbttaglist); + } + + public void readCustomNBT(NBTTagCompound tags) { + direction = tags.getByte("Direction"); + placementDirection = tags.getByte("Placement"); + } + + public void writeCustomNBT(NBTTagCompound tags) { + tags.setByte("Direction", direction); + tags.setByte("Placement", placementDirection); + } + + /* Packets */ + @Override + public Packet getDescriptionPacket() { + NBTTagCompound tag = new NBTTagCompound(); + writeToNBT(tag); + return new Packet132TileEntityData(xCoord, yCoord, zCoord, 1, tag); + } + + @Override + public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) { + readFromNBT(packet.data); + worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); + } + + public boolean hasExtended() { + return extension != 0; + } + + @Override + public void onInventoryChanged() { + super.onInventoryChanged(); + for (int i = 0; i < getMaxSize(); i++) { + if (getStackInSlot(i) != null) { + setBufferSlotContents(i, getStackInSlot(0).copy()); + getStackInBufferSlot(i).stackSize = 1; + } + } + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + @Override + public int getMaxSize() { + return 16; + } + + @Override + public int getInventoryStackLimit() { + return 1; + } + + public class InvCamo extends InventoryBasic { + + private InvCamo() { + super("camoSlot", false, 1); + } + + public ItemStack getCamoStack() { + return this.getStackInSlot(0); + } + + @Override + public void setInventorySlotContents(int slot, ItemStack content) { + super.setInventorySlotContents(slot, content); + if (slot == 0) + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + @Override + public void onInventoryChanged() { + super.onInventoryChanged(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } +} diff --git a/src/tconstruct/client/TProxyClient.java b/src/tconstruct/client/TProxyClient.java index d9ef408a293..3baed116e20 100644 --- a/src/tconstruct/client/TProxyClient.java +++ b/src/tconstruct/client/TProxyClient.java @@ -1,159 +1,47 @@ package tconstruct.client; +import com.google.common.collect.Lists; +import cpw.mods.fml.client.registry.*; +import cpw.mods.fml.common.registry.*; +import cpw.mods.fml.relauncher.Side; import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - +import java.util.*; +import javax.xml.parsers.*; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.model.ModelSlime; -import net.minecraft.client.particle.EntityAuraFX; -import net.minecraft.client.particle.EntityBreakingFX; -import net.minecraft.client.particle.EntityBubbleFX; -import net.minecraft.client.particle.EntityCloudFX; -import net.minecraft.client.particle.EntityCritFX; -import net.minecraft.client.particle.EntityDropParticleFX; -import net.minecraft.client.particle.EntityEnchantmentTableParticleFX; -import net.minecraft.client.particle.EntityExplodeFX; -import net.minecraft.client.particle.EntityFX; -import net.minecraft.client.particle.EntityFireworkSparkFX; -import net.minecraft.client.particle.EntityFlameFX; -import net.minecraft.client.particle.EntityFootStepFX; -import net.minecraft.client.particle.EntityHeartFX; -import net.minecraft.client.particle.EntityHugeExplodeFX; -import net.minecraft.client.particle.EntityLargeExplodeFX; -import net.minecraft.client.particle.EntityLavaFX; -import net.minecraft.client.particle.EntityNoteFX; -import net.minecraft.client.particle.EntityPortalFX; -import net.minecraft.client.particle.EntityReddustFX; -import net.minecraft.client.particle.EntitySmokeFX; -import net.minecraft.client.particle.EntitySnowShovelFX; -import net.minecraft.client.particle.EntitySpellParticleFX; -import net.minecraft.client.particle.EntitySplashFX; -import net.minecraft.client.particle.EntitySuspendFX; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.particle.*; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.settings.GameSettings; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.entity.Entity; +import net.minecraft.client.settings.*; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Icon; -import net.minecraft.util.ResourceLocation; +import net.minecraft.item.*; +import net.minecraft.util.*; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fluids.RenderBlockFluid; - import org.lwjgl.opengl.GL11; import org.w3c.dom.Document; - import tconstruct.TConstruct; -import tconstruct.blocks.logic.CastingBasinLogic; -import tconstruct.blocks.logic.CastingTableLogic; -import tconstruct.blocks.logic.CraftingStationLogic; -import tconstruct.blocks.logic.DrawbridgeLogic; -import tconstruct.blocks.logic.DryingRackLogic; -import tconstruct.blocks.logic.FrypanLogic; -import tconstruct.blocks.logic.PartBuilderLogic; -import tconstruct.blocks.logic.PatternChestLogic; -import tconstruct.blocks.logic.SmelteryLogic; -import tconstruct.blocks.logic.StencilTableLogic; -import tconstruct.blocks.logic.TileEntityLandmine; -import tconstruct.blocks.logic.ToolForgeLogic; -import tconstruct.blocks.logic.ToolStationLogic; -import tconstruct.client.block.BarricadeRender; -import tconstruct.client.block.BlockRenderCastingChannel; -import tconstruct.client.block.CastingBasinSpecialRender; -import tconstruct.client.block.CastingTableSpecialRenderer; -import tconstruct.client.block.DryingRackRender; -import tconstruct.client.block.DryingRackSpecialRender; -import tconstruct.client.block.FrypanRender; -import tconstruct.client.block.MachineRender; -import tconstruct.client.block.OreberryRender; -import tconstruct.client.block.PaneConnectedRender; -import tconstruct.client.block.PaneRender; -import tconstruct.client.block.PunjiRender; -import tconstruct.client.block.RenderLandmine; -import tconstruct.client.block.SearedRender; -import tconstruct.client.block.SlimeChannelRender; -import tconstruct.client.block.SlimePadRender; -import tconstruct.client.block.SmallFontRenderer; -import tconstruct.client.block.SmelteryRender; -import tconstruct.client.block.TableForgeRender; -import tconstruct.client.block.TableRender; -import tconstruct.client.block.TankRender; -import tconstruct.client.entity.CartRender; -import tconstruct.client.entity.CrystalRender; -import tconstruct.client.entity.FancyItemRender; -import tconstruct.client.entity.SlimeRender; -import tconstruct.client.entity.projectile.ArrowRenderCustom; -import tconstruct.client.entity.projectile.DaggerRenderCustom; -import tconstruct.client.entity.projectile.LaunchedItemRender; -import tconstruct.client.gui.ArmorExtendedGui; -import tconstruct.client.gui.CraftingStationGui; -import tconstruct.client.gui.DrawbridgeGui; -import tconstruct.client.gui.FrypanGui; -import tconstruct.client.gui.GuiLandmine; -import tconstruct.client.gui.GuiManual; -import tconstruct.client.gui.KnapsackGui; -import tconstruct.client.gui.PartCrafterGui; -import tconstruct.client.gui.PatternChestGui; -import tconstruct.client.gui.SmelteryGui; -import tconstruct.client.gui.StencilTableGui; -import tconstruct.client.gui.ToolForgeGui; -import tconstruct.client.gui.ToolStationGui; -import tconstruct.client.pages.BlankPage; -import tconstruct.client.pages.BlockCastPage; -import tconstruct.client.pages.BookPage; -import tconstruct.client.pages.ContentsTablePage; -import tconstruct.client.pages.CraftingPage; -import tconstruct.client.pages.FurnacePage; -import tconstruct.client.pages.MaterialPage; -import tconstruct.client.pages.ModifierPage; -import tconstruct.client.pages.PicturePage; -import tconstruct.client.pages.SectionPage; -import tconstruct.client.pages.SidebarPage; -import tconstruct.client.pages.TextPage; -import tconstruct.client.pages.TitlePage; -import tconstruct.client.pages.ToolPage; -import tconstruct.client.tabs.InventoryTabArmorExtended; -import tconstruct.client.tabs.InventoryTabKnapsack; -import tconstruct.client.tabs.InventoryTabVanilla; -import tconstruct.client.tabs.TabRegistry; -import tconstruct.common.TContent; -import tconstruct.common.TProxyCommon; -import tconstruct.entity.BlueSlime; -import tconstruct.entity.CartEntity; -import tconstruct.entity.Crystal; -import tconstruct.entity.FancyEntityItem; -import tconstruct.entity.projectile.ArrowEntity; -import tconstruct.entity.projectile.DaggerEntity; -import tconstruct.entity.projectile.LaunchedPotion; +import tconstruct.blocks.logic.*; +import tconstruct.client.block.*; +import tconstruct.client.entity.*; +import tconstruct.client.entity.projectile.*; +import tconstruct.client.gui.*; +import tconstruct.client.pages.*; +import tconstruct.client.tabs.*; +import tconstruct.common.*; +import tconstruct.entity.*; +import tconstruct.entity.projectile.*; import tconstruct.inventory.ContainerLandmine; import tconstruct.library.TConstructRegistry; -import tconstruct.library.client.TConstructClientRegistry; -import tconstruct.library.client.ToolGuiElement; +import tconstruct.library.client.*; import tconstruct.library.crafting.ToolBuilder; import tconstruct.library.tools.ToolCore; -import tconstruct.util.player.ArmorExtended; -import tconstruct.util.player.KnapsackInventory; - -import com.google.common.collect.Lists; - -import cpw.mods.fml.client.registry.ClientRegistry; -import cpw.mods.fml.client.registry.RenderingRegistry; -import cpw.mods.fml.common.registry.TickRegistry; -import cpw.mods.fml.common.registry.VillagerRegistry; -import cpw.mods.fml.relauncher.Side; +import tconstruct.util.player.*; public class TProxyClient extends TProxyCommon { @@ -188,6 +76,8 @@ public Object getClientGuiElement (int ID, EntityPlayer player, World world, int return new GuiLandmine(new ContainerLandmine(player, (TileEntityLandmine) world.getBlockTileEntity(x, y, z))); if (ID == craftingStationID) return new CraftingStationGui(player.inventory, (CraftingStationLogic) world.getBlockTileEntity(x, y, z), x, y, z); + if (ID == advDrawbridgeID) + return new AdvDrawbridgeGui(player.inventory, (AdvancedDrawbridgeLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); if (ID == manualGuiID) { diff --git a/src/tconstruct/client/gui/AdvDrawbridgeGui.java b/src/tconstruct/client/gui/AdvDrawbridgeGui.java new file mode 100644 index 00000000000..812b4f419ef --- /dev/null +++ b/src/tconstruct/client/gui/AdvDrawbridgeGui.java @@ -0,0 +1,115 @@ +package tconstruct.client.gui; + +import cpw.mods.fml.common.network.PacketDispatcher; +import java.io.*; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.network.packet.Packet250CustomPayload; +import net.minecraft.util.*; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL11; +import tconstruct.blocks.logic.AdvancedDrawbridgeLogic; + +public class AdvDrawbridgeGui extends GuiContainer +{ + public AdvancedDrawbridgeLogic logic; + + public AdvDrawbridgeGui(InventoryPlayer inventoryplayer, AdvancedDrawbridgeLogic frypan, World world, int x, int y, int z) + { + super(frypan.getGuiContainer(inventoryplayer, world, x, y, z)); + logic = frypan; + } + + protected void drawGuiContainerForegroundLayer (int par1, int par2) + { + //fontRenderer.drawString(StatCollector.translateToLocal("aggregator.glowstone"), 60, 6, 0x404040); + fontRenderer.drawString("Drawbridge", 8, 6, 0x404040); + fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040); + } + + private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/drawbridge.png"); + + protected void drawGuiContainerBackgroundLayer (float f, int i, int j) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(background); + int cornerX = (width - xSize) / 2; + int cornerY = (height - ySize) / 2; + drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize); + } + + public void initGui () + { + super.initGui(); + int cornerX = (this.width - this.xSize) / 2; + int cornerY = (this.height - this.ySize) / 2; + + this.buttonList.clear(); + GuiButton button = new DrawbridgeButton(0, cornerX + 131, cornerY + 18, 176, 0, 21, 22); + if (logic.getPlacementDirection() == 0) + button.enabled = false; + this.buttonList.add(button); + button = new DrawbridgeButton(1, cornerX + 146, cornerY + 34, 199, 23, 22, 21); + if (logic.getPlacementDirection() == 1) + button.enabled = false; + this.buttonList.add(button); + button = new DrawbridgeButton(2, cornerX + 132, cornerY + 48, 199, 0, 21, 22); + if (logic.getPlacementDirection() == 2) + button.enabled = false; + this.buttonList.add(button); + button = new DrawbridgeButton(3, cornerX + 117, cornerY + 34, 178, 23, 22, 21); + if (logic.getPlacementDirection() == 3) + button.enabled = false; + this.buttonList.add(button); + button = new DrawbridgeButton(4, cornerX + 135, cornerY + 40, 217, 0, 10, 10); + if (logic.getPlacementDirection() == 4) + button.enabled = false; + this.buttonList.add(button); + + this.buttonList.add(new SlotButton(5, this.width / 2 - 13, this.height / 2 - 52, 26, 26, "")); + } + + protected void actionPerformed (GuiButton button) + { + if(button.id == 5){ + return; + } + + for (Object o : buttonList) + { + GuiButton b = (GuiButton) o; + b.enabled = true; + } + button.enabled = false; + + logic.setPlacementDirection((byte) button.id); + updateServer((byte) button.id); + } + + void updateServer (byte direction) + { + ByteArrayOutputStream bos = new ByteArrayOutputStream(8); + DataOutputStream outputStream = new DataOutputStream(bos); + try + { + outputStream.writeByte(5); + outputStream.writeInt(logic.worldObj.provider.dimensionId); + outputStream.writeInt(logic.xCoord); + outputStream.writeInt(logic.yCoord); + outputStream.writeInt(logic.zCoord); + outputStream.writeByte(direction); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + Packet250CustomPayload packet = new Packet250CustomPayload(); + packet.channel = "TConstruct"; + packet.data = bos.toByteArray(); + packet.length = bos.size(); + + PacketDispatcher.sendPacketToServer(packet); + } +} diff --git a/src/tconstruct/client/gui/SlotButton.java b/src/tconstruct/client/gui/SlotButton.java new file mode 100644 index 00000000000..fb76051ef1e --- /dev/null +++ b/src/tconstruct/client/gui/SlotButton.java @@ -0,0 +1,125 @@ +package tconstruct.client.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +import net.minecraft.client.gui.GuiButton; + +public class SlotButton extends GuiButton { + protected static final ResourceLocation buttonTextures = new ResourceLocation("tinker:textures/gui/slotButton.png"); + + /** Button width in pixels */ + protected int width; + + /** Button height in pixels */ + protected int height; + + /** The x position of this control. */ + public int xPosition; + + /** The y position of this control. */ + public int yPosition; + + /** The string displayed on this control. */ + public String displayString; + + /** ID for this control. */ + public int id; + + /** True if this control is enabled, false to disable. */ + public boolean enabled; + + /** Hides the button completely if false. */ + public boolean drawButton; + protected boolean field_82253_i; + + public SlotButton(int par1, int par2, int par3, String par4Str) { + this(par1, par2, par3, 200, 20, par4Str); + } + + public SlotButton(int par1, int par2, int par3, int par4, int par5, String par6Str) { + super(par1, par2, par3, par4, par5, par6Str); + this.width = 200; + this.height = 20; + this.enabled = true; + this.drawButton = true; + this.id = par1; + this.xPosition = par2; + this.yPosition = par3; + this.width = par4; + this.height = par5; + this.displayString = par6Str; + } + + /** + * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over + * this button and 2 if it IS hovering over this button. + */ + protected int getHoverState(boolean par1) { + byte b0 = 1; + + if (!this.enabled) { + b0 = 0; + } else if (par1) { + b0 = 2; + } + + return b0; + } + + /** + * Draws this button to the screen. + */ + public void drawButton(Minecraft par1Minecraft, int par2, int par3) { + if (this.drawButton) { + FontRenderer fontrenderer = par1Minecraft.fontRenderer; + par1Minecraft.getTextureManager().bindTexture(buttonTextures); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.field_82253_i = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height; + int k = this.getHoverState(this.field_82253_i); + this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 26, this.width / 2, this.height); + this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 26, this.width / 2, this.height); + this.mouseDragged(par1Minecraft, par2, par3); + int l = 14737632; + + if (!this.enabled) { + l = -6250336; + } else if (this.field_82253_i) { + l = 16777120; + } + + this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l); + } + } + + /** + * Fired when the mouse button is dragged. Equivalent of + * MouseListener.mouseDragged(MouseEvent e). + */ + protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) { + } + + /** + * Fired when the mouse button is released. Equivalent of + * MouseListener.mouseReleased(MouseEvent e). + */ + public void mouseReleased(int par1, int par2) { + } + + /** + * Returns true if the mouse has been pressed on this control. Equivalent of + * MouseListener.mousePressed(MouseEvent e). + */ + public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) { + return this.enabled && this.drawButton && par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height; + } + + public boolean func_82252_a() { + return this.field_82253_i; + } + + public void func_82251_b(int par1, int par2) { + } +} \ No newline at end of file diff --git a/src/tconstruct/common/TContent.java b/src/tconstruct/common/TContent.java index 841ab2a3cc0..5c3365ed7d7 100644 --- a/src/tconstruct/common/TContent.java +++ b/src/tconstruct/common/TContent.java @@ -406,6 +406,7 @@ void registerBlocks() GameRegistry.registerBlock(redstoneMachine, RedstoneMachineItem.class, "Redstone.Machine"); GameRegistry.registerTileEntity(DrawbridgeLogic.class, "Drawbridge"); GameRegistry.registerTileEntity(FirestarterLogic.class, "Firestarter"); + GameRegistry.registerTileEntity(AdvancedDrawbridgeLogic.class, "AdvDrawbridge"); //Traps landmine = new BlockLandmine(PHConstruct.landmine).setHardness(0.5F).setResistance(0F).setStepSound(Block.soundMetalFootstep).setCreativeTab(CreativeTabs.tabRedstone) diff --git a/src/tconstruct/common/TProxyCommon.java b/src/tconstruct/common/TProxyCommon.java index d0885ecd785..a8e80d3b7b4 100644 --- a/src/tconstruct/common/TProxyCommon.java +++ b/src/tconstruct/common/TProxyCommon.java @@ -31,6 +31,7 @@ public class TProxyCommon implements IGuiHandler public static int drawbridgeID = 9; public static int landmineID = 10; public static int craftingStationID = 11; + public static int advDrawbridgeID = 12; public static int inventoryGui = 100; public static int armorGuiID = 101; public static int knapsackGuiID = 102; diff --git a/src/tconstruct/inventory/AdvancedDrawbridgeContainer.java b/src/tconstruct/inventory/AdvancedDrawbridgeContainer.java index 2b8d9756d51..1696b35b4e8 100644 --- a/src/tconstruct/inventory/AdvancedDrawbridgeContainer.java +++ b/src/tconstruct/inventory/AdvancedDrawbridgeContainer.java @@ -1,78 +1,78 @@ -//package tconstruct.inventory; -// -//import net.minecraft.entity.player.*; -//import net.minecraft.inventory.*; -//import net.minecraft.item.ItemStack; -//import tconstruct.blocks.logic.*; -// -//public class AdvancedDrawbridgeContainer extends Container -//{ -// public AdvancedDrawbridgeLogic logic; -// public int progress = 0; -// public int fuel = 0; -// public int fuelGague = 0; -// -// public AdvancedDrawbridgeContainer(InventoryPlayer inventoryplayer, AdvancedDrawbridgeLogic logic) -// { -// this.logic = logic; -// +package tconstruct.inventory; + +import net.minecraft.entity.player.*; +import net.minecraft.inventory.*; +import net.minecraft.item.ItemStack; +import tconstruct.blocks.logic.*; + +public class AdvancedDrawbridgeContainer extends Container +{ + public AdvancedDrawbridgeLogic logic; + public int progress = 0; + public int fuel = 0; + public int fuelGague = 0; + + public AdvancedDrawbridgeContainer(InventoryPlayer inventoryplayer, AdvancedDrawbridgeLogic logic) + { + this.logic = logic; + // this.addSlotToContainer(new DrawbridgeSlot(logic, logic.selSlot < logic.getSizeInventory() ? logic.selSlot : 0, 80, 36, logic)); -// this.addSlotToContainer(new SlotOpaqueBlocksOnly(logic, 1, 35, 36)); -// -// /* 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, 8 + row * 18, 84 + column * 18)); -// } -// } -// -// for (int column = 0; column < 9; column++) -// { -// this.addSlotToContainer(new Slot(inventoryplayer, column, 8 + column * 18, 142)); -// } -// } -// -// @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; -// } -//} + this.addSlotToContainer(new SlotOpaqueBlocksOnly(logic.camoInventory, 0, 35, 36)); + + /* 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, 8 + row * 18, 84 + column * 18)); + } + } + + for (int column = 0; column < 9; column++) + { + this.addSlotToContainer(new Slot(inventoryplayer, column, 8 + column * 18, 142)); + } + } + + @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; + } +} diff --git a/src/tconstruct/items/blocks/RedstoneMachineItem.java b/src/tconstruct/items/blocks/RedstoneMachineItem.java index 75ce50c97d7..dd7faa6e520 100644 --- a/src/tconstruct/items/blocks/RedstoneMachineItem.java +++ b/src/tconstruct/items/blocks/RedstoneMachineItem.java @@ -10,7 +10,7 @@ public class RedstoneMachineItem extends ItemBlock { - public static final String blockType[] = { "drawbridge", "firestarter" }; + public static final String blockType[] = { "drawbridge", "firestarter", "advdrawbridge" }; public RedstoneMachineItem(int id) { diff --git a/src/tconstruct/library/blocks/ExpandableInventoryLogic.java b/src/tconstruct/library/blocks/ExpandableInventoryLogic.java index 642ee5b1104..5bc13e712f3 100644 --- a/src/tconstruct/library/blocks/ExpandableInventoryLogic.java +++ b/src/tconstruct/library/blocks/ExpandableInventoryLogic.java @@ -1,6 +1,6 @@ package tconstruct.library.blocks; -import java.util.ArrayList; +import java.util.*; import net.minecraft.entity.player.*; import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; @@ -13,7 +13,7 @@ public ExpandableInventoryLogic() { super(0); } - protected ArrayList inventory; + protected ArrayList inventory = new ArrayList(); protected String invName; @Override @@ -151,6 +151,15 @@ public boolean isInvNameLocalized() { return this.invName != null && this.invName.length() > 0; } + public void cleanInventory(){ + Iterator i1 = inventory.iterator(); + while(i1.hasNext()){ + if(i1.next() == null){ + i1.remove(); + } + } + } + @Override public boolean isItemValidForSlot(int slot, ItemStack itemstack) { if (slot < getSizeInventory()) {