| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.block.material.MapColor;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.block.properties.IProperty;
|
| 7 | import net.minecraft.block.properties.PropertyEnum;
|
| 8 | import net.minecraft.block.state.BlockState;
|
| 9 | import net.minecraft.block.state.IBlockState;
|
| 10 | import net.minecraft.creativetab.CreativeTabs;
|
| 11 | import net.minecraft.item.EnumDyeColor;
|
| 12 | import net.minecraft.item.Item;
|
| 13 | import net.minecraft.item.ItemStack;
|
| 14 | import net.minecraft.util.BlockPos;
|
| 15 | import net.minecraft.util.EnumFacing;
|
| 16 | import net.minecraft.world.IBlockAccess;
|
| 17 | import net.minecraft.world.World;
|
| 18 |
|
| 19 | public class BlockCarpet extends Block
|
| 20 | {
|
| 21 | public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);
|
| 22 |
|
| 23 | protected BlockCarpet()
|
| 24 | {
|
| 25 | super(Material.carpet);
|
| 26 | this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE));
|
| 27 | this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F);
|
| 28 | this.setTickRandomly(true);
|
| 29 | this.setCreativeTab(CreativeTabs.tabDecorations);
|
| 30 | this.setBlockBoundsFromMeta(0);
|
| 31 | }
|
| 32 |
|
| 33 | /**
|
| 34 | * Get the MapColor for this Block and the given BlockState
|
| 35 | */
|
| 36 | public MapColor getMapColor(IBlockState state)
|
| 37 | {
|
| 38 | return ((EnumDyeColor)state.getValue(COLOR)).getMapColor();
|
| 39 | }
|
| 40 |
|
| 41 | /**
|
| 42 | * Used to determine ambient occlusion and culling when rebuilding chunks for render
|
| 43 | */
|
| 44 | public boolean isOpaqueCube()
|
| 45 | {
|
| 46 | return false;
|
| 47 | }
|
| 48 |
|
| 49 | public boolean isFullCube()
|
| 50 | {
|
| 51 | return false;
|
| 52 | }
|
| 53 |
|
| 54 | /**
|
| 55 | * Sets the block's bounds for rendering it as an item
|
| 56 | */
|
| 57 | public void setBlockBoundsForItemRender()
|
| 58 | {
|
| 59 | this.setBlockBoundsFromMeta(0);
|
| 60 | }
|
| 61 |
|
| 62 | public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
|
| 63 | {
|
| 64 | this.setBlockBoundsFromMeta(0);
|
| 65 | }
|
| 66 |
|
| 67 | protected void setBlockBoundsFromMeta(int meta)
|
| 68 | {
|
| 69 | int i = 0;
|
| 70 | float f = (float)(1 * (1 + i)) / 16.0F;
|
| 71 | this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, f, 1.0F);
|
| 72 | }
|
| 73 |
|
| 74 | public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
|
| 75 | {
|
| 76 | return super.canPlaceBlockAt(worldIn, pos) && this.canBlockStay(worldIn, pos);
|
| 77 | }
|
| 78 |
|
| 79 | /**
|
| 80 | * Called when a neighboring block changes.
|
| 81 | */
|
| 82 | public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
|
| 83 | {
|
| 84 | this.checkForDrop(worldIn, pos, state);
|
| 85 | }
|
| 86 |
|
| 87 | private boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
|
| 88 | {
|
| 89 | if (!this.canBlockStay(worldIn, pos))
|
| 90 | {
|
| 91 | this.dropBlockAsItem(worldIn, pos, state, 0);
|
| 92 | worldIn.setBlockToAir(pos);
|
| 93 | return false;
|
| 94 | }
|
| 95 | else
|
| 96 | {
|
| 97 | return true;
|
| 98 | }
|
| 99 | }
|
| 100 |
|
| 101 | private boolean canBlockStay(World worldIn, BlockPos pos)
|
| 102 | {
|
| 103 | return !worldIn.isAirBlock(pos.down());
|
| 104 | }
|
| 105 |
|
| 106 | public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
|
| 107 | {
|
| 108 | return side == EnumFacing.UP ? true : super.shouldSideBeRendered(worldIn, pos, side);
|
| 109 | }
|
| 110 |
|
| 111 | /**
|
| 112 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 113 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 114 | */
|
| 115 | public int damageDropped(IBlockState state)
|
| 116 | {
|
| 117 | return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
|
| 118 | }
|
| 119 |
|
| 120 | /**
|
| 121 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 122 | */
|
| 123 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 124 | {
|
| 125 | for (int i = 0; i < 16; ++i)
|
| 126 | {
|
| 127 | list.add(new ItemStack(itemIn, 1, i));
|
| 128 | }
|
| 129 | }
|
| 130 |
|
| 131 | /**
|
| 132 | * Convert the given metadata into a BlockState for this Block
|
| 133 | */
|
| 134 | public IBlockState getStateFromMeta(int meta)
|
| 135 | {
|
| 136 | return this.getDefaultState().withProperty(COLOR, EnumDyeColor.byMetadata(meta));
|
| 137 | }
|
| 138 |
|
| 139 | /**
|
| 140 | * Convert the BlockState into the correct metadata value
|
| 141 | */
|
| 142 | public int getMetaFromState(IBlockState state)
|
| 143 | {
|
| 144 | return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
|
| 145 | }
|
| 146 |
|
| 147 | protected BlockState createBlockState()
|
| 148 | {
|
| 149 | return new BlockState(this, new IProperty[] {COLOR});
|
| 150 | }
|
| 151 | }
|
| 152 |
|