Jump to content

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


Recommended Posts

Posted

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 !

Posted
  On 3/5/2016 at 2:06 PM, Major Squirrel said:

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.

Posted
  On 3/5/2016 at 3:49 PM, Choonster said:

  Quote

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 !

Posted
  On 3/5/2016 at 5:01 PM, Major Squirrel said:

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.

 

 

  Quote

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

.

 

 

  Quote

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.

Posted

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 !

Posted

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 !

Posted
  On 3/7/2016 at 10:30 AM, Major Squirrel said:

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.

Posted

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.

Squirrel ! Squirrel ! Squirrel !

Posted
  On 3/7/2016 at 12:52 PM, Major Squirrel said:

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.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
  • Topics

×
×
  • Create New...

Important Information

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