Jump to content

Hermaan

Members
  • Posts

    1
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

Hermaan's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I'm working on a custom chest and I want it to be placed, if you use a "spawn item" like the sign item. But when it is placed it always faces North instead facing the player. BlockChestIron: package hermaan.chests.client; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import hermaan.chests.Chests; import java.util.Iterator; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryLargeChest; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import static net.minecraftforge.common.ForgeDirection.*; public class BlockChestIron extends BlockContainer { private Random random = new Random(); public BlockChestIron(int par1) { super(par1, Material.iron); this.blockIndexInTexture = 27; this.setBlockName("Reinforced Chest"); this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); } @Override public String getTextureFile() { return "/hermaan/chests/client/textures/reinforced.png"; } /** * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. */ public boolean isOpaqueCube() { return false; } public int idDropped(int par1, Random random, int zero) { return Chests.ChestSpawnIron.shiftedIndex; } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } /** * The type of render function that is called for this block */ public int getRenderType() { return 22; } /** * Updates the blocks bounds based on its current state. Args: world, x, y, z */ public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { if (par1IBlockAccess.getBlockId(par2, par3, par4 - 1) == this.blockID) { this.setBlockBounds(0.0625F, 0.0F, 0.0F, 0.9375F, 0.875F, 0.9375F); } else if (par1IBlockAccess.getBlockId(par2, par3, par4 + 1) == this.blockID) { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 1.0F); } else if (par1IBlockAccess.getBlockId(par2 - 1, par3, par4) == this.blockID) { this.setBlockBounds(0.0F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); } else if (par1IBlockAccess.getBlockId(par2 + 1, par3, par4) == this.blockID) { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F, 0.875F, 0.9375F); } else { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); } } /** * Called whenever the block is added into the world. Args: world, x, y, z */ public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); this.unifyAdjacentChests(par1World, par2, par3, par4); int var5 = par1World.getBlockId(par2, par3, par4 - 1); int var6 = par1World.getBlockId(par2, par3, par4 + 1); int var7 = par1World.getBlockId(par2 - 1, par3, par4); int var8 = par1World.getBlockId(par2 + 1, par3, par4); if (var5 == this.blockID) { this.unifyAdjacentChests(par1World, par2, par3, par4 - 1); } if (var6 == this.blockID) { this.unifyAdjacentChests(par1World, par2, par3, par4 + 1); } if (var7 == this.blockID) { this.unifyAdjacentChests(par1World, par2 - 1, par3, par4); } if (var8 == this.blockID) { this.unifyAdjacentChests(par1World, par2 + 1, par3, par4); } } /** * Called when the block is placed in the world. */ public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving) { int var6 = par1World.getBlockId(par2, par3, par4 - 1); int var7 = par1World.getBlockId(par2, par3, par4 + 1); int var8 = par1World.getBlockId(par2 - 1, par3, par4); int var9 = par1World.getBlockId(par2 + 1, par3, par4); byte var10 = 0; int var11 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (var11 == 0) { var10 = 2; } if (var11 == 1) { var10 = 5; } if (var11 == 2) { var10 = 3; } if (var11 == 3) { var10 = 4; } if (var6 != this.blockID && var7 != this.blockID && var8 != this.blockID && var9 != this.blockID) { par1World.setBlockMetadataWithNotify(par2, par3, par4, var10); } else { if ((var6 == this.blockID || var7 == this.blockID) && (var10 == 4 || var10 == 5)) { if (var6 == this.blockID) { par1World.setBlockMetadataWithNotify(par2, par3, par4 - 1, var10); } else { par1World.setBlockMetadataWithNotify(par2, par3, par4 + 1, var10); } par1World.setBlockMetadataWithNotify(par2, par3, par4, var10); } if ((var8 == this.blockID || var9 == this.blockID) && (var10 == 2 || var10 == 3)) { if (var8 == this.blockID) { par1World.setBlockMetadataWithNotify(par2 - 1, par3, par4, var10); } else { par1World.setBlockMetadataWithNotify(par2 + 1, par3, par4, var10); } par1World.setBlockMetadataWithNotify(par2, par3, par4, var10); } } } /** * Turns the adjacent chests to a double chest. */ public void unifyAdjacentChests(World par1World, int par2, int par3, int par4) { if (!par1World.isRemote) { int var5 = par1World.getBlockId(par2, par3, par4 - 1); int var6 = par1World.getBlockId(par2, par3, par4 + 1); int var7 = par1World.getBlockId(par2 - 1, par3, par4); int var8 = par1World.getBlockId(par2 + 1, par3, par4); boolean var9 = true; int var10; int var11; boolean var12; byte var13; int var14; if (var5 != this.blockID && var6 != this.blockID) { if (var7 != this.blockID && var8 != this.blockID) { var13 = 3; if (Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var6]) { var13 = 3; } if (Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var5]) { var13 = 2; } if (Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var8]) { var13 = 5; } if (Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var7]) { var13 = 4; } } else { var10 = par1World.getBlockId(var7 == this.blockID ? par2 - 1 : par2 + 1, par3, par4 - 1); var11 = par1World.getBlockId(var7 == this.blockID ? par2 - 1 : par2 + 1, par3, par4 + 1); var13 = 3; var12 = true; if (var7 == this.blockID) { var14 = par1World.getBlockMetadata(par2 - 1, par3, par4); } else { var14 = par1World.getBlockMetadata(par2 + 1, par3, par4); } if (var14 == 2) { var13 = 2; } if ((Block.opaqueCubeLookup[var5] || Block.opaqueCubeLookup[var10]) && !Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var11]) { var13 = 3; } if ((Block.opaqueCubeLookup[var6] || Block.opaqueCubeLookup[var11]) && !Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var10]) { var13 = 2; } } } else { var10 = par1World.getBlockId(par2 - 1, par3, var5 == this.blockID ? par4 - 1 : par4 + 1); var11 = par1World.getBlockId(par2 + 1, par3, var5 == this.blockID ? par4 - 1 : par4 + 1); var13 = 5; var12 = true; if (var5 == this.blockID) { var14 = par1World.getBlockMetadata(par2, par3, par4 - 1); } else { var14 = par1World.getBlockMetadata(par2, par3, par4 + 1); } if (var14 == 4) { var13 = 4; } if ((Block.opaqueCubeLookup[var7] || Block.opaqueCubeLookup[var10]) && !Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var11]) { var13 = 5; } if ((Block.opaqueCubeLookup[var8] || Block.opaqueCubeLookup[var11]) && !Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var10]) { var13 = 4; } } par1World.setBlockMetadataWithNotify(par2, par3, par4, var13); } } @SideOnly(Side.CLIENT) /** * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side */ public int getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { return 4; } /** * Returns the block texture based on the side being looked at. Args: side */ public int getBlockTextureFromSide(int par1) { return 4; } /** * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z */ public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) { int var5 = 0; if (par1World.getBlockId(par2 - 1, par3, par4) == this.blockID) { ++var5; } if (par1World.getBlockId(par2 + 1, par3, par4) == this.blockID) { ++var5; } if (par1World.getBlockId(par2, par3, par4 - 1) == this.blockID) { ++var5; } if (par1World.getBlockId(par2, par3, par4 + 1) == this.blockID) { ++var5; } return var5 > 1 ? false : (this.isThereANeighborChest(par1World, par2 - 1, par3, par4) ? false : (this.isThereANeighborChest(par1World, par2 + 1, par3, par4) ? false : (this.isThereANeighborChest(par1World, par2, par3, par4 - 1) ? false : !this.isThereANeighborChest(par1World, par2, par3, par4 + 1)))); } /** * Checks the neighbor blocks to see if there is a chest there. Args: world, x, y, z */ private boolean isThereANeighborChest(World par1World, int par2, int par3, int par4) { return par1World.getBlockId(par2, par3, par4) != this.blockID ? false : (par1World.getBlockId(par2 - 1, par3, par4) == this.blockID ? true : (par1World.getBlockId(par2 + 1, par3, par4) == this.blockID ? true : (par1World.getBlockId(par2, par3, par4 - 1) == this.blockID ? true : par1World.getBlockId(par2, par3, par4 + 1) == this.blockID))); } /** * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are * their own) Args: x, y, z, neighbor blockID */ public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { super.onNeighborBlockChange(par1World, par2, par3, par4, par5); TileEntityChestIron var6 = (TileEntityChestIron)par1World.getBlockTileEntity(par2, par3, par4); if (var6 != null) { var6.updateContainingBlockInfo(); } } /** * ejects contained items into the world, and notifies neighbours of an update, as appropriate */ public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) { TileEntityChestIron var7 = (TileEntityChestIron)par1World.getBlockTileEntity(par2, par3, par4); if (var7 != null) { for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8) { ItemStack var9 = var7.getStackInSlot(var8); if (var9 != null) { float var10 = this.random.nextFloat() * 0.8F + 0.1F; float var11 = this.random.nextFloat() * 0.8F + 0.1F; EntityItem var14; for (float var12 = this.random.nextFloat() * 0.8F + 0.1F; var9.stackSize > 0; par1World.spawnEntityInWorld(var14)) { int var13 = this.random.nextInt(21) + 10; if (var13 > var9.stackSize) { var13 = var9.stackSize; } var9.stackSize -= var13; var14 = new EntityItem(par1World, (double)((float)par2 + var10), (double)((float)par3 + var11), (double)((float)par4 + var12), new ItemStack(var9.itemID, var13, var9.getItemDamage())); float var15 = 0.05F; var14.motionX = (double)((float)this.random.nextGaussian() * var15); var14.motionY = (double)((float)this.random.nextGaussian() * var15 + 0.2F); var14.motionZ = (double)((float)this.random.nextGaussian() * var15); if (var9.hasTagCompound()) { var14.func_92014_d().setTagCompound((NBTTagCompound)var9.getTagCompound().copy()); } } } } } super.breakBlock(par1World, par2, par3, par4, par5, par6); } /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { Object var10 = (TileEntityChestIron)par1World.getBlockTileEntity(par2, par3, par4); if (var10 == null) { return true; } else if (par1World.isBlockSolidOnSide(par2, par3 + 1, par4, DOWN)) { return true; } else if (isOcelotBlockingChest(par1World, par2, par3, par4)) { return true; } else if (par1World.getBlockId(par2 - 1, par3, par4) == this.blockID && (par1World.isBlockSolidOnSide(par2 - 1, par3 + 1, par4, DOWN) || isOcelotBlockingChest(par1World, par2 - 1, par3, par4))) { return true; } else if (par1World.getBlockId(par2 + 1, par3, par4) == this.blockID && (par1World.isBlockSolidOnSide(par2 + 1, par3 + 1, par4, DOWN) || isOcelotBlockingChest(par1World, par2 + 1, par3, par4))) { return true; } else if (par1World.getBlockId(par2, par3, par4 - 1) == this.blockID && (par1World.isBlockSolidOnSide(par2, par3 + 1, par4 - 1, DOWN) || isOcelotBlockingChest(par1World, par2, par3, par4 - 1))) { return true; } else if (par1World.getBlockId(par2, par3, par4 + 1) == this.blockID && (par1World.isBlockSolidOnSide(par2, par3 + 1, par4 + 1, DOWN) || isOcelotBlockingChest(par1World, par2, par3, par4 + 1))) { return true; } else { if (par1World.getBlockId(par2 - 1, par3, par4) == this.blockID) { var10 = new InventoryLargeChest("container.chestDouble", (TileEntityChestIron)par1World.getBlockTileEntity(par2 - 1, par3, par4), (IInventory)var10); } if (par1World.getBlockId(par2 + 1, par3, par4) == this.blockID) { var10 = new InventoryLargeChest("container.chestDouble", (IInventory)var10, (TileEntityChestIron)par1World.getBlockTileEntity(par2 + 1, par3, par4)); } if (par1World.getBlockId(par2, par3, par4 - 1) == this.blockID) { var10 = new InventoryLargeChest("container.chestDouble", (TileEntityChestIron)par1World.getBlockTileEntity(par2, par3, par4 - 1), (IInventory)var10); } if (par1World.getBlockId(par2, par3, par4 + 1) == this.blockID) { var10 = new InventoryLargeChest("container.chestDouble", (IInventory)var10, (TileEntityChestIron)par1World.getBlockTileEntity(par2, par3, par4 + 1)); } if (par1World.isRemote) { return true; } else { par5EntityPlayer.displayGUIChest((IInventory)var10); return true; } } } /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ public TileEntity createNewTileEntity(World par1World) { return new TileEntityChestIron(); } /** * Looks for a sitting ocelot within certain bounds. Such an ocelot is considered to be blocking access to the * chest. */ public static boolean isOcelotBlockingChest(World par0World, int par1, int par2, int par3) { Iterator var4 = par0World.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)par1, (double)(par2 + 1), (double)par3, (double)(par1 + 1), (double)(par2 + 2), (double)(par3 + 1))).iterator(); EntityOcelot var6; do { if (!var4.hasNext()) { return false; } EntityOcelot var5 = (EntityOcelot)var4.next(); var6 = (EntityOcelot)var5; } while (!var6.isSitting()); return true; } } ItemChestSpawnerIron: package hermaan.chests.client; import hermaan.chests.Chests; import hermaan.chests.CommonProxy; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class ItemChestSpawnerIron extends Item{ public ItemChestSpawnerIron(int par1) { super(par1); setMaxStackSize(64); setCreativeTab(CreativeTabs.tabDecorations); setIconIndex(0); setItemName("Iron Chest"); } public String getTextureFile () { return CommonProxy.ITEMS_PNG; } public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { if (par7 == 0) { return false; } else if (!par3World.getBlockMaterial(par4, par5, par6).isSolid()) { return false; } else { if (par7 == 1) { ++par5; } if (par7 == 2) { --par6; } if (par7 == 3) { ++par6; } if (par7 == 4) { --par4; } if (par7 == 5) { ++par4; } if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack)) { return false; } else if (!Chests.IronChest.canPlaceBlockAt(par3World, par4, par5, par6)) { return false; } else { int var11 = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) + 0.5D) & 15; par3World.setBlockAndMetadataWithNotify(par4, par5, par6, Chests.IronChest.blockID, var11); --par1ItemStack.stackSize; return true; } } } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.