Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED][1.16.3] Problems with coloring Blocks
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
IcedReaper

[SOLVED][1.16.3] Problems with coloring Blocks

By IcedReaper, October 24, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

IcedReaper    0

IcedReaper

IcedReaper    0

  • Tree Puncher
  • IcedReaper
  • Members
  • 0
  • 5 posts
Posted October 24, 2020 (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 October 25, 2020 by IcedReaper
marked as solved
  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    161

ChampionAsh5357

ChampionAsh5357    161

  • World Shaper
  • ChampionAsh5357
  • Members
  • 161
  • 1021 posts
Posted October 25, 2020

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.

  • Quote

Share this post


Link to post
Share on other sites

IcedReaper    0

IcedReaper

IcedReaper    0

  • Tree Puncher
  • IcedReaper
  • Members
  • 0
  • 5 posts
Posted October 25, 2020

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"
}

 

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Solarient
      GUIs

      By Solarient · Posted 4 minutes ago

      Ah. Thank you!
    • Draco18s
      [1.16.5] Help with custom Glass Block

      By Draco18s · Posted 32 minutes ago

      You do know what that returned int does, right?
    • Nitrix
      Forge dont want make any profile

      By Nitrix · Posted 42 minutes ago

      Comodo  
    • CptPICHU
      Modpack Server always kicking players

      By CptPICHU · Posted 1 hour ago

      Additional info:   https://pastebin.com/dGKb70Be   This might give some more info. Its the Minecraft Log itself.
    • diesieben07
      Printing the in_open_water parameter to Debug (F3) screen

      By diesieben07 · Posted 1 hour ago

      This is not ForgeAPI. This is decompiled Mojang code, as such documentation will be lackluster. You need to look at the source code, in particular func_234638_a_.
  • Topics

    • Solarient
      2
      GUIs

      By Solarient
      Started 9 hours ago

    • Luis_ST
      3
      [1.16.5] Help with custom Glass Block

      By Luis_ST
      Started Friday at 07:35 AM

    • Nitrix
      5
      Forge dont want make any profile

      By Nitrix
      Started Saturday at 06:53 PM

    • CptPICHU
      1
      Modpack Server always kicking players

      By CptPICHU
      Started 2 hours ago

    • Frozen Storm
      3
      Printing the in_open_water parameter to Debug (F3) screen

      By Frozen Storm
      Started 18 hours ago

  • Who's Online (See full list)

    • Alpvax
    • Bluperman949
    • Solarient
    • okurkova_omacka
    • CookieLukas
    • CptPICHU
    • vemerion
    • pupymk1
    • 3brazyy
    • KeksNinja
    • TheidenHD
    • LucyHonna
    • MrDuck20
    • vilnesjanicke@gmail.com
    • Frozen Storm
    • nightblyde
    • ChampionAsh5357
    • elite_mlgbro1
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED][1.16.3] Problems with coloring Blocks
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community