Jump to content

Recommended Posts

Posted (edited)

Hi,

 

I'm trying to dynamically color blocks (Metal Blocks).

It works fine for items (ingots, dust, etc) but it sadly doesn't work for blocks.

I'm having these events:

    @SubscribeEvent
    public static void colorItems(final ColorHandlerEvent.Item e) {
        ItemColors colors = e.getItemColors();

        ModuleCore.materials.forEach((materialName, materialDefinition) -> {
            materialDefinition.parts.forEach((part, item) -> {
                if(item instanceof BaseItem) {
                    Item i = (Item) item;

                    // This works as it's supposed to be.
                    colors.register((stack, tintIndex) -> materialDefinition.color.getRGB(), i);
                }
                else if(item instanceof MaterialBlock) {
                    Item i = ((MaterialBlock) item).item;

                    // These two were tests to see if I had to color the Blocks items instead of the block. But it didn't do anything.
                    colors.register((stack, tintIndex) -> materialDefinition.color.getRGB(), Item.getItemFromBlock((MaterialBlock) item));
                    colors.register((stack, tintIndex) -> materialDefinition.color.getRGB(), i);
                }
            });
        });
    }

    @SubscribeEvent
    public static void colorBlocks(final ColorHandlerEvent.Block e) {
        BlockColors colors = e.getBlockColors();

        ModuleCore.materials.forEach((materialName, materialDefinition) -> {
            if(materialDefinition.parts.containsKey(Part.BLOCK)) {
                // The code is executed but the block isn't colored.
                colors.register((state, worldIn, pos, tintIndex) -> materialDefinition.color.getRGB(), (Block) materialDefinition.parts.get(Part.BLOCK));
            }
        });
    }

When I add a Logger.info in the if-condition I can see that the method is called and executed for every material I have defined to have a Block.

The coloring of the BaseItems works fine, but all tries to color the Block doesn't seem to work.

 

I looked at the Documentation (which seems to be outdated),

I found this forum thread

I tried several other approaches, but all tries didn't seem to work.

I tried to use an alpha of 0 instead of 255, but it didn't had any influence too.

 

I can see in the Debugger that the colors are being a added (See attached screenshot of the Debugging Information)

 

Does anyone know what am I doing wrong and what do I have to change?

 

 

You can see the complete Code here (https://github.com/IcedReaper/IcedResources/blob/main/src/main/java/com/icedreaper/icedresources/handlers/ColorEventHandler.java) (I currently have the code to color the blocks commented out and instead implemented a way to create new colored images for the blocks, but this shouldn't be the way I'd imagine ;))

 

Thanks in Advance,

IcedReaper

grafik.png

Edited by IcedReaper
marked as solved
Posted

That's simple enough. The models you are registering doesn't have an assigned tint index for the specific face. For each face you want to be tinted, you need to set the tintIndex to the specific index being checked within the event itself (or any number if you're not checking for a specific one, most people go with 0). cube_all does not have a tint index specified for any of it's faces.

Posted

Thanks for the hint.

As I'm not that experienced with the model definitions I had to look some up, but I got it to work. :)

 

I now use the following model (if someone has the same problem)

{
  "parent": "block/block",
  "textures": {
    "all": "icedresources:blocks/base_block"
  },
  "elements": [
    {
      "from": [ 0, 0, 0 ],
      "to":   [ 16, 16, 16 ],
      "faces": {
        "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0 },
        "east":  { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0 },
        "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0 },
        "west":  { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0 },
        "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0 },
        "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0 }
      }
    }
  ]
}

 

Just change the block Texture and you can use it as a template/parent in your flat blocks you want to tint.

 

And your specific block.json files can then be as slim as:

{
  "parent": "icedresources:block/base_block"
}

 

  • Like 1

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

    • Is there a fix for this issue? I have tried reinstalling OpenAL.dll, switching Java versions, and even muting my game when it launched, but all of these attempts have resulted in my game crashing nonetheless. I have been dealing with this issue for approximately a week straight. I have not changed any sound settings, so I am very confused. Full Code: https://gnomebot.dev/paste/mclogs/beEBzpm "4/16/2025 12:16:30 AM 1000 Error Faulting application name: javaw.exe, version: **.**.**.**, time stamp: 23 0xd75c3041 24 Faulting module name: OpenAL.dll, version: **.**.**.**, time stamp: 0x647635a125 Exception code: 0xc0000409 26 Fault offset: 0x00000000000a2b05 27 Faulting process id: 0x10A0 28 Faulting application start time: 0x1DBAE81D04A6F2F 29 Faulting application path: C:\Users\********\curseforge\minecraft\Install\java30 \java-runtime-delta\bin\javaw.exe 31 Faulting module path: C:\Users\********\curseforge\minecraft\Install\natives\n32 eoforge-21.1.148\OpenAL.dll 33 Report Id: 28552180-f359-40cc-adeb-08dada7e99d8 34 Faulting package full name: 35 Faulting package-relative application ID:" Any sort of insight would be greatly appreciated, it's giving me a headache.
    • I'm new to this, if that wasn't obvious. My friend and I are trying to make a modpack for 1.19.2. I've made a modpack previously with 0 issues before and many of the same mods. However, I can't seem to find the issue when trying to load up his new modpack.   Any help would be greatly appreciated.
    • Im trying to make a customized modpack for just myself using the atm9 modpack as a base. It was working till recently, when curseforge force updated all the mods in the pack. Currently every time I get to the main menu I try and create a world in single player and it just says saving world. then generates a crash report.    Crash Report: https://pastebin.com/xXESPfJs   Latest Log Part 1: https://pastebin.com/Cb2VpUyr  Part 2: https://pastebin.com/9SWVn4Dx
    • Okay, for him the config file looked like this: flywheel-client.toml: #Select the backend to use. Set to "DEFAULT" to let Flywheel decide. backend = "DEFAULT" #Enable or disable instance update limiting with distance. limitUpdates = true #The number of worker threads to use. Set to -1 to let Flywheel decide. Set to 0 to disable parallelism. Requires a game restart to take effect. #Range: -1 ~ 12 workerThreads = -1 #Config options for Flywheel's built-in backends. [flw_backends]     #How smooth Flywheel's shader-based lighting should be. May have a large performance impact.     #Allowed Values: FLAT, TRI_LINEAR, SMOOTH, SMOOTH_INNER_FACE_CORRECTED     lightSmoothness = "SMOOTH" There was no "INSTANCING", so we changed "DEFAULT" to "OFF", but this didn't help. Changing it to "INSTANCING" didn't work as well.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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