Jump to content

[1.10.2] Item model - rotate element on x and z axis


XFactHD

Recommended Posts

I have an item (Acog Scope) and its model uses eight elements for each round part to make it look a bit more round. Now I have the problem that the Acog Scope's front end is bigger than the back end. To still be able to use eight elements for the roundness I would have to rotate some elements on the x and the z axis. Is there any way to achieve this with the vanilla models or do I have to use some tricks to achieve that?

Link to comment
Share on other sites

JSON models can only rotate at multiples of 22.5 degrees. If you want a rotation value of anything but that, you'd have to use a Wavefront model (.obj).

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Also: I think that rotation in a JSON file is a single fact having 3 inseparable elements. In other words, you can't use one property to set an 'x' and another property to set 'z' (or 'y'). Instead, you must design one property to set {'x', 'y', 'z'} together. Providing a rotation aggregate such as {x=90} implies { x=90, y=0, z=0 }. Providing a rotation aggregate with any other property means clobbering will occur, with the last applied rotation winning.

 

I think what that means is that your code should first take what you thought were its properties (perhaps based on input) and compose rendering variants according to rendering traits (output). Vanilla properties sometimes get in the way, resulting in ignored properties and other hacks.

 

Beware that some hacks can cause performance penalties (e.g. memory hogging). I must confess that I don't know exactly when memory is or is not wasted by ignored properties in underlying state maps. My mods might be horrible memory hogs, and I am old enough (coming from an era when every memory bit was precious) to almost feel bad about it.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Actually, I think it only supports X and Y, no Z no matter what you tell it.  Minecraft assumes that rotations on Z are actually rotations on X, plus a 90 degree rotation on Y, and thus ignores it in the json file, as "you really should just simplify that."

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

  • 4 weeks later...

So, I just got back to this mod and I am still at the point that I can't figure out a way to create the boxes with a rotation on the x and the z axis without needing to make a second model, rotating it in the block state file and combining the two models in code. Does anybody have an idea if this is even possible to do in a single model file? BTW, I am not talking about rotations in the block state file.

Link to comment
Share on other sites

Hi

 

I'm pretty sure you can only specify a vanilla rotation on any one axis, i.e. x or y or z.  You can't rotate on two axes.

 

I'd suggest to use a wavefront model as lars said.  You could use eg blender, or you could just write it out by hand.  The format is very simple

  https://en.wikipedia.org/wiki/Wavefront_.obj_file

and if your object only has around 20 faces, it might be the fastest way.

 

-TGG

Link to comment
Share on other sites

I am too dumb to use blender :/. I already thought about making a second model with the boxes I need, rotating it via a block state file and combining it with the other model in code. Do you know of a way to force a model to be loaded without it being bound to an item via ModelLoader.registerCustomModelResourceLocation()?

Link to comment
Share on other sites

I'm pretty sure you can only specify a vanilla rotation on any one axis, i.e. x or y or z.

 

Actually you can rotate on two Axis at the same time with the json format, as long as you specify them together.

 

BUT

 

Minecraft doesn't know WTF a z-rotation is.

 

It can do X, it can do Y, it can do X and Y, but it assumes that the z-axis is just rotation on the X axis plus a 90 degree rotation on the Y axis.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Oh that. Yeah no. Not possible. Unfortunately. You will need to use an OBJ.  Use litterally any program you want to.  Sketchup if you have to.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Actually yes.

 

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/client/ModelsCache.java

 

Which I shamelessly stole from someone else (uh...sorry, I've now forgotten who, one sec...) edit: Elix_x.

 

And here's a usage, it must occur in this event

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/ores/client/OreClientEventHandler.java#L18

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Soooo... I seem to have done something really wrong because this is not what I expected: http://imgur.com/a/2EeUB.

This is my implementation of what you linked me:

public enum ModelCache implements IResourceManagerReloadListener
{
    INSTANCE;

    ModelCache()
    {
        ((IReloadableResourceManager)Minecraft.getMinecraft().getResourceManager()).registerReloadListener(this);
    }

    public static final IModelState DEFAULTMODELSTATE = new IModelState()
    {
        @Override
        @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
        public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> opt)
        {
            return Optional.absent();
        }
    };
    public static final Function<ResourceLocation, TextureAtlasSprite> DEFAULTTEXTUREGETTER = new Function<ResourceLocation, TextureAtlasSprite>()
    {
        @Override
        public TextureAtlasSprite apply(ResourceLocation texture)
        {
            return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(texture.toString());
        }
    };

    private final Map<ResourceLocation, IModel> cache = new HashMap<>();
    private final Map<ResourceLocation, IBakedModel> bakedCache = new HashMap<>();

    public IBakedModel getOrLoadBakedModel(ResourceLocation location)
    {
        IBakedModel model = bakedCache.get(location);
        if(model == null)
        {
            model = getOrLoadModel(location).bake(DEFAULTMODELSTATE, DefaultVertexFormats.ITEM, DEFAULTTEXTUREGETTER);
            bakedCache.put(location, model);
        }
        return model;
    }

    private IModel getOrLoadModel(ResourceLocation location)
    {
        IModel model = cache.get(location);
        if(model == null)
        {
            try
            {
                model = ModelLoaderRegistry.getModel(location);
            }
            catch(Exception e)
            {
                LogHelper.info("Couldn't load model for location %s, allocating missing model!", location);
                e.printStackTrace();
                model = ModelLoaderRegistry.getMissingModel();
            }
            cache.put(location, model);
        }
        return model;
    }

    @Override
    public void onResourceManagerReload(IResourceManager resourceManager)
    {
        cache.clear();
        bakedCache.clear();
    }
}

 

This is the ModelBakeEventHandler:

@SubscribeEvent
public void onModelBake(ModelBakeEvent event)
{
        IRegistry<ModelResourceLocation, IBakedModel> registry = event.getModelRegistry();

        //ItemAttachment_Acog_Scope
        IBakedModel scope = registry.getObject(new ModelResourceLocation(new ResourceLocation(Reference.MOD_ID, "attachment/itemAttachment_acog_sight"), "inventory"));
        IBakedModel extra = ModelCache.INSTANCE.getOrLoadBakedModel(new ModelResourceLocation(new ResourceLocation(Reference.MOD_ID, "attachment/itemAttachment"), "acog_extra"));
        IBakedModel newModel = new ModelAcogScope(scope, extra);
        registry.putObject(new ModelResourceLocation(new ResourceLocation(Reference.MOD_ID, "attachment/itemAttachment_acog_sight"), "inventory"), newModel);
}

 

The blockstate file:

{
    "variants": {
        "acog_extra": { "model": "rssmc:special/itemAttachment_acog_sight_angled_rotated", "x": 45, "y": 90 }
    }
}

 

The model to be loaded this way:

{
    "textures": {
    },
    "elements": [
        {
            "name": "BottomAngled",
            "from": [ 7.0, 12.500000022351742, 6.000000014901161 ], 
            "to": [ 9.0, 13.000000014901161, 10.000000014901161 ], 
            "rotation": { "origin": [ 8.0, 13.000000014901161, 10.0 ], "axis": "x", "angle": -22.5 },
            "faces": {
                "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 0.4999999925494194 ] },
                "east": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 0.4999999925494194 ] },
                "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 0.4999999925494194 ] },
                "west": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 0.4999999925494194 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 4.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 4.0 ] }
            }
        },
        {
            "name": "TopAngled",
            "from": [ 7.0, 16.00000001490116, 6.0 ], 
            "to": [ 9.0, 16.50000000745058, 10.0 ], 
            "rotation": { "origin": [ 8.0, 16.0, 10.0 ], "axis": "x", "angle": 22.5 },
            "faces": {
                "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 0.4999999925494194 ] },
                "east": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 0.4999999925494194 ] },
                "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 0.4999999925494194 ] },
                "west": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 0.4999999925494194 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 4.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 4.0 ] }
            }
        },
        {
            "name": "RightAngled",
            "from": [ 9.49999999254942, 13.50000000745058, 6.0 ], 
            "to": [ 9.999999985098839, 15.50000000745058, 10.0 ], 
            "rotation": { "origin": [ 9.49999999254942, 13.0, 10.0 ], "axis": "y", "angle": -22.5 },
            "faces": {
                "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.4999999925494194, 2.0 ] },
                "east": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 2.0 ] },
                "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.4999999925494194, 2.0 ] },
                "west": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 2.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.4999999925494194, 4.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.4999999925494194, 4.0 ] }
            }
        },
        {
            "name": "LeftAngled",
            "from": [ 5.999999985098839, 13.50000000745058, 6.0 ], 
            "to": [ 6.499999977648258, 15.50000000745058, 10.0 ], 
            "rotation": { "origin": [ 6.500000007450581, 13.0, 10.0 ], "axis": "y", "angle": 22.5 },
            "faces": {
                "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.4999999925494194, 2.0 ] },
                "east": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 2.0 ] },
                "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.4999999925494194, 2.0 ] },
                "west": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 2.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.4999999925494194, 4.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 0.4999999925494194, 4.0 ] }
            }
        }
    ],
    "display": {
        "thirdperson_righthand": {
            "rotation": [ 90, 180, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, -60, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ 90, 180, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, -60, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "gui": {
            "rotation": [ 30, 45, 0 ],
            "translation": [ 0, 0, 0],
            "scale":[ 0.625, 0.625, 0.625 ]
        },
        "ground": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 3, 0],
            "scale":[ 0.35, 0.35, 0.35 ]
        },
        "fixed": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 0, 0],
            "scale":[ 0.5, 0.5, 0.5 ]
        }
    }
}

Link to comment
Share on other sites

Not sure, honestly. I started by merging the model I was already using (the one that I specified via ModelLoader.setCustomModelResourceLocation) and combined it with an existing vanilla model (in my case, carpet).  Oh, and only for one variant, too.

 

Once I had that working I did all the variants.  Once that worked I replaced the carpet with a new, custom model.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Found the error, it was the rotation in the blockstate file ("x": 45, "y": 90). Putting "z": 45 got ignored as expected. How am I supposed to define a rotation on the z axis?

 

As I said earlier, Minecraft assumes that all rotation around the Z axis is actually rotation around X plus a 90 degree rotation around Y.

i.e. models should not be able to define a different axial tilt East-West than North-South.  Instead, rotate around the North-South line, then rotate to face East.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Also, the north-south axis is the z axis.

 

And backwards, because Minecraft is weird.

(Positive X, Positive Z is South East, rather than the expected cartesian planar direction of North East)

 

Anyway, point was "you have to rotate around X, then y" in order to rotate around z.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Makes sense to me but if I define x as 90 degree and y as 90 degree, the model gets its northern face turned down and then rotated around the y axis making it display at a different position because the model isn't centered vertically within the 16x16x16 area. And defining x as 45 degree makes the model not load at all and throw a MissingVariantException.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • LadangToto2 adalah pilihan terbaik bagi Anda yang mencari pengalaman bermain slot gacor dengan transaksi mudah menggunakan Bank Mestika. Berikut adalah beberapa alasan mengapa Anda harus memilih LadangToto2: Slot Gacor Terbaik Kami menyajikan koleksi slot gacor terbaik yang menawarkan kesenangan bermain dan peluang kemenangan besar. Dengan fitur-fitur unggulan dan tema-tema menarik, setiap putaran permainan akan memberikan Anda pengalaman yang tak terlupakan. Transaksi Mudah dengan Bank Mestika Kami menyediakan layanan transaksi mudah melalui Bank Mestika untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa hambatan. Hadiah Hingga 100 Juta LadangToto2 memberikan kesempatan untuk meraih hadiah hingga 100 juta dalam kemenangan. Dengan jackpot dan hadiah-hadiah besar yang ditawarkan, setiap putaran permainan bisa menjadi peluang untuk meraih keberuntungan besar.  
    • Mengapa Memilih LadangToto? LadangToto adalah pilihan terbaik bagi Anda yang mencari pengalaman bermain slot gacor WD Maxwin dengan transaksi mudah menggunakan Bank BNI. Berikut adalah beberapa alasan mengapa Anda harus memilih LadangToto: Slot Gacor WD Maxwin Terbaik Kami menyajikan koleksi slot gacor WD Maxwin terbaik yang menawarkan kesenangan bermain dan peluang kemenangan besar. Dengan fitur-fitur unggulan dan tema-tema menarik, setiap putaran permainan akan memberikan Anda pengalaman yang tak terlupakan. Transaksi Mudah dengan Bank BNI Kami menyediakan layanan transaksi mudah melalui Bank BNI untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa hambatan.  
    • Akun Pro Kamboja adalah pilihan terbaik bagi Anda yang mencari pengalaman bermain slot Maxwin dengan transaksi mudah menggunakan Bank Lampung. Berikut adalah beberapa alasan mengapa Anda harus memilih Akun Pro Kamboja: Slot Maxwin Terbaik Kami menyajikan koleksi slot Maxwin terbaik yang menawarkan kesenangan bermain dan peluang kemenangan besar. Dengan fitur-fitur unggulan dan tema-tema menarik, setiap putaran permainan akan memberikan Anda pengalaman yang tak terlupakan. Transaksi Mudah dengan Bank Lampung Kami menyediakan layanan transaksi mudah melalui Bank Lampung untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa hambatan. Anti Rungkat Akun Pro Kamboja memberikan jaminan "anti rungkat" kepada para pemainnya. Dengan fitur ini, Anda dapat merasakan sensasi bermain dengan percaya diri, karena kami memastikan pengalaman bermain yang adil dan menyenangkan bagi semua pemain.  
    • BINGO188: Destinasi Terbaik untuk Pengalaman Slot yang Terjamin Selamat datang di BINGO188, tempat terbaik bagi para pecinta slot yang mencari pengalaman bermain yang terjamin dan penuh kemenangan. Di sini, kami menawarkan fitur unggulan yang dirancang untuk memastikan kepuasan dan keamanan Anda. Situs Slot Garansi Kekalahan 100 Kami memahami bahwa kadang-kadang kekalahan adalah bagian dari permainan. Namun, di BINGO188, kami memberikan jaminan keamanan dengan fitur garansi kekalahan 100. Jika Anda mengalami kekalahan, kami akan mengembalikan saldo Anda secara penuh. Kemenangan atau uang kembali, kami memastikan Anda tetap merasa aman dan nyaman. Bebas IP Tanpa TO Nikmati kebebasan bermain tanpa batasan IP dan tanpa harus khawatir tentang TO (Turn Over) di BINGO188. Fokuslah pada permainan Anda dan rasakan sensasi kemenangan tanpa hambatan. Server Thailand Paling Gacor Hari Ini Bergabunglah dengan server terbaik di Thailand hanya di BINGO188! Dengan tingkat kemenangan yang tinggi dan pengalaman bermain yang lancar, server kami dijamin akan memberikan Anda pengalaman slot yang tak tertandingi. Kesimpulan BINGO188 adalah pilihan terbaik bagi Anda yang menginginkan pengalaman bermain slot yang terjamin dan penuh kemenangan. Dengan fitur situs slot garansi kekalahan 100, bebas IP tanpa TO, dan server Thailand paling gacor hari ini, kami siap memberikan Anda pengalaman bermain yang aman, nyaman, dan menguntungkan. Bergabunglah sekarang dan mulailah petualangan slot Anda di BINGO188!
    • Mengapa Memilih AlibabaSlot? AlibabaSlot adalah pilihan terbaik bagi Anda yang mencari slot gacor dari Pgsoft dengan transaksi mudah menggunakan Bank Panin. Berikut adalah beberapa alasan mengapa Anda harus memilih AlibabaSlot: Slot Gacor dari Pgsoft Kami menyajikan koleksi slot gacor terbaik dari Pgsoft. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, setiap putaran permainan akan memberikan Anda kesenangan dan keuntungan yang maksimal. Transaksi Mudah dengan Bank Panin Kami menyediakan layanan transaksi mudah melalui Bank Panin untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa masalah.  
  • Topics

×
×
  • Create New...

Important Information

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