Advertisement
Guest User

Untitled

a guest
Sep 8th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. package mechcraft.items;
  2.  
  3. import cpw.mods.fml.client.FMLClientHandler;
  4. import cpw.mods.fml.relauncher.Side;
  5. import cpw.mods.fml.relauncher.SideOnly;
  6. import mechcraft.MechCraft;
  7. import mechcraft.entities.EntityBullet;
  8. import mechcraft.pcp.Inventories;
  9. import mechcraft.pcp.PacketReload;
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.world.World;
  16.  
  17. import java.util.List;
  18.  
  19. public class ItemFirearm extends Item {
  20.  
  21. private float recoil;
  22. private int delay = 20;
  23. private int ammoCount;
  24. private int reloadRate;
  25. private int capacity;
  26. private int reload;
  27. private int ammoConsumptionRate;
  28. private Item ammoType;
  29.  
  30. public ItemFirearm(int maxAmmoCount, float recoil, int fireRate, int reloadRate, Item ammoType)
  31. {
  32. super();
  33. this.setMaxStackSize(1);
  34. this.ammoCount = 0;
  35. this.recoil = recoil;
  36. this.delay = fireRate;
  37. this.reloadRate = reloadRate;
  38. this.reload = 0;
  39. this.ammoConsumptionRate = 1;
  40. this.ammoType = ammoType;
  41. setMaxStackSize(1);
  42. }
  43.  
  44. @Override
  45. @SuppressWarnings("unchecked")
  46. public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
  47.  
  48. if (itemStack.stackTagCompound != null) {
  49. int ammoleft = itemStack.stackTagCompound.getInteger("clip");
  50. list.add("Contains " + String.valueOf(ammoleft) + " round" + (ammoleft == 1 ? "" : "s"));
  51. }
  52. }
  53.  
  54.  
  55. @Override
  56. public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
  57. // verify tag compound:
  58. if (!itemStack.hasTagCompound()) {
  59. // didn't have one, so make a new one:
  60. itemStack.setTagCompound(new NBTTagCompound());
  61. }
  62. if (world.getWorldTime() > itemStack.getTagCompound().getLong("lastShotTime")) {
  63. if (entityPlayer.capabilities.isCreativeMode || itemStack.getTagCompound().getInteger("clip") > 0) {
  64. world.playSoundAtEntity(entityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  65. if (!world.isRemote) {
  66. world.spawnEntityInWorld(new EntityBullet(world, entityPlayer));
  67. itemStack.getTagCompound().setLong("lastShotTime", world.getWorldTime() + delay);
  68. itemStack.getTagCompound().setInteger("clip", itemStack.getTagCompound().getInteger("clip") - 1);
  69. renderRecoil();
  70. }
  71. }
  72. }
  73. return itemStack;
  74. }
  75.  
  76.  
  77.  
  78. @SideOnly(Side.CLIENT)
  79. public void renderRecoil()
  80. {
  81. Minecraft client = FMLClientHandler.instance().getClient();
  82. client.thePlayer.renderArmPitch -= this.recoil * 40.0F;
  83. client.thePlayer.renderArmYaw += this.recoil * 5.0F;
  84. client.thePlayer.rotationPitch -= this.recoil * 1.4F;
  85. }
  86. public void reload(EntityPlayer entityPlayer) {
  87.  
  88. if (!entityPlayer.worldObj.isRemote) {
  89. Inventories.consumeItem(entityPlayer, this.ammoType);
  90. }
  91.  
  92. if (entityPlayer.worldObj.isRemote) {
  93.  
  94. }
  95.  
  96. ItemStack gun = entityPlayer.getCurrentEquippedItem();
  97. gun.getTagCompound().setInteger("clip", this.capacity);
  98.  
  99. }
  100.  
  101. public int getReload() {
  102. return reload;
  103. }
  104.  
  105. @Override
  106. @SideOnly(Side.CLIENT)
  107. public boolean isFull3D() {
  108. return true;
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement