Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. package mechcraft.items;
  2.  
  3. import mechcraft.entities.EntityGrenadeRound;
  4. import net.minecraft.entity.Entity;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.init.Items;
  7. import net.minecraft.item.Item;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.world.World;
  11.  
  12. public class ItemGun extends Item {
  13.  
  14.  
  15. private int delay;
  16. public int capacity;
  17. public int clip;
  18. public int reloadAmount;
  19. public Entity entityFired;
  20. public Item Ammo;
  21.  
  22. public ItemGun(int capacity, Item Ammo, Entity entityFired, int delay) {
  23. this.capacity = capacity;
  24. this.Ammo = Ammo;
  25. this.entityFired = entityFired;
  26. this.delay = delay;
  27.  
  28. }
  29.  
  30.  
  31. public void NBTCreate(ItemStack itemStack) {
  32. if (itemStack.stackTagCompound == null) {
  33.  
  34. itemStack.setTagCompound(new NBTTagCompound());
  35. }
  36. if (!itemStack.getTagCompound().hasKey("Capacity")) {
  37. itemStack.stackTagCompound.setInteger("Capacity", capacity);
  38. }
  39. if (!itemStack.getTagCompound().hasKey("Clip")) {
  40. itemStack.stackTagCompound.setInteger("Clip", clip);
  41. }
  42. if (!itemStack.getTagCompound().hasKey("ReloadAmount")) {
  43. itemStack.stackTagCompound.setInteger("ReloadAmount", reloadAmount);
  44. }
  45. }
  46.  
  47.  
  48. @Override
  49. public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
  50. NBTCreate(itemStack);
  51. System.out.println("bang");
  52. if (world.getWorldTime() > itemStack.getTagCompound().getLong("lastShotTime")) {
  53. if (entityPlayer.capabilities.isCreativeMode ||itemStack.getTagCompound().getInteger("clip") > 0|| entityPlayer.inventory.consumeInventoryItem(Ammo)) {
  54. if (!world.isRemote) {
  55. itemStack.getTagCompound().setLong("lastShotTime", world.getWorldTime() + delay);
  56. world.spawnEntityInWorld(entityFired);
  57. itemStack.getTagCompound().setInteger("Clip", itemStack.getTagCompound().getInteger("Clip") - 1);
  58. System.out.println("FIRE");
  59. }
  60. }
  61. }
  62. return itemStack;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement