#render custom item

449 messages · Page 1 of 1 (latest)

untold onyx
#

hello, i have this code which works but i want to make it render the texture item-like. how would i do that? for now it renders it as a block. thanks for the help :)

@Nullable
    @Override
    public BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer) {
        // Get the sprites
        for(int i = 0; i < SPRITE_IDS.length; ++i) {
            sprites[i] = textureGetter.apply(SPRITE_IDS[i]);
        }
        // Build the mesh using the Renderer API
        Renderer renderer = RendererAccess.INSTANCE.getRenderer();
        MeshBuilder builder = renderer.meshBuilder();
        QuadEmitter emitter = builder.getEmitter();

        for(Direction direction : Direction.values()) {
            // UP and DOWN share the Y axis
            int spriteIdx = 0;
            // Add a new face to the mesh
            emitter.square(direction, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f);
            // Set the sprite of the face, must be called after .square()
            // We haven't specified any UV coordinates, so we want to use the whole texture. BAKE_LOCK_UV does exactly that.
            emitter.spriteBake(sprites[spriteIdx], MutableQuadView.BAKE_LOCK_UV);
            // Enable texture usage
            emitter.color(-1, -1, -1, -1);
            // Add the quad to the mesh
            emitter.emit();
        }
        mesh = builder.build();
        
        return this;
    }```
ripe stag
#

What's your end goal? The vanilla generated model system is quite complex, so you should utilize it whenever possible

untold onyx
#

for the first step i just want to take an item texture (in this example, diamond) and use my custom baker to render it as a diamond would render.

#

then the next step is to actually making the textures at runtime and using them.

ripe stag
#

In what way do you want to change them? Some things are easy to do without complicated setups

#

Specifically you can easily color item models or parts of them, and switch between a small number of premade models (which could be colored themselves)

untold onyx
untold onyx
#

i followed fabric's example for blocks but it didn't tell me anything about items. the item is rendered like a block which is not my goal. tried digging into minecraft's code but it didn't help much because i couldn't figure out from where they're getting the faces and such

ripe stag
#

I'm trying to figure out if you really need runtime generated textures. It's not easy to do, and usually when people think they want that, they actually want something much simpler

untold onyx
# ripe stag I'm trying to figure out if you really need runtime generated textures. It's not...

Subscribe to build the Blucubed castle! 🏰

✨ We’re working on making the mod playable! Join to stay in the loop: https://discord.gg/TveN5TTE7J

What would you try to craft? 🤔

Aseprite (pixel art program) https://www.aseprite.org/
PixelLab (AI art extension) https://www.pixellab.ai/

This video is largely about using AI, and specifically AI art....

▶ Play video
#

at the very beginning he tells what he did to achieve that but i didn't understand him much

#

@ripe stag my goal for now is to get the 3d effect of the item in my custom item

ripe stag
#

Based on what he said there, you'll have to do a lot of work to get this working correctly

untold onyx
#

can't i copy what minecraft did and place in in my bake function?

ripe stag
#

If you really want to, look at net.minecraft.client.render.model.json.ItemModelGenerator

untold onyx
untold onyx
ripe stag
#

I didn't propose that you just use ItemModelGenerator (although you should if possible). It's built on the assumption that it knows the texture beforehand, which won't really work for you

#

You'll probably have to partially reimplement it

untold onyx
ripe stag
#

If you've genned and attached sources you can just use find usages in intellij

untold onyx
ripe stag
#

If you have a blue bar at the top of minecraft classes, click the choose sources button and select the sources jar.

#

If you don't, you/something already attached them

untold onyx
ripe stag
#

If you see javadoc on minecraft classes it's attached. That's a fabric class, so it doesn't mean anything

untold onyx
ripe stag
#

Not all of them will have it

#

Just open the class (F4) and check for a blue banner/bar at the top

ripe stag
#

That means that its working

#

Those only appear in minecraft with sources

#

The blue bar would look like this:

untold onyx
#

and it disappeared

ripe stag
#

Good, then you've attached sources (mcdev did it for you)

#

Anyway, you can just ctrl-click the constructor to find usages

untold onyx
# ripe stag Anyway, you can just ctrl-click the constructor to find usages

okay. ty :)
i have another question tho, how do i register a sprite at runtime? i have this constructor but it doesn't register the sprite i think

public MyCustomItemModel() {
        MinecraftClient client = MinecraftClient.getInstance();
        NativeImage image = new NativeImage(NativeImage.Format.RGBA, 16, 16, false);
        for (int y = 0; y < 16; y++) {
            for (int x = 0; x < 16; x++) {
                image.setColor(x, y, 0xFFFF0000); // Red color in RGBA format
            }
        }

        NativeImageBackedTexture texture = new NativeImageBackedTexture(image);
        client.getTextureManager().registerTexture(RED_SQUARE_ID, texture);

        AbstractTexture b = client.getTextureManager().getTexture(RED_SQUARE_ID);
    }```
ripe stag
#

I don't know anything about the sprtie system besides how to get sprites from normal resources.

jaunty anchor
untold onyx
#

I already made my item to render like a diamond but my goal is to have a 16x16 NativeImage that is generated at runtime. Is it possible?

jaunty anchor
#

I would think you’d just register it as a texture and then use that?

untold onyx
#

In 1.21 they changed the way it works

#

I want to register it as a sprite

jaunty anchor
#

Oh I’m not sure about 1.21 sorry

#

If you poke around that repo though there’s an example of registering an image as a texture for 1.20, I think it’s in URLTexture or something under utils?

untold onyx
#

But if i register a texture

#

Can i use it dynamically without reloading the game?

jaunty anchor
#

Yeah, texture registering is all dynamic

untold onyx
untold onyx
#

i'll send you the code

#
public FourSidedFurnaceModel() {
        MinecraftClient client = MinecraftClient.getInstance();
        NativeImage image = new NativeImage(NativeImage.Format.RGBA, 16, 16, false);
        for (int y = 0; y < 16; y++) {
            for (int x = 0; x < 16; x++) {
                image.setColor(x, y, 0xFFFF0000); // Red color in RGBA format
            }
        }

        NativeImageBackedTexture texture = new NativeImageBackedTexture(image);
        client.getTextureManager().registerTexture(RED_SQUARE_ID, texture);
        client.getTextureManager().bindTexture(RED_SQUARE_ID);
    }```
jaunty anchor
#

Well I’m not sure what that bindTexture call is doing but I don’t think it would affect how an item looks?

untold onyx
jaunty anchor
untold onyx
jaunty anchor
#

?

untold onyx
# jaunty anchor ?

my goal is for example have an image from the web or something and render an item as that image

#

like an unknown texture

jaunty anchor
untold onyx
#

i read the code but didn't understand the parts i need

jaunty anchor
untold onyx
#

lemme test something

#

i think the makeUnbakedModel function is what i need

jaunty anchor
untold onyx
#

oh lol i didn't notice that this is your code lol

#

why is the inject important?

#

just curious

jaunty anchor
untold onyx
#

if i take the makeUnbakedModel.bake(...) and put it as a return value for my bake class, will it work as well?

untold onyx
#

why did you use hook btw?

jaunty anchor
#

I wanted to change the model on the fly, and forgot custom baking was a thing

untold onyx
#

where is the getItemModel function though?

#

i didn't find it under ItemStack

#

maybe it's because they changed the code in 1.21?

jaunty anchor
#

Maybe, you’re on yarn?

untold onyx
#

how can i change from yarn?

jaunty anchor
#

Then yeah, probably got changed or moved, I asked hakimen to push the 1.21 code, I’ll let you know if he responds

jaunty anchor
#

No yarn is fine it’s what I use too, was just making sure it wasn’t a mapping issue

untold onyx
#

oh i see

#

i'll try porting your code to mine

#

and let you know if any errors occur :)

jaunty anchor
#

Cool gl

untold onyx
#

ty

jaunty anchor
untold onyx
untold onyx
#

@jaunty anchor you know why "import net.minecraft.client.renderer.texture.TextureAtlasSprite;" is missing for me?

jaunty anchor
#

Like the line? Or it can’t find the import? Either way no I don’t

untold onyx
#

this is the only reference i found

jaunty anchor
#

No idea

#

It’s possible hakimen is on mojmaps ?

untold onyx
#

can you ask him?

#

btw @jaunty anchor you know what's this?

#

it's hard to debug like that

jaunty anchor
jaunty anchor
untold onyx
#

it would help me in the future

#

thank you very much!!

#

yeah he's using Mojang's mappings

#

also @jaunty anchor i have an error here - inside the ItemModelGenerator.create function. my debugger not jumping to the next line. it just freezes for some reason.

private JsonUnbakedModel makeUnbakedModel(){
        JsonObject modelJson = new JsonObject();
        modelJson.addProperty("parent", "builtin/generated");
        JsonObject textureList = new JsonObject();
        int count = 0;
        textureList.addProperty("layer" + count, dynamicTexture.toString());
        modelJson.add("textures", textureList);
        // we're just reimplementing the item base model
        modelJson.addProperty("gui_light", "front");
        JsonElement displayObj = JsonParser.parseString("{\"ground\": {\"rotation\": [ 0, 0, 0 ],\"translation\": [ 0, 2, 0],\"scale\":[ 0.5, 0.5, 0.5 ]},\"head\": {\"rotation\": [ 0, 180, 0 ],\"translation\": [ 0, 13, 7],\"scale\":[ 1, 1, 1]},\"thirdperson_righthand\": {\"rotation\": [ 0, 0, 0 ],\"translation\": [ 0, 3, 1 ],\"scale\": [ 0.55, 0.55, 0.55 ]},\"firstperson_righthand\": {\"rotation\": [ 0, -90, 25 ],\"translation\": [ 1.13, 3.2, 1.13],\"scale\": [ 0.68, 0.68, 0.68 ]},\"fixed\": {\"rotation\": [ 0, 180, 0 ],\"scale\": [ 1, 1, 1 ]}}");
        modelJson.add("display", displayObj);
        JsonUnbakedModel model = JsonUnbakedModel.deserialize(modelJson.toString());
        model.setParents((id) -> ModelLoader.GENERATION_MARKER);
        model = ITEM_MODEL_GENERATOR.create(FourSidedFurnaceModel::spriteLoader, model);
        return model;
    }

private static Sprite spriteLoader(SpriteIdentifier spriteId) {
        return spriteId.getSprite();
    }```


this is my code
#

@jaunty anchor seems like it is working but there are 2 problems:

  1. it doesn't recognize textures that i registered using registerTexture, it just renders missingno
  2. it doesn't load the texture at the first load, only when pressing F3 + T. maybe this is because the textures aren't loading or something idk.

i need to find a way to dynamicalyl put the texture inside a sprite, even a dynamic one and load it to the game. the guy from the video i sent yesterday is probably doing the same - using NativeImage and registering the sprite via the texture. you know maybe how can i map an image that residing for example in my desktop to a sprite and then load it as the item texture? sorry if i'm disturbing you

jaunty anchor
untold onyx
#

how can i check?

#

like i'm registering the texture now in the bake function

#

and then making the fake json model

untold onyx
#

I will try hooking the render model and make the unbaked method every tick maybe it would reload the model

#

But i have another issue

#

How can i register the sprite on the fly

untold onyx
#

@jaunty anchor i looked at your code and found URLSprite. I think this is exactly what i need. How can i use it to render the texture dynamically? Sorry if i’m asking alot, i’m kinda new to this🥲

jaunty anchor
untold onyx
#

so the 2 files you sent above from your code does exactly that?

#

i didn't understand how you knew all the coords and such to make it render

#

wait i'll ss

#

what is this renderdetailtexture file?

#

how did you know what vertex to input to the buffer?

jaunty anchor
#

It renders a texture in the corner of the item

#

It should only be in the gui though, not when it’s in your hand. Doesn’t sound like it’s what you want

untold onyx
#

i'll just try to mimic your code it sounds more reliable because you said it renders on the fly and mine only bakes on load and after each reload

#

will update

untold onyx
#

@jaunty anchor what is that?

public static final Codec<Spritelike> CODEC = TYPE_CODEC.dispatch("type", Spritelike::getType, SpritelikeType::getCodec);```

Spritelike.java
#

SpritelikeType::getCodec is the problem

#

nvm seems like chatgpt was able to fix that lol

jaunty anchor
untold onyx
#

which version did you build this on?

jaunty anchor
#

The codec is only used for serialization. So only important if you’re sending sprite data from server to client or other way around

#

1.20

untold onyx
#

oh i see

#

i'll update you if it crashes or another error occurs

untold onyx
#

@jaunty anchor how did you add the common folder to your projects?

untold onyx
#

my sub project doesn't recognize my root gradle.properties for some reason

#

i can send you in dms my build.gradle files because here i can't for some reason

jaunty anchor
untold onyx
#

like a bridge between the client and main

jaunty anchor
#

That’s not what that means

untold onyx
jaunty anchor
#

The common folder is because this mod is for forge and fabric

untold onyx
#

ohhhh

#

so how can i use the files in both the mod and client files?

#

because i need to make the item in the main and not client, right?

jaunty anchor
#

Rendering stuff should usually be only on the client

untold onyx
jaunty anchor
#

And you don’t have a strict source set divide so it doesn’t really matter anyways, just don’t call mc client stuff on the server and you’ll probably be fine

jaunty anchor
untold onyx
#

this sounds like the quickest way

jaunty anchor
#

Probably idk how your project is setup

untold onyx
#

@jaunty anchor

jaunty anchor
#

Oh so you do have a strict client common separation

untold onyx
#

when i click this it removes the red error but doesn't let me launch the game

#

and when i rebuild the gradle it just becomes red again

jaunty anchor
#

Then move that class into main

untold onyx
#

i'll just copy it

jaunty anchor
#

Client depends on main

#

I assume

#

Otherwise you have greater issues

jaunty anchor
untold onyx
#

but

#

it didn't work because the class in the photo uses client stuff

#

can't i register the item on the client side?

jaunty anchor
#

No, I suggest heading over to the fabric wiki and reading up on client server separation

untold onyx
#

how did it work on your project but doesn't on mine?

jaunty anchor
#

Because I don’t have a common/client source split

untold onyx
jaunty anchor
#

Not necessarily

#

The split is safer, the issues you’re hitting are that you don’t understand client vs server. Without the split you’d just hit issues later when the mod is actually in use

untold onyx
#

oh i see

#

so how can i get it to work?

#

because now it doesn't work in your model you just extend and override but i can't override that function because it contains client code

jaunty anchor
#

I don’t have a solution off the top of my head, I guess just move the interface off of the item and add a different model of calling functions for an item that’s purely client side

untold onyx
#

@jaunty anchor what is this?

#

do i really need it?

#

nvm i think i do

#

mmm

#

i'll try something

jaunty anchor
#

It depends, like I said you need some way to get the DynamicModelOverride out of the item stack, it doesn’t have to be via the item class itself necessarily

untold onyx
#

i see

#

i'm just doing new DynamicModelOverride

#

but what is fromJson? should it be true or false if i load the textures dynamically

#

nvm i think false

#

@jaunty anchor okay so i am in the game but i don't see the prints. why? did i do something wrong? should i register the injector somewhere?

#

nvm i did it :D
added it to the json file

#

now it renders the diamond :D i can't believe it worked lol

#

now just to find a way to register the texture dynamically😅

#

@jaunty anchor how can i use the URLSprite to draw the item?

jaunty anchor
#

Give it a url

#

Ask it for the texture and use that in the model override

#

Or something like that probably

untold onyx
#

my override now is the dynamicmodeloverride

#

oh like

#

call this

jaunty anchor
#

Yeah

untold onyx
#

like i think it loaded

#

wait i'll ss the code

#
package com.example.mixin;

import com.example.clientmisc.DynamicModelOverride;
import com.example.interfaces.IDynamicModelItem;
import com.example.utils.URLSprite;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.client.render.item.ItemModels;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.item.ItemStack;

import java.rmi.registry.Registry;
import java.util.Arrays;
import java.util.List;

@Mixin(ItemModels.class)
public class DynamicModelSwapper {
    Identifier itemIdentifier = Identifier.of("infinitecraft", "chatgpt");

    @Shadow
    @Final
    private BakedModelManager modelManager;

    @Inject(method= "getModel(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/client/render/model/BakedModel;",
        at=@At("HEAD"), cancellable=true)
    private void getDynamicModel(ItemStack stack, CallbackInfoReturnable<BakedModel> info){
        if(Registries.ITEM.getId(stack.getItem()).equals(itemIdentifier)) {
            URLSprite urlSprite = new URLSprite("https://cdn.sstatic.net/Img/home/illo-home-hero.png?v=4718e8f857c5", Identifier.of("infinitecraft", "bibi"));
            DynamicModelOverride override = new DynamicModelOverride(Identifier.of("infinitecraft", "chatgpt"), false, List.of(urlSprite.getTextureId()));
            BakedModel model = override.getBakedModel(modelManager);
            if(model != null){
                info.setReturnValue(model);
            }
        }
    }
}```
#

maybe i did something wrong?

untold onyx
#

maybe this is why?

#

nvm found it but it still doesn't render

jaunty anchor
#

Wdym by doesn’t render? Just gives a missing texture ?

#

Oh it’s probably baking the model before the texture is actually prepared

#

Actually I don’t remember if that iteration of url textures was blocking or not

untold onyx
untold onyx
#

i think it's blocking which is good

#

so

#

what it does is

#

if there is a texture

#

return it

#

else

#

bake it

#

and then put it in the texture map

#

and

#

return it

#

but it's still gives missingno like something's not right

jaunty anchor
untold onyx
#

i put it in the loop

#

but in some point it should've returned the id

#

like

#

it returns

#

but it doesn't exist in the sprite i think?

jaunty anchor
#

It returns a blank ID until the texture actually gets fetched and registered

untold onyx
#

so how can i wait for it to completely register

#

like it registers it only once so i think at some point in the loop i should see the image as an item

#

but this is not the case

#
public static boolean hasTexture(Identifier textureId){
        Identifier resourceId = Identifier.of(textureId.getNamespace(), "textures/" + textureId.getPath() + ".png");
        Optional<AbstractTexture> maybeTexture = Optional.ofNullable(MinecraftClient.getInstance().getTextureManager().getTexture(resourceId));
        return maybeTexture.isPresent();
    }```
#

i changed maybeTexture to actually look for the texture

#

and i think it found

#

it doesnt't find at the first loop but it does at the second and so on

#

@jaunty anchor

#

it looks like it is registered so i don't understand why it does that😅

#

omg i'm dumb

#

it threw errors to the console

#

oh nvm it stops after a while meaning the texture is present

#

but this is weird

jaunty anchor
#

lol

#

my guess is still that you're baking the model before the texture is actually ready

untold onyx
#

but this is weird

#

i only see this error once

#

and then it's gone

#

and it bakes the model in loops in the hook so i don't think it should be a problem when the texture got registered

#

because at some point it gets registered

#

and it even finds it in the texturemanager

jaunty anchor
#

hm

#

do you have your code pushed anywhere ?

untold onyx
#

wait a few mins

untold onyx
#

here :)

jaunty anchor
#

check that !urlSprite.getTextureId().equals(new Identifier(""))

#

before making the override

#

DynamicModelOverride caches the model made by textures based on the model id you give it. so it's not updating when the textures change

untold onyx
#

ohh

#

it doesn't update at all?

#

if the texture is missingno

#

lemme see

#

i did that

untold onyx
#

but now we know for sure that the texture is there

jaunty anchor
#

push again

untold onyx
untold onyx
jaunty anchor
#

anything in logs?

untold onyx
#

only once

jaunty anchor
#

why did you change getResourceManager to getTextureManager

untold onyx
#

i now reverted

#

will push

#

pushed

untold onyx
jaunty anchor
#

does it still give missing texture when you run it?

untold onyx
#

it gives me a completely invisible item

#

modelless

jaunty anchor
#

any error logs ?

untold onyx
untold onyx
jaunty anchor
#

try a 16x16 image

untold onyx
#

mm wait

untold onyx
#

do you happen to have one?

untold onyx
#

ty let's see

jaunty anchor
#

yeah

untold onyx
jaunty anchor
#

unfortunate

untold onyx
#

yep

jaunty anchor
#

i'd say stick a bunch of prints everywhere, make sure it's actually running the .getBakedModel() or whatever

#

or like, entering that if statement

untold onyx
#

lemme see

#

mm

#

you wouldn't believe it

jaunty anchor
#

yeah that makes sense

#

so it's not finding the textures

untold onyx
#

seems like it

#

you know why?

#

did it work for you in 1.20?

jaunty anchor
#

i never put the url loader with the model maker

#

give me a sec

untold onyx
#

okay

#

@jaunty anchor you know what's weird

#

i gave it an id of a texture that i know exists

#

but it still didn't find it

jaunty anchor
#

what id did you give it ?

untold onyx
#

oh forgot /item maybe

jaunty anchor
#

what id exactly

untold onyx
#

now

#

but before it was chatgpt no item

#

yep it didn't work either

jaunty anchor
#

print what the actual spriteId it returns is when it finds it

untold onyx
#

now it doesn't do nothing lol

#

lemme see something

#

oh nvm

#

wait

#

changed it to minecraft diamond let's see

#

@jaunty anchor

jaunty anchor
#

which did you change ?

untold onyx
jaunty anchor
#

that does basically nothing

#

i mean it's not nothing but it's just a unique id

untold onyx
#

yes

#

it finds the id

#

so

#

why doesn't it find it?

#

it does find it in getTextureManager but idk

#

it threw errors there

jaunty anchor
#

hm i guess yeah it might just never find it in resources

untold onyx
jaunty anchor
#

yeah

#

ok so then you might need to rewrite some of the model baking to use it as a texture rather than a texture resource

untold onyx
# jaunty anchor yeah

when i pass it the infinitecraft:item/chatgpt arg it works but it is a texture image i put inside

untold onyx
jaunty anchor
#

right, that's in your assets

untold onyx
#

yep

#

i don't know much about vertexes and so so

jaunty anchor
#

yeah, so i think the issue is that the textures it's expecting are like infinitecraft:item/chatgpt rather than an actual texture id like the sprite url returns

#

i forgot they were different sorry

#

i'm sure you can poke at it and get it to work, but i haven't done that before i don't think

jaunty anchor
#

idk probably not

untold onyx
#

do i need to know vertex and uv?

jaunty anchor
#

probably not

untold onyx
#

i see

#

Subscribe to build the Blucubed castle! 🏰

✨ We’re working on making the mod playable! Join to stay in the loop: https://discord.gg/TveN5TTE7J

What would you try to craft? 🤔

Aseprite (pixel art program) https://www.aseprite.org/
PixelLab (AI art extension) https://www.pixellab.ai/

This video is largely about using AI, and specifically AI art....

▶ Play video
jaunty anchor
#

oh actually i'm not sure it's possible to do it with this method

jaunty anchor
#

i forgot that it just constructs a json thing and then bakes that. i don't think the json can accept dynamic textures probably

#

there's probably some way to patch it all together though, i just don't know it and don't really want to spend the time looking for it rn

untold onyx
jaunty anchor
#

well you'd probably want to bake it yourself

#

and like i said before, i don't have much experience with actually making baked models

untold onyx
jaunty anchor
#

nope

untold onyx
#

mmm

#

i didn't think it would be that hard tbh

#

omg

#

i found the source

#

of the mod in the video

#

i'll take a look

#

i think it's here

#

luckily he's using fabric

#

tomorrow i'd test it

untold onyx
jaunty anchor
#

What’s that

#

Also yay, I’d love to see it

untold onyx
# jaunty anchor What’s that

in your makeUnbakedModel you have this

JsonElement displayObj = JsonParser.parseString("{\"ground\": {\"rotation\": [ 0, 0, 0 ],\"translation\": [ 0, 2, 0],\"scale\":[ 0.5, 0.5, 0.5 ]},\"head\": {\"rotation\": [ 0, 180, 0 ],\"translation\": [ 0, 13, 7],\"scale\":[ 1, 1, 1]},\"thirdperson_righthand\": {\"rotation\": [ 0, 0, 0 ],\"translation\": [ 0, 3, 1 ],\"scale\": [ 0.55, 0.55, 0.55 ]},\"firstperson_righthand\": {\"rotation\": [ 0, -90, 25 ],\"translation\": [ 1.13, 3.2, 1.13],\"scale\": [ 0.68, 0.68, 0.68 ]},\"fixed\": {\"rotation\": [ 0, 180, 0 ],\"scale\": [ 1, 1, 1 ]}}");```
untold onyx
untold onyx
jaunty anchor
#

Pulled them from the item model json I believe

untold onyx
jaunty anchor
#

Or maybe from somewhere else, I forget

jaunty anchor
#

Or it was in code somewhere, I don’t remember

untold onyx
#

but it's different lol

#

i looked at the one of diamond

#

but i didn't find any

jaunty anchor
#

Well yeah because those extend the base

#

Look for item/generated I think

untold onyx
#

mm okay

#

wait

#

found itt

#

i didn't know there is a parent lol

untold onyx
#
@Override
    public void emitItemQuads(ItemStack itemStack, Supplier<Random> supplier, RenderContext renderContext) {
        Renderer renderer = RendererAccess.INSTANCE.getRenderer();
        MeshBuilder builder = renderer.meshBuilder();
        QuadEmitter emitter = builder.getEmitter();

        NativeImage nativeImage = new NativeImage(16, 16, true);

        // Fill the image with a color (e.g., red)
        for (int x = 0; x < 16; x++) {
            for (int y = 0; y < 16; y++) {
                nativeImage.setColor(x, y, 0x694200); // ARGB format (alpha, red, green, blue)
            }
        }

        final int width = nativeImage.getHeight();
        final int height = nativeImage.getWidth();

        int[] pixelGrid = new int[width * height];

        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                pixelGrid[y * width + x] = nativeImage.getColor(x, y);
            }
        }

        float px = 0.0625f;

        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                final int color = pixelGrid[(y * width) + x]; // to index the array: multiply y by the stride (width) and add x
                if (color == -1) continue;

                for (Direction direction : Direction.values()) {
                    if (direction.equals(Direction.NORTH)) {
                        emitter.square(direction, 1.0f - (x + 1) * px, 1.0f - (y + 1) * px, 1.0f - x * px, 1.0f - y * px, (15 * px) / 2);
                    } else if (direction.equals(Direction.SOUTH)) {
                        emitter.square(direction, x * px, 1.0f - (y + 1) * px, (x + 1) * px, 1.0f - y * px, (1.0f - px) / 2);
                    } else if (direction.equals(Direction.EAST)) {
                        if (x != (width - 1) && pixelGrid[(y * width) + (x + 1)] != -1) continue; // cull face
                        emitter.square(direction, (1.0f - px) / 2, 1.0f - (y + 1) * px, (1.0f + px) / 2, 1.0f - y * px, 1.0f - (x + 1) * px);
                    } else if (direction.equals(Direction.WEST)) {
                        if (x != 0 && pixelGrid[(y * width) + (x - 1)] != -1) continue; // cull face
                        emitter.square(direction, (1.0f - px) / 2, 1.0f - (y + 1) * px, (1.0f + px) / 2, 1.0f - y * px, x * px);
                    } else if (direction.equals(Direction.UP)) {
                        if (y != 0 && pixelGrid[((y - 1) * width) + x] != -1) continue; // cull face
                        emitter.square(direction, x * px, (1.0f - px) / 2, (x + 1) * px, (1.0f + px) / 2, y * px);
                    } else if (direction.equals(Direction.DOWN)) {
                        if (y != (height - 1) && pixelGrid[((y + 1) * width) + x] != -1) continue; // cull face
                        emitter.square(direction, x * px, (1.0f - px) / 2, (x + 1) * px, (1.0f + px) / 2, 1.0f - (y + 1) * px);
                    }
                    
                    emitter.spriteBake(sprite, MutableQuadView.BAKE_LOCK_UV);
                    emitter.color((255 << 24) | color, (255 << 24) | color, (255 << 24) | color, (255 << 24) | color);
                    emitter.emit();
                }
            }
        }

        mesh = builder.build();
        mesh.outputTo(renderContext.getEmitter());
    }```
#

@jaunty anchor this is the code the guy that made the infinite items mod used to fill the colors in their appropriate pixels. i changed it to use native image and it works. now how did he know what the formula is for each direction?

jaunty anchor
#

I don’t know

untold onyx
#

it looks really complicated