| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.properties.IProperty;
|
| 6 | import net.minecraft.block.properties.PropertyDirection;
|
| 7 | import net.minecraft.block.state.BlockState;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.creativetab.CreativeTabs;
|
| 10 | import net.minecraft.entity.EntityLivingBase;
|
| 11 | import net.minecraft.entity.player.EntityPlayer;
|
| 12 | import net.minecraft.init.Blocks;
|
| 13 | import net.minecraft.inventory.InventoryEnderChest;
|
| 14 | import net.minecraft.item.Item;
|
| 15 | import net.minecraft.item.ItemStack;
|
| 16 | import net.minecraft.stats.StatList;
|
| 17 | import net.minecraft.tileentity.TileEntity;
|
| 18 | import net.minecraft.tileentity.TileEntityEnderChest;
|
| 19 | import net.minecraft.util.BlockPos;
|
| 20 | import net.minecraft.util.EnumFacing;
|
| 21 | import net.minecraft.util.EnumParticleTypes;
|
| 22 | import net.minecraft.world.World;
|
| 23 |
|
| 24 | public class BlockEnderChest extends BlockContainer
|
| 25 | {
|
| 26 | public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
|
| 27 |
|
| 28 | protected BlockEnderChest()
|
| 29 | {
|
| 30 | super(Material.rock);
|
| 31 | this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
| 32 | this.setCreativeTab(CreativeTabs.tabDecorations);
|
| 33 | this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
|
| 34 | }
|
| 35 |
|
| 36 | /**
|
| 37 | * Used to determine ambient occlusion and culling when rebuilding chunks for render
|
| 38 | */
|
| 39 | public boolean isOpaqueCube()
|
| 40 | {
|
| 41 | return false;
|
| 42 | }
|
| 43 |
|
| 44 | public boolean isFullCube()
|
| 45 | {
|
| 46 | return false;
|
| 47 | }
|
| 48 |
|
| 49 | /**
|
| 50 | * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
|
| 51 | */
|
| 52 | public int getRenderType()
|
| 53 | {
|
| 54 | return 2;
|
| 55 | }
|
| 56 |
|
| 57 | /**
|
| 58 | * Get the Item that this Block should drop when harvested.
|
| 59 | */
|
| 60 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 61 | {
|
| 62 | return Item.getItemFromBlock(Blocks.obsidian);
|
| 63 | }
|
| 64 |
|
| 65 | /**
|
| 66 | * Returns the quantity of items to drop on block destruction.
|
| 67 | */
|
| 68 | public int quantityDropped(Random random)
|
| 69 | {
|
| 70 | return 8;
|
| 71 | }
|
| 72 |
|
| 73 | protected boolean canSilkHarvest()
|
| 74 | {
|
| 75 | return true;
|
| 76 | }
|
| 77 |
|
| 78 | /**
|
| 79 | * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
|
| 80 | * IBlockstate
|
| 81 | */
|
| 82 | public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
| 83 | {
|
| 84 | return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
|
| 85 | }
|
| 86 |
|
| 87 | /**
|
| 88 | * Called by ItemBlocks after a block is set in the world, to allow post-place logic
|
| 89 | */
|
| 90 | public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
|
| 91 | {
|
| 92 | worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
|
| 93 | }
|
| 94 |
|
| 95 | public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
|
| 96 | {
|
| 97 | InventoryEnderChest inventoryenderchest = playerIn.getInventoryEnderChest();
|
| 98 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 99 |
|
| 100 | if (inventoryenderchest != null && tileentity instanceof TileEntityEnderChest)
|
| 101 | {
|
| 102 | if (worldIn.getBlockState(pos.up()).getBlock().isNormalCube())
|
| 103 | {
|
| 104 | return true;
|
| 105 | }
|
| 106 | else if (worldIn.isRemote)
|
| 107 | {
|
| 108 | return true;
|
| 109 | }
|
| 110 | else
|
| 111 | {
|
| 112 | inventoryenderchest.setChestTileEntity((TileEntityEnderChest)tileentity);
|
| 113 | playerIn.displayGUIChest(inventoryenderchest);
|
| 114 | playerIn.triggerAchievement(StatList.field_181738_V);
|
| 115 | return true;
|
| 116 | }
|
| 117 | }
|
| 118 | else
|
| 119 | {
|
| 120 | return true;
|
| 121 | }
|
| 122 | }
|
| 123 |
|
| 124 | /**
|
| 125 | * Returns a new instance of a block's tile entity class. Called on placing the block.
|
| 126 | */
|
| 127 | public TileEntity createNewTileEntity(World worldIn, int meta)
|
| 128 | {
|
| 129 | return new TileEntityEnderChest();
|
| 130 | }
|
| 131 |
|
| 132 | public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 133 | {
|
| 134 | for (int i = 0; i < 3; ++i)
|
| 135 | {
|
| 136 | int j = rand.nextInt(2) * 2 - 1;
|
| 137 | int k = rand.nextInt(2) * 2 - 1;
|
| 138 | double d0 = (double)pos.getX() + 0.5D + 0.25D * (double)j;
|
| 139 | double d1 = (double)((float)pos.getY() + rand.nextFloat());
|
| 140 | double d2 = (double)pos.getZ() + 0.5D + 0.25D * (double)k;
|
| 141 | double d3 = (double)(rand.nextFloat() * (float)j);
|
| 142 | double d4 = ((double)rand.nextFloat() - 0.5D) * 0.125D;
|
| 143 | double d5 = (double)(rand.nextFloat() * (float)k);
|
| 144 | worldIn.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5, new int[0]);
|
| 145 | }
|
| 146 | }
|
| 147 |
|
| 148 | /**
|
| 149 | * Convert the given metadata into a BlockState for this Block
|
| 150 | */
|
| 151 | public IBlockState getStateFromMeta(int meta)
|
| 152 | {
|
| 153 | EnumFacing enumfacing = EnumFacing.getFront(meta);
|
| 154 |
|
| 155 | if (enumfacing.getAxis() == EnumFacing.Axis.Y)
|
| 156 | {
|
| 157 | enumfacing = EnumFacing.NORTH;
|
| 158 | }
|
| 159 |
|
| 160 | return this.getDefaultState().withProperty(FACING, enumfacing);
|
| 161 | }
|
| 162 |
|
| 163 | /**
|
| 164 | * Convert the BlockState into the correct metadata value
|
| 165 | */
|
| 166 | public int getMetaFromState(IBlockState state)
|
| 167 | {
|
| 168 | return ((EnumFacing)state.getValue(FACING)).getIndex();
|
| 169 | }
|
| 170 |
|
| 171 | protected BlockState createBlockState()
|
| 172 | {
|
| 173 | return new BlockState(this, new IProperty[] {FACING});
|
| 174 | }
|
| 175 | }
|
| 176 |
|