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

Hello,

 

I am currently trying to color different Items using the same base texture and getColorFromItemStack.

My items register fine but are not colored in my inventory or in the world when I drop them.

 

Code for Item class

package com.jigeneagle.fentonindustries.items;

import com.jigeneagle.fentonindustries.Main;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class FIItem extends Item {

protected String sharedName;
protected boolean colored = false;
protected int sharedHexColor;

public FIItem(String registryName, CreativeTabs tab) {

	// Set Registry Data for Item
	this.sharedName = registryName;
	this.setRegistryName(sharedName);
	this.setUnlocalizedName(this.getRegistryName().toString());
	this.setCreativeTab(tab);
}

public FIItem(String registryName, CreativeTabs tab, int hexColor) {

	// Set Registry Data for Colored Item
	this.sharedName = registryName;
	this.setRegistryName(sharedName);
	this.setUnlocalizedName(this.getRegistryName().toString());
	this.setCreativeTab(tab);
	this.colored = true;
	this.sharedHexColor = hexColor;
}

public void registerItemModel() {
	Main.proxy.registerItemRenderer(this, 0, sharedName);
}

// "Lets just run the colors across the bottom of the screen while we get started."
public boolean hasColor(ItemStack itemStack) {
        return colored;
    }

@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack itemStack, int renderPass) {
	return sharedHexColor;
}
}

 

 

Code for Items class

package com.jigeneagle.fentonindustries.items;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class FIItems {

public static FIItem dustCopper;

public static void initItems() {
	dustCopper = register(new FIItem("dustCopper", CreativeTabs.BUILDING_BLOCKS, 0xB87333));
}

private static <T extends Item> T register(T item) {
	GameRegistry.register(item);
	((FIItem)item).registerItemModel();
	return item;
}
}

 

My plan is to simply pass a hexColor when I want to register an item with a color multiplier.

If an item doesn't need a color multiplied over it, I simply leave off the hexColor.

 

Is this an issue with how I am storing and passing the hexidecimal? I don't often use them.

 

If I am heading down the wrong path, what is the correct way to implement items with a hexColor multiplied over them?

sharedHexColor

needs to be white, not black, by default for this to work.  Right now if you don't pass a color the integer's default value of 0 is used.  That's 0x000000 which is black.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

You have various colour-related methods in your

FIItem

class, but Minecraft doesn't know anything about them.

 

You need to register an

IItemColor

implementation for any

Item

you want to colour. Do this by calling

ItemColors#registerItemColorHandler

in init from your client proxy.

 

For examples, look at

ItemColors#init

or my mod.

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

You have various colour-related methods in your

FIItem

class, but Minecraft doesn't know anything about them.

 

You need to register an

IItemColor

implementation for any

Item

you want to colour. Do this by calling

ItemColors#registerItemColorHandler

in init from your client proxy.

 

Thank You -- It did seem weird to think that Minecraft would just 'know' to call the functions for what I wanted to do.

The example was very helpful.

  • 3 months later...

Does anyone know which colour value system Minecraft uses? I've tried entering a simple RGB value like this 171(red)36(green)36(blue) without the braces and info in it of course, just a plain number 1713636. Didn't seem to work. Any ideas?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Colors in decompiled minecraft are in decimal.  171,36,36 would be 11215908.

However, you should express your colors in hex.  Which would be 0xAB2424.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Colors in decompiled minecraft are in decimal.  171,36,36 would be 11215908.

However, you should express your colors in hex.  Which would be 0xAB2424.

What exactly is a decimal colour code? I've found a reference to it here, but I still don't understand it.

 

The way I am trying to do it at the moment (and it's working perfect) is like this:

import java.awt.Color;

Color color = new Color(36, 36, 155);
int colorRGB = color.getRGB();

Why is it important to express them in a hex format, is there an advantage over decimal or is it just a matter of readability and convention?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Why is it important to express them in a hex format, is there an advantage over decimal or is it just a matter of readability and convention?

 

Readability.

And the decimal color is just the base 10 representation of the same value.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Readability.

And the decimal color is just the base 10 representation of the same value.

 

Alright, thanks. I think I will stick to the way I posted above, because I personally find it more readable then hex values. I can just open up Gimp, experiment with colours and copy RGB values, and if I were to use hex values I would need to constantly recalculate them.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Alright, thanks. I think I will stick to the way I posted above, because I personally find it more readable then hex values. I can just open up Gimp, experiment with colours and copy RGB values, and if I were to use hex values I would need to constantly recalculate them.

 

Gimp handles hex values as well.

Capture.png

You can copy and paste to that field.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Alright, thanks. I think I will stick to the way I posted above, because I personally find it more readable then hex values. I can just open up Gimp, experiment with colours and copy RGB values, and if I were to use hex values I would need to constantly recalculate them.

 

Gimp handles hex values as well.

Capture.png

You can copy and paste to that field.

Didn't know that HTML notation was actually a hexadecimal value, that's great. Thanks.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

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.