Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm rewriting my mod for 1.10 and am working on reimplementing the bows atm. While doing so, I've come across three problems.

- there's no pulling animation: When I start pulling the item image changes to the first one of the pulling animation which stays forever.

- shooting doesn't consume arrows, even when not in creative.

- when I shoot an arrow, it looks like one of my mobs. I suppose that I messed something up on the renderer, but I didn't find out, where.

Any help is appreciated.

Bow class, arrow render class and render factory implementation:

Spoiler

package anagkai.biodiversity.items;

import javax.annotation.Nullable;

import anagkai.biodiversity.Biodiversity;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumAction;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemBiodiversityBow extends Item
{
	private Item bow;
	private Item arrow;
	
    public ItemBiodiversityBow(String name, int durab)
    {
    	this.setUnlocalizedName(name);
        this.maxStackSize = 1;
        this.setMaxDamage(durab);
        this.setCreativeTab(Biodiversity.cTab);
        this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter()
        {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
            {
                if (entityIn == null)
                {
                    return 0.0F;
                }
                else
                {
                    ItemStack itemstack = entityIn.getActiveItemStack();
                    return itemstack != null && itemstack.getItem() == bow ? (float)(stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20.0F : 0.0F;
                }
            }

        });
        this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter()
        {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
            {
                return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F;
            }
        });
    }
    
    public void setBowAndArrow(Item bow, Item arrow){
    	this.bow = bow;
    	this.arrow = arrow;
    }

    private ItemStack findAmmo(EntityPlayer player)
    {
        if (this.isArrow(player.getHeldItem(EnumHand.OFF_HAND)))
        {
            return player.getHeldItem(EnumHand.OFF_HAND);
        }
        else if (this.isArrow(player.getHeldItem(EnumHand.MAIN_HAND)))
        {
            return player.getHeldItem(EnumHand.MAIN_HAND);
        }
        else
        {
            for (int i = 0; i < player.inventory.getSizeInventory(); ++i)
            {
                ItemStack itemstack = player.inventory.getStackInSlot(i);

                if (this.isArrow(itemstack))
                {
                    return itemstack;
                }
            }

            return null;
        }
    }

    protected boolean isArrow(@Nullable ItemStack stack)
    {
        return stack != null && stack.getItem() == arrow;
    }

    /**
     * Called when the player stops using an Item (stops holding the right mouse button).
     */
    public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
    {
        if (entityLiving instanceof EntityPlayer)
        {
            EntityPlayer entityplayer = (EntityPlayer)entityLiving;
            boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
            ItemStack itemstack = this.findAmmo(entityplayer);

            int i = this.getMaxItemUseDuration(stack) - timeLeft;
            i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer)entityLiving, i, itemstack != null || flag);
            if (i < 0) return;

            if (itemstack != null || flag)
            {
                if (itemstack == null)
                {
                    itemstack = new ItemStack(arrow);
                }

                float f = getArrowVelocity(i);

                if ((double)f >= 0.1D)
                {
                    boolean flag1 = (entityplayer.capabilities.isCreativeMode || isArrow(itemstack));

                    if (!worldIn.isRemote)
                    {
                        ItemArrow itemarrow = (ItemArrow)((ItemArrow)(itemstack.getItem() == arrow ? itemstack.getItem() : arrow));
                        EntityArrow entityarrow = null;                       
                        //
                        if(this.arrow == ItemsBiodiversity.cherryArrow){
                        	entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
                        }
                        else{
                        	entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
                        }
                        //
                        entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);

                        if (f == 1.0F)
                        {
                            entityarrow.setIsCritical(true);
                        }

                        int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);

                        if (j > 0)
                        {
                            entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
                        }

                        int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);

                        if (k > 0)
                        {
                            entityarrow.setKnockbackStrength(k);
                        }

                        if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
                        {
                            entityarrow.setFire(100);
                        }

                        stack.damageItem(1, entityplayer);

                        if (flag1)
                        {
                            entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                        }

                        worldIn.spawnEntityInWorld(entityarrow);
                    }

                    worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

                    if (!flag1)
                    {
                        --itemstack.stackSize;

                        if (itemstack.stackSize == 0)
                        {
                            entityplayer.inventory.deleteStack(itemstack);
                        }
                    }

                    entityplayer.addStat(StatList.getObjectUseStats(this));
                }
            }
        }
    }

    /**
     * Gets the velocity of the arrow entity from the bow's charge
     */
    public static float getArrowVelocity(int charge)
    {
        float f = (float)charge / 20.0F;
        f = (f * f + f * 2.0F) / 3.0F;

        if (f > 1.0F)
        {
            f = 1.0F;
        }

        return f;
    }

    /**
     * How long it takes to use or consume an item
     */
    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 72000;
    }

    /**
     * returns the action that specifies what animation to play when the items is being used
     */
    public EnumAction getItemUseAction(ItemStack stack)
    {
        return EnumAction.BOW;
    }

    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
    {
        boolean flag = this.findAmmo(playerIn) != null;

        ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemStackIn, worldIn, playerIn, hand, flag);
        if (ret != null) return ret;

        if (!playerIn.capabilities.isCreativeMode && !flag)
        {
            return !flag ? new ActionResult(EnumActionResult.FAIL, itemStackIn) : new ActionResult(EnumActionResult.PASS, itemStackIn);
        }
        else
        {
            playerIn.setActiveHand(hand);
            return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
        }
    }

    /**
     * Return the enchantability factor of the item, most of the time is based on material.
     */
    public int getItemEnchantability()
    {
        return 1;
    }
}

 

Spoiler

package anagkai.biodiversity.entities.renderer.arrows;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderArrow;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderCherryArrow extends RenderArrow{
public RenderCherryArrow(RenderManager manager) {
super(manager);
}
@Override
protected ResourceLocation getEntityTexture(Entity entity) {
return new ResourceLocation("biodiversity:textures/cherryArrow.png");
}
}

 

Spoiler

package anagkai.biodiversity.entities.renderer.arrows;

import anagkai.biodiversity.entities.arrows.EntityCherryArrow;
import anagkai.biodiversity.entities.models.ModelAnt;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraftforge.fml.client.registry.IRenderFactory;

public class EntityCherryArrowRF implements IRenderFactory<EntityCherryArrow>{

	@Override
	public RenderCherryArrow createRenderFor(RenderManager manager) {
		return new RenderCherryArrow(manager);
	}

}

 

If you need to see any other code, please tell me.

 

Edited by diesieben07
syntax hightlighting

  • Author

I managed to fix the rendering issues. For the bow there were wrong-named textures and for the error entity there was a problem with entity ids.

 

Any idea on where the problem with the arrows comes from?

  • Author
Spoiler

   public static void registerEntities(){
        EntityRegistry.registerModEntity(EntityGargoyle.class, "biodiversityGargoyle", 0, Biodiversity.MODID, 128, 1, true, 0x262626, 0x666666);
        addSpawns(EntityGargoyle.class, 15, 2, 4);
        
        //Fire Gargoyle
        EntityRegistry.registerModEntity(EntityGargoyleFire.class, "biodiversityGargoyleFire", 1, Biodiversity.MODID, 128, 1, true, 0xcc5200, 0xe9c04a);
        addSpawns(EntityGargoyleFire.class, 10, 2, 3);
        
        //Water Gargoyle
        EntityRegistry.registerModEntity(EntityGargoyleWater.class, "biodiversityGargoyleWater", 2, Biodiversity.MODID, 128, 1, true, 0x3669c7, 0x61c7f7);        
        addSpawns(EntityGargoyleWater.class, 10, 2, 3);
        
        //Wasp
        EntityRegistry.registerModEntity(EntityWasp.class, "biodiversityWasp", 3, Biodiversity.MODID, 128, 1, true, 0x1a1a1a, 0xfadf48);

        
        //Ant
        EntityRegistry.registerModEntity(EntityAnt.class, "biodiversityAnt", 4, Biodiversity.MODID, 128, 1, true, 0x3a241c, 0x1a100c);    
        addSpawns(EntityAnt.class, 20, 6, 10);

        //Vegetarian
        EntityRegistry.registerModEntity(EntityVegetarian.class, "biodiversityVegetarian", 5, Biodiversity.MODID, 128, 1, true, 0xccb4a3, 0x25290f);
        addSpawns(EntityVegetarian.class, 25, 4, 6);
        
        //Anteater
        EntityRegistry.registerModEntity(EntityAnteater.class, "biodiversityAnteater", 6, Biodiversity.MODID, 128, 1, true, 0xb3a6a1, 0x332b27);
        EntityRegistry.addSpawn(EntityAnteater.class, 40, 3, 4, EnumCreatureType.CREATURE, Biomes.JUNGLE);
        EntityRegistry.addSpawn(EntityAnteater.class, 40, 3, 4, EnumCreatureType.CREATURE, Biomes.JUNGLE_HILLS);
        
        //Dragonman
        EntityRegistry.registerModEntity(EntityDragonman.class, "biodiversityDragonman", 7, Biodiversity.MODID, 128, 1, true, 0x264f26, 0xcc3e6d);
        
        //Kangaroo
        EntityRegistry.registerModEntity(EntityKangaroo.class, "biodiversityKangaroo", 8, Biodiversity.MODID, 128, 1, true, 0x803d26, 0xd9b7ad);
        EntityRegistry.addSpawn(EntityKangaroo.class, 40, 3, 4, EnumCreatureType.CREATURE, Biomes.SAVANNA);
        EntityRegistry.addSpawn(EntityKangaroo.class, 40, 3, 4, EnumCreatureType.CREATURE, Biomes.SAVANNA_PLATEAU);
        
        EntityRegistry.registerModEntity(EntityCherryArrow.class, "biodiversityCherryArrow", 9, Biodiversity.MODID, 128, 1, true);
    }


 

 

I had the same entity id for the arrow as for EntityGargoyle. That's what made the arrows look like gargoyles. I meant the fact that even when not in creative, no arrows are used.

Edited by Anagkai

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.