diff --git a/src/main/java/dan200/computercraft/api/pocket/IPocketAccess.java b/src/main/java/dan200/computercraft/api/pocket/IPocketAccess.java index 2485cacf3..a84c2de62 100644 --- a/src/main/java/dan200/computercraft/api/pocket/IPocketAccess.java +++ b/src/main/java/dan200/computercraft/api/pocket/IPocketAccess.java @@ -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 The colors API} - 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java index b18ba839e..940adb89a 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -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 dye 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 dye 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 diff --git a/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java index acf37c6d2..790eb8b99 100644 --- a/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java @@ -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; diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 7adb8e3ff..d3c165767 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -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 ); + } + } } diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java index 424f6328e..fc78a2e85 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java @@ -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(); m_overrides = new ItemOverrideList( new ArrayList() ) { @@ -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 ); diff --git a/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java b/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java new file mode 100644 index 000000000..ce59b7fc5 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java @@ -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; + } +} diff --git a/src/main/java/dan200/computercraft/shared/common/IColouredItem.java b/src/main/java/dan200/computercraft/shared/common/IColouredItem.java new file mode 100644 index 000000000..fb28403bd --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/common/IColouredItem.java @@ -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 ); +} diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskExpanded.java b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskExpanded.java index 02df3b622..ab3c10330 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskExpanded.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskExpanded.java @@ -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(); + } } } diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java index 6b5c3f0f5..05581bf54 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java @@ -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 ); + } } diff --git a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java index 6a9191fd7..35bffc4f4 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java @@ -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; } diff --git a/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java b/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java index bd0d9470c..f6bb6dd1d 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java @@ -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(); } } diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java index 55d9a3982..df4f89854 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -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 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 ); + } + } } diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItemFactory.java b/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItemFactory.java index 80e7ca2c5..ad36d15da 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItemFactory.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItemFactory.java @@ -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; diff --git a/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModem.java b/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModem.java index 8d58a8365..73e37b1bd 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModem.java +++ b/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModem.java @@ -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 ); } } diff --git a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java index 0f6eb0370..0fade6195 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java @@ -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 diff --git a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java index a2661d834..784633e16 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java @@ -141,7 +141,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy private void addAllUpgradedTurtles( ComputerFamily family, List 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 diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 749abf8e8..251fd9809 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -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 ) ) ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/ITurtleTile.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/ITurtleTile.java index 00e96f398..f2c19266e 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/ITurtleTile.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/ITurtleTile.java @@ -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(); diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index 77b98d32e..d12349d87 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -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 diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index b82b8f7de..05a31b2ea 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -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 ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ITurtleItem.java b/src/main/java/dan200/computercraft/shared/turtle/items/ITurtleItem.java index ace66cecc..dc97bf8f3 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ITurtleItem.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ITurtleItem.java @@ -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 ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java index 9a0cbc0da..65f31bf3b 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java @@ -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 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 ) + ); + } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleLegacy.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleLegacy.java index aa389b524..0781223f6 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleLegacy.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleLegacy.java @@ -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 diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleNormal.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleNormal.java index c08a00810..92e5b664e 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleNormal.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleNormal.java @@ -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 diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItemFactory.java b/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItemFactory.java index 85064dc15..abac8477f 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItemFactory.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItemFactory.java @@ -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 ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java index 4d1209f1b..2a7775ace 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java @@ -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 ); } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java index f41c777cf..a423d1e47 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java @@ -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 ); } diff --git a/src/main/java/dan200/computercraft/shared/util/Colour.java b/src/main/java/dan200/computercraft/shared/util/Colour.java index d72dcabae..069617714 100644 --- a/src/main/java/dan200/computercraft/shared/util/Colour.java +++ b/src/main/java/dan200/computercraft/shared/util/Colour.java @@ -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() diff --git a/src/main/java/dan200/computercraft/shared/util/ColourTracker.java b/src/main/java/dan200/computercraft/shared/util/ColourTracker.java new file mode 100644 index 000000000..7be0ad300 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/util/ColourTracker.java @@ -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; + } +} diff --git a/src/main/java/dan200/computercraft/shared/util/ColourUtils.java b/src/main/java/dan200/computercraft/shared/util/ColourUtils.java new file mode 100644 index 000000000..6831230fa --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/util/ColourUtils.java @@ -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; + } + } + +} diff --git a/src/main/resources/assets/computercraft/models/block/turtle_white.json b/src/main/resources/assets/computercraft/models/block/turtle_white.json index 9feec113d..29d1477b2 100644 --- a/src/main/resources/assets/computercraft/models/block/turtle_white.json +++ b/src/main/resources/assets/computercraft/models/block/turtle_white.json @@ -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" } + } } ] } diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer.json new file mode 100644 index 000000000..73f3e3894 --- /dev/null +++ b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer.json @@ -0,0 +1,7 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "computercraft:items/pocket_computer_frame", + "layer1": "computercraft:items/pocket_computer_advanced" + } +} diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking.json index 917745152..e9827fc84 100644 --- a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking.json +++ b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking.json @@ -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" } } diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_off.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_off.json deleted file mode 100644 index c42373229..000000000 --- a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_off.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "computercraft:items/pocket_computer_advanced" - } -} diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on.json index 6c00a583f..581fe4c20 100644 --- a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on.json +++ b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on.json @@ -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" } } diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer.json b/src/main/resources/assets/computercraft/models/item/pocket_computer.json index 222b878b1..cdd234b0d 100644 --- a/src/main/resources/assets/computercraft/models/item/pocket_computer.json +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer.json @@ -1,6 +1,7 @@ { "parent": "item/generated", "textures": { - "layer0": "computercraft:items/pocket_computer" + "layer0": "computercraft:items/pocket_computer_frame", + "layer1": "computercraft:items/pocket_computer" } } diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking.json index d794bc3a8..fe3eb8ec7 100644 --- a/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking.json +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking.json @@ -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" } } diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_colour.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_colour.json new file mode 100644 index 000000000..82d9b31b0 --- /dev/null +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_colour.json @@ -0,0 +1,7 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "computercraft:items/pocket_computer_frame", + "layer1": "computercraft:items/pocket_computer_colour" + } +} diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_colour_blinking.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_colour_blinking.json new file mode 100644 index 000000000..776ed5a1b --- /dev/null +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_colour_blinking.json @@ -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" + } +} diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_colour_on.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_colour_on.json new file mode 100644 index 000000000..086378b4f --- /dev/null +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_colour_on.json @@ -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" + } +} diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_on.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_on.json index 5e1723b62..10a845d54 100644 --- a/src/main/resources/assets/computercraft/models/item/pocket_computer_on.json +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_on.json @@ -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" } } diff --git a/src/main/resources/assets/computercraft/textures/blocks/turtle_white.png b/src/main/resources/assets/computercraft/textures/blocks/turtle_white.png index a2dd732fa..0050df1c4 100644 Binary files a/src/main/resources/assets/computercraft/textures/blocks/turtle_white.png and b/src/main/resources/assets/computercraft/textures/blocks/turtle_white.png differ diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer.png b/src/main/resources/assets/computercraft/textures/items/pocket_computer.png index f066cc2f4..16757c61e 100644 Binary files a/src/main/resources/assets/computercraft/textures/items/pocket_computer.png and b/src/main/resources/assets/computercraft/textures/items/pocket_computer.png differ diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer_advanced.png b/src/main/resources/assets/computercraft/textures/items/pocket_computer_advanced.png index d262102d8..c81c88e23 100644 Binary files a/src/main/resources/assets/computercraft/textures/items/pocket_computer_advanced.png and b/src/main/resources/assets/computercraft/textures/items/pocket_computer_advanced.png differ diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink.png b/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink.png index 23ad6b40e..ccbfe7510 100644 Binary files a/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink.png and b/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink.png differ diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink_advanced.png b/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink_advanced.png deleted file mode 100644 index d360e8ce1..000000000 Binary files a/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink_advanced.png and /dev/null differ diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink_advanced.png.mcmeta b/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink_advanced.png.mcmeta deleted file mode 100644 index e962dcee6..000000000 --- a/src/main/resources/assets/computercraft/textures/items/pocket_computer_blink_advanced.png.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "animation": { - "frametime": 8, - "frames": [ 0, 1 ] - } -} diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer_colour.png b/src/main/resources/assets/computercraft/textures/items/pocket_computer_colour.png new file mode 100644 index 000000000..8055d0c7c Binary files /dev/null and b/src/main/resources/assets/computercraft/textures/items/pocket_computer_colour.png differ diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer_frame.png b/src/main/resources/assets/computercraft/textures/items/pocket_computer_frame.png new file mode 100644 index 000000000..0a446b222 Binary files /dev/null and b/src/main/resources/assets/computercraft/textures/items/pocket_computer_frame.png differ diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer_on.png b/src/main/resources/assets/computercraft/textures/items/pocket_computer_on.png index 4addbc205..c0d3956bb 100644 Binary files a/src/main/resources/assets/computercraft/textures/items/pocket_computer_on.png and b/src/main/resources/assets/computercraft/textures/items/pocket_computer_on.png differ diff --git a/src/main/resources/assets/computercraft/textures/items/pocket_computer_on_advanced.png b/src/main/resources/assets/computercraft/textures/items/pocket_computer_on_advanced.png deleted file mode 100644 index 4915ccec8..000000000 Binary files a/src/main/resources/assets/computercraft/textures/items/pocket_computer_on_advanced.png and /dev/null differ