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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • file:///C:/Users/Danie/Downloads/Capture.JPG I keep experiencing this error, does anyone know how to fix it here is the report: file:///C:/Users/Danie/AppData/Roaming/.minecraft/crash-reports/Bug_report1.txt
    • Hi, i am unable to join a multiplayer server my friend and i created. We started it with some mods then decided to add some others and this is when the error appeared. We are using Curseforge, the server is in 1.20.1 . The full error message is "Internal Exception: io.netty.handler.codec.DecoderException: java.lang.ArrayIndexOutOfBoundsException: Index 17196645 out of bounds for length 13" I am the only one with that issue, my friends can log in and out no problem. I have tried switching minecraft account but that doesn't help so i guess the bug is on my side. We use the same mod profile so i know the error doesn't come from there. Solo works fine tho Here is the latest.log file https://pastebin.com/X6J9Fnnf. If you need more informations to try and investigate, please let me know. Big thanks to anyone that will try to help
    • [00:02:07] [main/ERROR]: Missing or unsupported mandatory dependencies:     Mod ID: 'kotlinforforge', Requested by: 'flightlib', Expected range: '[4.3.0,)', Actual version: '[MISSING]'     Mod ID: 'terrablender', Requested by: 'biomesoplenty', Expected range: '[2.2.0.154,)', Actual version: '[MISSING]'     Mod ID: 'geckolib', Requested by: 'cakescosmetics', Expected range: '[4.4,)', Actual version: '[MISSING]'     Mod ID: 'balm', Requested by: 'waystones', Expected range: '[7.2.0,)', Actual version: '[MISSING]'     Mod ID: 'oculus', Requested by: 'irisflw', Expected range: '[1.6.15,)', Actual version: '[MISSING]'     Mod ID: 'cupboard', Requested by: 'betterfpsdist', Expected range: '[1.20.1-1.5,)', Actual version: '[MISSING]' [00:02:53] [main/WARN]: Mod file C:\Users\ezkid\AppData\Roaming\.minecraft\libraries\net\minecraftforge\fmlcore\1.20.1-47.2.32\fmlcore-1.20.1-47.2.32.jar is missing mods.toml file [00:02:54] [main/WARN]: Mod file C:\Users\ezkid\AppData\Roaming\.minecraft\libraries\net\minecraftforge\javafmllanguage\1.20.1-47.2.32\javafmllanguage-1.20.1-47.2.32.jar is missing mods.toml file [00:02:54] [main/WARN]: Mod file C:\Users\ezkid\AppData\Roaming\.minecraft\libraries\net\minecraftforge\lowcodelanguage\1.20.1-47.2.32\lowcodelanguage-1.20.1-47.2.32.jar is missing mods.toml file [00:02:54] [main/WARN]: Mod file C:\Users\ezkid\AppData\Roaming\.minecraft\libraries\net\minecraftforge\mclanguage\1.20.1-47.2.32\mclanguage-1.20.1-47.2.32.jar is missing mods.toml file [00:02:65] [main/ERROR]: Skipping early mod setup due to previous error
    • Guns and more cool stuff
    • nvm i did it, turn out i just needed to install a drive or smth
  • Topics

×
×
  • Create New...

Important Information

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