Jump to content

[1.8.9][Item][SOLVED] Having trouble rendering custom bow + his durability


Major Squirrel

Recommended Posts

Good evening,

 

I'm having trouble rendering a custom bow when the player is using it. I noticed that Minecraft has a String array inside the ItemBow class that contains three "bow states" : pulling_0, pulling_1 and plluing_2, and I simply can't find in the code where Minecraft does register their models. I found out how to register the bow on standby, but not the bow on its different pulling states.

 

Furthermore, I'm having trouble with the custom bow item duration. Basically, my custom bow is just a copy/paste of the Minecraft ItemBow (for training purposes) except that I change the maxDamage variable of the Item. For the base ItemBow, the wiki says that its maxDamage default value is 385. I changed it to 4 on my custom one : it works well, meaning that I can shoot four times with my bow, but then it displays the Item with a red zero over it (instead of breaking and disappearing) :

 

width=800 height=423http://s12.postimg.org/8ur9z9wrx/2016_03_05_15_01_12.png[/img]

 

Then, when rightclicking on the Item, it just disappears. I must admit I would need a little help here.

 

ItemBow.java (my custom one)

 

Thank you in advance for your time and your precious help. :)

 

EDIT: currently working on the "pulling bow" models thanks to this topic

 

UPDATE1: after registering the "pulling bow" models, I don't know how to tell the game to render the current bow state model. It seems that it is hardcoded, for the base bow, in RenderItem#renderItemModelForEntity method located in the net.minecraft.client.renderer.entity package. I would need some further infos here.    see Choonster answer below !

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

UPDATE1: after registering the "pulling bow" models, I don't know how to tell the game to render the current bow state model. It seems that it is hardcoded, for the base bow, in RenderItem#renderItemModelForEntity method located in the net.minecraft.client.renderer.entity package. I would need some further infos here.

 

Override

Item#getModel

to return the

ModelResourceLocation

of the appropriate model based on the remaining use time (using the same logic as the vanilla bow). You can see an example of this here (model registration is here and here).

 

Edit: Fix link tag.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

UPDATE1: after registering the "pulling bow" models, I don't know how to tell the game to render the current bow state model. It seems that it is hardcoded, for the base bow, in RenderItem#renderItemModelForEntity method located in the net.minecraft.client.renderer.entity package. I would need some further infos here.

 

Override

Item#getModel

to return the

ModelResourceLocation

of the appropriate model based on the remaining use time (using the same logic as the vanilla bow). You can see an example of this here (model registration is here and here[/urk]).

 

Thank you Choonster, you're the man.

 

Just a question about your code, I don't understand what does your filter do and how do you do to register models in inventory or in hand, in your ModModelManager ? (for now the "pulling models" display successfully in game, thanks to you)

 

Furthermore, why do we have to register our items models from blockstates, especially for bows ?

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Just a question about your code, I don't understand what does your filter do

 

ModItems.items

is a collection of all of my mod's

Item

instances. Using Java 8's Stream API, I create a stream from that collection, filter out the items that have already had a model registered and then call

registerItemModel(Item)

for each remaining item. This registers the default model for the item, i.e. the

inventory

variant of the model with the item's registry name.

 

 

how do you do to register models in inventory or in hand, in your ModModelManager ?

 

The various overloads of

ModModelManager#registerItemModel

all boil down to registering the model with

ModelBakery.registerItemVariants

(so Minecraft loads it), creating an

ItemMeshDefinition

that returns a single constant

ModelResourceLocation

and registering it for an

Item

with

ModelLoader.setCustomMeshDefinition

(so Minecraft uses it for that

Item

). This uses a single model for every metadata value of the

Item

.

 

The various overloads of

ModModelManager#registerItemModelForMeta

all boil down to registering a

ModelResourceLocation

for a specific metadata value of the

Item

with

ModelLoader.setCustomModelResourceLocation

. This automatically calls

ModelBakery.registerItemVariants

.

 

 

Furthermore, why do we have to register our items models from blockstates, especially for bows ?

 

You don't have to, you can use regular item models in the same way (use multiple model paths with the

inventory

variant instead of a single model path with multiple variants). Forge added the option to use blockstates files for items a while back, so I wanted to try out the new feature.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Thank you for you explanation ! I understand better how Minecraft model loading works. :)

 

The only problem left is the Item durability, I didn't find where the problem could come from. Example : for the custom bow, the durability is set to 3. I can shoot 4 arrows in-game, so it seems that it is +1 in-game (according to the Bow wiki page). After shooting four arrows, the player can hear the "broken object" sound and sees the Item with the red zero over it. It just has to rightclick on the Item so that it disappears. I think I might miss something.

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Good morning,

 

I solved the problem of Item durability. I didn't extend my custom bow to the Minecraft ItemBow class. I had to do this to pass my Item into a specific method from ItemStack, especially a specific if condition :

 

    /**
     * Damages the item in the ItemStack
     */
    public void damageItem(int amount, EntityLivingBase entityIn)
    {
        if (!(entityIn instanceof EntityPlayer) || !((EntityPlayer)entityIn).capabilities.isCreativeMode)
        {
            if (this.isItemStackDamageable())
            {
                if (this.attemptDamageItem(amount, entityIn.getRNG()))
                {
                    entityIn.renderBrokenItemStack(this);
                    --this.stackSize;

                    if (entityIn instanceof EntityPlayer)
                    {
                        EntityPlayer entityplayer = (EntityPlayer)entityIn;
                        entityplayer.triggerAchievement(StatList.objectBreakStats[item.getIdFromItem(this.item)]);

                        if (this.stackSize == 0 && this.getItem() instanceof ItemBow)
                        {
                            entityplayer.destroyCurrentEquippedItem();
                        }
                    }

                    if (this.stackSize < 0)
                    {
                        this.stackSize = 0;
                    }

                    this.itemDamage = 0;
                }
            }
        }
    }

 

if (this.stackSize == 0 && this.getItem() instanceof ItemBow) only checks for instances of the ItemBow : once I extended my custom bow to the correct one, my Items got destroyed well !

 

The only problem left is a new one : when using the Minecraft ItemBow, there is a special effect(/render ?) that "zooms" the player vision, to better aim the target. Even extending the ItemBow, it doesn't work on mine, could you guys give me some help/tips there ?

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

The only problem left is a new one : when using the Minecraft ItemBow, there is a special effect(/render ?) that "zooms" the player vision, to better aim the target. Even extending the ItemBow, it doesn't work on mine, could you guys give me some help/tips there ?

 

You need to subscribe to

FOVUpdateEvent

to modify the FOV like the vanilla bow does if the player is using your bow. You can see how I do this here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Thank you very much Choonster, it does work very well !

 

Before locking this topic and marking it as solved, could you tell me where did you find the code in Minecraft sources ? I couldn't find it, I'm bad.

 

Vanilla handles the FOV modification for the bow in

AbstractClientPlayer#getFovModifier

, this also fires

FOVUpdateEvent

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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