Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted (edited)

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
Posted

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!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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