Jump to content

Automatic NailGun


AzureusNation123

Recommended Posts

Ok so i already have my NailGun. BUT my question is how do i make this AUTOMATIC!!!!!! MUHAHAHA *cough *cough

 

 

 

public class Itemnailgun extends Item

{

    public Itemnailgun(int par1)

    {

        super(par1);

        this.maxStackSize = 1;

        this.setMaxDamage(126);

    }

 

    /**

    * How long it takes to use or consume an item

    */

    public int getMaxItemUseDuration(ItemStack par1ItemStack)

    {

        return 1800;

    }

 

    /**

    * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer

    */

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

    {

   

    boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;

   

    if (var5 || par3EntityPlayer.inventory.hasItem(Class3.nail.itemID))

        {

 

            EntityNails var8 = new EntityNails(par2World, par3EntityPlayer, 2.0F);

 

          par1ItemStack.damageItem(1, par3EntityPlayer);

            par2World.playSoundAtEntity(par3EntityPlayer, "Nailgun.shot", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) * 0.5F);

 

            if (var5)

            {

                var8.canBePickedUp = 2;

            }

            else

            {

                par3EntityPlayer.inventory.consumeInventoryItem(Class3.nail.itemID);

            }

 

            if (!par2World.isRemote)

            {

                par2World.spawnEntityInWorld(var8);

            }

        }

 

        if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Class3.nail.itemID))

        {

            par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));

        }

 

        return par1ItemStack;

    }

 

    /**

    * Return the enchantability factor of the item, most of the time is based on material.

    */

    public int getItemEnchantability()

    {

        return 1;

    }

 

    public String getTextureFile()

    {

        return ClientProxy.RANGED_PNG;

    }

    public boolean isFull3D()

    {

    return true;

    }

}

 

 

Link to comment
Share on other sites

well that wasn't too hard, just had to remove

if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Class3.nail.itemID))
           {
               par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
           }

now it should work fine

 

if you want to slow down the fire rate then just add a private variable containing the time isnce the lasst shot then do

if(coolDown = 0){
//do code
coolDown++
}
else if(coolDown == 5) //time between shots in ticks
{
coolDown = 0;
}
else coolDown++;

 

hope that works for you, i only tested with a quickly made item which fires arrows  :P

 

[EDIT] define cooldown outside the onItemRightClick method

Link to comment
Share on other sites

code? (if you just copy and pasted mine I forgot an =, the first should be if(coolDown == 0){)

 

otherwise show the code and where the error is being thrown, I did the coolDown thing without testing it, or typing it into the IDE, just as idea but it should work

Link to comment
Share on other sites

the gun no longer shoots now :(

 

 

 

public class ItemGunAK47 extends Item

{

private int coolDown = 0;

 

    public ItemGunAK47(int par1)

    {

        super(par1);

        this.maxStackSize = 1;

        this.setMaxDamage(3000);

    }

 

    /**

    * How long it takes to use or consume an item

    */

    public int getMaxItemUseDuration(ItemStack par1ItemStack)

    {

        return 3000;

    }

 

    /**

    * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer

    */

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

    {

    boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;

   

    if(coolDown == 0)

    {

    if (var5 || par3EntityPlayer.inventory.hasItem(Class3.a762x39mm.itemID))

    {

 

    Entitya762x39mm var8 = new Entitya762x39mm(par2World, par3EntityPlayer, 2.0F);

 

    par1ItemStack.damageItem(1, par3EntityPlayer);

    par2World.playSoundAtEntity(par3EntityPlayer, "Nailgun.shot", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) * 0.5F);

 

    if (var5)

    {

    var8.canBePickedUp = 2;

    }

    else

    {

    par3EntityPlayer.inventory.consumeInventoryItem(Class3.a762x39mm.itemID);

    }

 

    if (!par2World.isRemote)

    {

    par2World.spawnEntityInWorld(var8);

    }

    }

   

    coolDown++;

    }

    else if(coolDown == 5) //time between shots in ticks

    {

    coolDown = 0;

    }

    else coolDown++;

   

    return par1ItemStack;

   

    }

 

    /**

    * Return the enchantability factor of the item, most of the time is based on material.

    */

    public int getItemEnchantability()

    {

        return 1;

    }

 

    public String getTextureFile()

    {

        return ClientProxy.GUNS_PNG;

    }

    public boolean isFull3D()

    {

    return true;

    }

}

 

 

Link to comment
Share on other sites

this is what i got to work now

package yagoki.mtech.item;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class TestItem extends Item
{

public TestItem(int par1)
{
	super(par1);
}

public static Item
testItem;

public static void addItems()
{
	testItem = new TestItem(1000).setItemName("testItem").setCreativeTab(CreativeTabs.tabMisc);
}

private int coolDown = 0;
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
	if(coolDown == 0||coolDown == 1)
	{
		System.out.println(coolDown + " @1@");

		if (true)
		{
			System.out.println(coolDown + " @1.1@");
			EntityArrow var8 = new EntityArrow(world, player, 2.0F);
			stack.damageItem(1, player);

			if (!world.isRemote) world.spawnEntityInWorld(var8);
		}

		coolDown++;
	}
	else if(coolDown == 5) //time between shots in ticks
	{
		System.out.println(coolDown + " @2@");
		coolDown = 0;
	}
	else {
    	System.out.println(coolDown + " @3@");
		coolDown++;
	}

	return stack;
}

}

 

it didn't work if it was called for only one tick, but adding the "if(countDown ==1||countDown == 2){" made it work for me. I can't comment on what this will do with a custom entity as i'm too lazy to make one, but best of luck

 

[EDIT] you can remove the println() bits they were just my debug stuff, you know... cuz idiots and stuff... you probably don't nee this edit... i'll stop typing now.

 

also the if(true) was just cuz i cba to remove the if statement and did't think to change it back to the if creative or has ammo thingy

Link to comment
Share on other sites

ok that now works but my LAST question. when i put the guns to shoot at 2 or below nothing happens, but the debug cod just says @3@ and nothing else

 

 

 

 

public class ItemGunAK47 extends Item

{

private int coolDown = 0;

 

    public ItemGunAK47(int par1)

    {

        super(par1);

        this.maxStackSize = 1;

        this.setMaxDamage(3000);

    }

 

    /**

    * How long it takes to use or consume an item

    */

    public int getMaxItemUseDuration(ItemStack par1ItemStack)

    {

        return 3000;

    }

 

    /**

    * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer

    */

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

    {

    boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;

   

    if(coolDown == 0||coolDown == 1)

      {

    System.out.println(coolDown + " @1@");

    if (var5 || par3EntityPlayer.inventory.hasItem(Class3.a762x39mm.itemID))

    {

 

    System.out.println(coolDown + " @1.1@");

    Entitya762x39mm var8 = new Entitya762x39mm(par2World, par3EntityPlayer, 2.0F);

 

    par1ItemStack.damageItem(1, par3EntityPlayer);

    par2World.playSoundAtEntity(par3EntityPlayer, "Nailgun.shot", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) * 0.5F);

 

    if (var5)

    {

    var8.canBePickedUp = 2;

    }

    else

    {

    par3EntityPlayer.inventory.consumeInventoryItem(Class3.a762x39mm.itemID);

    }

 

    if (!par2World.isRemote)

    {

    par2World.spawnEntityInWorld(var8);

    }

    }

   

    coolDown++;

      }

      else if(coolDown == 0.2) //time between shots in ticks

      {

      System.out.println(coolDown + " @2@");

      coolDown = 0;

      }

      else {

          System.out.println(coolDown + " @3@");

      coolDown++;

      }

   

    return par1ItemStack;

   

    }

 

    /**

    * Return the enchantability factor of the item, most of the time is based on material.

    */

    public int getItemEnchantability()

    {

        return 1;

    }

 

    public String getTextureFile()

    {

        return ClientProxy.GUNS_PNG;

    }

    public boolean isFull3D()

    {

    return true;

    }

}

 

 

Link to comment
Share on other sites

ok i'm guessing this is just a momentary derp on your part, but you've told it to check if countDown (an int) is equal to 0.2 (a float/double) as this will never happen the variable never gets reset once it progresses past 1. so ether replace the variable with an int of value 2 or larger dependent on your required delay, or use a >= check rather than ==

 

not going to get pissed off and tell you to learn java as i make these mistakes all the time and i've been doing this for ages (only recently minecraft)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.