Jump to content

Recommended Posts

Posted (edited)

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
Posted

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?

Posted (edited)
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...

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Back then there was a number which determined the tier of an item and block. If the block tier is lower or equal to the item number, the block would be mined. this however, has changed and now it goes by "needs_netherite_tool" which is fine, until you realized that some mods had items and blocks that exceeded these values. You can make you own "needs_mod_tool" but I feel that this is more limiting(and just more work) than before. So is there anyway to use something similar to the old tier system while also still being compatible with a lot of other mod tools?
    • Well, when I log in to the server, sometimes within an hour, sometimes within a minute, the server closes and informs me that there was a Ticking entity error. Below is the crash report
    • Try switching to Windowed or Borderless Window mode in Minecraft. These modes make it easier for the recorder to capture gameplay, as it still has access to the display without the game taking up all of the graphics resources.
    • This forum is for Forge, not NeoForge. Please go to them for support.
    • Forge version: 55.0.0 Minecraft version: 1.21.5 Downloads: As this is the start of a new version, it is recommended that you check the downloads page and use the latest version to receive any bug fixes. Downloads page Intro: Good evening! Today, we have released our initial build of Forge 55.0 for Minecraft 1.21.5. 1.21.5 is the newest member of the 1.21 family of versions, which was released yesterday on March 25, 2025. As a reminder, the first minor (X.0) of a Forge version is a beta. Forge betas are marked as such on the bottom left of the title screen and are candidates for any breaking changes. Additionally, there are a couple of important things to note about this update, which I've made sure to mention in this post as well. Feel free to chat with us about bugs or these implementation changes on GitHub and in our Discord server. As always, we will continue to keep all versions of 1.21 and 1.20 in active support as covered by our tiered support policy. Cheers, happy modding, and good luck porting! Rendering Refactor For those who tuned in to Minecraft Live on March 22, 2025, you may already know that Mojang have announced their intention to bring their new Vibrant Visuals overhaul to Java in the future. They've taken the first steps toward this by refactoring how rendering pipelines and render types are handled internally. This has, in turn, made many of Forge's rendering APIs that have existed for years obsolete, as they (for the most part) can be done directly in vanilla. If there was a rendering API that was provided by Forge which you believe should be re-implemented, we're happy to discuss on GitHub through an issue or a pull request. Deprecation of weapon-like ToolActions In 1.21.5, Minecraft added new data components for defining the characteristics of weapons in data. This includes attack speed, block tags which define efficient blocks, and more. As such, we will begin marking our ToolActions solution for this as deprecated. ToolActions were originally added to address the problem of creating modded tools that needed to perform the same actions as vanilla tools. There are still a few tool actions that will continue to be used, such as the shears tool action for example. There are some existing Forge tool actions that are currently obsolete and have no effect given the way the new data components are implemented. We will continue to work on these deprecations and invite you to chat with us on GitHub or Discord if you have any questions.
  • Topics

×
×
  • Create New...

Important Information

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