Jump to content

Recommended Posts

Posted

This is what I am trying to accomplish:

WlifahP.png

As you can see, the digits only show in the inventory view, which is what I want. I accomplish this by using a combination of .json item layers and an IPerspectiveAwareModel.

 

Relevant .json / code:

 

// layer_00 json:
{
    "parent": "zeldaswordskills:item/bomb_bag",
    "textures": {
        // layer0 is same as parent
        "layer1": "zeldaswordskills:items/digits/0",  // ones place - these are actual separate textures, obviously
        "layer2": "zeldaswordskills:items/digits/00" // tens place
    }
}

// Perspective-aware model which was constructed with the base model (no extra layers) and a dynamically 
// determined layer model based on the current bombs held, e.g. base_model_layer_00
@Override
public Pair<IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType) {
switch (cameraTransformType) {
case FIRST_PERSON:
	RenderItem.applyVanillaTransform(baseModel.getItemCameraTransforms().firstPerson);
	return Pair.of(baseModel, null);
case GUI: // only this one returns the layered model
	RenderItem.applyVanillaTransform(layeredModel.getItemCameraTransforms().gui);
	return Pair.of(layeredModel, null);
case HEAD:
	RenderItem.applyVanillaTransform(baseModel.getItemCameraTransforms().head);
	return Pair.of(baseModel, null);
case THIRD_PERSON:
	RenderItem.applyVanillaTransform(baseModel.getItemCameraTransforms().thirdPerson);
	return Pair.of(baseModel, null);
default:
	break;
}
return Pair.of(baseModel, null);
}

 

That all works fine.

 

My question is: how can I do this without having to create one .json model for every single possible number of items held, i.e. 00-99 ?

 

I've looked at the various options available, and from what I can see none of them are aware of which layer is being rendered at any given point; if I had access to the current layer (and probably also the current camera transform), I could use that to directly render the digits during the second / third render pass, and leave the first pass as is.

 

Is direct manipulation of the BakedQuads (as shown in TGG's chessboard item tutorial) the only way to do this? If I do it that way, should I still register each of the digit textures, or is it fine to use them directly?

Posted

In my opinion your best shot is to add 4 BakedQuads (or edit existing ones, explained in edit) like the chessboard does.

4 Quads as in: 1 and 2 digit on front and on back of item.

 

As for textures - you have 2 options:

Register 10 textures (atlas sprite) of every digit and use them to make BakedQuads OR use vanilla's Fonts - you can get number texture and draw it as Quad.

 

Problem with layers is the fact that one item.json can have ONLY 5 layers (0-4). That is hardcoded. There might be possibility of editing it tho.

 

"I've looked at the various options available, and from what I can see none of them are aware of which layer is being rendered at any given point"

They kinda do. Every BakedQuad has tintIndex - that is your renderPass

quad.getTintIndex() is the layerX used to bake quad from item.json. (I think this is what you are after)

Sadly as mentioned before - you can only have 5 layers in item.

 

EDIT

I got lost in writing this. More clear answer - in getGeneralQuads() you can iterate through "baseItemModel.getGeneralQuads()" and check if BakedQuad has tint index of your layer (1st or 2nd digit). Then you can grab that Quad and change its texture.

 

EDIT 2

Might be useful: front and back face of item is NORTH and SOUTH. (seems like always)

1.7.10 is no longer supported by forge, you are on your own.

Posted

I ended up ignoring the layers altogether and going with TGG's wonderfully magical method.

 

Only step I had to take was to subscribe to TextureStitchEvent.Pre and make sure my digit textures got added to the sprite sheet, then return a new model for the GUI view with the number of bombs held set during handleItemState.

 

I was kind of lazy before and actually made 30 textures for the digits, one for each 0-9 for each of three place values, where the digit was offset internally within the texture. It was trivial using TGG's method to cut that down to one texture per digit and simply offset it by an amount based on its place, and now I can even trim the texture sizes down from 16x16 to their actual size (5x7).

 

EDIT: Actually, Minecraft won't let me trim the textures down, complaining about a 'broken aspect ratio' <sigh>. Doesn't matter, though, as I still cut out 20 redundant textures.

Posted

Hey, this might be very lazy of me, but belive me I tried.

 

Could you please share your repo/code of your TextureStitchEvent.Pre.

I want to know how to add texture into sheet.

Also - how to find it (the texture) later - talking ab out getting it.

 

I'd really appreciate sharing (can be via priv msg if you want).

 

I really don't know what is what in those atlases stuff and whatever else there it.

 

Thanks.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Sure, no problem ;)

@SubscribeEvent
public void onStitchTexture(TextureStitchEvent.Pre event) {
// My textures are in a sub-directory of the items textures directory
// but you could do the same for blocks or any other directory within your resources/.../textures location
String digit = "items/digits/";
for (int i = 0; i < 9; ++i) {
	event.map.registerSprite(new ResourceLocation(ModInfo.ID, digit + i));
}
}

// Then to retrieve the texture for "0":
String location = ModInfo.ID + ":items/digits/0";
TextureAtlasSprite sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location);

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 need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

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