| 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.PropertyBool;
|
| 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.init.Blocks;
|
| 13 | import net.minecraft.item.Item;
|
| 14 | import net.minecraft.item.ItemStack;
|
| 15 | import net.minecraft.util.BlockPos;
|
| 16 | import net.minecraft.util.IStringSerializable;
|
| 17 | import net.minecraft.world.IBlockAccess;
|
| 18 | import net.minecraft.world.World;
|
| 19 |
|
| 20 | public class BlockDirt extends Block
|
| 21 | {
|
| 22 | public static final PropertyEnum<BlockDirt.DirtType> VARIANT = PropertyEnum.<BlockDirt.DirtType>create("variant", BlockDirt.DirtType.class);
|
| 23 | public static final PropertyBool SNOWY = PropertyBool.create("snowy");
|
| 24 |
|
| 25 | protected BlockDirt()
|
| 26 | {
|
| 27 | super(Material.ground);
|
| 28 | this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockDirt.DirtType.DIRT).withProperty(SNOWY, Boolean.valueOf(false)));
|
| 29 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 30 | }
|
| 31 |
|
| 32 | /**
|
| 33 | * Get the MapColor for this Block and the given BlockState
|
| 34 | */
|
| 35 | public MapColor getMapColor(IBlockState state)
|
| 36 | {
|
| 37 | return ((BlockDirt.DirtType)state.getValue(VARIANT)).func_181066_d();
|
| 38 | }
|
| 39 |
|
| 40 | /**
|
| 41 | * Get the actual Block state of this Block at the given position. This applies properties not visible in the
|
| 42 | * metadata, such as fence connections.
|
| 43 | */
|
| 44 | public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
|
| 45 | {
|
| 46 | if (state.getValue(VARIANT) == BlockDirt.DirtType.PODZOL)
|
| 47 | {
|
| 48 | Block block = worldIn.getBlockState(pos.up()).getBlock();
|
| 49 | state = state.withProperty(SNOWY, Boolean.valueOf(block == Blocks.snow || block == Blocks.snow_layer));
|
| 50 | }
|
| 51 |
|
| 52 | return state;
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 57 | */
|
| 58 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 59 | {
|
| 60 | list.add(new ItemStack(this, 1, BlockDirt.DirtType.DIRT.getMetadata()));
|
| 61 | list.add(new ItemStack(this, 1, BlockDirt.DirtType.COARSE_DIRT.getMetadata()));
|
| 62 | list.add(new ItemStack(this, 1, BlockDirt.DirtType.PODZOL.getMetadata()));
|
| 63 | }
|
| 64 |
|
| 65 | /**
|
| 66 | * Gets the meta to use for the Pick Block ItemStack result
|
| 67 | */
|
| 68 | public int getDamageValue(World worldIn, BlockPos pos)
|
| 69 | {
|
| 70 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 71 | return iblockstate.getBlock() != this ? 0 : ((BlockDirt.DirtType)iblockstate.getValue(VARIANT)).getMetadata();
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Convert the given metadata into a BlockState for this Block
|
| 76 | */
|
| 77 | public IBlockState getStateFromMeta(int meta)
|
| 78 | {
|
| 79 | return this.getDefaultState().withProperty(VARIANT, BlockDirt.DirtType.byMetadata(meta));
|
| 80 | }
|
| 81 |
|
| 82 | /**
|
| 83 | * Convert the BlockState into the correct metadata value
|
| 84 | */
|
| 85 | public int getMetaFromState(IBlockState state)
|
| 86 | {
|
| 87 | return ((BlockDirt.DirtType)state.getValue(VARIANT)).getMetadata();
|
| 88 | }
|
| 89 |
|
| 90 | protected BlockState createBlockState()
|
| 91 | {
|
| 92 | return new BlockState(this, new IProperty[] {VARIANT, SNOWY});
|
| 93 | }
|
| 94 |
|
| 95 | /**
|
| 96 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 97 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 98 | */
|
| 99 | public int damageDropped(IBlockState state)
|
| 100 | {
|
| 101 | BlockDirt.DirtType blockdirt$dirttype = (BlockDirt.DirtType)state.getValue(VARIANT);
|
| 102 |
|
| 103 | if (blockdirt$dirttype == BlockDirt.DirtType.PODZOL)
|
| 104 | {
|
| 105 | blockdirt$dirttype = BlockDirt.DirtType.DIRT;
|
| 106 | }
|
| 107 |
|
| 108 | return blockdirt$dirttype.getMetadata();
|
| 109 | }
|
| 110 |
|
| 111 | public static enum DirtType implements IStringSerializable
|
| 112 | {
|
| 113 | DIRT(0, "dirt", "default", MapColor.dirtColor),
|
| 114 | COARSE_DIRT(1, "coarse_dirt", "coarse", MapColor.dirtColor),
|
| 115 | PODZOL(2, "podzol", MapColor.obsidianColor);
|
| 116 |
|
| 117 | private static final BlockDirt.DirtType[] METADATA_LOOKUP = new BlockDirt.DirtType[values().length];
|
| 118 | private final int metadata;
|
| 119 | private final String name;
|
| 120 | private final String unlocalizedName;
|
| 121 | private final MapColor field_181067_h;
|
| 122 |
|
| 123 | private DirtType(int p_i46396_3_, String p_i46396_4_, MapColor p_i46396_5_)
|
| 124 | {
|
| 125 | this(p_i46396_3_, p_i46396_4_, p_i46396_4_, p_i46396_5_);
|
| 126 | }
|
| 127 |
|
| 128 | private DirtType(int p_i46397_3_, String p_i46397_4_, String p_i46397_5_, MapColor p_i46397_6_)
|
| 129 | {
|
| 130 | this.metadata = p_i46397_3_;
|
| 131 | this.name = p_i46397_4_;
|
| 132 | this.unlocalizedName = p_i46397_5_;
|
| 133 | this.field_181067_h = p_i46397_6_;
|
| 134 | }
|
| 135 |
|
| 136 | public int getMetadata()
|
| 137 | {
|
| 138 | return this.metadata;
|
| 139 | }
|
| 140 |
|
| 141 | public String getUnlocalizedName()
|
| 142 | {
|
| 143 | return this.unlocalizedName;
|
| 144 | }
|
| 145 |
|
| 146 | public MapColor func_181066_d()
|
| 147 | {
|
| 148 | return this.field_181067_h;
|
| 149 | }
|
| 150 |
|
| 151 | public String toString()
|
| 152 | {
|
| 153 | return this.name;
|
| 154 | }
|
| 155 |
|
| 156 | public static BlockDirt.DirtType byMetadata(int metadata)
|
| 157 | {
|
| 158 | if (metadata < 0 || metadata >= METADATA_LOOKUP.length)
|
| 159 | {
|
| 160 | metadata = 0;
|
| 161 | }
|
| 162 |
|
| 163 | return METADATA_LOOKUP[metadata];
|
| 164 | }
|
| 165 |
|
| 166 | public String getName()
|
| 167 | {
|
| 168 | return this.name;
|
| 169 | }
|
| 170 |
|
| 171 | static {
|
| 172 | for (BlockDirt.DirtType blockdirt$dirttype : values())
|
| 173 | {
|
| 174 | METADATA_LOOKUP[blockdirt$dirttype.getMetadata()] = blockdirt$dirttype;
|
| 175 | }
|
| 176 | }
|
| 177 | }
|
| 178 | }
|
| 179 |
|