1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-14 19:25:43 +00:00

Merge pull request #230 from SquidDev-CC/feature/dye-improvements

Dye improvements
This commit is contained in:
Daniel Ratcliffe 2017-05-14 21:45:33 +01:00 committed by GitHub
commit 42874073e9
52 changed files with 682 additions and 392 deletions

View File

@ -23,26 +23,40 @@ public interface IPocketAccess
Entity getEntity();
/**
* Get the colour of the pocket computer's light.
* Get the colour of this pocket computer as a RGB number.
*
* See {@link #setLight(int)} for the values this may return.
* @return The colour this pocket computer is. This will be a RGB colour between {@code 0x000000} and
* {@code 0xFFFFFF} or -1 if it has no colour.
* @see #setColour(int)
*/
int getColour();
/**
* Set the colour of the pocket computer to a RGB number.
*
* @return The colour of the pocket computer's light.
* @param colour The colour this pocket computer should be changed to. This should be a RGB colour between
* {@code 0x000000} and {@code 0xFFFFFF} or -1 to reset to the default colour.
* @see #getColour()
*/
void setColour( int colour );
/**
* Get the colour of this pocket computer's light as a RGB number.
*
* @return The colour this light is. This will be a RGB colour between {@code 0x000000} and {@code 0xFFFFFF} or
* -1 if it has no colour.
* @see #setLight(int)
*/
int getLight();
/**
* Set the colour of the pocket computer's light. Use {@link 0} to turn it off.
* Set the colour of the pocket computer's light to a RGB number.
*
* Colours take the form of an integer between 0 and 15, using the opposite order to those in
* {@link <a href="http://www.computercraft.info/wiki/Colors_(API)#Colors">The colors API</a>} - so 0 being black,
* 1 representing red, 2 representing green all the way up to 15 for white.
*
* @param value The colour the light should have.
* @param colour The colour this modem's light will be changed to. This should be a RGB colour between
* {@code 0x000000} and {@code 0xFFFFFF} or -1 to reset to the default colour.
* @see #getLight()
*/
void setLight( int value );
void setLight( int colour );
/**
* Get the upgrade-specific NBT.

View File

@ -118,22 +118,22 @@ public interface ITurtleAccess
void setSelectedSlot( int slot );
/**
* Sets the colour of the turtle, as if the player had dyed it with a dye item.
* Set the colour of the turtle to a RGB number.
*
* @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()
* @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.
* @see #getColour()
*/
void setDyeColour( int dyeColour );
void setColour( int colour );
/**
* Gets the colour the turtle has been dyed.
* Get the colour of this turtle as a RGB number.
*
* @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()
* @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.
* @see #setColour(int)
*/
int getDyeColour();
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

@ -9,6 +9,7 @@ package dan200.computercraft.client.proxy;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.*;
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
import dan200.computercraft.shared.computer.blocks.ComputerState;
import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
@ -47,7 +48,6 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.client.registry.ClientRegistry;
@ -112,61 +112,66 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
private ModelResourceLocation pocket_computer_off = new ModelResourceLocation( "computercraft:pocket_computer", "inventory" );
private ModelResourceLocation pocket_computer_on = new ModelResourceLocation( "computercraft:pocket_computer_on", "inventory" );
private ModelResourceLocation pocket_computer_blinking = new ModelResourceLocation( "computercraft:pocket_computer_blinking", "inventory" );
private ModelResourceLocation advanced_pocket_computer_off = new ModelResourceLocation( "computercraft:advanced_pocket_computer_off", "inventory" );
private ModelResourceLocation advanced_pocket_computer_off = new ModelResourceLocation( "computercraft:advanced_pocket_computer", "inventory" );
private ModelResourceLocation advanced_pocket_computer_on = new ModelResourceLocation( "computercraft:advanced_pocket_computer_on", "inventory" );
private ModelResourceLocation advanced_pocket_computer_blinking = new ModelResourceLocation( "computercraft:advanced_pocket_computer_blinking", "inventory" );
private ModelResourceLocation colour_pocket_computer_off = new ModelResourceLocation( "computercraft:pocket_computer_colour", "inventory" );
private ModelResourceLocation colour_pocket_computer_on = new ModelResourceLocation( "computercraft:pocket_computer_colour_on", "inventory" );
private ModelResourceLocation colour_pocket_computer_blinking = new ModelResourceLocation( "computercraft:pocket_computer_colour_blinking", "inventory" );
@Nonnull
@Override
public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack )
{
ItemPocketComputer itemPocketComputer = (ItemPocketComputer)stack.getItem();
switch( itemPocketComputer.getFamily( stack ) )
ItemPocketComputer itemPocketComputer = (ItemPocketComputer) stack.getItem();
ComputerState state = itemPocketComputer.getState( stack );
if( itemPocketComputer.getColour( stack ) == -1 )
{
case Advanced:
switch( itemPocketComputer.getFamily( stack ) )
{
switch( itemPocketComputer.getState( stack ) )
{
case Off:
default:
case Advanced:
switch( state )
{
return advanced_pocket_computer_off;
case Off:
default:
return advanced_pocket_computer_off;
case On:
return advanced_pocket_computer_on;
case Blinking:
return advanced_pocket_computer_blinking;
}
case On:
case Normal:
default:
switch( state )
{
return advanced_pocket_computer_on;
case Off:
default:
return pocket_computer_off;
case On:
return pocket_computer_on;
case Blinking:
return pocket_computer_blinking;
}
case Blinking:
{
return advanced_pocket_computer_blinking;
}
}
}
case Normal:
default:
}
else
{
switch( state )
{
switch( itemPocketComputer.getState( stack ) )
{
case Off:
default:
{
return pocket_computer_off;
}
case On:
{
return pocket_computer_on;
}
case Blinking:
{
return pocket_computer_blinking;
}
}
case Off:
default:
return colour_pocket_computer_off;
case On:
return colour_pocket_computer_on;
case Blinking:
return colour_pocket_computer_blinking;
}
}
}
}, new String[] {
"pocket_computer", "pocket_computer_on", "pocket_computer_blinking",
"advanced_pocket_computer_off", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking",
"advanced_pocket_computer", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking",
"pocket_computer_colour", "pocket_computer_colour_on", "pocket_computer_colour_blinking",
} );
// Setup client forge handlers
@ -189,12 +194,26 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
mc.getItemColors().registerItemColorHandler( new IItemColor()
{
@Override
public int getColorFromItemstack( @Nonnull ItemStack stack, int layout )
public int getColorFromItemstack( @Nonnull ItemStack stack, int layer )
{
if( layout != 1 ) return 0xFFFFFF;
Colour colour = Colour.fromInt( ComputerCraft.Items.pocketComputer.getLightState( stack ) );
return colour == null ? Colour.Black.getHex() : colour.getHex();
switch( layer )
{
case 0:
default:
return 0xFFFFFF;
case 1:
{
// Frame colour
int colour = ComputerCraft.Items.pocketComputer.getColour( stack );
return colour == -1 ? 0xFFFFFF : colour;
}
case 2:
{
// Light colour
int colour = ComputerCraft.Items.pocketComputer.getLightState( stack );
return colour == -1 ? Colour.Black.getHex() : colour;
}
}
}
}, ComputerCraft.Items.pocketComputer );
@ -515,20 +534,20 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
}
}
@SideOnly(Side.CLIENT)
private static class DiskColorHandler implements IItemColor
{
private final ItemDiskLegacy disk;
@SideOnly(Side.CLIENT)
private static class DiskColorHandler implements IItemColor
{
private final ItemDiskLegacy disk;
private DiskColorHandler(ItemDiskLegacy disk)
{
this.disk = disk;
}
private DiskColorHandler( ItemDiskLegacy disk )
{
this.disk = disk;
}
@Override
public int getColorFromItemstack( @Nonnull ItemStack stack, int layer)
{
return layer == 0 ? 0xFFFFFF : disk.getColor(stack);
}
}
@Override
public int getColorFromItemstack( @Nonnull ItemStack stack, int layer )
{
return layer == 0 ? 0xFFFFFF : disk.getColour( stack );
}
}
}

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

@ -0,0 +1,106 @@
package dan200.computercraft.shared.common;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.ColourTracker;
import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ColourableRecipe implements IRecipe
{
@Override
public boolean matches( @Nonnull InventoryCrafting inv, @Nonnull World worldIn )
{
boolean hasColourable = false;
boolean hasDye = false;
for( int i = 0; i < inv.getSizeInventory(); i++ )
{
ItemStack stack = inv.getStackInSlot( i );
if( stack == null ) continue;
if( stack.getItem() instanceof IColouredItem )
{
if( hasColourable ) return false;
hasColourable = true;
}
else if( ColourUtils.getStackColour( stack ) >= 0 )
{
hasDye = true;
}
else
{
return false;
}
}
return hasColourable && hasDye;
}
@Nullable
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inv )
{
ItemStack colourable = null;
ColourTracker tracker = new ColourTracker();
for( int i = 0; i < inv.getSizeInventory(); ++i )
{
ItemStack stack = inv.getStackInSlot( i );
if( stack == null ) continue;
if( stack.getItem() instanceof IColouredItem )
{
colourable = stack;
}
else
{
int index = ColourUtils.getStackColour( stack );
if( index < 0 ) continue;
Colour colour = Colour.values()[ index ];
tracker.addColour( colour.getR(), colour.getG(), colour.getB() );
}
}
if( colourable == null )
{
return null;
}
return ((IColouredItem) colourable.getItem()).setColour( colourable, tracker.getColour() );
}
@Override
public int getRecipeSize()
{
return 2;
}
@Nullable
@Override
public ItemStack getRecipeOutput()
{
return null;
}
@Nonnull
@Override
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inv )
{
ItemStack[] results = new ItemStack[ inv.getSizeInventory() ];
for( int i = 0; i < results.length; ++i )
{
ItemStack stack = inv.getStackInSlot( i );
results[ i ] = ForgeHooks.getContainerItem( stack );
}
return results;
}
}

View File

@ -0,0 +1,10 @@
package dan200.computercraft.shared.common;
import net.minecraft.item.ItemStack;
public interface IColouredItem
{
int getColour( ItemStack stack );
ItemStack setColour( ItemStack stack, int colour );
}

View File

@ -44,7 +44,7 @@ public class ItemDiskExpanded extends ItemDiskLegacy
return -1;
}
@Override
@Override
protected void setDiskID( ItemStack stack, int id )
{
if( id >= 0 )
@ -58,10 +58,18 @@ public class ItemDiskExpanded extends ItemDiskLegacy
nbt.setInteger( "diskID", id );
}
}
public int getColor( ItemStack stack )
@Override
public int getColour( ItemStack stack )
{
NBTTagCompound nbt = stack.getTagCompound();
return nbt != null && nbt.hasKey("color") ? nbt.getInteger("color") : Colour.values()[ Math.min(15, stack.getItemDamage()) ].getHex();
if( nbt != null && nbt.hasKey( "color" ) )
{
return nbt.getInteger( "color" );
}
else
{
return Colour.values()[ Math.min( 15, stack.getItemDamage() ) ].getHex();
}
}
}

View File

@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@ -24,7 +25,7 @@ import javax.annotation.Nonnull;
import java.util.List;
public class ItemDiskLegacy extends Item
implements IMedia
implements IMedia, IColouredItem
{
public ItemDiskLegacy()
{
@ -142,7 +143,8 @@ public class ItemDiskLegacy extends Item
return ComputerCraftAPI.createSaveDirMount( world, "computer/disk/" + diskID, ComputerCraft.floppySpaceLimit );
}
public int getColor( ItemStack stack )
@Override
public int getColour( ItemStack stack )
{
return Colour.Blue.getHex();
}
@ -152,4 +154,10 @@ public class ItemDiskLegacy extends Item
{
return true;
}
@Override
public ItemStack setColour( ItemStack stack, int colour )
{
return ItemDiskExpanded.createFromIDAndColour( getDiskID( stack ), getLabel( stack ), colour );
}
}

View File

@ -8,6 +8,8 @@ package dan200.computercraft.shared.media.recipes;
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.ColourTracker;
import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
@ -18,129 +20,60 @@ import javax.annotation.Nonnull;
public class DiskRecipe implements IRecipe
{
public DiskRecipe()
{
}
@Override
public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world )
public boolean matches( @Nonnull InventoryCrafting inv, @Nonnull World world )
{
boolean diskFound = false;
boolean paperFound = false;
boolean redstoneFound = false;
boolean dyeFound = false;
for (int var5 = 0; var5 < inventory.getSizeInventory(); ++var5)
for( int i = 0; i < inv.getSizeInventory(); ++i )
{
ItemStack var6 = inventory.getStackInSlot(var5);
ItemStack stack = inv.getStackInSlot( i );
if (var6 != null)
if( stack != null )
{
if (var6.getItem() instanceof ItemDiskLegacy )
if( stack.getItem() == Items.PAPER )
{
if (diskFound || redstoneFound || paperFound) // make sure no redstone or paper already accepted if disk there
{
return false;
}
diskFound = true;
}
else if( var6.getItem() == Items.DYE )
{
dyeFound = true;
}
else if( var6.getItem() == Items.PAPER )
{
if(paperFound || diskFound)
{
return false;
}
if( paperFound ) return false;
paperFound = true;
}
else if (var6.getItem() == Items.REDSTONE)
else if( stack.getItem() == Items.REDSTONE )
{
if (redstoneFound || diskFound)
{
return false;
}
if( redstoneFound ) return false;
redstoneFound = true;
}
else
else if( ColourUtils.getStackColour( stack ) < 0 )
{
return false;
}
}
}
return (redstoneFound && paperFound) || (diskFound && dyeFound);
return redstoneFound && paperFound;
}
@Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting par1InventoryCrafting)
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inv )
{
int diskID = -1;
String diskLabel = null;
ColourTracker tracker = new ColourTracker();
int[] var3 = new int[3];
int var4 = 0;
int var5 = 0;
ItemDiskLegacy var6;
int var7;
int var9;
float var10;
float var11;
int var17;
boolean dyeFound = false;
for (var7 = 0; var7 < par1InventoryCrafting.getSizeInventory(); ++var7)
for( int i = 0; i < inv.getSizeInventory(); ++i )
{
ItemStack var8 = par1InventoryCrafting.getStackInSlot(var7);
ItemStack stack = inv.getStackInSlot( i );
if (var8 != null)
if( stack == null ) continue;
if( stack.getItem() != Items.PAPER && stack.getItem() != Items.REDSTONE )
{
if (var8.getItem() instanceof ItemDiskLegacy )
{
var6 = (ItemDiskLegacy)var8.getItem();
diskID = var6.getDiskID( var8 );
diskLabel = var6.getLabel( var8 );
}
else if (var8.getItem() == Items.DYE)
{
dyeFound = true;
float[] var14 = Colour.values()[ var8.getItemDamage() & 0xf ].getRGB();
int var16 = (int)(var14[0] * 255.0F);
int var15 = (int)(var14[1] * 255.0F);
var17 = (int)(var14[2] * 255.0F);
var4 += Math.max(var16, Math.max(var15, var17));
var3[0] += var16;
var3[1] += var15;
var3[2] += var17;
++var5;
}
else if (!(var8.getItem() != Items.PAPER || var8.getItem() != Items.REDSTONE))
{
return null;
}
int index = ColourUtils.getStackColour( stack );
if( index < 0 ) continue;
Colour colour = Colour.values()[ index ];
tracker.addColour( colour.getR(), colour.getG(), colour.getB() );
}
}
if( !dyeFound )
{
return ItemDiskLegacy.createFromIDAndColour( diskID, diskLabel, Colour.Blue.getHex() );
}
var7 = var3[0] / var5;
int var13 = var3[1] / var5;
var9 = var3[2] / var5;
var10 = (float)var4 / (float)var5;
var11 = (float)Math.max(var7, Math.max(var13, var9));
var7 = (int)((float)var7 * var10 / var11);
var13 = (int)((float)var13 * var10 / var11);
var9 = (int)((float)var9 * var10 / var11);
var17 = (var7 << 8) + var13;
var17 = (var17 << 8) + var9;
return ItemDiskLegacy.createFromIDAndColour( diskID, diskLabel, var17 );
return ItemDiskLegacy.createFromIDAndColour( -1, null, tracker.hasColour() ? tracker.getColour() : Colour.Blue.getHex() );
}
@Override
@ -157,13 +90,13 @@ public class DiskRecipe implements IRecipe
@Nonnull
@Override
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inv )
{
ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ];
for (int i = 0; i < results.length; ++i)
ItemStack[] results = new ItemStack[ inv.getSizeInventory() ];
for( int i = 0; i < results.length; ++i )
{
ItemStack stack = inventoryCrafting.getStackInSlot(i);
results[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(stack);
ItemStack stack = inv.getStackInSlot( i );
results[ i ] = net.minecraftforge.common.ForgeHooks.getContainerItem( stack );
}
return results;
}

View File

@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -38,21 +39,47 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
}
@Override
public int getLight()
public int getColour()
{
int value = getUserData().getInteger( "modemLight" );
return value >= 0 && value <= 15 ? value : 0;
return ComputerCraft.Items.pocketComputer.getColour( m_stack );
}
@Override
public void setLight( int value )
public void setColour( int colour )
{
if( value < 0 || value > 15 ) throw new IllegalArgumentException( "Colour out of bounds" );
ComputerCraft.Items.pocketComputer.setColourDirect( m_stack, colour );
updateUpgradeNBTData();
}
@Override
public int getLight()
{
NBTTagCompound tag = getUserData();
if( tag.getInteger( "modemLight" ) != value )
if( tag.hasKey( "modemLight", Constants.NBT.TAG_ANY_NUMERIC ) )
{
tag.setInteger( "modemLight", value );
return tag.getInteger( "modemLight" );
}
else
{
return -1;
}
}
@Override
public void setLight( int colour )
{
NBTTagCompound tag = getUserData();
if( colour >= 0 && colour <= 0xFFFFFF )
{
if( !tag.hasKey( "modemLight", Constants.NBT.TAG_ANY_NUMERIC ) || tag.getInteger( "modemLight" ) != colour )
{
tag.setInteger( "modemLight", colour );
updateUserData();
}
}
else if( tag.hasKey( "modemLight", Constants.NBT.TAG_ANY_NUMERIC ) )
{
tag.removeTag( "modemLight" );
updateUserData();
}
}

View File

@ -11,6 +11,7 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.computer.blocks.ComputerState;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
@ -38,7 +39,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import java.util.List;
public class ItemPocketComputer extends Item implements IComputerItem, IMedia
public class ItemPocketComputer extends Item implements IComputerItem, IMedia, IColouredItem
{
public ItemPocketComputer()
{
@ -48,7 +49,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
setCreativeTab( ComputerCraft.mainCreativeTab );
}
public ItemStack create( int id, String label, ComputerFamily family, IPocketUpgrade upgrade )
public ItemStack create( int id, String label, int colour, ComputerFamily family, IPocketUpgrade upgrade )
{
// Ignore types we can't handle
if( family != ComputerFamily.Normal && family != ComputerFamily.Advanced )
@ -76,6 +77,14 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
{
result.setStackDisplayName( label );
}
if( colour != -1 )
{
NBTTagCompound tag = result.getTagCompound();
if( tag == null ) result.setTagCompound( tag = new NBTTagCompound() );
tag.setInteger( "colour", colour );
}
return result;
}
@ -88,10 +97,10 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
private void getSubItems( List<ItemStack> list, ComputerFamily family )
{
list.add( PocketComputerItemFactory.create( -1, null, family, null ) );
list.add( PocketComputerItemFactory.create( -1, null, -1, family, null ) );
for (IPocketUpgrade upgrade : ComputerCraft.getVanillaPocketUpgrades())
{
list.add( PocketComputerItemFactory.create( -1, null, family, upgrade ) );
list.add( PocketComputerItemFactory.create( -1, null, -1, family, upgrade ) );
}
}
@ -457,12 +466,12 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
if( computer != null && computer.isOn() )
{
NBTTagCompound computerNBT = computer.getUserData();
if( computerNBT != null )
if( computerNBT != null && computerNBT.hasKey( "modemLight", Constants.NBT.TAG_ANY_NUMERIC ) )
{
return computerNBT.getInteger( "modemLight" );
}
}
return 0;
return -1;
}
public IPocketUpgrade getUpgrade( ItemStack stack )
@ -525,4 +534,33 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
return sub;
}
}
@Override
public int getColour( ItemStack stack )
{
NBTTagCompound tag = stack.getTagCompound();
return tag != null && tag.hasKey( "colour", Constants.NBT.TAG_ANY_NUMERIC ) ? tag.getInteger( "colour" ) : -1;
}
@Override
public ItemStack setColour( ItemStack stack, int colour )
{
ItemStack copy = stack.copy();
setColourDirect( copy, colour );
return copy;
}
public void setColourDirect( ItemStack stack, int colour )
{
NBTTagCompound tag = stack.getTagCompound();
if( colour == -1 )
{
if( tag != null ) tag.removeTag( "colour" );
}
else
{
if( tag == null ) stack.setTagCompound( tag = new NBTTagCompound() );
tag.setInteger( "colour", colour );
}
}
}

View File

@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
public class PocketComputerItemFactory
{
public static ItemStack create( int id, String label, ComputerFamily family, IPocketUpgrade upgrade )
public static ItemStack create( int id, String label, int colour, ComputerFamily family, IPocketUpgrade upgrade )
{
ItemPocketComputer computer = ComputerCraft.Items.pocketComputer;
switch( family )
@ -21,7 +21,7 @@ public class PocketComputerItemFactory
case Normal:
case Advanced:
{
return computer.create( id, label, family, upgrade );
return computer.create( id, label, colour, family, upgrade );
}
}
return null;

View File

@ -5,7 +5,6 @@ import dan200.computercraft.api.pocket.IPocketAccess;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
@ -77,7 +76,7 @@ public class PocketModem implements IPocketUpgrade
modem.setLocation( entity.getEntityWorld(), entity.posX, entity.posY, entity.posZ );
}
access.setLight( modem.isActive() ? Colour.Red.ordinal() : Colour.Black.ordinal() );
access.setLight( modem.isActive() ? 0xBA0000 : -1 );
}
}

View File

@ -33,7 +33,7 @@ public class PocketComputerUpgradeRecipe implements IRecipe
@Override
public ItemStack getRecipeOutput()
{
return PocketComputerItemFactory.create( -1, null, ComputerFamily.Normal, null );
return PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, null );
}
@Override
@ -111,7 +111,8 @@ public class PocketComputerUpgradeRecipe implements IRecipe
ComputerFamily family = itemComputer.getFamily( computer );
int computerID = itemComputer.getComputerID( computer );
String label = itemComputer.getLabel( computer );
return PocketComputerItemFactory.create( computerID, label, family, upgrade );
int colour = itemComputer.getColour( computer );
return PocketComputerItemFactory.create( computerID, label, colour, family, upgrade );
}
@Nonnull

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

@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.core.computer.MainThread;
import dan200.computercraft.shared.common.ColourableRecipe;
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
import dan200.computercraft.shared.common.TileGeneric;
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
@ -276,6 +277,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
RecipeSorter.register( "computercraft:impostor", ImpostorRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" );
RecipeSorter.register( "computercraft:impostor_shapeless", ImpostorShapelessRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
RecipeSorter.register( "computercraft:disk", DiskRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
RecipeSorter.register( "computercraft:colour", ColourableRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
RecipeSorter.register( "computercraft:printout", PrintoutRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
RecipeSorter.register( "computercraft:pocket_computer_upgrade", PocketComputerUpgradeRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
@ -375,6 +377,9 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
// Disk
GameRegistry.addRecipe( new DiskRecipe() );
// Colourable items (turtles, disks)
GameRegistry.addRecipe( new ColourableRecipe() );
// Impostor Disk recipes (to fool NEI)
ItemStack paper = new ItemStack( Items.PAPER, 1 );
ItemStack redstone = new ItemStack( Items.REDSTONE, 1 );
@ -415,7 +420,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
GameRegistry.addRecipe( new ImpostorShapelessRecipe( bookPrintout, new ItemStack[]{leather, singlePrintout, string} ) );
// Pocket Computer
ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Normal, null );
ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, null );
GameRegistry.addRecipe( pocketComputer,
"XXX", "XYX", "XZX",
'X', Blocks.STONE,
@ -424,7 +429,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
);
// Advanced Pocket Computer
ItemStack advancedPocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Advanced, null );
ItemStack advancedPocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, null );
GameRegistry.addRecipe( advancedPocketComputer,
"XXX", "XYX", "XZX",
'X', Items.GOLD_INGOT,
@ -447,13 +452,13 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
GameRegistry.addRecipe( new ImpostorRecipe(
1, 2,
new ItemStack[]{ upgrade.getCraftingItem(), pocketComputer },
PocketComputerItemFactory.create( -1, null, ComputerFamily.Normal, upgrade )
PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, upgrade )
) );
GameRegistry.addRecipe( new ImpostorRecipe(
1, 2,
new ItemStack[]{ upgrade.getCraftingItem(), advancedPocketComputer },
PocketComputerItemFactory.create( -1, null, ComputerFamily.Advanced, upgrade )
PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, upgrade )
) );
}

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;
@ -116,7 +113,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;
@ -138,7 +135,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 +215,7 @@ public class TurtleBrain implements ITurtleAccess
}
// Read colour
if( nbttagcompound.hasKey( "colourIndex" ) )
{
m_colour = Colour.values()[ nbttagcompound.getInteger( "colourIndex" ) ];
}
else
{
m_colour = null;
}
m_colourHex = ColourUtils.getHexColour( nbttagcompound );
// Read overlay
if( nbttagcompound.hasKey( "overlay_mod" ) )
@ -324,9 +314,9 @@ public class TurtleBrain implements ITurtleAccess
}
// Write colour
if( m_colour != null )
if( m_colourHex != -1 )
{
nbttagcompound.setInteger( "colourIndex", m_colour.ordinal() );
nbttagcompound.setInteger( "colour", m_colourHex );
}
// Write overlay
@ -383,9 +373,9 @@ public class TurtleBrain implements ITurtleAccess
}
// Colour
if( m_colour != null )
if( m_colourHex != -1 )
{
nbttagcompound.setInteger( "colourIndex", m_colour.ordinal() );
nbttagcompound.setInteger( "colour", m_colourHex );
}
// Overlay
@ -438,14 +428,7 @@ 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 );
// Overlay
if( nbttagcompound.hasKey( "overlay_mod" ) && nbttagcompound.hasKey( "overlay_path" ) )
@ -776,12 +759,6 @@ public class TurtleBrain implements ITurtleAccess
m_owner.updateBlock();
}
@Override
public int getDyeColour()
{
return (m_colour != null) ? m_colour.ordinal() : -1;
}
public ResourceLocation getOverlay()
{
return m_overlay;
@ -796,21 +773,51 @@ public class TurtleBrain implements ITurtleAccess
}
}
@Override
public int getDyeColour()
{
if( m_colourHex == -1 ) return -1;
Colour colour = Colour.fromHex( m_colourHex );
return colour == null ? -1 : colour.ordinal();
}
public void setDyeColour( int dyeColour )
{
Colour newColour = null;
int newColour = -1;
if( dyeColour >= 0 && dyeColour < 16 )
{
newColour = Colour.values()[ dyeColour ];
newColour = Colour.values()[ dyeColour ].getHex();
}
if( m_colour != newColour )
if( m_colourHex != newColour )
{
m_colour = newColour;
m_colourHex = newColour;
m_owner.updateBlock();
}
}
@Override
public void setColour( int colour )
{
if( colour >= 0 && colour <= 0xFFFFFF )
{
if( m_colourHex != colour )
{
m_colourHex = colour;
m_owner.updateBlock();
}
}
else if( m_colourHex != -1 )
{
m_colourHex = -1;
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

@ -0,0 +1,48 @@
package dan200.computercraft.shared.util;
/**
* A reimplementation of the colour system in {@link net.minecraft.item.crafting.RecipesArmorDyes}, but
* bundled together as an object.
*/
public class ColourTracker
{
private int total;
private int totalR;
private int totalG;
private int totalB;
private int count;
public void addColour( int r, int g, int b )
{
total += Math.max( r, Math.max( g, b ) );
totalR += r;
totalG += g;
totalB += b;
count++;
}
public void addColour( float r, float g, float b )
{
addColour( (int) (r * 255), (int) (g * 255), (int) (b * 255) );
}
public boolean hasColour()
{
return count > 0;
}
public int getColour()
{
int avgR = totalR / count;
int avgG = totalG / count;
int avgB = totalB / count;
float avgTotal = (float) total / (float) count;
float avgMax = (float) Math.max( avgR, Math.max( avgG, avgB ) );
avgR = (int) (avgR * avgTotal / avgMax);
avgG = (int) (avgG * avgTotal / avgMax);
avgB = (int) (avgB * avgTotal / avgMax);
return (avgR << 16) | (avgG << 8) | avgB;
}
}

View File

@ -0,0 +1,74 @@
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;
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;
}
}
}

View File

@ -4,29 +4,6 @@
"texture": "computercraft:blocks/turtle_white"
},
"elements": [
{
"from": [ 2, 2, 2 ],
"to": [ 14, 14, 13 ],
"faces": {
"down": { "uv": [ 2.75, 0, 5.75, 2.75 ], "texture": "#texture" },
"up": { "uv": [ 5.75, 0, 8.75, 2.75 ], "texture": "#texture" },
"north": { "uv": [ 8.5, 5.75, 11.5, 2.75 ], "texture": "#texture" },
"south": { "uv": [ 2.75, 5.75, 5.75, 2.75 ], "texture": "#texture" },
"west": { "uv": [ 0, 5.75, 2.75, 2.75 ], "texture": "#texture" },
"east": { "uv": [ 5.75, 5.75, 8.5, 2.75 ], "texture": "#texture" }
}
},
{
"from": [ 3, 6, 13 ],
"to": [ 13, 13, 15 ],
"faces": {
"down": { "uv": [ 9.25, 0, 11.75, 0.5 ], "texture": "#texture" },
"up": { "uv": [ 11.75, 0, 14.25, 0.5 ], "texture": "#texture" },
"south": { "uv": [ 9.25, 2.25, 11.75, 0.5 ], "texture": "#texture" },
"west": { "uv": [ 8.75, 2.25, 9.25, 0.5 ], "texture": "#texture" },
"east": { "uv": [ 11.75, 2.25, 12.25, 0.5 ], "texture": "#texture" }
}
},
{
"from": [ 2, 2, 2 ],
"to": [ 14, 14, 13 ],
@ -49,6 +26,29 @@
"west": { "uv": [ 8.75, 8, 9.25, 6.25 ], "texture": "#texture", "tintindex":0 },
"east": { "uv": [ 11.75, 8, 12.25, 6.25 ], "texture": "#texture", "tintindex":0 }
}
},
{
"from": [ 2, 2, 2 ],
"to": [ 14, 14, 13 ],
"faces": {
"down": { "uv": [ 2.75, 0, 5.75, 2.75 ], "texture": "#texture" },
"up": { "uv": [ 5.75, 0, 8.75, 2.75 ], "texture": "#texture" },
"north": { "uv": [ 8.5, 5.75, 11.5, 2.75 ], "texture": "#texture" },
"south": { "uv": [ 2.75, 5.75, 5.75, 2.75 ], "texture": "#texture" },
"west": { "uv": [ 0, 5.75, 2.75, 2.75 ], "texture": "#texture" },
"east": { "uv": [ 5.75, 5.75, 8.5, 2.75 ], "texture": "#texture" }
}
},
{
"from": [ 3, 6, 13 ],
"to": [ 13, 13, 15 ],
"faces": {
"down": { "uv": [ 9.25, 0, 11.75, 0.5 ], "texture": "#texture" },
"up": { "uv": [ 11.75, 0, 14.25, 0.5 ], "texture": "#texture" },
"south": { "uv": [ 9.25, 2.25, 11.75, 0.5 ], "texture": "#texture" },
"west": { "uv": [ 8.75, 2.25, 9.25, 0.5 ], "texture": "#texture" },
"east": { "uv": [ 11.75, 2.25, 12.25, 0.5 ], "texture": "#texture" }
}
}
]
}

View File

@ -0,0 +1,7 @@
{
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_frame",
"layer1": "computercraft:items/pocket_computer_advanced"
}
}

View File

@ -1,7 +1,8 @@
{
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_blink_advanced",
"layer1": "computercraft:items/pocket_computer_light"
"layer0": "computercraft:items/pocket_computer_blink",
"layer1": "computercraft:items/pocket_computer_advanced",
"layer2": "computercraft:items/pocket_computer_light"
}
}

View File

@ -1,6 +0,0 @@
{
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_advanced"
}
}

View File

@ -1,7 +1,8 @@
{
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_on_advanced",
"layer1": "computercraft:items/pocket_computer_light"
"layer0": "computercraft:items/pocket_computer_on",
"layer1": "computercraft:items/pocket_computer_advanced",
"layer2": "computercraft:items/pocket_computer_light"
}
}

View File

@ -1,6 +1,7 @@
{
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer"
"layer0": "computercraft:items/pocket_computer_frame",
"layer1": "computercraft:items/pocket_computer"
}
}

View File

@ -2,6 +2,7 @@
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_blink",
"layer1": "computercraft:items/pocket_computer_light"
"layer1": "computercraft:items/pocket_computer",
"layer2": "computercraft:items/pocket_computer_light"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_frame",
"layer1": "computercraft:items/pocket_computer_colour"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_blink",
"layer1": "computercraft:items/pocket_computer_colour",
"layer2": "computercraft:items/pocket_computer_light"
}
}

View File

@ -0,0 +1,8 @@
{
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_on",
"layer1": "computercraft:items/pocket_computer_colour",
"layer2": "computercraft:items/pocket_computer_light"
}
}

View File

@ -2,6 +2,7 @@
"parent": "item/generated",
"textures": {
"layer0": "computercraft:items/pocket_computer_on",
"layer1": "computercraft:items/pocket_computer_light"
"layer1": "computercraft:items/pocket_computer",
"layer2": "computercraft:items/pocket_computer_light"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 B

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 B

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 B

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 B

View File

@ -1,6 +0,0 @@
{
"animation": {
"frametime": 8,
"frames": [ 0, 1 ]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B