1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-31 19:29:13 +00:00

Allow dying pocket computers too

This splits up the pocket computer textures and models into the frame
(off, on, blinking), colour layer (normal, advanced, custom) and modem
light.
This commit is contained in:
SquidDev 2017-05-14 15:02:56 +01:00
parent a6b870dfbb
commit b37dbbd0af
26 changed files with 184 additions and 71 deletions

View File

@ -22,6 +22,24 @@ public interface IPocketAccess
@Nullable @Nullable
Entity getEntity(); Entity getEntity();
/**
* Get the colour of this pocket computer as a RGB number.
*
* @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.
*
* @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. * Get the colour of this pocket computer's light as a RGB number.
* *

View File

@ -9,6 +9,7 @@ package dan200.computercraft.client.proxy;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.*; import dan200.computercraft.client.gui.*;
import dan200.computercraft.client.render.TileEntityMonitorRenderer; 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.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
@ -111,61 +112,66 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
private ModelResourceLocation pocket_computer_off = new ModelResourceLocation( "computercraft:pocket_computer", "inventory" ); 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_on = new ModelResourceLocation( "computercraft:pocket_computer_on", "inventory" );
private ModelResourceLocation pocket_computer_blinking = new ModelResourceLocation( "computercraft:pocket_computer_blinking", "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_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 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 @Nonnull
@Override @Override
public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack ) public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack )
{ {
ItemPocketComputer itemPocketComputer = (ItemPocketComputer)stack.getItem(); ItemPocketComputer itemPocketComputer = (ItemPocketComputer) stack.getItem();
ComputerState state = itemPocketComputer.getState( stack );
if( itemPocketComputer.getColour( stack ) == -1 )
{
switch( itemPocketComputer.getFamily( stack ) ) switch( itemPocketComputer.getFamily( stack ) )
{ {
case Advanced: case Advanced:
{ switch( state )
switch( itemPocketComputer.getState( stack ) )
{ {
case Off: case Off:
default: default:
{
return advanced_pocket_computer_off; return advanced_pocket_computer_off;
}
case On: case On:
{
return advanced_pocket_computer_on; return advanced_pocket_computer_on;
}
case Blinking: case Blinking:
{
return advanced_pocket_computer_blinking; return advanced_pocket_computer_blinking;
} }
}
}
case Normal: case Normal:
default: default:
{ switch( state )
switch( itemPocketComputer.getState( stack ) )
{ {
case Off: case Off:
default: default:
{
return pocket_computer_off; return pocket_computer_off;
}
case On: case On:
{
return pocket_computer_on; return pocket_computer_on;
}
case Blinking: case Blinking:
{
return pocket_computer_blinking; return pocket_computer_blinking;
} }
} }
} }
else
{
switch( state )
{
case Off:
default:
return colour_pocket_computer_off;
case On:
return colour_pocket_computer_on;
case Blinking:
return colour_pocket_computer_blinking;
}
} }
} }
}, new String[] { }, new String[] {
"pocket_computer", "pocket_computer_on", "pocket_computer_blinking", "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 // Setup client forge handlers
@ -188,13 +194,27 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
mc.getItemColors().registerItemColorHandler( new IItemColor() mc.getItemColors().registerItemColorHandler( new IItemColor()
{ {
@Override @Override
public int getColorFromItemstack( @Nonnull ItemStack stack, int layout ) public int getColorFromItemstack( @Nonnull ItemStack stack, int layer )
{ {
if( layout != 1 ) return 0xFFFFFF; 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 ); int colour = ComputerCraft.Items.pocketComputer.getLightState( stack );
return colour == -1 ? Colour.Black.getHex() : colour; return colour == -1 ? Colour.Black.getHex() : colour;
} }
}
}
}, ComputerCraft.Items.pocketComputer ); }, ComputerCraft.Items.pocketComputer );
// Setup renderers // Setup renderers

View File

@ -38,6 +38,19 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
return m_entity; return m_entity;
} }
@Override
public int getColour()
{
return ComputerCraft.Items.pocketComputer.getColour( m_stack );
}
@Override
public void setColour( int colour )
{
ComputerCraft.Items.pocketComputer.setColourDirect( m_stack, colour );
updateUpgradeNBTData();
}
@Override @Override
public int getLight() public int getLight()
{ {

View File

@ -11,6 +11,7 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.media.IMedia; import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.computer.blocks.ComputerState; import dan200.computercraft.shared.computer.blocks.ComputerState;
import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
@ -38,7 +39,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
public class ItemPocketComputer extends Item implements IComputerItem, IMedia public class ItemPocketComputer extends Item implements IComputerItem, IMedia, IColouredItem
{ {
public ItemPocketComputer() public ItemPocketComputer()
{ {
@ -48,7 +49,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
setCreativeTab( ComputerCraft.mainCreativeTab ); 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 // Ignore types we can't handle
if( family != ComputerFamily.Normal && family != ComputerFamily.Advanced ) if( family != ComputerFamily.Normal && family != ComputerFamily.Advanced )
@ -76,6 +77,14 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
{ {
result.setStackDisplayName( label ); result.setStackDisplayName( label );
} }
if( colour != -1 )
{
NBTTagCompound tag = result.getTagCompound();
if( tag == null ) result.setTagCompound( tag = new NBTTagCompound() );
tag.setInteger( "colour", colour );
}
return result; return result;
} }
@ -88,10 +97,10 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
private void getSubItems( List<ItemStack> list, ComputerFamily family ) 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()) for (IPocketUpgrade upgrade : ComputerCraft.getVanillaPocketUpgrades())
{ {
list.add( PocketComputerItemFactory.create( -1, null, family, upgrade ) ); list.add( PocketComputerItemFactory.create( -1, null, -1, family, upgrade ) );
} }
} }
@ -525,4 +534,33 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
return sub; 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 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; ItemPocketComputer computer = ComputerCraft.Items.pocketComputer;
switch( family ) switch( family )
@ -21,7 +21,7 @@ public class PocketComputerItemFactory
case Normal: case Normal:
case Advanced: case Advanced:
{ {
return computer.create( id, label, family, upgrade ); return computer.create( id, label, colour, family, upgrade );
} }
} }
return null; return null;

View File

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

View File

@ -420,7 +420,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
GameRegistry.addRecipe( new ImpostorShapelessRecipe( bookPrintout, new ItemStack[]{leather, singlePrintout, string} ) ); GameRegistry.addRecipe( new ImpostorShapelessRecipe( bookPrintout, new ItemStack[]{leather, singlePrintout, string} ) );
// Pocket Computer // Pocket Computer
ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Normal, null ); ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, null );
GameRegistry.addRecipe( pocketComputer, GameRegistry.addRecipe( pocketComputer,
"XXX", "XYX", "XZX", "XXX", "XYX", "XZX",
'X', Blocks.STONE, 'X', Blocks.STONE,
@ -429,7 +429,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
); );
// Advanced Pocket Computer // 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, GameRegistry.addRecipe( advancedPocketComputer,
"XXX", "XYX", "XZX", "XXX", "XYX", "XZX",
'X', Items.GOLD_INGOT, 'X', Items.GOLD_INGOT,
@ -452,13 +452,13 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
GameRegistry.addRecipe( new ImpostorRecipe( GameRegistry.addRecipe( new ImpostorRecipe(
1, 2, 1, 2,
new ItemStack[]{ upgrade.getCraftingItem(), pocketComputer }, new ItemStack[]{ upgrade.getCraftingItem(), pocketComputer },
PocketComputerItemFactory.create( -1, null, ComputerFamily.Normal, upgrade ) PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, upgrade )
) ); ) );
GameRegistry.addRecipe( new ImpostorRecipe( GameRegistry.addRecipe( new ImpostorRecipe(
1, 2, 1, 2,
new ItemStack[]{ upgrade.getCraftingItem(), advancedPocketComputer }, new ItemStack[]{ upgrade.getCraftingItem(), advancedPocketComputer },
PocketComputerItemFactory.create( -1, null, ComputerFamily.Advanced, upgrade ) PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, upgrade )
) ); ) );
} }

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", "parent": "item/generated",
"textures": { "textures": {
"layer0": "computercraft:items/pocket_computer_blink_advanced", "layer0": "computercraft:items/pocket_computer_blink",
"layer1": "computercraft:items/pocket_computer_light" "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", "parent": "item/generated",
"textures": { "textures": {
"layer0": "computercraft:items/pocket_computer_on_advanced", "layer0": "computercraft:items/pocket_computer_on",
"layer1": "computercraft:items/pocket_computer_light" "layer1": "computercraft:items/pocket_computer_advanced",
"layer2": "computercraft:items/pocket_computer_light"
} }
} }

View File

@ -1,6 +1,7 @@
{ {
"parent": "item/generated", "parent": "item/generated",
"textures": { "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", "parent": "item/generated",
"textures": { "textures": {
"layer0": "computercraft:items/pocket_computer_blink", "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", "parent": "item/generated",
"textures": { "textures": {
"layer0": "computercraft:items/pocket_computer_on", "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: 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