Guest User

Untitled

a guest
Jun 15th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. package com.mightydanp.eot.block;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import com.mightydanp.eot.Eot;
  7. import com.mightydanp.eot.block.BlockDefaultOre.EnumType;
  8. import com.mightydanp.eot.item.ItemEssenceOre;
  9. import com.mightydanp.eot.item.ModItems;
  10. import com.mightydanp.eot.lib.BlockStrings;
  11. import com.mightydanp.eot.lib.References;
  12.  
  13. import net.minecraftforge.fml.common.registry.GameRegistry;
  14. import net.minecraftforge.fml.relauncher.Side;
  15. import net.minecraftforge.fml.relauncher.SideOnly;
  16. import net.minecraft.block.Block;
  17. import net.minecraft.block.material.Material;
  18. import net.minecraft.block.properties.IProperty;
  19. import net.minecraft.block.properties.PropertyEnum;
  20. import net.minecraft.block.state.BlockStateContainer;
  21. import net.minecraft.block.state.IBlockState;
  22. import net.minecraft.client.Minecraft;
  23. import net.minecraft.creativetab.CreativeTabs;
  24. import net.minecraft.entity.item.EntityItem;
  25. import net.minecraft.entity.player.EntityPlayer;
  26. import net.minecraft.init.Blocks;
  27. import net.minecraft.item.Item;
  28. import net.minecraft.item.ItemStack;
  29. import net.minecraft.tileentity.TileEntity;
  30. import net.minecraft.util.EnumHand;
  31. import net.minecraft.util.IStringSerializable;
  32. import net.minecraft.util.math.BlockPos;
  33. import net.minecraft.util.math.RayTraceResult;
  34. import net.minecraft.world.IBlockAccess;
  35. import net.minecraft.world.World;
  36.  
  37. public class BlockEssenceOre extends Block implements IMetaBlockName{
  38.  
  39. public static final PropertyEnum TYPE = PropertyEnum.create("essenceOre", BlockEssenceOre.EnumType.class);
  40.  
  41. public float originalHardness;
  42.  
  43.  
  44. protected BlockEssenceOre(String unlocalizedName) {
  45. super(Material.ROCK);
  46. this.setCreativeTab(Eot.eotTab);
  47. this.setUnlocalizedName(unlocalizedName);
  48. this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.ESSENCEOREMAGIC));
  49. }
  50.  
  51. @Override
  52. public Block setHardness(float par1){
  53. originalHardness = par1;
  54. return super.setHardness(par1);
  55. }
  56.  
  57. @Override
  58. protected BlockStateContainer createBlockState() {
  59. return new BlockStateContainer(this, new IProperty[] { TYPE });
  60. }
  61.  
  62. @Override
  63. public IBlockState getStateFromMeta(int meta) {
  64. return getDefaultState().withProperty(TYPE, EnumType.values()[meta]);
  65. }
  66.  
  67. @Override
  68. public int getMetaFromState(IBlockState state) {
  69. return ((Enum<EnumType>) state.getValue(TYPE)).ordinal();
  70. }
  71.  
  72. @Override
  73. public int damageDropped(IBlockState state) {
  74. return getMetaFromState(state);
  75. }
  76.  
  77. @SuppressWarnings({ "unchecked", "rawtypes" })
  78. @Override
  79. public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
  80. for (EnumType t : EnumType.values())
  81. list.add(new ItemStack(itemIn, 1, t.ordinal()));
  82. }
  83.  
  84. @Override
  85. public String getSpecialName(ItemStack stack) {
  86. return EnumType.values()[stack.getItemDamage()].name().toLowerCase();
  87. }
  88.  
  89.  
  90. public Item getItemDropped(IBlockState state, Random rand, int fortune){
  91.  
  92. int randomDrop = rand.nextInt(100);
  93.  
  94. if(randomDrop<=60){
  95. return ModItems.essenceChunks;
  96. }
  97. return null;
  98. }
  99.  
  100. public int quantityDroppedWithBonus(int fortune, Random random){
  101. if (fortune > 0)
  102. {
  103. int j = random.nextInt(fortune + 2) - 1;
  104.  
  105. if (j < 0)
  106. {
  107. return j++;
  108. }
  109. return quantityDropped(random) * (j + 1);
  110. }
  111. return quantityDropped(random);
  112.  
  113. }
  114.  
  115. @Override
  116. public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) {
  117. if(player.getHeldItem(EnumHand.MAIN_HAND) != null){;
  118. EntityItem entityItem = new EntityItem(worldIn, player.posX , player.posY , player.posZ, new ItemStack(ModItems.magicalStone, 1, 16));
  119. Random random = worldIn.rand;
  120. int randomDrop = random.nextInt(99);
  121.  
  122. if(player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.hammerMysterious){
  123. if(randomDrop<=10){
  124. worldIn.spawnEntityInWorld(entityItem);
  125. }
  126. }
  127. }
  128. }
  129.  
  130. @Override
  131. public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn){
  132.  
  133. if(!(playerIn.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.hammerMysterious)){
  134. this.blockHardness = -1;
  135. return;
  136. }
  137. this.blockHardness = originalHardness;
  138. super.onBlockClicked(worldIn, pos, playerIn);
  139.  
  140. }
  141.  
  142. @Override
  143. public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player){
  144. return new ItemStack(Item.getItemFromBlock(this), 1, this.getMetaFromState(world.getBlockState(pos)));
  145. }
  146.  
  147.  
  148. public enum EnumType implements IStringSerializable {
  149. ESSENCEOREMAGIC(0, "essenceOreMagic"),
  150. ESSENCEOREAIR(1, "essenceOreAir"),
  151. ESSENCEOREEARTH(2, "essenceOreEarth"),
  152. ESSENCEOREFIRE(3, "essenceOreFire"),
  153. ESSENCEOREWATER(4, "essenceOreWater"),;
  154.  
  155. private int ID;
  156. private String name;
  157.  
  158. private EnumType(int ID, String name) {
  159. this.ID = ID;
  160. this.name = name;
  161. }
  162.  
  163. @Override
  164. public String getName() {
  165. return this.name;
  166. }
  167.  
  168. public int getID() {
  169. return this.ID;
  170. }
  171.  
  172. @Override
  173. public String toString() {
  174. return this.getName();
  175. }
  176. }
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment