| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import net.minecraft.block.material.MapColor;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 6 | import net.minecraft.creativetab.CreativeTabs;
|
| 7 | import net.minecraft.entity.EntityLivingBase;
|
| 8 | import net.minecraft.entity.player.EntityPlayer;
|
| 9 | import net.minecraft.init.Blocks;
|
| 10 | import net.minecraft.item.ItemStack;
|
| 11 | import net.minecraft.stats.StatList;
|
| 12 | import net.minecraft.tileentity.TileEntity;
|
| 13 | import net.minecraft.tileentity.TileEntityBeacon;
|
| 14 | import net.minecraft.util.BlockPos;
|
| 15 | import net.minecraft.util.EnumFacing;
|
| 16 | import net.minecraft.util.EnumWorldBlockLayer;
|
| 17 | import net.minecraft.util.HttpUtil;
|
| 18 | import net.minecraft.world.World;
|
| 19 | import net.minecraft.world.WorldServer;
|
| 20 | import net.minecraft.world.chunk.Chunk;
|
| 21 |
|
| 22 | public class BlockBeacon extends BlockContainer
|
| 23 | {
|
| 24 | public BlockBeacon()
|
| 25 | {
|
| 26 | super(Material.glass, MapColor.diamondColor);
|
| 27 | this.setHardness(3.0F);
|
| 28 | this.setCreativeTab(CreativeTabs.tabMisc);
|
| 29 | }
|
| 30 |
|
| 31 | /**
|
| 32 | * Returns a new instance of a block's tile entity class. Called on placing the block.
|
| 33 | */
|
| 34 | public TileEntity createNewTileEntity(World worldIn, int meta)
|
| 35 | {
|
| 36 | return new TileEntityBeacon();
|
| 37 | }
|
| 38 |
|
| 39 | public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
|
| 40 | {
|
| 41 | if (worldIn.isRemote)
|
| 42 | {
|
| 43 | return true;
|
| 44 | }
|
| 45 | else
|
| 46 | {
|
| 47 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 48 |
|
| 49 | if (tileentity instanceof TileEntityBeacon)
|
| 50 | {
|
| 51 | playerIn.displayGUIChest((TileEntityBeacon)tileentity);
|
| 52 | playerIn.triggerAchievement(StatList.field_181730_N);
|
| 53 | }
|
| 54 |
|
| 55 | return true;
|
| 56 | }
|
| 57 | }
|
| 58 |
|
| 59 | /**
|
| 60 | * Used to determine ambient occlusion and culling when rebuilding chunks for render
|
| 61 | */
|
| 62 | public boolean isOpaqueCube()
|
| 63 | {
|
| 64 | return false;
|
| 65 | }
|
| 66 |
|
| 67 | public boolean isFullCube()
|
| 68 | {
|
| 69 | return false;
|
| 70 | }
|
| 71 |
|
| 72 | /**
|
| 73 | * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
|
| 74 | */
|
| 75 | public int getRenderType()
|
| 76 | {
|
| 77 | return 3;
|
| 78 | }
|
| 79 |
|
| 80 | /**
|
| 81 | * Called by ItemBlocks after a block is set in the world, to allow post-place logic
|
| 82 | */
|
| 83 | public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
|
| 84 | {
|
| 85 | super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
| 86 |
|
| 87 | if (stack.hasDisplayName())
|
| 88 | {
|
| 89 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 90 |
|
| 91 | if (tileentity instanceof TileEntityBeacon)
|
| 92 | {
|
| 93 | ((TileEntityBeacon)tileentity).setName(stack.getDisplayName());
|
| 94 | }
|
| 95 | }
|
| 96 | }
|
| 97 |
|
| 98 | /**
|
| 99 | * Called when a neighboring block changes.
|
| 100 | */
|
| 101 | public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
|
| 102 | {
|
| 103 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 104 |
|
| 105 | if (tileentity instanceof TileEntityBeacon)
|
| 106 | {
|
| 107 | ((TileEntityBeacon)tileentity).updateBeacon();
|
| 108 | worldIn.addBlockEvent(pos, this, 1, 0);
|
| 109 | }
|
| 110 | }
|
| 111 |
|
| 112 | public EnumWorldBlockLayer getBlockLayer()
|
| 113 | {
|
| 114 | return EnumWorldBlockLayer.CUTOUT;
|
| 115 | }
|
| 116 |
|
| 117 | public static void updateColorAsync(final World worldIn, final BlockPos glassPos)
|
| 118 | {
|
| 119 | HttpUtil.field_180193_a.submit(new Runnable()
|
| 120 | {
|
| 121 | public void run()
|
| 122 | {
|
| 123 | Chunk chunk = worldIn.getChunkFromBlockCoords(glassPos);
|
| 124 |
|
| 125 | for (int i = glassPos.getY() - 1; i >= 0; --i)
|
| 126 | {
|
| 127 | final BlockPos blockpos = new BlockPos(glassPos.getX(), i, glassPos.getZ());
|
| 128 |
|
| 129 | if (!chunk.canSeeSky(blockpos))
|
| 130 | {
|
| 131 | break;
|
| 132 | }
|
| 133 |
|
| 134 | IBlockState iblockstate = worldIn.getBlockState(blockpos);
|
| 135 |
|
| 136 | if (iblockstate.getBlock() == Blocks.beacon)
|
| 137 | {
|
| 138 | ((WorldServer)worldIn).addScheduledTask(new Runnable()
|
| 139 | {
|
| 140 | public void run()
|
| 141 | {
|
| 142 | TileEntity tileentity = worldIn.getTileEntity(blockpos);
|
| 143 |
|
| 144 | if (tileentity instanceof TileEntityBeacon)
|
| 145 | {
|
| 146 | ((TileEntityBeacon)tileentity).updateBeacon();
|
| 147 | worldIn.addBlockEvent(blockpos, Blocks.beacon, 1, 0);
|
| 148 | }
|
| 149 | }
|
| 150 | });
|
| 151 | }
|
| 152 | }
|
| 153 | }
|
| 154 | });
|
| 155 | }
|
| 156 | }
|
| 157 |
|