| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.properties.PropertyBool;
|
| 6 | import net.minecraft.block.state.IBlockState;
|
| 7 | import net.minecraft.creativetab.CreativeTabs;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.item.Item;
|
| 10 | import net.minecraft.item.ItemStack;
|
| 11 | import net.minecraft.util.BlockPos;
|
| 12 | import net.minecraft.util.EnumParticleTypes;
|
| 13 | import net.minecraft.util.EnumWorldBlockLayer;
|
| 14 | import net.minecraft.world.ColorizerFoliage;
|
| 15 | import net.minecraft.world.IBlockAccess;
|
| 16 | import net.minecraft.world.World;
|
| 17 | import net.minecraft.world.biome.BiomeColorHelper;
|
| 18 |
|
| 19 | public abstract class BlockLeaves extends BlockLeavesBase
|
| 20 | {
|
| 21 | public static final PropertyBool DECAYABLE = PropertyBool.create("decayable");
|
| 22 | public static final PropertyBool CHECK_DECAY = PropertyBool.create("check_decay");
|
| 23 | int[] surroundings;
|
| 24 | protected int iconIndex;
|
| 25 | protected boolean isTransparent;
|
| 26 |
|
| 27 | public BlockLeaves()
|
| 28 | {
|
| 29 | super(Material.leaves, false);
|
| 30 | this.setTickRandomly(true);
|
| 31 | this.setCreativeTab(CreativeTabs.tabDecorations);
|
| 32 | this.setHardness(0.2F);
|
| 33 | this.setLightOpacity(1);
|
| 34 | this.setStepSound(soundTypeGrass);
|
| 35 | }
|
| 36 |
|
| 37 | public int getBlockColor()
|
| 38 | {
|
| 39 | return ColorizerFoliage.getFoliageColor(0.5D, 1.0D);
|
| 40 | }
|
| 41 |
|
| 42 | public int getRenderColor(IBlockState state)
|
| 43 | {
|
| 44 | return ColorizerFoliage.getFoliageColorBasic();
|
| 45 | }
|
| 46 |
|
| 47 | public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
|
| 48 | {
|
| 49 | return BiomeColorHelper.getFoliageColorAtPos(worldIn, pos);
|
| 50 | }
|
| 51 |
|
| 52 | public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
| 53 | {
|
| 54 | int i = 1;
|
| 55 | int j = i + 1;
|
| 56 | int k = pos.getX();
|
| 57 | int l = pos.getY();
|
| 58 | int i1 = pos.getZ();
|
| 59 |
|
| 60 | if (worldIn.isAreaLoaded(new BlockPos(k - j, l - j, i1 - j), new BlockPos(k + j, l + j, i1 + j)))
|
| 61 | {
|
| 62 | for (int j1 = -i; j1 <= i; ++j1)
|
| 63 | {
|
| 64 | for (int k1 = -i; k1 <= i; ++k1)
|
| 65 | {
|
| 66 | for (int l1 = -i; l1 <= i; ++l1)
|
| 67 | {
|
| 68 | BlockPos blockpos = pos.add(j1, k1, l1);
|
| 69 | IBlockState iblockstate = worldIn.getBlockState(blockpos);
|
| 70 |
|
| 71 | if (iblockstate.getBlock().getMaterial() == Material.leaves && !((Boolean)iblockstate.getValue(CHECK_DECAY)).booleanValue())
|
| 72 | {
|
| 73 | worldIn.setBlockState(blockpos, iblockstate.withProperty(CHECK_DECAY, Boolean.valueOf(true)), 4);
|
| 74 | }
|
| 75 | }
|
| 76 | }
|
| 77 | }
|
| 78 | }
|
| 79 | }
|
| 80 |
|
| 81 | public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 82 | {
|
| 83 | if (!worldIn.isRemote)
|
| 84 | {
|
| 85 | if (((Boolean)state.getValue(CHECK_DECAY)).booleanValue() && ((Boolean)state.getValue(DECAYABLE)).booleanValue())
|
| 86 | {
|
| 87 | int i = 4;
|
| 88 | int j = i + 1;
|
| 89 | int k = pos.getX();
|
| 90 | int l = pos.getY();
|
| 91 | int i1 = pos.getZ();
|
| 92 | int j1 = 32;
|
| 93 | int k1 = j1 * j1;
|
| 94 | int l1 = j1 / 2;
|
| 95 |
|
| 96 | if (this.surroundings == null)
|
| 97 | {
|
| 98 | this.surroundings = new int[j1 * j1 * j1];
|
| 99 | }
|
| 100 |
|
| 101 | if (worldIn.isAreaLoaded(new BlockPos(k - j, l - j, i1 - j), new BlockPos(k + j, l + j, i1 + j)))
|
| 102 | {
|
| 103 | BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
| 104 |
|
| 105 | for (int i2 = -i; i2 <= i; ++i2)
|
| 106 | {
|
| 107 | for (int j2 = -i; j2 <= i; ++j2)
|
| 108 | {
|
| 109 | for (int k2 = -i; k2 <= i; ++k2)
|
| 110 | {
|
| 111 | Block block = worldIn.getBlockState(blockpos$mutableblockpos.set(k + i2, l + j2, i1 + k2)).getBlock();
|
| 112 |
|
| 113 | if (block != Blocks.log && block != Blocks.log2)
|
| 114 | {
|
| 115 | if (block.getMaterial() == Material.leaves)
|
| 116 | {
|
| 117 | this.surroundings[(i2 + l1) * k1 + (j2 + l1) * j1 + k2 + l1] = -2;
|
| 118 | }
|
| 119 | else
|
| 120 | {
|
| 121 | this.surroundings[(i2 + l1) * k1 + (j2 + l1) * j1 + k2 + l1] = -1;
|
| 122 | }
|
| 123 | }
|
| 124 | else
|
| 125 | {
|
| 126 | this.surroundings[(i2 + l1) * k1 + (j2 + l1) * j1 + k2 + l1] = 0;
|
| 127 | }
|
| 128 | }
|
| 129 | }
|
| 130 | }
|
| 131 |
|
| 132 | for (int i3 = 1; i3 <= 4; ++i3)
|
| 133 | {
|
| 134 | for (int j3 = -i; j3 <= i; ++j3)
|
| 135 | {
|
| 136 | for (int k3 = -i; k3 <= i; ++k3)
|
| 137 | {
|
| 138 | for (int l3 = -i; l3 <= i; ++l3)
|
| 139 | {
|
| 140 | if (this.surroundings[(j3 + l1) * k1 + (k3 + l1) * j1 + l3 + l1] == i3 - 1)
|
| 141 | {
|
| 142 | if (this.surroundings[(j3 + l1 - 1) * k1 + (k3 + l1) * j1 + l3 + l1] == -2)
|
| 143 | {
|
| 144 | this.surroundings[(j3 + l1 - 1) * k1 + (k3 + l1) * j1 + l3 + l1] = i3;
|
| 145 | }
|
| 146 |
|
| 147 | if (this.surroundings[(j3 + l1 + 1) * k1 + (k3 + l1) * j1 + l3 + l1] == -2)
|
| 148 | {
|
| 149 | this.surroundings[(j3 + l1 + 1) * k1 + (k3 + l1) * j1 + l3 + l1] = i3;
|
| 150 | }
|
| 151 |
|
| 152 | if (this.surroundings[(j3 + l1) * k1 + (k3 + l1 - 1) * j1 + l3 + l1] == -2)
|
| 153 | {
|
| 154 | this.surroundings[(j3 + l1) * k1 + (k3 + l1 - 1) * j1 + l3 + l1] = i3;
|
| 155 | }
|
| 156 |
|
| 157 | if (this.surroundings[(j3 + l1) * k1 + (k3 + l1 + 1) * j1 + l3 + l1] == -2)
|
| 158 | {
|
| 159 | this.surroundings[(j3 + l1) * k1 + (k3 + l1 + 1) * j1 + l3 + l1] = i3;
|
| 160 | }
|
| 161 |
|
| 162 | if (this.surroundings[(j3 + l1) * k1 + (k3 + l1) * j1 + (l3 + l1 - 1)] == -2)
|
| 163 | {
|
| 164 | this.surroundings[(j3 + l1) * k1 + (k3 + l1) * j1 + (l3 + l1 - 1)] = i3;
|
| 165 | }
|
| 166 |
|
| 167 | if (this.surroundings[(j3 + l1) * k1 + (k3 + l1) * j1 + l3 + l1 + 1] == -2)
|
| 168 | {
|
| 169 | this.surroundings[(j3 + l1) * k1 + (k3 + l1) * j1 + l3 + l1 + 1] = i3;
|
| 170 | }
|
| 171 | }
|
| 172 | }
|
| 173 | }
|
| 174 | }
|
| 175 | }
|
| 176 | }
|
| 177 |
|
| 178 | int l2 = this.surroundings[l1 * k1 + l1 * j1 + l1];
|
| 179 |
|
| 180 | if (l2 >= 0)
|
| 181 | {
|
| 182 | worldIn.setBlockState(pos, state.withProperty(CHECK_DECAY, Boolean.valueOf(false)), 4);
|
| 183 | }
|
| 184 | else
|
| 185 | {
|
| 186 | this.destroy(worldIn, pos);
|
| 187 | }
|
| 188 | }
|
| 189 | }
|
| 190 | }
|
| 191 |
|
| 192 | public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
|
| 193 | {
|
| 194 | if (worldIn.isRainingAt(pos.up()) && !World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && rand.nextInt(15) == 1)
|
| 195 | {
|
| 196 | double d0 = (double)((float)pos.getX() + rand.nextFloat());
|
| 197 | double d1 = (double)pos.getY() - 0.05D;
|
| 198 | double d2 = (double)((float)pos.getZ() + rand.nextFloat());
|
| 199 | worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
|
| 200 | }
|
| 201 | }
|
| 202 |
|
| 203 | private void destroy(World worldIn, BlockPos pos)
|
| 204 | {
|
| 205 | this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
|
| 206 | worldIn.setBlockToAir(pos);
|
| 207 | }
|
| 208 |
|
| 209 | /**
|
| 210 | * Returns the quantity of items to drop on block destruction.
|
| 211 | */
|
| 212 | public int quantityDropped(Random random)
|
| 213 | {
|
| 214 | return random.nextInt(20) == 0 ? 1 : 0;
|
| 215 | }
|
| 216 |
|
| 217 | /**
|
| 218 | * Get the Item that this Block should drop when harvested.
|
| 219 | */
|
| 220 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 221 | {
|
| 222 | return Item.getItemFromBlock(Blocks.sapling);
|
| 223 | }
|
| 224 |
|
| 225 | /**
|
| 226 | * Spawns this Block's drops into the World as EntityItems.
|
| 227 | */
|
| 228 | public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
|
| 229 | {
|
| 230 | if (!worldIn.isRemote)
|
| 231 | {
|
| 232 | int i = this.getSaplingDropChance(state);
|
| 233 |
|
| 234 | if (fortune > 0)
|
| 235 | {
|
| 236 | i -= 2 << fortune;
|
| 237 |
|
| 238 | if (i < 10)
|
| 239 | {
|
| 240 | i = 10;
|
| 241 | }
|
| 242 | }
|
| 243 |
|
| 244 | if (worldIn.rand.nextInt(i) == 0)
|
| 245 | {
|
| 246 | Item item = this.getItemDropped(state, worldIn.rand, fortune);
|
| 247 | spawnAsEntity(worldIn, pos, new ItemStack(item, 1, this.damageDropped(state)));
|
| 248 | }
|
| 249 |
|
| 250 | i = 200;
|
| 251 |
|
| 252 | if (fortune > 0)
|
| 253 | {
|
| 254 | i -= 10 << fortune;
|
| 255 |
|
| 256 | if (i < 40)
|
| 257 | {
|
| 258 | i = 40;
|
| 259 | }
|
| 260 | }
|
| 261 |
|
| 262 | this.dropApple(worldIn, pos, state, i);
|
| 263 | }
|
| 264 | }
|
| 265 |
|
| 266 | protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance)
|
| 267 | {
|
| 268 | }
|
| 269 |
|
| 270 | protected int getSaplingDropChance(IBlockState state)
|
| 271 | {
|
| 272 | return 20;
|
| 273 | }
|
| 274 |
|
| 275 | /**
|
| 276 | * Used to determine ambient occlusion and culling when rebuilding chunks for render
|
| 277 | */
|
| 278 | public boolean isOpaqueCube()
|
| 279 | {
|
| 280 | return !this.fancyGraphics;
|
| 281 | }
|
| 282 |
|
| 283 | /**
|
| 284 | * Pass true to draw this block using fancy graphics, or false for fast graphics.
|
| 285 | */
|
| 286 | public void setGraphicsLevel(boolean fancy)
|
| 287 | {
|
| 288 | this.isTransparent = fancy;
|
| 289 | this.fancyGraphics = fancy;
|
| 290 | this.iconIndex = fancy ? 0 : 1;
|
| 291 | }
|
| 292 |
|
| 293 | public EnumWorldBlockLayer getBlockLayer()
|
| 294 | {
|
| 295 | return this.isTransparent ? EnumWorldBlockLayer.CUTOUT_MIPPED : EnumWorldBlockLayer.SOLID;
|
| 296 | }
|
| 297 |
|
| 298 | public boolean isVisuallyOpaque()
|
| 299 | {
|
| 300 | return false;
|
| 301 | }
|
| 302 |
|
| 303 | public abstract BlockPlanks.EnumType getWoodType(int meta);
|
| 304 | }
|
| 305 |
|