Jump to content

[1.10.2] Dynamically Rotate OBJ Model Item/Block in Hand


izzie.llg

Recommended Posts

Hi all,

 

I am trying to render a cereal box (a 3D OBJ Model) in my hand and on keypress rotate the model to make it look like I'm pouring cereal. It could either be a block or an item, whichever I can make this work with.

The model is rendering fine in my hand, but I don't know how I can dynamically change the Z-axis rotation. In lets say 1.7.10, I would use an IItemRenderer and control the rotation with a variable in a custom TileEntitySpecialRenderer class. But since the IItemRenderer class is no longer in 1.10.2 I'm not sure what to do.

Maybe use variants in the JSON file? If so could someone please link me a tutorial on adding variants to the Item/Block class that can then be accessed in the JSON?

 

Thanks,

Izzie

Link to comment
Share on other sites

I believe you can do this much like the Bow handles it's pulling animation (IItemPropertyGetter's & overrides in the model.json¹)

There isn't much to it. Look at ItemBow's constructor, as well as the bow.json inside ForgeSrc/assets/minecraft/models/item

 

¹If you are using the .obj directly as your model, then you can use the ForgeBlockstate to transform the first-person, third-person & gui elements, per stage. I have an example of the BlockState transformation here.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

Hi,

 

Thanks for your reply. I looked at the ItemBow class. There is this in the Constructor:

Spoiler

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() == Items.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;
    }
});

 

 

and then in the bow.JSON setting the model based on the pull variable:

Spoiler

{
    "parent": "item/generated",
    "textures": {
        "layer0": "items/bow_standby"
    },
    "display": {
        "thirdperson_righthand": {
            "rotation": [ -80, 260, -40 ],
            "translation": [ -1, -2, 2.5 ],
            "scale": [ 0.9, 0.9, 0.9 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ -80, -280, 40 ],
            "translation": [ -1, -2, 2.5 ],
            "scale": [ 0.9, 0.9, 0.9 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, -90, 25 ],
            "translation": [ 1.13, 3.2, 1.13],
            "scale": [ 0.68, 0.68, 0.68 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 90, -25 ],
            "translation": [ 1.13, 3.2, 1.13],
            "scale": [ 0.68, 0.68, 0.68 ]
        }
    },
    "overrides": [
        {
            "predicate": {
                "pulling": 1
            },
            "model": "item/bow_pulling_0"
        },
        {
            "predicate": {
                "pulling": 1,
                "pull": 0.65
            },
            "model": "item/bow_pulling_1"
        },
        {
            "predicate": {
                "pulling": 1,
                "pull": 0.9
            },
            "model": "item/bow_pulling_2"
        }
    ]
}

 

 

Which all makes sense but i don't think it will work with OBJ models. After debugging I found this code in OBJModel.java:

@Override
public ItemOverrideList getOverrides() {
	return ItemOverrideList.NONE;
}

Which means just before Minecraft would apply the overrides its checking to see if there are any overrides, which in the above code return none. 

So the apply function in "Item#addPropertyOverride" in my CerealBox class never gets called at all.

 

Any other suggestions? Or will I have to add like 9 different json files each with a slightly incremented rotation and switch between them on itemUse?

Edited by izzie.llg
Link to comment
Share on other sites

Or another thought:

I saw somewhere that you could put "variables" (not in the usual sense, but values that are calculated at runtime) inside the json file that you can manipulate outside the file in code. So I could have the Z-axis rotation as a variable in the json that I could change on ItemUse. Can you please tell me where to start on this idea? 

 

Thanks!

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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