Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. package com.theishiopian.foragecraft.items;
  2.  
  3. import com.theishiopian.foragecraft.entity.EntityRockFlat;
  4. import com.theishiopian.foragecraft.entity.EntityRockNormal;
  5. import com.theishiopian.foragecraft.init.ModBlocks.RockType;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.entity.projectile.EntityThrowable;
  13. import net.minecraft.init.SoundEvents;
  14. import net.minecraft.item.ItemBlock;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.ActionResult;
  17. import net.minecraft.util.DamageSource;
  18. import net.minecraft.util.EnumActionResult;
  19. import net.minecraft.util.EnumHand;
  20. import net.minecraft.util.SoundCategory;
  21. import net.minecraft.world.World;
  22. import net.minecraftforge.client.model.ModelLoader;
  23. import net.minecraftforge.fml.relauncher.Side;
  24. import net.minecraftforge.fml.relauncher.SideOnly;
  25.  
  26. public class RockItem extends ItemBlock
  27. {
  28. RockType type;
  29.  
  30. public RockItem(Block block, RockType t)
  31. {
  32. super(block);
  33.  
  34. String name = null;
  35.  
  36. switch(t)
  37. {
  38. case NORMAL: name = "rock_normal";
  39. break;
  40. case FLAT: name = "rock_flat";
  41. break;
  42. }
  43.  
  44. type = t;
  45.  
  46. setUnlocalizedName(name);
  47. setRegistryName(name);
  48. setCreativeTab(CreativeTabs.MATERIALS);
  49. }
  50.  
  51. @SideOnly(Side.CLIENT)
  52. public void initModel()
  53. {
  54. ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(this.getRegistryName(), "inventory"));
  55. }
  56.  
  57. public RockType getRockType()
  58. {
  59. return type;
  60. }
  61.  
  62. @Override
  63. public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
  64. {
  65. switch(type)
  66. {
  67. case FLAT: target.attackEntityFrom(DamageSource.GENERIC, 2);
  68. break;
  69. case NORMAL: target.attackEntityFrom(DamageSource.GENERIC, 3);
  70. break;
  71. }
  72. return true;
  73. }
  74.  
  75. @Override
  76. public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
  77. {
  78. ItemStack itemstack = playerIn.getHeldItem(handIn);
  79.  
  80. if (!playerIn.capabilities.isCreativeMode)
  81. {
  82. itemstack.shrink(1);
  83. }
  84.  
  85. worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  86.  
  87. if (!worldIn.isRemote)
  88. {
  89. EntityThrowable rock = new EntityRockNormal(worldIn, playerIn);
  90. switch(type)
  91. {
  92.  
  93. case NORMAL: rock = new EntityRockNormal(worldIn, playerIn);
  94. break;
  95. case FLAT: rock = new EntityRockFlat(worldIn, playerIn);
  96. break;
  97. default:
  98. break;
  99. }
  100.  
  101.  
  102. rock.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
  103. worldIn.spawnEntity(rock);
  104. }
  105.  
  106. return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
  107. }
  108.  
  109. @Override
  110. public float getStrVsBlock(ItemStack stack, IBlockState state)
  111. {
  112. // anything will break faster if you hit it with a rock enough
  113. int e = 0;
  114.  
  115. switch(type)
  116. {
  117. case FLAT: e = 2;
  118. break;
  119. case NORMAL: e = 3;
  120. break;
  121. }
  122. return e;
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement