| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.properties.IProperty;
|
| 6 | import net.minecraft.block.properties.PropertyEnum;
|
| 7 | import net.minecraft.block.properties.PropertyInteger;
|
| 8 | import net.minecraft.block.state.BlockState;
|
| 9 | import net.minecraft.block.state.IBlockState;
|
| 10 | import net.minecraft.entity.player.EntityPlayer;
|
| 11 | import net.minecraft.init.Blocks;
|
| 12 | import net.minecraft.init.Items;
|
| 13 | import net.minecraft.item.Item;
|
| 14 | import net.minecraft.item.ItemBlock;
|
| 15 | import net.minecraft.item.ItemStack;
|
| 16 | import net.minecraft.stats.StatList;
|
| 17 | import net.minecraft.tileentity.TileEntity;
|
| 18 | import net.minecraft.tileentity.TileEntityFlowerPot;
|
| 19 | import net.minecraft.util.BlockPos;
|
| 20 | import net.minecraft.util.EnumFacing;
|
| 21 | import net.minecraft.util.EnumWorldBlockLayer;
|
| 22 | import net.minecraft.util.IStringSerializable;
|
| 23 | import net.minecraft.util.StatCollector;
|
| 24 | import net.minecraft.world.IBlockAccess;
|
| 25 | import net.minecraft.world.World;
|
| 26 |
|
| 27 | public class BlockFlowerPot extends BlockContainer
|
| 28 | {
|
| 29 | public static final PropertyInteger LEGACY_DATA = PropertyInteger.create("legacy_data", 0, 15);
|
| 30 | public static final PropertyEnum<BlockFlowerPot.EnumFlowerType> CONTENTS = PropertyEnum.<BlockFlowerPot.EnumFlowerType>create("contents", BlockFlowerPot.EnumFlowerType.class);
|
| 31 |
|
| 32 | public BlockFlowerPot()
|
| 33 | {
|
| 34 | super(Material.circuits);
|
| 35 | this.setDefaultState(this.blockState.getBaseState().withProperty(CONTENTS, BlockFlowerPot.EnumFlowerType.EMPTY).withProperty(LEGACY_DATA, Integer.valueOf(0)));
|
| 36 | this.setBlockBoundsForItemRender();
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Gets the localized name of this block. Used for the statistics page.
|
| 41 | */
|
| 42 | public String getLocalizedName()
|
| 43 | {
|
| 44 | return StatCollector.translateToLocal("item.flowerPot.name");
|
| 45 | }
|
| 46 |
|
| 47 | /**
|
| 48 | * Sets the block's bounds for rendering it as an item
|
| 49 | */
|
| 50 | public void setBlockBoundsForItemRender()
|
| 51 | {
|
| 52 | float f = 0.375F;
|
| 53 | float f1 = f / 2.0F;
|
| 54 | this.setBlockBounds(0.5F - f1, 0.0F, 0.5F - f1, 0.5F + f1, f, 0.5F + f1);
|
| 55 | }
|
| 56 |
|
| 57 | /**
|
| 58 | * Used to determine ambient occlusion and culling when rebuilding chunks for render
|
| 59 | */
|
| 60 | public boolean isOpaqueCube()
|
| 61 | {
|
| 62 | return false;
|
| 63 | }
|
| 64 |
|
| 65 | /**
|
| 66 | * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
|
| 67 | */
|
| 68 | public int getRenderType()
|
| 69 | {
|
| 70 | return 3;
|
| 71 | }
|
| 72 |
|
| 73 | public boolean isFullCube()
|
| 74 | {
|
| 75 | return false;
|
| 76 | }
|
| 77 |
|
| 78 | public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
|
| 79 | {
|
| 80 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 81 |
|
| 82 | if (tileentity instanceof TileEntityFlowerPot)
|
| 83 | {
|
| 84 | Item item = ((TileEntityFlowerPot)tileentity).getFlowerPotItem();
|
| 85 |
|
| 86 | if (item instanceof ItemBlock)
|
| 87 | {
|
| 88 | return Block.getBlockFromItem(item).colorMultiplier(worldIn, pos, renderPass);
|
| 89 | }
|
| 90 | }
|
| 91 |
|
| 92 | return 16777215;
|
| 93 | }
|
| 94 |
|
| 95 | public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
|
| 96 | {
|
| 97 | ItemStack itemstack = playerIn.inventory.getCurrentItem();
|
| 98 |
|
| 99 | if (itemstack != null && itemstack.getItem() instanceof ItemBlock)
|
| 100 | {
|
| 101 | TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);
|
| 102 |
|
| 103 | if (tileentityflowerpot == null)
|
| 104 | {
|
| 105 | return false;
|
| 106 | }
|
| 107 | else if (tileentityflowerpot.getFlowerPotItem() != null)
|
| 108 | {
|
| 109 | return false;
|
| 110 | }
|
| 111 | else
|
| 112 | {
|
| 113 | Block block = Block.getBlockFromItem(itemstack.getItem());
|
| 114 |
|
| 115 | if (!this.canNotContain(block, itemstack.getMetadata()))
|
| 116 | {
|
| 117 | return false;
|
| 118 | }
|
| 119 | else
|
| 120 | {
|
| 121 | tileentityflowerpot.setFlowerPotData(itemstack.getItem(), itemstack.getMetadata());
|
| 122 | tileentityflowerpot.markDirty();
|
| 123 | worldIn.markBlockForUpdate(pos);
|
| 124 | playerIn.triggerAchievement(StatList.field_181736_T);
|
| 125 |
|
| 126 | if (!playerIn.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
|
| 127 | {
|
| 128 | playerIn.inventory.setInventorySlotContents(playerIn.inventory.currentItem, (ItemStack)null);
|
| 129 | }
|
| 130 |
|
| 131 | return true;
|
| 132 | }
|
| 133 | }
|
| 134 | }
|
| 135 | else
|
| 136 | {
|
| 137 | return false;
|
| 138 | }
|
| 139 | }
|
| 140 |
|
| 141 | private boolean canNotContain(Block blockIn, int meta)
|
| 142 | {
|
| 143 | return blockIn != Blocks.yellow_flower && blockIn != Blocks.red_flower && blockIn != Blocks.cactus && blockIn != Blocks.brown_mushroom && blockIn != Blocks.red_mushroom && blockIn != Blocks.sapling && blockIn != Blocks.deadbush ? blockIn == Blocks.tallgrass && meta == BlockTallGrass.EnumType.FERN.getMeta() : true;
|
| 144 | }
|
| 145 |
|
| 146 | public Item getItem(World worldIn, BlockPos pos)
|
| 147 | {
|
| 148 | TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);
|
| 149 | return tileentityflowerpot != null && tileentityflowerpot.getFlowerPotItem() != null ? tileentityflowerpot.getFlowerPotItem() : Items.flower_pot;
|
| 150 | }
|
| 151 |
|
| 152 | /**
|
| 153 | * Gets the meta to use for the Pick Block ItemStack result
|
| 154 | */
|
| 155 | public int getDamageValue(World worldIn, BlockPos pos)
|
| 156 | {
|
| 157 | TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);
|
| 158 | return tileentityflowerpot != null && tileentityflowerpot.getFlowerPotItem() != null ? tileentityflowerpot.getFlowerPotData() : 0;
|
| 159 | }
|
| 160 |
|
| 161 | /**
|
| 162 | * Returns true only if block is flowerPot
|
| 163 | */
|
| 164 | public boolean isFlowerPot()
|
| 165 | {
|
| 166 | return true;
|
| 167 | }
|
| 168 |
|
| 169 | public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
|
| 170 | {
|
| 171 | return super.canPlaceBlockAt(worldIn, pos) && World.doesBlockHaveSolidTopSurface(worldIn, pos.down());
|
| 172 | }
|
| 173 |
|
| 174 | /**
|
| 175 | * Called when a neighboring block changes.
|
| 176 | */
|
| 177 | public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
|
| 178 | {
|
| 179 | if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()))
|
| 180 | {
|
| 181 | this.dropBlockAsItem(worldIn, pos, state, 0);
|
| 182 | worldIn.setBlockToAir(pos);
|
| 183 | }
|
| 184 | }
|
| 185 |
|
| 186 | public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
| 187 | {
|
| 188 | TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);
|
| 189 |
|
| 190 | if (tileentityflowerpot != null && tileentityflowerpot.getFlowerPotItem() != null)
|
| 191 | {
|
| 192 | spawnAsEntity(worldIn, pos, new ItemStack(tileentityflowerpot.getFlowerPotItem(), 1, tileentityflowerpot.getFlowerPotData()));
|
| 193 | }
|
| 194 |
|
| 195 | super.breakBlock(worldIn, pos, state);
|
| 196 | }
|
| 197 |
|
| 198 | public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
|
| 199 | {
|
| 200 | super.onBlockHarvested(worldIn, pos, state, player);
|
| 201 |
|
| 202 | if (player.capabilities.isCreativeMode)
|
| 203 | {
|
| 204 | TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);
|
| 205 |
|
| 206 | if (tileentityflowerpot != null)
|
| 207 | {
|
| 208 | tileentityflowerpot.setFlowerPotData((Item)null, 0);
|
| 209 | }
|
| 210 | }
|
| 211 | }
|
| 212 |
|
| 213 | /**
|
| 214 | * Get the Item that this Block should drop when harvested.
|
| 215 | */
|
| 216 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 217 | {
|
| 218 | return Items.flower_pot;
|
| 219 | }
|
| 220 |
|
| 221 | private TileEntityFlowerPot getTileEntity(World worldIn, BlockPos pos)
|
| 222 | {
|
| 223 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 224 | return tileentity instanceof TileEntityFlowerPot ? (TileEntityFlowerPot)tileentity : null;
|
| 225 | }
|
| 226 |
|
| 227 | /**
|
| 228 | * Returns a new instance of a block's tile entity class. Called on placing the block.
|
| 229 | */
|
| 230 | public TileEntity createNewTileEntity(World worldIn, int meta)
|
| 231 | {
|
| 232 | Block block = null;
|
| 233 | int i = 0;
|
| 234 |
|
| 235 | switch (meta)
|
| 236 | {
|
| 237 | case 1:
|
| 238 | block = Blocks.red_flower;
|
| 239 | i = BlockFlower.EnumFlowerType.POPPY.getMeta();
|
| 240 | break;
|
| 241 |
|
| 242 | case 2:
|
| 243 | block = Blocks.yellow_flower;
|
| 244 | break;
|
| 245 |
|
| 246 | case 3:
|
| 247 | block = Blocks.sapling;
|
| 248 | i = BlockPlanks.EnumType.OAK.getMetadata();
|
| 249 | break;
|
| 250 |
|
| 251 | case 4:
|
| 252 | block = Blocks.sapling;
|
| 253 | i = BlockPlanks.EnumType.SPRUCE.getMetadata();
|
| 254 | break;
|
| 255 |
|
| 256 | case 5:
|
| 257 | block = Blocks.sapling;
|
| 258 | i = BlockPlanks.EnumType.BIRCH.getMetadata();
|
| 259 | break;
|
| 260 |
|
| 261 | case 6:
|
| 262 | block = Blocks.sapling;
|
| 263 | i = BlockPlanks.EnumType.JUNGLE.getMetadata();
|
| 264 | break;
|
| 265 |
|
| 266 | case 7:
|
| 267 | block = Blocks.red_mushroom;
|
| 268 | break;
|
| 269 |
|
| 270 | case 8:
|
| 271 | block = Blocks.brown_mushroom;
|
| 272 | break;
|
| 273 |
|
| 274 | case 9:
|
| 275 | block = Blocks.cactus;
|
| 276 | break;
|
| 277 |
|
| 278 | case 10:
|
| 279 | block = Blocks.deadbush;
|
| 280 | break;
|
| 281 |
|
| 282 | case 11:
|
| 283 | block = Blocks.tallgrass;
|
| 284 | i = BlockTallGrass.EnumType.FERN.getMeta();
|
| 285 | break;
|
| 286 |
|
| 287 | case 12:
|
| 288 | block = Blocks.sapling;
|
| 289 | i = BlockPlanks.EnumType.ACACIA.getMetadata();
|
| 290 | break;
|
| 291 |
|
| 292 | case 13:
|
| 293 | block = Blocks.sapling;
|
| 294 | i = BlockPlanks.EnumType.DARK_OAK.getMetadata();
|
| 295 | }
|
| 296 |
|
| 297 | return new TileEntityFlowerPot(Item.getItemFromBlock(block), i);
|
| 298 | }
|
| 299 |
|
| 300 | protected BlockState createBlockState()
|
| 301 | {
|
| 302 | return new BlockState(this, new IProperty[] {CONTENTS, LEGACY_DATA});
|
| 303 | }
|
| 304 |
|
| 305 | /**
|
| 306 | * Convert the BlockState into the correct metadata value
|
| 307 | */
|
| 308 | public int getMetaFromState(IBlockState state)
|
| 309 | {
|
| 310 | return ((Integer)state.getValue(LEGACY_DATA)).intValue();
|
| 311 | }
|
| 312 |
|
| 313 | /**
|
| 314 | * Get the actual Block state of this Block at the given position. This applies properties not visible in the
|
| 315 | * metadata, such as fence connections.
|
| 316 | */
|
| 317 | public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
|
| 318 | {
|
| 319 | BlockFlowerPot.EnumFlowerType blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.EMPTY;
|
| 320 | TileEntity tileentity = worldIn.getTileEntity(pos);
|
| 321 |
|
| 322 | if (tileentity instanceof TileEntityFlowerPot)
|
| 323 | {
|
| 324 | TileEntityFlowerPot tileentityflowerpot = (TileEntityFlowerPot)tileentity;
|
| 325 | Item item = tileentityflowerpot.getFlowerPotItem();
|
| 326 |
|
| 327 | if (item instanceof ItemBlock)
|
| 328 | {
|
| 329 | int i = tileentityflowerpot.getFlowerPotData();
|
| 330 | Block block = Block.getBlockFromItem(item);
|
| 331 |
|
| 332 | if (block == Blocks.sapling)
|
| 333 | {
|
| 334 | switch (BlockPlanks.EnumType.byMetadata(i))
|
| 335 | {
|
| 336 | case OAK:
|
| 337 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.OAK_SAPLING;
|
| 338 | break;
|
| 339 |
|
| 340 | case SPRUCE:
|
| 341 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.SPRUCE_SAPLING;
|
| 342 | break;
|
| 343 |
|
| 344 | case BIRCH:
|
| 345 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.BIRCH_SAPLING;
|
| 346 | break;
|
| 347 |
|
| 348 | case JUNGLE:
|
| 349 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.JUNGLE_SAPLING;
|
| 350 | break;
|
| 351 |
|
| 352 | case ACACIA:
|
| 353 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.ACACIA_SAPLING;
|
| 354 | break;
|
| 355 |
|
| 356 | case DARK_OAK:
|
| 357 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.DARK_OAK_SAPLING;
|
| 358 | break;
|
| 359 |
|
| 360 | default:
|
| 361 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.EMPTY;
|
| 362 | }
|
| 363 | }
|
| 364 | else if (block == Blocks.tallgrass)
|
| 365 | {
|
| 366 | switch (i)
|
| 367 | {
|
| 368 | case 0:
|
| 369 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.DEAD_BUSH;
|
| 370 | break;
|
| 371 |
|
| 372 | case 2:
|
| 373 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.FERN;
|
| 374 | break;
|
| 375 |
|
| 376 | default:
|
| 377 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.EMPTY;
|
| 378 | }
|
| 379 | }
|
| 380 | else if (block == Blocks.yellow_flower)
|
| 381 | {
|
| 382 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.DANDELION;
|
| 383 | }
|
| 384 | else if (block == Blocks.red_flower)
|
| 385 | {
|
| 386 | switch (BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, i))
|
| 387 | {
|
| 388 | case POPPY:
|
| 389 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.POPPY;
|
| 390 | break;
|
| 391 |
|
| 392 | case BLUE_ORCHID:
|
| 393 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.BLUE_ORCHID;
|
| 394 | break;
|
| 395 |
|
| 396 | case ALLIUM:
|
| 397 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.ALLIUM;
|
| 398 | break;
|
| 399 |
|
| 400 | case HOUSTONIA:
|
| 401 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.HOUSTONIA;
|
| 402 | break;
|
| 403 |
|
| 404 | case RED_TULIP:
|
| 405 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.RED_TULIP;
|
| 406 | break;
|
| 407 |
|
| 408 | case ORANGE_TULIP:
|
| 409 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.ORANGE_TULIP;
|
| 410 | break;
|
| 411 |
|
| 412 | case WHITE_TULIP:
|
| 413 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.WHITE_TULIP;
|
| 414 | break;
|
| 415 |
|
| 416 | case PINK_TULIP:
|
| 417 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.PINK_TULIP;
|
| 418 | break;
|
| 419 |
|
| 420 | case OXEYE_DAISY:
|
| 421 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.OXEYE_DAISY;
|
| 422 | break;
|
| 423 |
|
| 424 | default:
|
| 425 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.EMPTY;
|
| 426 | }
|
| 427 | }
|
| 428 | else if (block == Blocks.red_mushroom)
|
| 429 | {
|
| 430 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.MUSHROOM_RED;
|
| 431 | }
|
| 432 | else if (block == Blocks.brown_mushroom)
|
| 433 | {
|
| 434 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.MUSHROOM_BROWN;
|
| 435 | }
|
| 436 | else if (block == Blocks.deadbush)
|
| 437 | {
|
| 438 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.DEAD_BUSH;
|
| 439 | }
|
| 440 | else if (block == Blocks.cactus)
|
| 441 | {
|
| 442 | blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.CACTUS;
|
| 443 | }
|
| 444 | }
|
| 445 | }
|
| 446 |
|
| 447 | return state.withProperty(CONTENTS, blockflowerpot$enumflowertype);
|
| 448 | }
|
| 449 |
|
| 450 | public EnumWorldBlockLayer getBlockLayer()
|
| 451 | {
|
| 452 | return EnumWorldBlockLayer.CUTOUT;
|
| 453 | }
|
| 454 |
|
| 455 | public static enum EnumFlowerType implements IStringSerializable
|
| 456 | {
|
| 457 | EMPTY("empty"),
|
| 458 | POPPY("rose"),
|
| 459 | BLUE_ORCHID("blue_orchid"),
|
| 460 | ALLIUM("allium"),
|
| 461 | HOUSTONIA("houstonia"),
|
| 462 | RED_TULIP("red_tulip"),
|
| 463 | ORANGE_TULIP("orange_tulip"),
|
| 464 | WHITE_TULIP("white_tulip"),
|
| 465 | PINK_TULIP("pink_tulip"),
|
| 466 | OXEYE_DAISY("oxeye_daisy"),
|
| 467 | DANDELION("dandelion"),
|
| 468 | OAK_SAPLING("oak_sapling"),
|
| 469 | SPRUCE_SAPLING("spruce_sapling"),
|
| 470 | BIRCH_SAPLING("birch_sapling"),
|
| 471 | JUNGLE_SAPLING("jungle_sapling"),
|
| 472 | ACACIA_SAPLING("acacia_sapling"),
|
| 473 | DARK_OAK_SAPLING("dark_oak_sapling"),
|
| 474 | MUSHROOM_RED("mushroom_red"),
|
| 475 | MUSHROOM_BROWN("mushroom_brown"),
|
| 476 | DEAD_BUSH("dead_bush"),
|
| 477 | FERN("fern"),
|
| 478 | CACTUS("cactus");
|
| 479 |
|
| 480 | private final String name;
|
| 481 |
|
| 482 | private EnumFlowerType(String name)
|
| 483 | {
|
| 484 | this.name = name;
|
| 485 | }
|
| 486 |
|
| 487 | public String toString()
|
| 488 | {
|
| 489 | return this.name;
|
| 490 | }
|
| 491 |
|
| 492 | public String getName()
|
| 493 | {
|
| 494 | return this.name;
|
| 495 | }
|
| 496 | }
|
| 497 | }
|
| 498 |
|