Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I want to in-code color my block. I am using this code:

@Override
public int getRenderColor(IBlockState state) {
	return new Color(0, 0, 255).getRGB();
}

@Override
public int getBlockColor() {
	return new Color(0, 0, 255).getRGB();
}

@Override
public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) {
	return new Color(0, 0, 255).getRGB();
}

 

but it only colors the particles. How can i also color the block itself.

btw.: my block is

EnumWorldBlockLayer.TRANSLUCENT

 

 

EDIT: Solution:

package com.laser.tile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.biome.BiomeColorHelper;
import net.minecraftforge.fml.relauncher.*;

@SideOnly(Side.CLIENT)
public class ModColorHandler {
private static final Minecraft minecraft = Minecraft.getMinecraft();

public static void registerColorHandlers() {
	final BlockColors blockColors = minecraft.getBlockColors();
	registerBlockColorHandlers(blockColors);
}

private static void registerBlockColorHandlers(final BlockColors blockColors) {
	final IBlockColor laserColorHandler = (state, blockAccess, pos, tintIndex) -> {
		if (blockAccess != null && pos != null) {
			TileLaserX laser = (TileLaserX) (blockAccess.getBlockState(pos).getBlock());
			return laser.getColor();
		}

		return 16777215;
	};

//		if(laserColorHandler != null && ModBlocks.laser_x != null){
	blockColors.registerBlockColorHandler(laserColorHandler, ModBlocks.laser_x);
//		}
}
}

call "registerBlockColorHandlers" in init method!

Your block's model needs to specify a tint index for each face it wants coloured. See the wiki for more details or the grass model for an example.

 

I'd also suggest updating to 1.9.4 or at least 1.8.9. In 1.9+, these methods have been replaced by the

IBlockColor

/

IItemColor

interfaces.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

I have changed my mod to 1.9.4, but now my block isn't changing its color :(

So how would i do the same in 1.9.4?

I tried to use

IBlockColor.colorMultiplier

but that doesn't affect my block color.

  • Author

public TileLaserX(Material materialIn) {
	super(materialIn);
	this.setLightOpacity(0);
	this.setLightLevel(0.5F);
	this.useNeighborBrightness = true;
}

@Override
public int colorMultiplier(IBlockState statei, IBlockAccess worldIni, BlockPos posi, int tintIndexi) {
	int col = new Color(0, 0, 255).getRGB();
	Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler((state, access, pos, tintIndex) -> col, ModBlocks.laser_x);
	return col;
}

constructor and colorMultiplier method.

 

and these are my JSONs:

{
    "textures": {
        "particle": "#clear"
    },
    "elements": [
        {   "from": [ 0, 6, 6 ],
            "to": [ 16, 10, 10 ],
            "faces": {
                "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "cullface": "down", "tintindex": 1 },
                "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 1 },
                "north": { "uv": [ 0, 8, 16, 16 ], "texture": "#all", "cullface": "north", "tintindex": 1 },
                "south": { "uv": [ 0, 8, 16, 16 ], "texture": "#all", "cullface": "south", "tintindex": 1 },
                "west":  { "uv": [ 0, 8, 16, 16 ], "texture": "#all", "cullface": "west", "tintindex": 1 },
                "east":  { "uv": [ 0, 8, 16, 16 ], "texture": "#all", "cullface": "east", "tintindex": 1 }
            }
        }
    ]
}

 

{
"parent": "lasermod:block/ray",
"textures":{
	"all": "lasermod:blocks/laser",
	"clear": "lasermod:blocks/clear"
}
}

 

{
"variants": {
	"normal": {"model": "lasermod:laser"}
}
}

  • Author

I looked through "BlockLeaves" but i didn't find anything about color.

Where exactly do i have to do the color-registry stuff, or where can i find the colorisation?

  • Author

I made a color registerer:

package com.laser.tile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.biome.BiomeColorHelper;
import net.minecraftforge.fml.relauncher.*;

@SideOnly(Side.CLIENT)
public class ModColorHandler {
private static final Minecraft minecraft = Minecraft.getMinecraft();

public static void registerColorHandlers() {
	final BlockColors blockColors = minecraft.getBlockColors();
	registerBlockColorHandlers(blockColors);
}

private static void registerBlockColorHandlers(final BlockColors blockColors) {
	final IBlockColor laserColorHandler = (state, blockAccess, pos, tintIndex) -> {
		if (blockAccess != null && pos != null) {
			TileLaserX laser = (TileLaserX) (blockAccess.getBlockState(pos).getBlock());
			return laser.getColor();
		}

		return 16777215;
	};

	if(laserColorHandler != null && ModBlocks.laser_x != null){
		blockColors.registerBlockColorHandler(laserColorHandler, ModBlocks.laser_x);
	}
}
}

 

but when i call it in the preinit method, then i get a nullpointer exception.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.