Jump to content

[1.7.10] I'm trying to create a gun using extends ItemBow [SOLVED]


geoboom

Recommended Posts

Hey guys! I'm quite new to the forums and I decided to post here after ages searching and googling for solution to my problem but to no avail. I am trying to create a gun based off extends ItemBow but without any draw-back animation or anything I just want the gun to hold up and fire arrows (with a gun sound and and invisible arrows). But every time I try to do it and set every single texture to "tm:garand", the textures all show purple and black on the gun in the game. Please help me, here is my code:

 

TutorialMod.Java:

 

package geoboom.tutorial;

 

import geoboom.tutorial.item.ItemGarand;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemBow;

import net.minecraft.item.ItemFood;

import net.minecraft.item.ItemStack;

import net.minecraftforge.common.util.EnumHelper;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.EventHandler;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

 

@Mod(modid = "tm", name = "Tutorial Mod", version = "1.0")

public class TutorialMod {

 

public static Item itemGarand;

 

public static final Item.ToolMaterial cheeseToolMaterial = EnumHelper.addToolMaterial("cheeseToolMaterial", 4, 2000, 25.0F, 10.0F, 30);

 

@EventHandler

public void preInit(FMLPreInitializationEvent event){

//Item/Block init and registering

//Config Handling

 

itemGarand = new ItemGarand().setUnlocalizedName("ItemGarand").setTextureName("tm:garand");

GameRegistry.registerItem(itemGarand, itemGarand.getUnlocalizedName().substring(5));

}

 

@EventHandler

public void init(FMLInitializationEvent event){

//Proxy, TileEntity, entity, GUI and Packet Registering

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event){

 

}

 

public static CreativeTabs tabTutorialMod = new CreativeTabs("tabTutorialMod"){

@Override

public Item getTabIconItem(){

return new ItemStack(itemTable).getItem();

}

};

}

 

 

 

 

ItemGarand.java:

 

package geoboom.tutorial.item;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.enchantment.Enchantment;

import net.minecraft.enchantment.EnchantmentHelper;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.projectile.EntityArrow;

import net.minecraft.init.Items;

import net.minecraft.item.EnumAction;

import net.minecraft.item.Item;

import net.minecraft.item.ItemBow;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import net.minecraft.world.World;

import net.minecraftforge.common.MinecraftForge;

import net.minecraftforge.event.entity.player.ArrowLooseEvent;

import net.minecraftforge.event.entity.player.ArrowNockEvent;

 

public class ItemGarand extends Item

{

    public static final String[] bowPullIconNameArray = new String[] {"tm:garand", "tm:garand", "tm:garand"};

    @SideOnly(Side.CLIENT)

    private IIcon[] iconArray;

    private static final String __OBFID = "CL_00001777";

   

    public ItemGarand()

    {

    this.setFull3D();

    this.setTextureName("tm:garand");

        this.maxStackSize = 1;

        this.setMaxDamage(384);

        this.setCreativeTab(CreativeTabs.tabCombat);

    }

 

    /**

    * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount

    */

    public void onPlayerStoppedUsing(ItemStack p_77615_1_, World p_77615_2_, EntityPlayer p_77615_3_, int p_77615_4_)

    {

        int j = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_;

 

        ArrowLooseEvent event = new ArrowLooseEvent(p_77615_3_, p_77615_1_, j);

        MinecraftForge.EVENT_BUS.post(event);

        if (event.isCanceled())

        {

            return;

        }

        j = event.charge;

 

        boolean flag = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0;

 

        if (flag || p_77615_3_.inventory.hasItem(Items.arrow))

        {

            float f = (float)j / 20.0F;

            f = (f * f + f * 2.0F) / 3.0F;

 

            if ((double)f < 0.1D)

            {

                return;

            }

 

            if (f > 1.0F)

            {

                f = 1.0F;

            }

 

            EntityArrow entityarrow = new EntityArrow(p_77615_2_, p_77615_3_, f * 2.0F);

 

            if (f == 1.0F)

            {

                entityarrow.setIsCritical(true);

            }

 

            int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_);

 

            if (k > 0)

            {

                entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);

            }

 

            int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_);

 

            if (l > 0)

            {

                entityarrow.setKnockbackStrength(l);

            }

 

            if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0)

            {

                entityarrow.setFire(100);

            }

 

            p_77615_1_.damageItem(1, p_77615_3_);

            p_77615_2_.playSoundAtEntity(p_77615_3_, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

 

            if (flag)

            {

                entityarrow.canBePickedUp = 2;

            }

            else

            {

                p_77615_3_.inventory.consumeInventoryItem(Items.arrow);

            }

 

            if (!p_77615_2_.isRemote)

            {

                p_77615_2_.spawnEntityInWorld(entityarrow);

            }

        }

    }

 

    public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_)

    {

        return p_77654_1_;

    }

 

    /**

    * How long it takes to use or consume an item

    */

    public int getMaxItemUseDuration(ItemStack p_77626_1_)

    {

        return 72000;

    }

 

    /**

    * returns the action that specifies what animation to play when the items is being used

    */

    public EnumAction getItemUseAction(ItemStack p_77661_1_)

    {

        return EnumAction.bow;

    }

 

    /**

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

    */

    public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)

    {

        ArrowNockEvent event = new ArrowNockEvent(p_77659_3_, p_77659_1_);

        MinecraftForge.EVENT_BUS.post(event);

        if (event.isCanceled())

        {

            return event.result;

        }

 

        if (p_77659_3_.capabilities.isCreativeMode || p_77659_3_.inventory.hasItem(Items.arrow))

        {

            p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));

        }

 

        return p_77659_1_;

    }

 

    /**

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

    */

    public int getItemEnchantability()

    {

        return 1;

    }

 

    @SideOnly(Side.CLIENT)

    public void registerIcons(IIconRegister p_94581_1_)

    {

        this.itemIcon = p_94581_1_.registerIcon(this.getIconString() + "_standby");

        this.iconArray = new IIcon[bowPullIconNameArray.length];

 

        for (int i = 0; i < this.iconArray.length; ++i)

        {

            this.iconArray = p_94581_1_.registerIcon(this.getIconString() + "_" + bowPullIconNameArray);

        }

    }

 

    /**

    * used to cycle through icons based on their used duration, i.e. for the bow

    */

    @SideOnly(Side.CLIENT)

    public IIcon getItemIconForUseDuration(int p_94599_1_)

    {

        return this.iconArray[p_94599_1_];

    }

}

 

 

 

Thank you very much!

Link to comment
Share on other sites

Is there an error in the client log?

Yeah it should tell you where it's looking for your texture but can't find it

 

There are absolutely no errors in the client logs or anything. Also, when I create another test object and I .setTextureName("tm:garand"); it, the texture shows up perfectly.

Link to comment
Share on other sites

It doesn't matter what you set the texture name to if you override registerIcons - that's where the icons are registered, and you are registering a bunch as though you were going to have the bow pulling animations.

 

If you're going to copy code, at least take the time to read it and try to figure out what each part is for.

 

And to fix your problem, remove registerIcons entirely and remove every IIcon field / method in there - you don't need them if you are just using a single texture.

Link to comment
Share on other sites

It doesn't matter what you set the texture name to if you override registerIcons - that's where the icons are registered, and you are registering a bunch as though you were going to have the bow pulling animations.

 

If you're going to copy code, at least take the time to read it and try to figure out what each part is for.

 

And to fix your problem, remove registerIcons entirely and remove every IIcon field / method in there - you don't need them if you are just using a single texture.

 

Thank you very much! This solved my problem ^^

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.



×
×
  • Create New...

Important Information

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