| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.block.material.MapColor;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.block.state.IBlockState;
|
| 7 | import net.minecraft.creativetab.CreativeTabs;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.init.Items;
|
| 10 | import net.minecraft.item.EnumDyeColor;
|
| 11 | import net.minecraft.item.Item;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 | import net.minecraft.util.MathHelper;
|
| 14 | import net.minecraft.world.World;
|
| 15 |
|
| 16 | public class BlockOre extends Block
|
| 17 | {
|
| 18 | public BlockOre()
|
| 19 | {
|
| 20 | this(Material.rock.getMaterialMapColor());
|
| 21 | }
|
| 22 |
|
| 23 | public BlockOre(MapColor p_i46390_1_)
|
| 24 | {
|
| 25 | super(Material.rock, p_i46390_1_);
|
| 26 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 27 | }
|
| 28 |
|
| 29 | /**
|
| 30 | * Get the Item that this Block should drop when harvested.
|
| 31 | */
|
| 32 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 33 | {
|
| 34 | return this == Blocks.coal_ore ? Items.coal : (this == Blocks.diamond_ore ? Items.diamond : (this == Blocks.lapis_ore ? Items.dye : (this == Blocks.emerald_ore ? Items.emerald : (this == Blocks.quartz_ore ? Items.quartz : Item.getItemFromBlock(this)))));
|
| 35 | }
|
| 36 |
|
| 37 | /**
|
| 38 | * Returns the quantity of items to drop on block destruction.
|
| 39 | */
|
| 40 | public int quantityDropped(Random random)
|
| 41 | {
|
| 42 | return this == Blocks.lapis_ore ? 4 + random.nextInt(5) : 1;
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Get the quantity dropped based on the given fortune level
|
| 47 | */
|
| 48 | public int quantityDroppedWithBonus(int fortune, Random random)
|
| 49 | {
|
| 50 | if (fortune > 0 && Item.getItemFromBlock(this) != this.getItemDropped((IBlockState)this.getBlockState().getValidStates().iterator().next(), random, fortune))
|
| 51 | {
|
| 52 | int i = random.nextInt(fortune + 2) - 1;
|
| 53 |
|
| 54 | if (i < 0)
|
| 55 | {
|
| 56 | i = 0;
|
| 57 | }
|
| 58 |
|
| 59 | return this.quantityDropped(random) * (i + 1);
|
| 60 | }
|
| 61 | else
|
| 62 | {
|
| 63 | return this.quantityDropped(random);
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | /**
|
| 68 | * Spawns this Block's drops into the World as EntityItems.
|
| 69 | */
|
| 70 | public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
|
| 71 | {
|
| 72 | super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
|
| 73 |
|
| 74 | if (this.getItemDropped(state, worldIn.rand, fortune) != Item.getItemFromBlock(this))
|
| 75 | {
|
| 76 | int i = 0;
|
| 77 |
|
| 78 | if (this == Blocks.coal_ore)
|
| 79 | {
|
| 80 | i = MathHelper.getRandomIntegerInRange(worldIn.rand, 0, 2);
|
| 81 | }
|
| 82 | else if (this == Blocks.diamond_ore)
|
| 83 | {
|
| 84 | i = MathHelper.getRandomIntegerInRange(worldIn.rand, 3, 7);
|
| 85 | }
|
| 86 | else if (this == Blocks.emerald_ore)
|
| 87 | {
|
| 88 | i = MathHelper.getRandomIntegerInRange(worldIn.rand, 3, 7);
|
| 89 | }
|
| 90 | else if (this == Blocks.lapis_ore)
|
| 91 | {
|
| 92 | i = MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
|
| 93 | }
|
| 94 | else if (this == Blocks.quartz_ore)
|
| 95 | {
|
| 96 | i = MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
|
| 97 | }
|
| 98 |
|
| 99 | this.dropXpOnBlockBreak(worldIn, pos, i);
|
| 100 | }
|
| 101 | }
|
| 102 |
|
| 103 | /**
|
| 104 | * Gets the meta to use for the Pick Block ItemStack result
|
| 105 | */
|
| 106 | public int getDamageValue(World worldIn, BlockPos pos)
|
| 107 | {
|
| 108 | return 0;
|
| 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 this == Blocks.lapis_ore ? EnumDyeColor.BLUE.getDyeDamage() : 0;
|
| 118 | }
|
| 119 | }
|
| 120 |
|