| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.material.MapColor;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.block.state.IBlockState;
|
| 7 | import net.minecraft.creativetab.CreativeTabs;
|
| 8 | import net.minecraft.entity.EntityLivingBase;
|
| 9 | import net.minecraft.entity.player.EntityPlayer;
|
| 10 | import net.minecraft.init.Blocks;
|
| 11 | import net.minecraft.item.ItemStack;
|
| 12 | import net.minecraft.tileentity.TileEntity;
|
| 13 | import net.minecraft.tileentity.TileEntityEnchantmentTable;
|
| 14 | import net.minecraft.util.BlockPos;
|
| 15 | import net.minecraft.util.EnumFacing;
|
| 16 | import net.minecraft.util.EnumParticleTypes;
|
| 17 | import net.minecraft.world.World;
|
| 18 |
|
| 19 | public class BlockEnchantmentTable extends BlockContainer
|
| 20 | {
|
| 21 | protected BlockEnchantmentTable()
|
| 22 | {
|
| 23 | super(Material.rock, MapColor.redColor);
|
| 24 | this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
|
| 25 | this.setLightOpacity(0);
|
| 26 | this.setCreativeTab(CreativeTabs.tabDecorations);
|
| 27 | }
|
| 28 |
|
| 29 | public boolean isFullCube()
|
| 30 | {
|
| 31 | return false;
|
| 32 | }
|
| 33 |
|
| 34 | public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 35 | {
|
| 36 | super.randomDisplayTick(worldIn, pos, state, rand);
|
| 37 |
|
| 38 | for (int i = -2; i <= 2; ++i)
|
| 39 | {
|
| 40 | for (int j = -2; j <= 2; ++j)
|
| 41 | {
|
| 42 | if (i > -2 && i < 2 && j == -1)
|
| 43 | {
|
| 44 | j = 2;
|
| 45 | }
|
| 46 |
|
| 47 | if (rand.nextInt(16) == 0)
|
| 48 | {
|
| 49 | for (int k = 0; k <= 1; ++k)
|
| 50 | {
|
| 51 | BlockPos blockpos = pos.add(i, k, j);
|
| 52 |
|
| 53 | if (worldIn.getBlockState(blockpos).getBlock() == Blocks.bookshelf)
|
| 54 | {
|
| 55 | if (!worldIn.isAirBlock(pos.add(i / 2, 0, j / 2)))
|
| 56 | {
|
| 57 | break;
|
| 58 | }
|
| 59 |
|
| 60 | worldIn.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, (double)pos.getX() + 0.5D, (double)pos.getY() + 2.0D, (double)pos.getZ() + 0.5D, (double)((float)i + rand.nextFloat()) - 0.5D, (double)((float)k - rand.nextFloat() - 1.0F), (double)((float)j + rand.nextFloat()) - 0.5D, new int[0]);
|
| 61 | }
|
| 62 | }
|
| 63 | }
|
| 64 | }
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | /**
|
| 69 | * Used to determine ambient occlusion and culling when rebuilding chunks for render
|
| 70 | */
|
| 71 | public boolean isOpaqueCube()
|
| 72 | {
|
| 73 | return false;
|
| 74 | }
|
| 75 |
|
| 76 | /**
|
| 77 | * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
|
| 78 | */
|
| 79 | public int getRenderType()
|
| 80 | {
|
| 81 | return 3;
|
| 82 | }
|
| 83 |
|
| 84 | /**
|
| 85 | * Returns a new instance of a block's tile entity class. Called on placing the block.
|
| 86 | */
|
| 87 | public TileEntity createNewTileEntity(World worldIn, int meta)
|
| 88 | {
|
| 89 | return new TileEntityEnchantmentTable();
|
| 90 | }
|
| 91 |
|
| 92 | public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
|
| 93 | {
|
| 94 | if (worldIn.isRemote)
|
| 95 | {
|
| 96 | return true;
|
| 97 | }
|
| 98 | else
|
| 99 | {
|
| 100 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 101 |
|
| 102 | if (tileentity instanceof TileEntityEnchantmentTable)
|
| 103 | {
|
| 104 | playerIn.displayGui((TileEntityEnchantmentTable)tileentity);
|
| 105 | }
|
| 106 |
|
| 107 | return true;
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | /**
|
| 112 | * Called by ItemBlocks after a block is set in the world, to allow post-place logic
|
| 113 | */
|
| 114 | public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
|
| 115 | {
|
| 116 | super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
| 117 |
|
| 118 | if (stack.hasDisplayName())
|
| 119 | {
|
| 120 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 121 |
|
| 122 | if (tileentity instanceof TileEntityEnchantmentTable)
|
| 123 | {
|
| 124 | ((TileEntityEnchantmentTable)tileentity).setCustomName(stack.getDisplayName());
|
| 125 | }
|
| 126 | }
|
| 127 | }
|
| 128 | }
|
| 129 |
|