| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.Random;
|
| 5 | import net.minecraft.block.material.MapColor;
|
| 6 | import net.minecraft.block.material.Material;
|
| 7 | import net.minecraft.block.properties.IProperty;
|
| 8 | import net.minecraft.block.properties.PropertyEnum;
|
| 9 | import net.minecraft.block.state.BlockState;
|
| 10 | import net.minecraft.block.state.IBlockState;
|
| 11 | import net.minecraft.creativetab.CreativeTabs;
|
| 12 | import net.minecraft.item.EnumDyeColor;
|
| 13 | import net.minecraft.item.Item;
|
| 14 | import net.minecraft.item.ItemStack;
|
| 15 | import net.minecraft.util.BlockPos;
|
| 16 | import net.minecraft.util.EnumWorldBlockLayer;
|
| 17 | import net.minecraft.world.World;
|
| 18 |
|
| 19 | public class BlockStainedGlass extends BlockBreakable
|
| 20 | {
|
| 21 | public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);
|
| 22 |
|
| 23 | public BlockStainedGlass(Material materialIn)
|
| 24 | {
|
| 25 | super(materialIn, false);
|
| 26 | this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE));
|
| 27 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 28 | }
|
| 29 |
|
| 30 | /**
|
| 31 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 32 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 33 | */
|
| 34 | public int damageDropped(IBlockState state)
|
| 35 | {
|
| 36 | return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 41 | */
|
| 42 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 43 | {
|
| 44 | for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
|
| 45 | {
|
| 46 | list.add(new ItemStack(itemIn, 1, enumdyecolor.getMetadata()));
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | /**
|
| 51 | * Get the MapColor for this Block and the given BlockState
|
| 52 | */
|
| 53 | public MapColor getMapColor(IBlockState state)
|
| 54 | {
|
| 55 | return ((EnumDyeColor)state.getValue(COLOR)).getMapColor();
|
| 56 | }
|
| 57 |
|
| 58 | public EnumWorldBlockLayer getBlockLayer()
|
| 59 | {
|
| 60 | return EnumWorldBlockLayer.TRANSLUCENT;
|
| 61 | }
|
| 62 |
|
| 63 | /**
|
| 64 | * Returns the quantity of items to drop on block destruction.
|
| 65 | */
|
| 66 | public int quantityDropped(Random random)
|
| 67 | {
|
| 68 | return 0;
|
| 69 | }
|
| 70 |
|
| 71 | protected boolean canSilkHarvest()
|
| 72 | {
|
| 73 | return true;
|
| 74 | }
|
| 75 |
|
| 76 | public boolean isFullCube()
|
| 77 | {
|
| 78 | return false;
|
| 79 | }
|
| 80 |
|
| 81 | /**
|
| 82 | * Convert the given metadata into a BlockState for this Block
|
| 83 | */
|
| 84 | public IBlockState getStateFromMeta(int meta)
|
| 85 | {
|
| 86 | return this.getDefaultState().withProperty(COLOR, EnumDyeColor.byMetadata(meta));
|
| 87 | }
|
| 88 |
|
| 89 | public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
|
| 90 | {
|
| 91 | if (!worldIn.isRemote)
|
| 92 | {
|
| 93 | BlockBeacon.updateColorAsync(worldIn, pos);
|
| 94 | }
|
| 95 | }
|
| 96 |
|
| 97 | public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
| 98 | {
|
| 99 | if (!worldIn.isRemote)
|
| 100 | {
|
| 101 | BlockBeacon.updateColorAsync(worldIn, pos);
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 | /**
|
| 106 | * Convert the BlockState into the correct metadata value
|
| 107 | */
|
| 108 | public int getMetaFromState(IBlockState state)
|
| 109 | {
|
| 110 | return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
|
| 111 | }
|
| 112 |
|
| 113 | protected BlockState createBlockState()
|
| 114 | {
|
| 115 | return new BlockState(this, new IProperty[] {COLOR});
|
| 116 | }
|
| 117 | }
|
| 118 |
|