Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mechcraft.items;
- import mechcraft.entities.EntityGrenadeRound;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Items;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.world.World;
- public class ItemGun extends Item {
- private int delay;
- public int capacity;
- public int clip;
- public int reloadAmount;
- public Entity entityFired;
- public Item Ammo;
- public ItemGun(int capacity, Item Ammo, Entity entityFired, int delay) {
- this.capacity = capacity;
- this.Ammo = Ammo;
- this.entityFired = entityFired;
- this.delay = delay;
- }
- public void NBTCreate(ItemStack itemStack) {
- if (itemStack.stackTagCompound == null) {
- itemStack.setTagCompound(new NBTTagCompound());
- }
- if (!itemStack.getTagCompound().hasKey("Capacity")) {
- itemStack.stackTagCompound.setInteger("Capacity", capacity);
- }
- if (!itemStack.getTagCompound().hasKey("Clip")) {
- itemStack.stackTagCompound.setInteger("Clip", clip);
- }
- if (!itemStack.getTagCompound().hasKey("ReloadAmount")) {
- itemStack.stackTagCompound.setInteger("ReloadAmount", reloadAmount);
- }
- }
- @Override
- public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
- NBTCreate(itemStack);
- System.out.println("bang");
- if (world.getWorldTime() > itemStack.getTagCompound().getLong("lastShotTime")) {
- if (entityPlayer.capabilities.isCreativeMode ||itemStack.getTagCompound().getInteger("clip") > 0|| entityPlayer.inventory.consumeInventoryItem(Ammo)) {
- if (!world.isRemote) {
- itemStack.getTagCompound().setLong("lastShotTime", world.getWorldTime() + delay);
- world.spawnEntityInWorld(entityFired);
- itemStack.getTagCompound().setInteger("Clip", itemStack.getTagCompound().getInteger("Clip") - 1);
- System.out.println("FIRE");
- }
- }
- }
- return itemStack;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement