Posted March 12, 20178 yr Hello everyone! I'm facing a small problem updating my mod to 1.11.2 from 1.7.10: I use a LOT of .obj renders, which work well for me, but I get a small problem : In my mod, the icon in inventory is a 2d texture, while the held item is a 3d model. I load my item with a blockstate.json like so : { "forge_marker": 1, "defaults": { "custom": { "flip-v": true }, "model": "rcmod:blaster.obj", "textures": { "#Material__210": "rcmod:models/items/blaster" } }, "variants": { "normal": [{ "transform": { "firstperson": { "translation": [0.2, 0, 0.3], "rotation": [ { "y": 180}, {"x": 0}, {"z": 0} ], "scale": 0.04 }, "thirdperson": { "translation": [0.025, -0.05, 0.23], "rotation": [ { "y": 180}, {"x": 0}, {"z": 0} ], "scale": 0.04 }, "gui": { "translation": [0.3, -0.2, 0], "rotation": [ { "y": -90}, {"x": 0}, {"z": 0} ], "scale": 0.035 }, "ground": { "translation": [0.0, 0.0, -0.1], "scale": 0.024 }, "fixed": { "translation": [-0.2, -0.1, 0.0], "rotation": [ { "y": 90}, {"x": 0}, {"z": 0} ], "scale": 0.03 } }}] } } And I get shown this ingame : As you can see, the model in itself works fine, but the icon in the inventory is just a render of the item. Is there any way to set it to an actual 2d icon ? (such as the other ones shown in the bar)
March 13, 20178 yr Author Update : Adding the "inventory" variant to my json does not work. In code, I use : ModelLoader.setCustomModelResourceLocation(blaster, 0, new ModelResourceLocation(new ResourceLocation(RcMod.MODID, "blaster"), "normal")); Changing normal to inventory makes it use the icon in both hand and inventory, which is not what I want. I cannot find any solutions to this.
March 13, 20178 yr By default, the same model is used for an item regardless of where it's being rendered (e.g. in the hand or in the inventory). You'll need to create an IPerspectiveAwareModel wrapper that uses either the full OBJ model or the simple JSON model based on where it's being rendered (the TransformType). diesieben07 helped someone else with something similar 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.
March 13, 20178 yr Author Oh indeed! Thanks for the resource, I'll update when/if it works for me (with the solution of course).
March 14, 20178 yr Author I can get the item to render 2D in inventory, but I can't figure out how to render the .obj via an item model json. I'd rather use code to render my item, but I don't understand how/where can I put OpenGL code to render the obj (I use a lib to load objs which is REALLY convenient for me to use, way more than Forge's OBJLoader (support for UVs < 0 and > 1 especially)) Here's my IPerspectiveModel version: Spoiler package com.gugu42.rcmod.client.render; import java.util.List; import javax.vecmath.Matrix4f; import org.apache.commons.lang3.tuple.Pair; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.EnumFacing; import net.minecraftforge.client.model.IPerspectiveAwareModel; public class Inventory2DItemModel implements IPerspectiveAwareModel { public final IBakedModel model2D, model3D; public Inventory2DItemModel(IBakedModel model2d, IBakedModel model3d) { super(); this.model2D = model2d; this.model3D = model3d; } @Override public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType) { Matrix4f transform = null; switch(cameraTransformType) { case GUI: if(model2D instanceof IPerspectiveAwareModel){ Pair<? extends IBakedModel, Matrix4f> result =((IPerspectiveAwareModel) model2D).handlePerspective(cameraTransformType); return result; } return Pair.of(this.model2D,transform); default: if(model3D instanceof IPerspectiveAwareModel){ Pair<? extends IBakedModel, Matrix4f> result =((IPerspectiveAwareModel) model3D).handlePerspective(cameraTransformType); return result; } return Pair.of(this.model3D,transform); } } @Override public boolean isAmbientOcclusion() {return false;} @Override public boolean isGui3d() {return false;} @Override public boolean isBuiltInRenderer() {return false;} @Override public TextureAtlasSprite getParticleTexture() {return null;} @Override public ItemCameraTransforms getItemCameraTransforms() {return ItemCameraTransforms.DEFAULT;} @Override public ItemOverrideList getOverrides() {return ItemOverrideList.NONE;} @Override public List<BakedQuad> getQuads(IBlockState state, EnumFacing side,long rand) {return null;} } And the .json I use to -try- to load my OBJ : Spoiler { "model": "rcmod:weapons/blaster/blaster.obj", "textures": { "#Material__210": "rcmod:models/items/blaster" }, "transform": { "firstperson": { "translation": [0.2, 0, 0.3], "rotation": [ { "y": 180}, {"x": 0}, {"z": 0} ], "scale": 0.04 }, "thirdperson": { "translation": [0.025, -0.05, 0.23], "rotation": [ { "y": 180}, {"x": 0}, {"z": 0} ], "scale": 0.04 }, "gui": { "translation": [0.3, -0.2, 0], "rotation": [ { "y": -90}, {"x": 0}, {"z": 0} ], "scale": 0.035 }, "ground": { "translation": [0.0, 0.0, -0.1], "scale": 0.024 }, "fixed": { "translation": [-0.2, -0.1, 0.0], "rotation": [ { "y": 90}, {"x": 0}, {"z": 0} ], "scale": 0.03 } } } Hopefully I can find a way to render my items via code but at the moment; I am lost! EDIT : Changed "transform" to "display" and it works. However, I'm still interested in loading item obj via code Edited March 14, 20178 yr by Gugu42
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.