From 8faa70ba46a4e24e0c9ecc42f98fc8d53986708b Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Mon, 26 Jan 2015 22:41:48 -0500 Subject: [PATCH] Rewrite presents. Still a bit WIP, needs sounds and lid animation --- .../com/cricketcraft/chisel/Features.java | 18 +- .../chisel/block/BlockPresent.java | 294 ++++++---------- .../block/tileentity/TileEntityPresent.java | 325 +++++++++++++----- .../chisel/carving/CarvableHelper.java | 4 +- .../render/item/ItemPresentRenderer.java | 74 ---- .../client/render/tile/RenderPresent.java | 212 ++++++------ .../chisel/init/ChiselBlocks.java | 4 +- .../inventory/InventoryLargePresent.java | 103 ------ .../chisel/network/PacketHandler.java | 2 + .../message/MessagePresentConnect.java | 60 ++++ .../chisel/proxy/ClientProxy.java | 9 +- .../chisel/proxy/CommonProxy.java | 2 +- 12 files changed, 543 insertions(+), 564 deletions(-) delete mode 100644 src/main/java/com/cricketcraft/chisel/client/render/item/ItemPresentRenderer.java delete mode 100644 src/main/java/com/cricketcraft/chisel/inventory/InventoryLargePresent.java create mode 100644 src/main/java/com/cricketcraft/chisel/network/message/MessagePresentConnect.java diff --git a/src/main/java/com/cricketcraft/chisel/Features.java b/src/main/java/com/cricketcraft/chisel/Features.java index ca8135bc..bc0784af 100644 --- a/src/main/java/com/cricketcraft/chisel/Features.java +++ b/src/main/java/com/cricketcraft/chisel/Features.java @@ -1,6 +1,5 @@ package com.cricketcraft.chisel; -import java.util.ArrayList; import java.util.List; import net.minecraft.block.Block; @@ -66,6 +65,7 @@ import com.cricketcraft.chisel.init.ChiselBlocks; import com.cricketcraft.chisel.init.ChiselItems; import com.cricketcraft.chisel.init.ChiselTabs; import com.cricketcraft.chisel.item.ItemBallOMoss; +import com.cricketcraft.chisel.item.ItemBlockPresent; import com.cricketcraft.chisel.item.ItemCarvable; import com.cricketcraft.chisel.item.ItemCarvableSlab; import com.cricketcraft.chisel.item.ItemCloudInABottle; @@ -1310,7 +1310,7 @@ public enum Features { limestone_slab.carverHelper.addVariation("tile.limestoneSlab.13.desc", 13, "limestone/terrain-pistonback-lightfour"); limestone_slab.carverHelper.addVariation("tile.limestoneSlab.14.desc", 14, "limestone/terrain-pistonback-lightmarker"); limestone_slab.carverHelper.addVariation("tile.limestoneSlab.15.desc", 15, "limestone/terrain-pistonback-lightpanel"); - limestone_slab.carverHelper.register(limestone_slab, "limestone_slab", ItemCarvableSlab.class); + limestone_slab.carverHelper.registerAll(limestone_slab, "limestone_slab", ItemCarvableSlab.class); registerSlabTop(limestone_slab, limestone_slab.top); Carving.chisel.registerOre("limestone_slab", "limestone_slab"); @@ -1388,7 +1388,7 @@ public enum Features { marble_slab.carverHelper.addVariation("tile.marbleSlab.13.desc", 13, "marbleslab/marble-arranged-bricks"); marble_slab.carverHelper.addVariation("tile.marbleSlab.14.desc", 14, "marbleslab/marble-fancy-bricks"); marble_slab.carverHelper.addVariation("tile.marbleSlab.15.desc", 15, "marbleslab/marble-blocks"); - marble_slab.carverHelper.register(marble_slab, "marble_slab", ItemCarvableSlab.class); + marble_slab.carverHelper.registerAll(marble_slab, "marble_slab", ItemCarvableSlab.class); registerSlabTop(marble_slab, marble_slab.top); Carving.chisel.registerOre("marble_slab", "marble_slab"); @@ -1507,7 +1507,7 @@ public enum Features { marble_pillar_slab.carverHelper.addVariation("tile.marblePillarSlab.14.desc", 14, "marblepillarslab/carved"); marble_pillar_slab.carverHelper.addVariation("tile.marblePillarSlab.15.desc", 15, "marblepillarslab/ornamental"); } - marble_pillar_slab.carverHelper.register(marble_pillar_slab, "marble_pillar_slab", ItemCarvableSlab.class); + marble_pillar_slab.carverHelper.registerAll(marble_pillar_slab, "marble_pillar_slab", ItemCarvableSlab.class); registerSlabTop(marble_pillar_slab, marble_pillar_slab.top); } @@ -1724,17 +1724,17 @@ public enum Features { @Override void addBlocks() { - for (int x = 0; x < 16; x++) { - present[x] = (BlockPresent) new BlockPresent(x).setCreativeTab(ChiselTabs.tabOtherChiselBlocks).setHardness(2.0F).setResistance(10.0F).setBlockName("present"); - GameRegistry.registerBlock(present[x], "chest" + x); - Carving.chisel.addVariation("present", present[x], 0, (x + 1)); + BlockPresent present = (BlockPresent) new BlockPresent().setCreativeTab(ChiselTabs.tabOtherChiselBlocks).setHardness(2.0F).setResistance(10.0F).setBlockName("present"); + for (int i = 0; i < 16; i++) { + present.carverHelper.addVariation("tile.present.desc." + i, i, Blocks.chest); } + present.carverHelper.registerAll(present, "present", ItemBlockPresent.class); Carving.chisel.registerOre("present", "chest"); } @Override void addRecipes() { - GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(ChiselBlocks.present[meta]), new ItemStack(Blocks.chest, 1), dyeOres[meta])); + GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(ChiselBlocks.present, 1, meta), new ItemStack(Blocks.chest, 1), dyeOres[meta])); } @Override diff --git a/src/main/java/com/cricketcraft/chisel/block/BlockPresent.java b/src/main/java/com/cricketcraft/chisel/block/BlockPresent.java index 6bef6e30..dc8aff01 100644 --- a/src/main/java/com/cricketcraft/chisel/block/BlockPresent.java +++ b/src/main/java/com/cricketcraft/chisel/block/BlockPresent.java @@ -1,19 +1,16 @@ package com.cricketcraft.chisel.block; -import java.util.Iterator; -import java.util.Random; +import java.util.List; import net.minecraft.block.Block; -import net.minecraft.block.BlockChest; +import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.Entity; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.passive.EntityOcelot; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; @@ -21,46 +18,42 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import com.cricketcraft.chisel.Chisel; import com.cricketcraft.chisel.api.ICarvable; import com.cricketcraft.chisel.block.tileentity.TileEntityPresent; import com.cricketcraft.chisel.carving.CarvableHelper; import com.cricketcraft.chisel.carving.CarvableVariation; -import com.cricketcraft.chisel.inventory.InventoryLargePresent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockPresent extends BlockChest implements ICarvable { +public class BlockPresent extends Block implements ICarvable { - private final Random random = new Random(); - private int type; public CarvableHelper carverHelper; + + private float minX, minY, minZ, maxX, maxY, maxZ; - public BlockPresent(int type) { - super(1); - this.type = type; + public BlockPresent() { + super(Material.wood); carverHelper = new CarvableHelper(); - setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0875F, 0.9365F); + minX = 0.0625F; + minZ = 0.0625F; + maxX = 0.9375F; + maxY = 0.875F; + maxZ = 0.9375F; + setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ); } - public String getKindOfChest(int type) { + public String getModelTexture(int type) { return "textures/blocks/present/presentChest" + type; } - - private static boolean isCatSittingOnMe(World world, int x, int y, int z) { - Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getBoundingBox(x, y + 1, z, x + 1, y + 2, z + 1)).iterator(); - EntityOcelot ocelot; - - do { - if (!iterator.hasNext()) { - return false; - } - - Entity entity = (Entity) iterator.next(); - ocelot = (EntityOcelot) entity; - } while (!ocelot.isSitting()); - - return true; + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < 16; i++) { + list.add(new ItemStack(item, 1, i)); + } } @Override @@ -79,96 +72,23 @@ public class BlockPresent extends BlockChest implements ICarvable { } @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemStack) { - Block front = world.getBlock(x, y, z - 1); - Block back = world.getBlock(x, y, z + 1); - Block left = world.getBlock(x - 1, y, z); - Block right = world.getBlock(x + 1, y, z); - byte metadata = 0; - int rot = MathHelper.floor_double((entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; - - if (rot == 0) { - metadata = 2; - } - - if (rot == 1) { - metadata = 5; - } - - if (rot == 2) { - metadata = 3; - } - - if (rot == 3) { - metadata = 4; - } - - if (front != this && back != this && left != this && right != this) { - world.setBlockMetadataWithNotify(x, y, z, metadata, 3); - } else { - if ((front == this || back == this) && (metadata == 4 || metadata == 5)) { - if (front == this) { - world.setBlockMetadataWithNotify(x, y, z - 1, metadata, 3); - } else { - world.setBlockMetadataWithNotify(x, y, z + 1, metadata, 3); - } - - world.setBlockMetadataWithNotify(x, y, z, metadata, 3); - } - - if ((left == this || right == this) && (metadata == 2 || metadata == 3)) { - if (left == this) { - world.setBlockMetadataWithNotify(x - 1, y, z, metadata, 3); - } else { - world.setBlockMetadataWithNotify(x + 1, y, z, metadata, 3); - } - - world.setBlockMetadataWithNotify(x, y, z, metadata, 3); - } - } - } - - @Override - public boolean canPlaceBlockAt(World world, int x, int y, int z) { - int l = 0; - - if (world.getBlock(x - 1, y, z) == this) { - ++l; - } - - if (world.getBlock(x + 1, y, z) == this) { - ++l; - } - - if (world.getBlock(x, y, z - 1) == this) { - ++l; - } - - if (world.getBlock(x, y, z + 1) == this) { - ++l; - } - - return l > 1 ? false : (areSurroundingBlocksMe(world, x, y - 1, z) ? false : (areSurroundingBlocksMe(world, x, y + 1, z) ? false : (areSurroundingBlocksMe(world, x, y, z - 1) ? false - : !areSurroundingBlocksMe(world, x, y, z + 1)))); - } - - private boolean areSurroundingBlocksMe(World world, int x, int y, int z) { - return world.getBlock(x, y, z) != this ? false : (world.getBlock(x - 1, y, z) == this ? true : (world.getBlock(x + 1, y, z) == this ? true : (world.getBlock(x, y, z - 1) == this ? true - : world.getBlock(x, y, z + 1) == this))); - } - - @Override - public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) { - super.onNeighborBlockChange(world, x, y, z, neighbor); - TileEntityPresent tileEntityPresent = (TileEntityPresent) world.getTileEntity(x, y, z); - - if (tileEntityPresent != null) { - tileEntityPresent.updateContainingBlockInfo(); + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { + super.onBlockPlacedBy(world, x, y, z, player, stack); + int heading = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; + TileEntityPresent te = (TileEntityPresent) world.getTileEntity(x, y, z); + world.setBlockMetadataWithNotify(x, y, z, heading, 3); + te.findConnections(); + if (te.isConnected()) { + TileEntityPresent other = te.getConnection(); + world.setBlockMetadataWithNotify(other.xCoord, other.yCoord, other.zCoord, heading, 3); } + te.setType(stack.getItemDamage()); + world.markBlockForUpdate(x, y, z); } @Override public void breakBlock(World world, int x, int y, int z, Block present, int meta) { + TileEntityPresent tileEntityPresent = (TileEntityPresent) world.getTileEntity(x, y, z); if (tileEntityPresent != null) { @@ -176,28 +96,7 @@ public class BlockPresent extends BlockChest implements ICarvable { ItemStack itemStack = tileEntityPresent.getStackInSlot(c); if (itemStack != null) { - float f = random.nextFloat() * 0.8F + 0.1F; - float f1 = random.nextFloat() * 0.8F + 0.1F; - EntityItem entityItem; - - for (float f2 = random.nextFloat() * 0.8F + 0.1F; itemStack.stackSize > 0; world.spawnEntityInWorld(entityItem)) { - int stack = random.nextInt(21) + 10; - - if (stack > itemStack.stackSize) { - stack = itemStack.stackSize; - } - - itemStack.stackSize -= stack; - entityItem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemStack.getItem(), stack, itemStack.getItemDamage())); - float motion = 0.05F; - entityItem.motionX = random.nextGaussian() * motion; - entityItem.motionY = random.nextGaussian() * motion + 0.2F; - entityItem.motionZ = random.nextGaussian() * motion; - - if (itemStack.hasTagCompound()) { - entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy()); - } - } + dropBlockAsItem(world, x, y, z, itemStack); } } @@ -208,23 +107,75 @@ public class BlockPresent extends BlockChest implements ICarvable { } @Override - public TileEntity createNewTileEntity(World world, int par2) { - return new TileEntityPresent(type); + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int hitX, float hitY, float hitZ, float p_149727_9_) { + if (!world.isSideSolid(x, y + 1, z, ForgeDirection.DOWN)) { + player.openGui(Chisel.instance, 2, world, x, y, z); + return true; + } + return false; } @Override - public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int direction) { - if (!canProvidePower()) { - return 0; + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { + return getBoundingBox((TileEntityPresent) world.getTileEntity(x, y, z)); + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { + return getBoundingBox((TileEntityPresent) world.getTileEntity(x, y, z)); + } + + public AxisAlignedBB getBoundingBox(TileEntityPresent me) { + if (me == null) { + return AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ); + } + int x = me.xCoord, y = me.yCoord, z = me.zCoord; + if (me.isConnected()) { + ForgeDirection dir = me.getConnectionDir(); + if (dir != ForgeDirection.NORTH && (!me.isParent() || dir == ForgeDirection.SOUTH)) { + return AxisAlignedBB.getBoundingBox(x + minX, y + minY, z + minZ, x + maxX + dir.offsetX, y + maxY, z + maxZ + dir.offsetZ); + } else { + return AxisAlignedBB.getBoundingBox(x + dir.offsetX + minX, y + minY, z + dir.offsetZ + minZ, x + maxX, y + maxY, z + maxZ); + } + } + return AxisAlignedBB.getBoundingBox(x + minX, y + minY, z + minZ, x + maxX, y + maxY, z + maxZ); + } + + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) + { + TileEntityPresent te = (TileEntityPresent) world.getTileEntity(x, y, z); + if (!te.isConnected()) { + setBlockBounds(0.0625F, 0, 0.0625F, 0.9375F, 0.875F, 0.9365F); } else { - int players = ((TileEntityPresent) world.getTileEntity(x, y, z)).numPlayersUsing; - return MathHelper.clamp_int(players, 0, 15); + ForgeDirection dir = te.getConnectionDir(); + switch (dir) { + case EAST: + setBlockBounds(0.0625F, 0, 0.0625F, 1, 0.875F, 0.9365F); + break; + case NORTH: + setBlockBounds(0.0625F, 0, 0, 0.9375F, 0.875F, 0.9365F); + break; + case SOUTH: + setBlockBounds(0.0625F, 0, 0.0625F, 0.9375F, 0.875F, 1); + break; + case WEST: + setBlockBounds(0, 0, 0.0625F, 0.9375F, 0.875F, 0.9365F); + break; + default: + setBlockBounds(0.0625F, 0, 0.0625F, 0.9375F, 0.875F, 0.9365F); + break; + } } } + + @Override + public boolean hasTileEntity(int metadata) { + return true; + } @Override - public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int strength) { - return strength == 1 ? isProvidingWeakPower(world, x, y, z, strength) : 0; + public TileEntity createTileEntity(World world, int metadata) { + return new TileEntityPresent(); } @Override @@ -234,7 +185,11 @@ public class BlockPresent extends BlockChest implements ICarvable { @Override public int getComparatorInputOverride(World world, int x, int y, int z, int strength) { - return Container.calcRedstoneFromInventory(getInventory(world, x, y, z)); + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof TileEntityPresent) { + return Container.calcRedstoneFromInventory((TileEntityPresent) te); + } + return 0; } @Override @@ -243,47 +198,10 @@ public class BlockPresent extends BlockChest implements ICarvable { this.blockIcon = register.registerIcon("planks_oak"); } - public IInventory getInventory(World world, int x, int y, int z) { - Object object = world.getTileEntity(x, y, z); - - if (object == null) { - return null; - } else if (world.isSideSolid(x, y + 1, z, ForgeDirection.DOWN)) { - return null; - } else if (isCatSittingOnMe(world, x, y, z)) { - return null; - } else if (world.getBlock(x - 1, y, z) == this && (world.isSideSolid(x - 1, y + 1, z, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y - 1, z))) { - return null; - } else if (world.getBlock(x + 1, y, z) == this && (world.isSideSolid(x + 1, y + 1, z, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y + 1, z))) { - return null; - } else if (world.getBlock(x, y, z - 1) == this && (world.isSideSolid(x, y + 1, z - 1, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y, z - 1))) { - return null; - } else if (world.getBlock(x, y, z + 1) == this && (world.isSideSolid(x, y + 1, z + 1, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y, z + 1))) { - return null; - } else { - if (world.getBlock(x - 1, y, z) == this) { - object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x - 1, y, z), (IInventory) object); - } - - if (world.getBlock(x + 1, y, z) == this) { - object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x + 1, y, z), (IInventory) object); - } - - if (world.getBlock(x, y, z - 1) == this) { - object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x, y, z - 1), (IInventory) object); - } - - if (world.getBlock(x, y, z + 1) == this) { - object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x, y, z + 1), (IInventory) object); - } - - return (IInventory) object; - } - } - @Override public CarvableVariation getVariation(IBlockAccess world, int x, int y, int z, int metadata) { - return carverHelper.getVariation(metadata); + TileEntity te = world.getTileEntity(x, y, z); + return te instanceof TileEntityPresent ? carverHelper.getVariation(((TileEntityPresent) te).getType()) : carverHelper.getVariation(metadata); } @Override diff --git a/src/main/java/com/cricketcraft/chisel/block/tileentity/TileEntityPresent.java b/src/main/java/com/cricketcraft/chisel/block/tileentity/TileEntityPresent.java index 80c8d638..9baf49f0 100644 --- a/src/main/java/com/cricketcraft/chisel/block/tileentity/TileEntityPresent.java +++ b/src/main/java/com/cricketcraft/chisel/block/tileentity/TileEntityPresent.java @@ -1,110 +1,271 @@ package com.cricketcraft.chisel.block.tileentity; -import java.util.Iterator; -import java.util.List; - import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; -import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.ForgeDirection; -import com.cricketcraft.chisel.inventory.ContainerPresent; -import com.cricketcraft.chisel.inventory.InventoryLargePresent; +import com.cricketcraft.chisel.init.ChiselBlocks; +import com.cricketcraft.chisel.network.PacketHandler; +import com.cricketcraft.chisel.network.message.MessagePresentConnect; -public class TileEntityPresent extends TileEntityChest { +public class TileEntityPresent extends TileEntity implements IInventory { - public int type; - private int ticksSinceSync; - - public TileEntityPresent(int type) { - this.type = type; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D; - } + private TileEntityPresent connection = null; + private ForgeDirection cachedDir = null; + private boolean isParent; + private ItemStack[] inventory = new ItemStack[27]; + private int type; + private boolean autoSearch = true; @Override public void updateEntity() { - super.updateEntity(); - this.checkForAdjacentChests(); - ++this.ticksSinceSync; - float f; + if (isConnected() && connection.isInvalid()) { + disconnect(); + } - if (!this.worldObj.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0) { - this.numPlayersUsing = 0; - f = 5.0F; - List list = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(this.xCoord - f, this.yCoord - f, - this.zCoord - f, this.xCoord + 1 + f, this.yCoord + 1 + f, this.zCoord + 1 + f)); - Iterator iterator = list.iterator(); + if (autoSearch && worldObj != null /* ugh */) { + if (cachedDir != null) { + connectTo(cachedDir); + } else { + findConnections(); + } + autoSearch = false; + } + } - while (iterator.hasNext()) { - EntityPlayer entityplayer = (EntityPlayer) iterator.next(); + public boolean isConnected() { + return connection != null; + } - if (entityplayer.openContainer instanceof ContainerPresent) { - IInventory iinventory = ((ContainerChest) entityplayer.openContainer).getLowerChestInventory(); + private boolean connectTo(TileEntityPresent present, ForgeDirection dir) { + if (present.type == type && !present.isConnected() && Math.abs(present.xCoord - xCoord + present.yCoord - yCoord + present.zCoord - zCoord) == 1) { + connection = present; + connection.connection = this; + connection.cachedDir = dir.getOpposite(); + cachedDir = dir; + isParent = !present.isParent; + PacketHandler.INSTANCE.sendToDimension(new MessagePresentConnect(this, dir, true), worldObj.provider.dimensionId); + return true; + } + return false; + } - if (iinventory == this || iinventory instanceof InventoryLargePresent && ((InventoryLargePresent) iinventory).isPartOfLargePresent(this)) { - ++this.numPlayersUsing; + public boolean connectTo(ForgeDirection dir) { + TileEntity te = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ); + if (te instanceof TileEntityPresent) { + return connectTo((TileEntityPresent) te, dir); + } + return false; + } + + public void disconnect() { + if (isConnected()) { + this.connection.cachedDir = null; + this.connection.connection = null; + this.cachedDir = null; + this.connection = null; + PacketHandler.INSTANCE.sendToDimension(new MessagePresentConnect(this, ForgeDirection.UNKNOWN, false), worldObj.provider.dimensionId); + } + } + + public TileEntityPresent getConnection() { + return connection; + } + + public ForgeDirection getConnectionDir() { + return cachedDir == null ? ForgeDirection.UNKNOWN : cachedDir; + } + + public boolean isParent() { + return isParent || !isConnected(); + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public void findConnections() { + if (!isConnected()) { + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + if (dir != ForgeDirection.UP && dir != ForgeDirection.DOWN) { + if (connectTo(dir)) { + break; } } } } + } + + public TileEntityPresent getParent() { + return isParent || connection == null ? this : connection; + } - this.prevLidAngle = this.lidAngle; - f = 0.1F; - double d2; + @Override + public AxisAlignedBB getRenderBoundingBox() { + return ChiselBlocks.present.getBoundingBox(this); + } - if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F && this.adjacentChestZNeg == null && this.adjacentChestXNeg == null) { - double d1 = this.xCoord + 0.5D; - d2 = this.zCoord + 0.5D; + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + NBTTagList nbttaglist = new NBTTagList(); - if (this.adjacentChestZPos != null) { - d2 += 0.5D; + for (int i = 0; i < inventory.length; ++i) + { + if (inventory[i] != null) + { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte) i); + inventory[i].writeToNBT(nbttagcompound1); + nbttaglist.appendTag(nbttagcompound1); } - - if (this.adjacentChestXPos != null) { - d1 += 0.5D; - } - - this.worldObj.playSoundEffect(d1, this.yCoord + 0.5D, d2, "random.chestopen", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F); } - if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) { - float f1 = this.lidAngle; - - if (this.numPlayersUsing > 0) { - this.lidAngle += f; - } else { - this.lidAngle -= f; - } - - if (this.lidAngle > 1.0F) { - this.lidAngle = 1.0F; - } - - float f2 = 0.5F; - - if (this.lidAngle < f2 && f1 >= f2 && this.adjacentChestZNeg == null && this.adjacentChestXNeg == null) { - d2 = this.xCoord + 0.5D; - double d0 = this.zCoord + 0.5D; - - if (this.adjacentChestZPos != null) { - d0 += 0.5D; - } - - if (this.adjacentChestXPos != null) { - d2 += 0.5D; - } - - this.worldObj.playSoundEffect(d2, this.yCoord + 0.5D, d0, "random.chestclosed", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F); - } - - if (this.lidAngle < 0.0F) { - this.lidAngle = 0.0F; - } + tag.setTag("Items", nbttaglist); + tag.setBoolean("isParent", isParent); + tag.setInteger("presentType", type); + if (cachedDir != null) { + tag.setInteger("conDir", cachedDir.ordinal()); } } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + NBTTagList nbttaglist = tag.getTagList("Items", 10); + inventory = new ItemStack[this.getSizeInventory()]; + + for (int i = 0; i < nbttaglist.tagCount(); ++i) + { + NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); + int j = nbttagcompound1.getByte("Slot") & 255; + + if (j >= 0 && j < inventory.length) + { + inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + } + } + + this.isParent = tag.getBoolean("isParent"); + + this.type = tag.getInteger("presentType"); + if (tag.hasKey("conDir")) { + cachedDir = ForgeDirection.values()[tag.getInteger("conDir")]; + } + autoSearch = true; + } + + /* IInventory */ + + @Override + public int getSizeInventory() { + return isConnected() ? inventory.length + connection.inventory.length : inventory.length; + } + + @Override + public ItemStack getStackInSlot(int slot) { + if (slot >= inventory.length) { + return isConnected() ? connection.inventory[slot % inventory.length] : null; + } else { + return inventory[slot]; + } + } + + @Override + public ItemStack decrStackSize(int slot, int amount) + { + ItemStack[] inv = inventory; + if (isConnected() && slot >= inventory.length) { + inv = connection.inventory; + } + + if (inv[slot] != null) + { + ItemStack itemstack; + + if (inv[slot].stackSize <= amount) + { + itemstack = inv[slot]; + inv[slot] = null; + this.markDirty(); + return itemstack; + } + else + { + itemstack = inv[slot].splitStack(amount); + + if (inv[slot].stackSize == 0) + { + inv[slot] = null; + } + + this.markDirty(); + return itemstack; + } + } + else + { + return null; + } + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return getStackInSlot(slot); + } + + @Override + public void setInventorySlotContents(int slot, ItemStack stack) { + if (slot < inventory.length) { + inventory[slot] = stack; + } else if (isConnected()) { + connection.inventory[slot % inventory.length] = stack; + } + } + + @Override + public String getInventoryName() { + return "chisel.present"; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { + return true; + } + + @Override + public void openInventory() { + ; + } + + @Override + public void closeInventory() { + ; + } + + @Override + public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { + return true; + } } diff --git a/src/main/java/com/cricketcraft/chisel/carving/CarvableHelper.java b/src/main/java/com/cricketcraft/chisel/carving/CarvableHelper.java index cbbc938e..81db120f 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/CarvableHelper.java +++ b/src/main/java/com/cricketcraft/chisel/carving/CarvableHelper.java @@ -255,7 +255,7 @@ public class CarvableHelper { } public void registerAll(Block block, String name) { - register(block, name, ItemCarvable.class); + registerAll(block, name, ItemCarvable.class); } public void registerBlock(Block block, String name) { @@ -267,7 +267,7 @@ public class CarvableHelper { GameRegistry.registerBlock(block, cl, name); } - public void register(Block block, String name, Class cl) { + public void registerAll(Block block, String name, Class cl) { registerBlock(block, name, cl); registerVariations(name, block); } diff --git a/src/main/java/com/cricketcraft/chisel/client/render/item/ItemPresentRenderer.java b/src/main/java/com/cricketcraft/chisel/client/render/item/ItemPresentRenderer.java deleted file mode 100644 index bd629928..00000000 --- a/src/main/java/com/cricketcraft/chisel/client/render/item/ItemPresentRenderer.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.cricketcraft.chisel.client.render.item; - -import net.minecraft.client.model.ModelChest; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.IItemRenderer; - -import org.lwjgl.opengl.GL11; - -import com.cricketcraft.chisel.Chisel; -import com.cricketcraft.chisel.block.BlockPresent; - -import cpw.mods.fml.client.FMLClientHandler; - -public class ItemPresentRenderer implements IItemRenderer { - - private final ModelChest model = new ModelChest(); - BlockPresent present; - private int meta; - - public ItemPresentRenderer(int type) { - present = new BlockPresent(type); - this.meta = type; - } - - @Override - public boolean handleRenderType(ItemStack item, ItemRenderType type) { - return type != ItemRenderType.FIRST_PERSON_MAP; - } - - @Override - public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { - return true; - } - - @Override - public void renderItem(ItemRenderType type, ItemStack item, Object... data) { - FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(Chisel.MOD_ID, present.getKindOfChest(meta) + ".png")); - switch (type) { - case ENTITY: - renderBlock(0.0F, 1.0F, 0.0F); - break; - case EQUIPPED: - renderBlock(0.5F, 1.5F, 0.5F); - break; - case EQUIPPED_FIRST_PERSON: - renderBlock(0.5F, 1.0F, 0.5F); - break; - case INVENTORY: - renderInventory(1.0F, 1.0F, 1.0F); - break; - default: - break; - } - } - - private void renderBlock(float x, float y, float z) { - GL11.glPushMatrix(); - GL11.glTranslatef(x, y, z); - GL11.glScaled(-1, -1, 1); - model.renderAll(); - GL11.glPopMatrix(); - } - - private void renderInventory(float x, float y, float z) { - GL11.glPushMatrix(); - GL11.glTranslatef(x, y, z); - GL11.glRotatef(180F, 1F, 0, 0); - GL11.glRotatef(-90F, 0, 1F, 0); - GL11.glScalef(1.0F, 1.0F, 1.0F); - model.renderAll(); - GL11.glPopMatrix(); - } -} diff --git a/src/main/java/com/cricketcraft/chisel/client/render/tile/RenderPresent.java b/src/main/java/com/cricketcraft/chisel/client/render/tile/RenderPresent.java index 59d8bac5..dcf906cf 100644 --- a/src/main/java/com/cricketcraft/chisel/client/render/tile/RenderPresent.java +++ b/src/main/java/com/cricketcraft/chisel/client/render/tile/RenderPresent.java @@ -1,126 +1,144 @@ package com.cricketcraft.chisel.client.render.tile; -import net.minecraft.block.Block; +import java.util.HashMap; + import net.minecraft.client.model.ModelChest; import net.minecraft.client.model.ModelLargeChest; -import net.minecraft.client.renderer.tileentity.TileEntityChestRenderer; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import com.cricketcraft.chisel.Chisel; -import com.cricketcraft.chisel.block.BlockPresent; import com.cricketcraft.chisel.block.tileentity.TileEntityPresent; +import com.cricketcraft.chisel.init.ChiselBlocks; +import com.google.common.collect.Maps; -import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.client.FMLClientHandler; -public class RenderPresent extends TileEntityChestRenderer { +public class RenderPresent extends TileEntitySpecialRenderer implements IItemRenderer { private ModelChest smallChest = new ModelChest(); private ModelChest largeChest = new ModelLargeChest(); - - public RenderPresent() { - } + + private HashMap textureCache = Maps.newHashMap(); public void renderTileEntityAt(TileEntityPresent present, double x, double y, double z, float partialTicks) { - int i; - - if (!present.hasWorldObj()) { - i = 0; - } else { - Block block = present.getBlockType(); - i = present.getBlockMetadata(); - - if (block instanceof BlockPresent && i == 0) { - try { - ((BlockPresent) block).func_149954_e(present.getWorldObj(), present.xCoord, present.yCoord, present.zCoord); - } catch (ClassCastException e) { - FMLLog.severe("[Chisel 2] Attempted to render a present at %d, %d, %d that was not a present", present.xCoord, present.yCoord, present.zCoord); - } - i = present.getBlockMetadata(); + GL11.glPushMatrix(); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F); + GL11.glScalef(1.0F, -1.0F, -1.0F); + int meta = present.getBlockMetadata(); + bindTexture(present); + if (!present.isConnected()) { + GL11.glRotatef(90 * meta + 180, 0, 1, 0); + switch(present.getBlockMetadata()) { + case 0: + GL11.glTranslatef(-1, 0, -1); + break; + case 1: + GL11.glTranslatef(0, 0, -1); + break; + case 3: + GL11.glTranslatef(-1, 0, 0); + break; } - - present.checkForAdjacentChests(); + smallChest.renderAll(); + } else if (present.isParent()) { + ForgeDirection dir = present.getConnectionDir(); + switch(dir) { + case NORTH: + GL11.glRotatef(-90, 0, 1, 0); + GL11.glTranslatef(0, 0, -1); + break; + case SOUTH: + GL11.glRotatef(-90, 0, 1, 0); + GL11.glTranslatef(-1, 0, -1); + break; + case WEST: + GL11.glTranslatef(-1, 0, 0); + break; + default: + break; + } + if (meta == 0 || meta == 3) { + GL11.glRotatef(180, 0, 1, 0); + GL11.glTranslatef(-2, 0, -1); + } + largeChest.renderAll(); } - - if (present.adjacentChestZNeg == null && present.adjacentChestXNeg == null) { - BlockPresent blockPresent = (BlockPresent) present.getWorldObj().getBlock(present.xCoord, present.yCoord, present.zCoord); - ModelChest smallOrLargeChest; - if (present.adjacentChestZPos == null && present.adjacentChestXPos == null) { - smallOrLargeChest = smallChest; - this.bindTexture(new ResourceLocation(Chisel.MOD_ID, blockPresent.getKindOfChest(present.type) + ".png")); - } else { - smallOrLargeChest = largeChest; - this.bindTexture(new ResourceLocation(Chisel.MOD_ID, blockPresent.getKindOfChest(present.type) + "_double.png")); - } - - GL11.glPushMatrix(); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F); - GL11.glScalef(1.0F, -1.0F, -1.0F); - GL11.glTranslatef(0.5F, 0.5F, 0.5F); - short short1 = 0; - - if (i == 2) { - short1 = 180; - } - - if (i == 3) { - short1 = 0; - } - - if (i == 4) { - short1 = 90; - } - - if (i == 5) { - short1 = -90; - } - - if (i == 2 && present.adjacentChestXPos != null) { - GL11.glTranslatef(1.0F, 0.0F, 0.0F); - } - - if (i == 5 && present.adjacentChestZPos != null) { - GL11.glTranslatef(0.0F, 0.0F, -1.0F); - } - - GL11.glRotatef(short1, 0.0F, 1.0F, 0.0F); - GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - float f1 = present.prevLidAngle + (present.lidAngle - present.prevLidAngle) * partialTicks; - float f2; - - if (present.adjacentChestZNeg != null) { - f2 = present.adjacentChestZNeg.prevLidAngle + (present.adjacentChestZNeg.lidAngle - present.adjacentChestZNeg.prevLidAngle) * partialTicks; - - if (f2 > f1) { - f1 = f2; - } - } - - if (present.adjacentChestXNeg != null) { - f2 = present.adjacentChestXNeg.prevLidAngle + (present.adjacentChestXNeg.lidAngle - present.adjacentChestXNeg.prevLidAngle) * partialTicks; - - if (f2 > f1) { - f1 = f2; - } - } - - f1 = 1.0F - f1; - f1 = 1.0F - f1 * f1 * f1; - smallOrLargeChest.chestLid.rotateAngleX = -(f1 * (float) Math.PI / 2.0F); - smallOrLargeChest.renderAll(); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - GL11.glPopMatrix(); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + } + + private void bindTexture(TileEntityPresent present) { + int idx = present.getType() + (present.isConnected() ? 0 : 16); + ResourceLocation rl = textureCache.get(idx); + if (rl == null) { + String res = ChiselBlocks.present.getModelTexture(present.getType()); + res += present.isConnected() ? "_double.png" : ".png"; + rl = new ResourceLocation("chisel", res); + textureCache.put(idx, rl); } + bindTexture(rl); } @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTicks) { this.renderTileEntityAt((TileEntityPresent) tileEntity, x, y, z, partialTicks); } + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) { + return type != ItemRenderType.FIRST_PERSON_MAP; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { + return true; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(Chisel.MOD_ID, ChiselBlocks.present.getModelTexture(item.getItemDamage()) + ".png")); + switch (type) { + case ENTITY: + renderBlock(0.0F, 1.0F, 0.0F); + break; + case EQUIPPED: + renderBlock(0.5F, 1.5F, 0.5F); + break; + case EQUIPPED_FIRST_PERSON: + renderBlock(0.5F, 1.0F, 0.5F); + break; + case INVENTORY: + renderInventory(1.0F, 1.0F, 1.0F); + break; + default: + break; + } + } + + private void renderBlock(float x, float y, float z) { + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, z); + GL11.glScaled(-1, -1, 1); + smallChest.renderAll(); + GL11.glPopMatrix(); + } + + private void renderInventory(float x, float y, float z) { + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, z); + GL11.glRotatef(180F, 1F, 0, 0); + GL11.glRotatef(-90F, 0, 1F, 0); + GL11.glScalef(1.0F, 1.0F, 1.0F); + smallChest.renderAll(); + GL11.glPopMatrix(); + } } diff --git a/src/main/java/com/cricketcraft/chisel/init/ChiselBlocks.java b/src/main/java/com/cricketcraft/chisel/init/ChiselBlocks.java index 545aa927..b61cd287 100644 --- a/src/main/java/com/cricketcraft/chisel/init/ChiselBlocks.java +++ b/src/main/java/com/cricketcraft/chisel/init/ChiselBlocks.java @@ -113,6 +113,8 @@ public final class ChiselBlocks { public static final BlockCarvable bloodRune = null; public static final BlockCarvable bloodBrick = null; + public static final BlockPresent present = null; + // Arrays can't be final because of how @ObjectHolder works public static BlockCarvableStairs[] marbleStairs = new BlockCarvableStairs[8]; public static BlockCarvableStairs[] limestoneStairs = new BlockCarvableStairs[8]; @@ -123,8 +125,6 @@ public final class ChiselBlocks { public static BlockCarvable[] planks = new BlockCarvable[6]; - public static BlockPresent[] present = new BlockPresent[16]; - public static BlockCarvablePumpkin[] pumpkin = new BlockCarvablePumpkin[16]; public static BlockCarvablePumpkin[] jackolantern = new BlockCarvablePumpkin[16]; diff --git a/src/main/java/com/cricketcraft/chisel/inventory/InventoryLargePresent.java b/src/main/java/com/cricketcraft/chisel/inventory/InventoryLargePresent.java deleted file mode 100644 index b8c85c79..00000000 --- a/src/main/java/com/cricketcraft/chisel/inventory/InventoryLargePresent.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.cricketcraft.chisel.inventory; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class InventoryLargePresent implements IInventory { - - private String name; - private IInventory upper, lower; - - public InventoryLargePresent(String name, IInventory upper, IInventory lower) { - this.name = name; - - if (upper == null) { - upper = lower; - } - - if (lower == null) { - lower = upper; - } - - this.upper = upper; - this.lower = lower; - } - - @Override - public int getSizeInventory() { - return upper.getSizeInventory() + lower.getSizeInventory(); - } - - public boolean isPartOfLargePresent(IInventory inventory) { - return upper == inventory || lower == inventory; - } - - @Override - public ItemStack getStackInSlot(int slot) { - return slot >= upper.getSizeInventory() ? lower.getStackInSlot(slot - upper.getSizeInventory()) : upper.getStackInSlot(slot); - } - - @Override - public ItemStack decrStackSize(int slot, int size) { - return slot >= upper.getSizeInventory() ? lower.getStackInSlot(slot - upper.getSizeInventory()) : upper.getStackInSlot(slot); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return slot >= upper.getSizeInventory() ? lower.getStackInSlotOnClosing(slot - upper.getSizeInventory()) : upper.getStackInSlotOnClosing(slot); - } - - @Override - public void setInventorySlotContents(int slot, ItemStack stack) { - if (slot >= upper.getSizeInventory()) { - lower.setInventorySlotContents(slot - upper.getSizeInventory(), stack); - } else { - upper.setInventorySlotContents(slot, stack); - } - } - - @Override - public String getInventoryName() { - return upper.hasCustomInventoryName() ? upper.getInventoryName() : (lower.hasCustomInventoryName() ? lower.getInventoryName() : name); - } - - @Override - public boolean hasCustomInventoryName() { - return upper.hasCustomInventoryName() || lower.hasCustomInventoryName(); - } - - @Override - public int getInventoryStackLimit() { - return upper.getInventoryStackLimit(); - } - - @Override - public void markDirty() { - upper.markDirty(); - lower.markDirty(); - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return upper.isUseableByPlayer(player) && lower.isUseableByPlayer(player); - } - - @Override - public void openInventory() { - upper.openInventory(); - lower.openInventory(); - } - - @Override - public void closeInventory() { - upper.closeInventory(); - ; - lower.closeInventory(); - } - - @Override - public boolean isItemValidForSlot(int slot, ItemStack stack) { - return true; - } -} diff --git a/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java b/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java index 44e742a3..290e2cd9 100644 --- a/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java +++ b/src/main/java/com/cricketcraft/chisel/network/PacketHandler.java @@ -4,6 +4,7 @@ import com.cricketcraft.chisel.Chisel; import com.cricketcraft.chisel.network.message.MessageAutoChisel; import com.cricketcraft.chisel.network.message.MessageChiselMode; import com.cricketcraft.chisel.network.message.MessageChiselSound; +import com.cricketcraft.chisel.network.message.MessagePresentConnect; import com.cricketcraft.chisel.network.message.MessageSlotUpdate; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; @@ -20,5 +21,6 @@ public class PacketHandler { INSTANCE.registerMessage(MessageSlotUpdate.Handler.class, MessageSlotUpdate.class, id++, Side.CLIENT); INSTANCE.registerMessage(MessageAutoChisel.Handler.class, MessageAutoChisel.class, id++, Side.CLIENT); INSTANCE.registerMessage(MessageChiselMode.Handler.class, MessageChiselMode.class, id++, Side.SERVER); + INSTANCE.registerMessage(MessagePresentConnect.Handler.class, MessagePresentConnect.class, id++, Side.CLIENT); } } \ No newline at end of file diff --git a/src/main/java/com/cricketcraft/chisel/network/message/MessagePresentConnect.java b/src/main/java/com/cricketcraft/chisel/network/message/MessagePresentConnect.java new file mode 100644 index 00000000..b0f94b76 --- /dev/null +++ b/src/main/java/com/cricketcraft/chisel/network/message/MessagePresentConnect.java @@ -0,0 +1,60 @@ +package com.cricketcraft.chisel.network.message; + +import io.netty.buffer.ByteBuf; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +import com.cricketcraft.chisel.block.tileentity.TileEntityPresent; +import com.cricketcraft.chisel.network.message.base.MessageCoords; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; + + +public class MessagePresentConnect extends MessageCoords { + + private ForgeDirection dir; + private boolean connect; + + public MessagePresentConnect() { + super(); + } + + public MessagePresentConnect(TileEntityPresent present, ForgeDirection dir, boolean connecting) { + super(present); + this.dir = dir; + this.connect = connecting; + } + + @Override + public void toBytes(ByteBuf buf) { + super.toBytes(buf); + buf.writeInt(dir.ordinal()); + buf.writeBoolean(connect); + } + + @Override + public void fromBytes(ByteBuf buf) { + super.fromBytes(buf); + dir = ForgeDirection.values()[buf.readInt()]; + connect = buf.readBoolean(); + } + + public static class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(MessagePresentConnect message, MessageContext ctx) { + TileEntity te = message.getTileEntity(ctx); + if (te instanceof TileEntityPresent) { + if (message.connect) { + ((TileEntityPresent) te).connectTo(message.dir); + } else { + ((TileEntityPresent) te).disconnect(); + } + } + return null; + } + } + +} diff --git a/src/main/java/com/cricketcraft/chisel/proxy/ClientProxy.java b/src/main/java/com/cricketcraft/chisel/proxy/ClientProxy.java index 9a57427d..4b032ec4 100644 --- a/src/main/java/com/cricketcraft/chisel/proxy/ClientProxy.java +++ b/src/main/java/com/cricketcraft/chisel/proxy/ClientProxy.java @@ -23,7 +23,6 @@ import com.cricketcraft.chisel.client.render.BlockSnakeStoneRenderer; import com.cricketcraft.chisel.client.render.BlockTexturedOreRenderer; import com.cricketcraft.chisel.client.render.RenderStandardBlockNoSunlight; import com.cricketcraft.chisel.client.render.item.ItemChiselRenderer; -import com.cricketcraft.chisel.client.render.item.ItemPresentRenderer; import com.cricketcraft.chisel.client.render.tile.RenderAutoChisel; import com.cricketcraft.chisel.client.render.tile.RenderPresent; import com.cricketcraft.chisel.entity.EntityBallOMoss; @@ -65,11 +64,9 @@ public class ClientProxy extends CommonProxy { MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ChiselBlocks.autoChisel), rac); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAutoChisel.class, rac); - ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPresent.class, new RenderPresent()); - - for (int x = 0; x < 16; x++) { - MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ChiselBlocks.present[x]), new ItemPresentRenderer(x)); - } + RenderPresent rp = new RenderPresent(); + MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ChiselBlocks.present), rp); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPresent.class, rp); RenderingRegistry.registerEntityRenderingHandler(EntityCloudInABottle.class, new RenderSnowball(ChiselItems.cloudinabottle)); RenderingRegistry.registerEntityRenderingHandler(EntityBallOMoss.class, new RenderSnowball(ChiselItems.ballomoss)); diff --git a/src/main/java/com/cricketcraft/chisel/proxy/CommonProxy.java b/src/main/java/com/cricketcraft/chisel/proxy/CommonProxy.java index aa2a8bb9..620ac259 100644 --- a/src/main/java/com/cricketcraft/chisel/proxy/CommonProxy.java +++ b/src/main/java/com/cricketcraft/chisel/proxy/CommonProxy.java @@ -12,7 +12,7 @@ public class CommonProxy { public void registerTileEntities() { GameRegistry.registerTileEntity(TileEntityAutoChisel.class, "autoChisel"); - GameRegistry.registerTileEntity(TileEntityPresent.class, "tile.present.present"); + GameRegistry.registerTileEntity(TileEntityPresent.class, "tile.chisel.present"); } public void preInit() {