1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-13 11:40:29 +00:00

Allow dying turtles arbitrary colours

- Makes ITurtleItem implement IColourableItem
 - Only cache one turtle item model for all colours, rather than one for
   each colour.
 - Allow ITurtleAccess to set an arbitrary colour.
This commit is contained in:
SquidDev 2017-05-11 18:44:02 +01:00
parent 88de097c1c
commit 8c36eccfef
17 changed files with 181 additions and 134 deletions

View File

@ -123,6 +123,7 @@ public interface ITurtleAccess
* @param dyeColour 0-15 to dye the turtle one of the 16 standard Minecraft <em>dye</em> colours, or -1 to remove
* the dye from the turtle.
* @see #getDyeColour()
* @see #setColour(int)
*/
void setDyeColour( int dyeColour );
@ -130,11 +131,28 @@ public interface ITurtleAccess
* Gets the colour the turtle has been dyed.
*
* @return 0-15 if the turtle has been dyed one of the 16 standard Minecraft <em>dye</em> colours, -1 if the turtle
* is clean.
* @see #getDyeColour()
* is clean or has no corresponding dye.
* @see #setDyeColour(int)
* @see #getColour()
*/
int getDyeColour();
/**
* Set the colour of the turtle to a RGB number.
*
* @param colour The colour this turtle should be changed to. This should be a RGB colour between {@code 0x000000}
* and {@code 0xFFFFFF} or -1 to reset to the default colour.
*/
void setColour( int colour );
/**
* Set the colour of the turtle to a RGB number.
*
* @return The colour this turtle is. This will be a RGB colour between {@code 0x000000} and {@code 0xFFFFFF} or
* -1 if it has no colour.
*/
int getColour();
/**
* Get the inventory of this turtle
*

View File

@ -14,7 +14,6 @@ import dan200.computercraft.shared.proxy.CCTurtleProxyCommon;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemMeshDefinition;
@ -199,8 +198,8 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon
if( tintIndex == 0 )
{
ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem();
Colour colour = turtle.getColour( stack );
if( colour != null ) return colour.getHex();
int colour = turtle.getColour( stack );
if( colour != -1 ) return colour;
}
return 0xFFFFFF;

View File

@ -12,7 +12,6 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.turtle.entity.TurtleVisionCamera;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Holiday;
import dan200.computercraft.shared.util.HolidayUtil;
import net.minecraft.block.state.IBlockState;
@ -51,24 +50,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
private static ModelResourceLocation ADVANCED_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_advanced", "inventory" );
private static ModelResourceLocation COLOUR_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_white", "inventory" );
private static ModelResourceLocation BEGINNER_TURTLE_MODEL = new ModelResourceLocation( "computercraftedu:CC-TurtleJunior", "inventory" );
private static ModelResourceLocation[] BEGINNER_TURTLE_COLOUR_MODELS = new ModelResourceLocation[] {
new ModelResourceLocation( "computercraftedu:turtleJunior_black", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_red", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_green", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_brown", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_blue", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_purple", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_cyan", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_lightGrey", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_grey", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_pink", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_lime", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_yellow", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_lightBlue", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_magenta", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_orange", "inventory" ),
new ModelResourceLocation( "computercraftedu:turtleJunior_white", "inventory" ),
};
private static ModelResourceLocation BEGINNER_TURTLE_COLOUR_MODEL = new ModelResourceLocation( "computercraftedu:turtleJunior_white", "inventory" );
private static ModelResourceLocation ELF_OVERLAY_MODEL = new ModelResourceLocation( "computercraft:turtle_elf_overlay", "inventory" );
public TileEntityTurtleRenderer()
@ -96,17 +78,17 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
}
}
public static ModelResourceLocation getTurtleModel( ComputerFamily family, Colour colour )
public static ModelResourceLocation getTurtleModel( ComputerFamily family, boolean coloured )
{
switch( family )
{
case Normal:
default:
return colour != null ? COLOUR_TURTLE_MODEL : NORMAL_TURTLE_MODEL;
return coloured ? COLOUR_TURTLE_MODEL : NORMAL_TURTLE_MODEL;
case Advanced:
return colour != null ? COLOUR_TURTLE_MODEL : ADVANCED_TURTLE_MODEL;
return coloured ? COLOUR_TURTLE_MODEL : ADVANCED_TURTLE_MODEL;
case Beginners:
return colour != null ? BEGINNER_TURTLE_COLOUR_MODELS[ colour.ordinal() ] : BEGINNER_TURTLE_MODEL;
return coloured ? BEGINNER_TURTLE_COLOUR_MODEL : BEGINNER_TURTLE_MODEL;
}
}
@ -161,7 +143,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
GlStateManager.translate( -0.5f, 0.0f, -0.5f );
// Render the turtle
Colour colour;
int colour;
ComputerFamily family;
ResourceLocation overlay;
if( turtle != null )
@ -172,12 +154,12 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
}
else
{
colour = null;
colour = -1;
family = ComputerFamily.Normal;
overlay = null;
}
renderModel( state, getTurtleModel( family, colour ), colour == null ? null : new int[] { colour.getHex() } );
renderModel( state, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } );
// Render the overlay
ModelResourceLocation overlayModel = getTurtleOverlayModel(

View File

@ -12,7 +12,6 @@ import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Holiday;
import dan200.computercraft.shared.util.HolidayUtil;
import net.minecraft.block.state.IBlockState;
@ -40,13 +39,13 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
private static class TurtleModelCombination
{
public final ComputerFamily m_family;
public final Colour m_colour;
public final boolean m_colour;
public final ITurtleUpgrade m_leftUpgrade;
public final ITurtleUpgrade m_rightUpgrade;
public final ResourceLocation m_overlay;
public final boolean m_christmas;
public TurtleModelCombination( ComputerFamily family, Colour colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas )
public TurtleModelCombination( ComputerFamily family, boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas )
{
m_family = family;
m_colour = colour;
@ -83,7 +82,7 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
final int prime = 31;
int result = 1;
result = prime * result + m_family.hashCode();
result = prime * result + (m_colour != null ? m_colour.hashCode() : 0);
result = prime * result + (m_colour ? 1 : 0);
result = prime * result + (m_leftUpgrade != null ? m_leftUpgrade.hashCode() : 0);
result = prime * result + (m_rightUpgrade != null ? m_rightUpgrade.hashCode() : 0);
result = prime * result + (m_overlay != null ? m_overlay.hashCode() : 0);
@ -98,7 +97,7 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
public TurtleSmartItemModel()
{
m_defaultItem = TurtleItemFactory.create( -1, null, null, ComputerFamily.Normal, null, null, 0, null );
m_defaultItem = TurtleItemFactory.create( -1, null, -1, ComputerFamily.Normal, null, null, 0, null );
m_cachedModels = new HashMap<TurtleModelCombination, IBakedModel>();
m_overrides = new ItemOverrideList( new ArrayList<ItemOverride>() )
{
@ -108,12 +107,12 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload
{
ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem();
ComputerFamily family = turtle.getFamily( stack );
Colour colour = turtle.getColour( stack );
int colour = turtle.getColour( stack );
ITurtleUpgrade leftUpgrade = turtle.getUpgrade( stack, TurtleSide.Left );
ITurtleUpgrade rightUpgrade = turtle.getUpgrade( stack, TurtleSide.Right );
ResourceLocation overlay = turtle.getOverlay( stack );
boolean christmas = HolidayUtil.getCurrentHoliday() == Holiday.Christmas;
TurtleModelCombination combo = new TurtleModelCombination( family, colour, leftUpgrade, rightUpgrade, overlay, christmas );
TurtleModelCombination combo = new TurtleModelCombination( family, colour != -1, leftUpgrade, rightUpgrade, overlay, christmas );
if( m_cachedModels.containsKey( combo ) )
{
return m_cachedModels.get( combo );

View File

@ -141,7 +141,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
private void addAllUpgradedTurtles( ComputerFamily family, List<ItemStack> list )
{
ItemStack basicStack = TurtleItemFactory.create( -1, null, null, family, null, null, 0, null );
ItemStack basicStack = TurtleItemFactory.create( -1, null, -1, family, null, null, 0, null );
if( basicStack != null )
{
list.add( basicStack );
@ -160,7 +160,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
{
if ( isUpgradeSuitableForFamily( family, upgrade ) )
{
ItemStack stack = TurtleItemFactory.create( -1, null, null, family, upgrade, null, 0, null );
ItemStack stack = TurtleItemFactory.create( -1, null, -1, family, upgrade, null, 0, null );
if( stack != null )
{
list.add( stack );
@ -292,11 +292,11 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
continue;
}
ItemStack baseTurtle = TurtleItemFactory.create( -1, null, null, family, null, null, 0, null );
ItemStack baseTurtle = TurtleItemFactory.create( -1, null, -1, family, null, null, 0, null );
if( baseTurtle != null )
{
ItemStack craftedTurtle = TurtleItemFactory.create( -1, null, null, family, upgrade, null, 0, null );
ItemStack craftedTurtleFlipped = TurtleItemFactory.create( -1, null, null, family, null, upgrade, 0, null );
ItemStack craftedTurtle = TurtleItemFactory.create( -1, null, -1, family, upgrade, null, 0, null );
ItemStack craftedTurtleFlipped = TurtleItemFactory.create( -1, null, -1, family, null, upgrade, 0, null );
recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { baseTurtle, craftingItem }, craftedTurtle ) );
recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { craftingItem, baseTurtle }, craftedTurtleFlipped ) );
@ -307,11 +307,11 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
{
ItemStack otherCraftingItem = otherUpgrade.getCraftingItem();
ItemStack otherCraftedTurtle = TurtleItemFactory.create( -1, null, null, family, null, otherUpgrade, 0, null );
ItemStack comboCraftedTurtle = TurtleItemFactory.create( -1, null, null, family, upgrade, otherUpgrade, 0, null );
ItemStack otherCraftedTurtle = TurtleItemFactory.create( -1, null, -1, family, null, otherUpgrade, 0, null );
ItemStack comboCraftedTurtle = TurtleItemFactory.create( -1, null, -1, family, upgrade, otherUpgrade, 0, null );
ItemStack otherCraftedTurtleFlipped = TurtleItemFactory.create( -1, null, null, family, otherUpgrade, null, 0, null );
ItemStack comboCraftedTurtleFlipped = TurtleItemFactory.create( -1, null, null, family, otherUpgrade, upgrade, 0, null );
ItemStack otherCraftedTurtleFlipped = TurtleItemFactory.create( -1, null, -1, family, otherUpgrade, null, 0, null );
ItemStack comboCraftedTurtleFlipped = TurtleItemFactory.create( -1, null, -1, family, otherUpgrade, upgrade, 0, null );
recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { otherCraftingItem, craftedTurtle }, comboCraftedTurtle ) );
recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { otherCraftedTurtle, craftingItem }, comboCraftedTurtle ) );
@ -361,7 +361,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
iron, ComputerItemFactory.create( -1, null, ComputerFamily.Normal ), iron,
iron, new ItemStack( Blocks.CHEST, 1 ), iron,
},
TurtleItemFactory.create( -1, null, null, ComputerFamily.Normal, null, null, 0, null )
TurtleItemFactory.create( -1, null, -1, ComputerFamily.Normal, null, null, 0, null )
) );
// Advanced Turtle
@ -379,7 +379,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
gold, ComputerItemFactory.create( -1, null, ComputerFamily.Advanced ), gold,
gold, new ItemStack( Blocks.CHEST, 1 ), gold,
},
TurtleItemFactory.create( -1, null, null, ComputerFamily.Advanced, null, null, 0, null )
TurtleItemFactory.create( -1, null, -1, ComputerFamily.Advanced, null, null, 0, null )
) );
// Upgrades

View File

@ -11,13 +11,12 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.common.IDirectionalTile;
import dan200.computercraft.shared.computer.blocks.IComputerTile;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
public interface ITurtleTile extends IComputerTile, IDirectionalTile
{
Colour getColour();
int getColour();
ResourceLocation getOverlay();
ITurtleUpgrade getUpgrade( TurtleSide side );
ITurtleAccess getAccess();

View File

@ -17,7 +17,6 @@ import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.turtle.apis.TurtleAPI;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.InventoryUtil;
import dan200.computercraft.shared.util.RedstoneUtil;
import dan200.computercraft.shared.util.WorldUtil;
@ -202,14 +201,14 @@ public class TileTurtle extends TileComputerBase
}
return true;
}
else if( currentItem.getItem() == Items.WATER_BUCKET && m_brain.getDyeColour() != -1 )
else if( currentItem.getItem() == Items.WATER_BUCKET && m_brain.getColour() != -1 )
{
// Water to remove turtle colour
if( !worldObj.isRemote )
{
if( m_brain.getDyeColour() != -1 )
if( m_brain.getColour() != -1 )
{
m_brain.setDyeColour( -1 );
m_brain.setColour( -1 );
if( !player.capabilities.isCreativeMode )
{
player.setHeldItem( EnumHand.MAIN_HAND, new ItemStack( Items.BUCKET ) );
@ -417,14 +416,9 @@ public class TileTurtle extends TileComputerBase
}
@Override
public Colour getColour()
public int getColour()
{
int dye = m_brain.getDyeColour();
if( dye >= 0 )
{
return Colour.values()[ dye ];
}
return null;
return m_brain.getColour();
}
@Override

View File

@ -16,10 +16,7 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.DirectionUtil;
import dan200.computercraft.shared.util.Holiday;
import dan200.computercraft.shared.util.HolidayUtil;
import dan200.computercraft.shared.util.*;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
@ -117,6 +114,7 @@ public class TurtleBrain implements ITurtleAccess
private int m_selectedSlot;
private int m_fuelLevel;
private Colour m_colour;
private int m_colourHex;
private ResourceLocation m_overlay;
private int m_instanceID;
@ -139,6 +137,7 @@ public class TurtleBrain implements ITurtleAccess
m_selectedSlot = 0;
m_fuelLevel = 0;
m_colour = null;
m_colourHex = -1;
m_overlay = null;
m_instanceID = -1;
@ -218,14 +217,8 @@ public class TurtleBrain implements ITurtleAccess
}
// Read colour
if( nbttagcompound.hasKey( "colourIndex" ) )
{
m_colour = Colour.values()[ nbttagcompound.getInteger( "colourIndex" ) ];
}
else
{
m_colour = null;
}
m_colour = ColourUtils.getColour( nbttagcompound );
m_colourHex = ColourUtils.getHexColour( nbttagcompound );
// Read overlay
if( nbttagcompound.hasKey( "overlay_mod" ) )
@ -328,6 +321,10 @@ public class TurtleBrain implements ITurtleAccess
{
nbttagcompound.setInteger( "colourIndex", m_colour.ordinal() );
}
else if( m_colourHex != -1 )
{
nbttagcompound.setInteger( "colour", m_colourHex );
}
// Write overlay
if( m_overlay != null )
@ -387,6 +384,10 @@ public class TurtleBrain implements ITurtleAccess
{
nbttagcompound.setInteger( "colourIndex", m_colour.ordinal() );
}
else if( m_colourHex != -1 )
{
nbttagcompound.setInteger( "colour", m_colourHex );
}
// Overlay
if( m_overlay != null )
@ -438,14 +439,8 @@ public class TurtleBrain implements ITurtleAccess
}
// Colour
if( nbttagcompound.hasKey( "colourIndex" ) )
{
m_colour = Colour.values()[ nbttagcompound.getInteger( "colourIndex" ) ];
}
else
{
m_colour = null;
}
m_colourHex = ColourUtils.getHexColour( nbttagcompound );
m_colour = ColourUtils.getColour( nbttagcompound );
// Overlay
if( nbttagcompound.hasKey( "overlay_mod" ) && nbttagcompound.hasKey( "overlay_path" ) )
@ -779,7 +774,7 @@ public class TurtleBrain implements ITurtleAccess
@Override
public int getDyeColour()
{
return (m_colour != null) ? m_colour.ordinal() : -1;
return m_colour != null ? m_colour.ordinal() : -1;
}
public ResourceLocation getOverlay()
@ -807,10 +802,37 @@ public class TurtleBrain implements ITurtleAccess
if( m_colour != newColour )
{
m_colour = newColour;
m_colourHex = newColour == null ? -1 : newColour.getHex();
m_owner.updateBlock();
}
}
@Override
public void setColour( int colour )
{
if( colour >= 0 && colour <= 0xFFFFFF )
{
if( m_colourHex != colour )
{
m_colourHex = colour;
m_colour = Colour.fromHex( colour );
m_owner.updateBlock();
}
}
else if( m_colourHex != -1 )
{
m_colourHex = -1;
m_colour = null;
m_owner.updateBlock();
}
}
@Override
public int getColour()
{
return m_colourHex;
}
@Override
public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side )
{

View File

@ -8,15 +8,14 @@ package dan200.computercraft.shared.turtle.items;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.computer.items.IComputerItem;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public interface ITurtleItem extends IComputerItem
public interface ITurtleItem extends IComputerItem, IColouredItem
{
ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side );
int getFuelLevel( ItemStack stack );
Colour getColour( ItemStack stack );
ResourceLocation getOverlay( ItemStack stack );
}

View File

@ -13,7 +13,6 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ItemComputerBase;
import dan200.computercraft.shared.turtle.blocks.ITurtleTile;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@ -41,7 +40,7 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
setHasSubtypes( true );
}
public abstract ItemStack create( int id, String label, Colour colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay );
public abstract ItemStack create( int id, String label, int colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay );
@Override
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull List<ItemStack> list )
@ -100,10 +99,10 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
turtle.getAccess().setFuelLevel( fuelLevel );
// Set colour
Colour colour = getColour( stack );
if( colour != null )
int colour = getColour( stack );
if( colour != -1 )
{
turtle.getAccess().setDyeColour( colour.ordinal() );
turtle.getAccess().setColour( colour );
}
// Set overlay
@ -172,17 +171,13 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
}
}
// ITurtleItem implementation
@Override
public abstract ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side );
@Override
public abstract Colour getColour( ItemStack stack );
@Override
public abstract ResourceLocation getOverlay( ItemStack stack );
@Override
public abstract int getFuelLevel( ItemStack stack );
public ItemStack setColour( ItemStack stack, int colour )
{
return TurtleItemFactory.create(
getComputerID( stack ), getLabel( stack ), colour, getFamily( stack ),
getUpgrade( stack, TurtleSide.Left ), getUpgrade( stack, TurtleSide.Right ),
getFuelLevel( stack ), getOverlay( stack )
);
}
}

View File

@ -11,7 +11,6 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ItemComputer;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -27,12 +26,12 @@ public class ItemTurtleLegacy extends ItemTurtleBase
}
@Override
public ItemStack create( int id, String label, Colour colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay )
public ItemStack create( int id, String label, int colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay )
{
// Legacy turtles only support pickaxes and modems
if( (leftUpgrade != null && leftUpgrade != ComputerCraft.Upgrades.diamondPickaxe ) ||
(rightUpgrade != null && rightUpgrade != ComputerCraft.Upgrades.wirelessModem) ||
(colour != null) || (overlay != null) )
(colour != -1) || (overlay != null) )
{
return null;
}
@ -130,9 +129,9 @@ public class ItemTurtleLegacy extends ItemTurtleBase
}
@Override
public Colour getColour( ItemStack stack )
public int getColour( ItemStack stack )
{
return null;
return -1;
}
@Override

View File

@ -9,15 +9,16 @@ package dan200.computercraft.shared.turtle.items;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.Constants;
public class ItemTurtleNormal extends ItemTurtleBase
public class ItemTurtleNormal extends ItemTurtleBase implements IColouredItem
{
public ItemTurtleNormal( Block block )
{
@ -27,7 +28,7 @@ public class ItemTurtleNormal extends ItemTurtleBase
}
@Override
public ItemStack create( int id, String label, Colour colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay )
public ItemStack create( int id, String label, int colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay )
{
// Build the stack
ItemStack stack = new ItemStack( this, 1, 0 );
@ -64,9 +65,9 @@ public class ItemTurtleNormal extends ItemTurtleBase
{
nbt.setInteger( "fuelLevel", fuelLevel );
}
if( colour != null )
if( colour != -1 )
{
nbt.setInteger( "colourIndex", colour.ordinal() );
nbt.setInteger( "colour", colour );
}
if( overlay != null )
{
@ -151,18 +152,10 @@ public class ItemTurtleNormal extends ItemTurtleBase
}
@Override
public Colour getColour( ItemStack stack )
public int getColour( ItemStack stack )
{
if( stack.hasTagCompound() )
{
NBTTagCompound nbt = stack.getTagCompound();
if( nbt.hasKey( "colourIndex" ) )
{
int index = nbt.getInteger( "colourIndex" ) & 0xf;
return Colour.values()[ index ];
}
}
return null;
NBTTagCompound tag = stack.getTagCompound();
return tag == null ? -1 : ColourUtils.getHexColour( tag );
}
@Override

View File

@ -47,7 +47,7 @@ public class TurtleItemFactory
return create( -1, null, turtle.getColour(), turtle.getFamily(), leftUpgrade, rightUpgrade, 0, turtle.getOverlay() );
}
public static ItemStack create( int id, String label, Colour colour, ComputerFamily family, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay )
public static ItemStack create( int id, String label, int colour, ComputerFamily family, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay )
{
switch( family )
{

View File

@ -37,7 +37,7 @@ public class TurtleRecipe implements IRecipe
@Override
public ItemStack getRecipeOutput()
{
return TurtleItemFactory.create( -1, null, null, m_family, null, null, 0, null );
return TurtleItemFactory.create( -1, null, -1, m_family, null, null, 0, null );
}
@Override
@ -84,11 +84,11 @@ public class TurtleRecipe implements IRecipe
// Construct the new stack
if( m_family != ComputerFamily.Beginners )
{
return TurtleItemFactory.create( computerID, label, null, m_family, null, null, 0, null );
return TurtleItemFactory.create( computerID, label, -1, m_family, null, null, 0, null );
}
else
{
return TurtleItemFactory.create( -1, label, null, m_family, null, null, 0, null );
return TurtleItemFactory.create( -1, label, -1, m_family, null, null, 0, null );
}
}

View File

@ -37,7 +37,7 @@ public class TurtleUpgradeRecipe implements IRecipe
@Override
public ItemStack getRecipeOutput()
{
return TurtleItemFactory.create( -1, null, null, ComputerFamily.Normal, null, null, 0, null );
return TurtleItemFactory.create( -1, null, -1, ComputerFamily.Normal, null, null, 0, null );
}
@Override
@ -154,7 +154,7 @@ public class TurtleUpgradeRecipe implements IRecipe
int computerID = itemTurtle.getComputerID( turtle );
String label = itemTurtle.getLabel( turtle );
int fuelLevel = itemTurtle.getFuelLevel( turtle );
Colour colour = itemTurtle.getColour( turtle );
int colour = itemTurtle.getColour( turtle );
ResourceLocation overlay = itemTurtle.getOverlay( turtle );
return TurtleItemFactory.create( computerID, label, colour, family, upgrades[0], upgrades[1], fuelLevel, overlay );
}

View File

@ -25,14 +25,25 @@ public enum Colour
Orange( 0xf2b233 ),
White( 0xf0f0f0 );
public static final Colour[] VALUES = values();
public static Colour fromInt( int colour )
{
if( colour >= 0 && colour < 16 )
{
return Colour.values()[ colour ];
return Colour.VALUES[ colour ];
}
return null;
}
public static Colour fromHex(int colour) {
for( Colour entry : VALUES )
{
if( entry.getHex() == colour ) return entry;
}
return null;
}
private int m_hex;
private float[] m_rgb;
@ -49,12 +60,12 @@ public enum Colour
public Colour getNext()
{
return Colour.values()[ (ordinal() + 1) % 16 ];
return Colour.VALUES[ (ordinal() + 1) % 16 ];
}
public Colour getPrevious()
{
return Colour.values()[ (ordinal() + 15) % 16 ];
return Colour.VALUES[ (ordinal() + 15) % 16 ];
}
public int getHex()

View File

@ -1,10 +1,14 @@
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;
public class ColourUtils
import javax.annotation.Nonnull;
public final class ColourUtils
{
private static final String[] DYES = new String[] {
"dyeBlack", "dyeRed", "dyeGreen", "dyeBrown",
@ -34,4 +38,37 @@ public class ColourUtils
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;
}
}
}