1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-07-14 16:02:57 +00:00
SquidDev a0e7c4a74c Add a little bit of source code checking to Gradle
- Adds a CheckStyle configuration which is pretty similar to CC's
   existing one.
 - Add the Gradle license plugin.
 - Ensure the existing source code is compatible with these additional
   checks.

See #239
2019-06-08 00:28:03 +01:00

83 lines
2.2 KiB
Java

/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.util;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils;
import javax.annotation.Nonnull;
public final 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;
private ColourUtils() {}
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;
}
public static int getHexColour( @Nonnull NBTTagCompound tag )
{
if( tag.hasKey( "colourIndex", Constants.NBT.TAG_ANY_NUMERIC ) )
{
return Colour.VALUES[tag.getInteger( "colourIndex" ) & 0xF].getHex();
}
else if( tag.hasKey( "colour", Constants.NBT.TAG_ANY_NUMERIC ) )
{
return tag.getInteger( "colour" );
}
else if( tag.hasKey( "color", Constants.NBT.TAG_ANY_NUMERIC ) )
{
return tag.getInteger( "color" );
}
else
{
return -1;
}
}
public static Colour getColour( @Nonnull NBTTagCompound tag )
{
if( tag.hasKey( "colourIndex", Constants.NBT.TAG_ANY_NUMERIC ) )
{
return Colour.fromInt( tag.getInteger( "colourIndex" ) & 0xF );
}
else
{
return null;
}
}
}