mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-16 14:37:39 +00:00
Add more general item colouring system
This allows for other items, such as turtles, to be dyed in the future. This also adds support for the ore dictionary, meaning you can use other mod's dyes to colour items.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package dan200.computercraft.shared.util;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
public class ColourUtils
|
||||
{
|
||||
private static final String[] DYES = new String[] {
|
||||
"dyeBlack", "dyeRed", "dyeGreen", "dyeBrown",
|
||||
"dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray",
|
||||
"dyeGray", "dyePink", "dyeLime", "dyeYellow",
|
||||
"dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite"
|
||||
};
|
||||
|
||||
private static int[] ids;
|
||||
|
||||
public static int getStackColour( ItemStack stack )
|
||||
{
|
||||
if( ids == null )
|
||||
{
|
||||
int ids[] = ColourUtils.ids = new int[ DYES.length ];
|
||||
for( int i = 0; i < DYES.length; i++ )
|
||||
{
|
||||
ids[ i ] = OreDictionary.getOreID( DYES[ i ] );
|
||||
}
|
||||
}
|
||||
|
||||
for( int id : OreDictionary.getOreIDs( stack ) )
|
||||
{
|
||||
int index = ArrayUtils.indexOf( ids, id );
|
||||
if( index >= 0 ) return index;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user