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

hi,

I started to update one of my mods to 1.8 this weekend and I'm stuck on the bow textures.

By doing research on how the minecraft bow work, I found this in net.minecraft.client.renderer.entity.RenderItem :

    public void renderItemModelForEntity(ItemStack stack, EntityLivingBase entityToRenderFor, ItemCameraTransforms.TransformType cameraTransformType)
    {
        IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack);

        if (entityToRenderFor instanceof EntityPlayer)
        {
            EntityPlayer entityplayer = (EntityPlayer)entityToRenderFor;
            Item item = stack.getItem();
            ModelResourceLocation modelresourcelocation = null;

            if (item == Items.fishing_rod && entityplayer.fishEntity != null)
            {
                modelresourcelocation = new ModelResourceLocation("fishing_rod_cast", "inventory");
            }
            else if (item == Items.bow && entityplayer.getItemInUse() != null)
            {
                int i = stack.getMaxItemUseDuration() - entityplayer.getItemInUseCount();

                if (i >= 18)
                {
                    modelresourcelocation = new ModelResourceLocation("bow_pulling_2", "inventory");
                }
                else if (i > 13)
                {
                    modelresourcelocation = new ModelResourceLocation("bow_pulling_1", "inventory");
                }
                else if (i > 0)
                {
                    modelresourcelocation = new ModelResourceLocation("bow_pulling_0", "inventory");
                }
            }
            else
            {
                modelresourcelocation = item.getModel(stack, entityplayer, stack.getMaxItemUseDuration() - entityplayer.getItemInUseCount());
            }

            if (modelresourcelocation != null)
            {
                ibakedmodel = this.itemModelMesher.getModelManager().getModel(modelresourcelocation);
            }
        }

        this.renderItemModelTransform(stack, ibakedmodel, cameraTransformType);
    }

but apparently forge did not have hook or event to allow modder to use it.

Is there any other way to do a custom bow or it would add an event or hook to forge ?

  • Author

                modelresourcelocation = item.getModel(stack, entityplayer, stack.getMaxItemUseDuration() - entityplayer.getItemInUseCount());

Indeed, it was just under my eyes and I didn't even see it x)

thank you !

 

EDIT :

It's working, if someone else has the same problem, here's how:

package your.package;

import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;

public class ItemCustomBow extends ItemBow
{
    @Override
    public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining)
    {
        ModelResourceLocation modelresourcelocation = new ModelResourceLocation(TestMod.MODID + ":custom_bow", "inventory");

        if(stack.getItem() == this && player.getItemInUse() != null)
        {
            if(useRemaining >= 18)
            {
                modelresourcelocation = new ModelResourceLocation(TestMod.MODID + ":custom_bow_pull2", "inventory");
            }
            else if(useRemaining > 13)
            {
                modelresourcelocation = new ModelResourceLocation(TestMod.MODID + ":custom_bow_pull1", "inventory");
            }
            else if(useRemaining > 0)
            {
                modelresourcelocation = new ModelResourceLocation(TestMod.MODID + ":custom_bow_pull0", "inventory");
            }
        }
        return modelresourcelocation;
    }
}

and the main class :

package your.package;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@Mod(modid = TestMod.MODID, name = "Test Mod", version = "1.0.0", acceptedMinecraftVersions = "[1.8.0,)")
public class TestMod
{
    public static final String MODID = "testmod";
    public static Item customBow;
    
    @EventHandler
    public void preLoad(FMLPreInitializationEvent event)
    {
        customBow = new ItemCustomBow().setUnlocalizedName("customBow");
        GameRegistry.registerItem(customBow, "custom_bow");
    }
    
    @EventHandler
    public void load(FMLInitializationEvent event)
    {
        if(event.getSide().isClient())
        {
            ModelBakery.addVariantName(customBow, new String[] {MODID + ":custom_bow", MODID + ":custom_bow_pull0", MODID + ":custom_bow_pull1", MODID + ":custom_bow_pull2"});

            registerItem(customBow, 0, MODID + ":custom_bow");
            registerItem(customBow, 1, MODID + ":custom_bow_pull0");
            registerItem(customBow, 2, MODID + ":custom_bow_pull1");
            registerItem(customBow, 3, MODID + ":custom_bow_pull2");
        }
    }
    
    @SideOnly(Side.CLIENT)
    public static void registerItem(Item item, int metadata, String itemName)
    {
        ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
        mesher.register(item, metadata, new ModelResourceLocation(itemName, "inventory"));
    }
}

  • 3 weeks later...

i have a question over your question

 

if you have more than one ItemCustomBow in the hot bar

wen you pull one of the bows  all the bows in hot bar get pulled to or just afect the one you have in hands?

i have a question over your question

 

if you have more than one ItemCustomBow in the hot bar

wen you pull one of the bows  all the bows in hot bar get pulled to or just afect the one you have in hands?

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.