mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-10-15 20:21:42 +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:
@@ -22,6 +22,24 @@ public interface IPocketAccess
|
||||
@Nullable
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
@@ -111,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
|
||||
@@ -188,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;
|
||||
|
||||
int colour = ComputerCraft.Items.pocketComputer.getLightState( stack );
|
||||
return colour == -1 ? Colour.Black.getHex() : colour;
|
||||
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 );
|
||||
|
||||
|
||||
@@ -38,6 +38,19 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
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
|
||||
public int getLight()
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.media.IMedia;
|
||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import dan200.computercraft.shared.common.IColouredItem;
|
||||
import dan200.computercraft.shared.computer.blocks.ComputerState;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
@@ -38,7 +39,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemPocketComputer extends Item implements IComputerItem, IMedia
|
||||
public class ItemPocketComputer extends Item implements IComputerItem, IMedia, IColouredItem
|
||||
{
|
||||
public ItemPocketComputer()
|
||||
{
|
||||
@@ -48,7 +49,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
public ItemStack create( int id, String label, ComputerFamily family, IPocketUpgrade upgrade )
|
||||
public ItemStack create( int id, String label, int colour, ComputerFamily family, IPocketUpgrade upgrade )
|
||||
{
|
||||
// Ignore types we can't handle
|
||||
if( family != ComputerFamily.Normal && family != ComputerFamily.Advanced )
|
||||
@@ -76,6 +77,14 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
|
||||
{
|
||||
result.setStackDisplayName( label );
|
||||
}
|
||||
|
||||
if( colour != -1 )
|
||||
{
|
||||
NBTTagCompound tag = result.getTagCompound();
|
||||
if( tag == null ) result.setTagCompound( tag = new NBTTagCompound() );
|
||||
tag.setInteger( "colour", colour );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -88,10 +97,10 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
|
||||
|
||||
private void getSubItems( List<ItemStack> list, ComputerFamily family )
|
||||
{
|
||||
list.add( PocketComputerItemFactory.create( -1, null, family, null ) );
|
||||
list.add( PocketComputerItemFactory.create( -1, null, -1, family, null ) );
|
||||
for (IPocketUpgrade upgrade : ComputerCraft.getVanillaPocketUpgrades())
|
||||
{
|
||||
list.add( PocketComputerItemFactory.create( -1, null, family, upgrade ) );
|
||||
list.add( PocketComputerItemFactory.create( -1, null, -1, family, upgrade ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+3
-2
@@ -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
|
||||
|
||||
@@ -420,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,
|
||||
@@ -429,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,
|
||||
@@ -452,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 )
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user