mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 13:42:59 +00:00 
			
		
		
		
	Allow changing the colour of the modem light
This now uses an integer between 0 and 15 to represent a colour, rather than a simple on/off flag.
This commit is contained in:
		| @@ -23,29 +23,40 @@ public interface IPocketAccess | ||||
|     Entity getEntity(); | ||||
|  | ||||
|     /** | ||||
|      * Get if the modem light is turned on | ||||
|      * Get the colour of the modem light. | ||||
|      * | ||||
|      * @return If the modem light is turned on | ||||
|      * See {@link #setLight(int)} for the values this may return. | ||||
|      * | ||||
|      * @return The colour of the modem light. | ||||
|      * @see #setLight(int) | ||||
|      */ | ||||
|     boolean getModemLight(); | ||||
|     int getLight(); | ||||
|  | ||||
|     /** | ||||
|      * Turn on/off the modem light | ||||
|      * Set the colour of the modem light. Use {@link 0} to turn it off. | ||||
|      * | ||||
|      * @param value If the light should be on | ||||
|      * Colours take the form of an integer between 0 and 15, using the opposite order to those in | ||||
|      * {@link <a href="http://www.computercraft.info/wiki/Colors_(API)#Colors">The colors API</a>}  - so 0 being black, | ||||
|      * 1 representing red, 2 representing green all the way up to 15 for white. | ||||
|      * | ||||
|      * @param value The colour the light should have. | ||||
|      * @see #getLight() | ||||
|      */ | ||||
|     void setModemLight( boolean value ); | ||||
|     void setLight( int value ); | ||||
|  | ||||
|     /** | ||||
|      * Get the upgrade specific NBT | ||||
|      * | ||||
|      * @return The upgrade's NBT | ||||
|      * @see #updateUpgradeNBTData() | ||||
|      */ | ||||
|     @Nonnull | ||||
|     NBTTagCompound getUpgradeNBTData(); | ||||
|  | ||||
|     /** | ||||
|      * Mark the upgrade specific NBT as dirty | ||||
|      * | ||||
|      * @see #getUpgradeNBTData() | ||||
|      */ | ||||
|     void updateUpgradeNBTData(); | ||||
|  | ||||
|   | ||||
| @@ -25,6 +25,7 @@ import dan200.computercraft.shared.pocket.items.ItemPocketComputer; | ||||
| import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon; | ||||
| import dan200.computercraft.shared.turtle.blocks.TileTurtle; | ||||
| import dan200.computercraft.shared.turtle.entity.TurtleVisionCamera; | ||||
| import dan200.computercraft.shared.util.Colour; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.client.Minecraft; | ||||
| import net.minecraft.client.renderer.GlStateManager; | ||||
| @@ -53,7 +54,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||||
| import net.minecraftforge.fml.common.gameevent.TickEvent; | ||||
| import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||||
| import org.lwjgl.opengl.GL11; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.util.ArrayList; | ||||
| @@ -117,19 +117,14 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon | ||||
|             private ModelResourceLocation pocket_computer_off = new ModelResourceLocation( "computercraft:pocketComputer", "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_on_modem_on = new ModelResourceLocation( "computercraft:pocket_computer_on_modem_on", "inventory" ); | ||||
|             private ModelResourceLocation pocket_computer_blinking_modem_on = new ModelResourceLocation( "computercraft:pocket_computer_blinking_modem_on", "inventory" ); | ||||
|             private ModelResourceLocation advanced_pocket_computer_off = new ModelResourceLocation( "computercraft:advanced_pocket_computer_off", "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_on_modem_on = new ModelResourceLocation( "computercraft:advanced_pocket_computer_on_modem_on", "inventory" ); | ||||
|             private ModelResourceLocation advanced_pocket_computer_blinking_modem_on = new ModelResourceLocation( "computercraft:advanced_pocket_computer_blinking_modem_on", "inventory" ); | ||||
|  | ||||
|             @Override | ||||
|             public ModelResourceLocation getModelLocation( ItemStack stack ) | ||||
|             { | ||||
|                 ItemPocketComputer itemPocketComputer = (ItemPocketComputer)stack.getItem(); | ||||
|                 boolean modemOn = itemPocketComputer.getLightState( stack ); | ||||
|                 switch( itemPocketComputer.getFamily( stack ) ) | ||||
|                 { | ||||
|                     case Advanced: | ||||
| @@ -143,11 +138,11 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon | ||||
|                             } | ||||
|                             case On: | ||||
|                             { | ||||
|                                 return modemOn ? advanced_pocket_computer_on_modem_on : advanced_pocket_computer_on; | ||||
|                                 return advanced_pocket_computer_on; | ||||
|                             } | ||||
|                             case Blinking: | ||||
|                             { | ||||
|                                 return modemOn ? advanced_pocket_computer_blinking_modem_on : advanced_pocket_computer_blinking; | ||||
|                                 return advanced_pocket_computer_blinking; | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
| @@ -163,24 +158,36 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon | ||||
|                             } | ||||
|                             case On: | ||||
|                             { | ||||
|                                 return modemOn ? pocket_computer_on_modem_on : pocket_computer_on; | ||||
|                                 return pocket_computer_on; | ||||
|                             } | ||||
|                             case Blinking: | ||||
|                             { | ||||
|                                 return modemOn ? pocket_computer_blinking_modem_on : pocket_computer_blinking; | ||||
|                                 return pocket_computer_blinking; | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         }, new String[] { | ||||
|             "pocketComputer", "pocket_computer_on", "pocket_computer_blinking", "pocket_computer_on_modem_on", "pocket_computer_blinking_modem_on", | ||||
|             "advanced_pocket_computer_off", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking", "advanced_pocket_computer_on_modem_on", "advanced_pocket_computer_blinking_modem_on", | ||||
|             "pocketComputer", "pocket_computer_on", "pocket_computer_blinking", | ||||
|             "advanced_pocket_computer_off", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking", | ||||
|         } ); | ||||
|  | ||||
|         // Setup | ||||
| 		mc.getItemColors().registerItemColorHandler(new DiskColorHandler(ComputerCraft.Items.disk), ComputerCraft.Items.disk); | ||||
| 		mc.getItemColors().registerItemColorHandler(new DiskColorHandler(ComputerCraft.Items.diskExpanded), ComputerCraft.Items.diskExpanded); | ||||
|         mc.getItemColors().registerItemColorHandler( new DiskColorHandler( ComputerCraft.Items.disk ), ComputerCraft.Items.disk ); | ||||
|         mc.getItemColors().registerItemColorHandler( new DiskColorHandler( ComputerCraft.Items.diskExpanded ), ComputerCraft.Items.diskExpanded ); | ||||
|  | ||||
|         mc.getItemColors().registerItemColorHandler( new IItemColor() | ||||
|         { | ||||
|             @Override | ||||
|             public int getColorFromItemstack( ItemStack stack, int layout ) | ||||
|             { | ||||
|                 if( layout != 1 ) return 0xFFFFFF; | ||||
|  | ||||
|                 Colour colour = Colour.fromInt( ComputerCraft.Items.pocketComputer.getLightState( stack ) ); | ||||
|                 return colour == null ? Colour.Black.getHex() : colour.getHex(); | ||||
|             } | ||||
|         }, ComputerCraft.Items.pocketComputer ); | ||||
|  | ||||
|         // Setup renderers | ||||
|         ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() ); | ||||
|   | ||||
| @@ -40,18 +40,21 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean getModemLight() | ||||
|     public int getLight() | ||||
|     { | ||||
|         return getUserData().getBoolean( "modemLight" ); | ||||
|         int value = getUserData().getInteger( "modemLight" ); | ||||
|         return value >= 0 && value <= 15 ? value : 0; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void setModemLight( boolean value ) | ||||
|     public void setLight( int value ) | ||||
|     { | ||||
|         if( value < 0 || value > 15 ) throw new IllegalArgumentException( "Colour out of bounds" ); | ||||
|  | ||||
|         NBTTagCompound tag = getUserData(); | ||||
|         if( tag.getBoolean( "modemLight" ) != value ) | ||||
|         if( tag.getInteger( "modemLight" ) != value ) | ||||
|         { | ||||
|             tag.setBoolean( "modemLight", value ); | ||||
|             tag.setInteger( "modemLight", value ); | ||||
|             updateUserData(); | ||||
|         } | ||||
|     } | ||||
| @@ -117,11 +120,13 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public ItemStack getStack() { | ||||
|     public ItemStack getStack() | ||||
|     { | ||||
|         return m_stack; | ||||
|     } | ||||
|  | ||||
|     public IPocketUpgrade getUpgrade() { | ||||
|     public IPocketUpgrade getUpgrade() | ||||
|     { | ||||
|         return m_upgrade; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -32,6 +32,8 @@ import net.minecraft.util.EnumHand; | ||||
| import net.minecraft.util.SoundEvent; | ||||
| import net.minecraft.world.World; | ||||
| import net.minecraftforge.common.util.Constants; | ||||
| import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| @@ -433,6 +435,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia | ||||
|         stack.getTagCompound().setInteger( "sessionID", sessionID ); | ||||
|     } | ||||
|  | ||||
|     @SideOnly(Side.CLIENT) | ||||
|     public ComputerState getState( ItemStack stack ) | ||||
|     { | ||||
|         ClientComputer computer = getClientComputer( stack ); | ||||
| @@ -443,18 +446,19 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia | ||||
|         return ComputerState.Off; | ||||
|     } | ||||
|  | ||||
|     public boolean getLightState( ItemStack stack ) | ||||
|     @SideOnly(Side.CLIENT) | ||||
|     public int getLightState( ItemStack stack ) | ||||
|     { | ||||
|         ClientComputer computer = getClientComputer( stack ); | ||||
|         if( computer != null && computer.isOn() ) | ||||
|         { | ||||
|             NBTTagCompound computerNBT = computer.getUserData(); | ||||
|             if( computerNBT != null && computerNBT.getBoolean( "modemLight" ) ) | ||||
|             if( computerNBT != null ) | ||||
|             { | ||||
|                 return true; | ||||
|                 return computerNBT.getInteger( "modemLight" ); | ||||
|             } | ||||
|         } | ||||
|         return false; | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     public static IPocketUpgrade getUpgrade( ItemStack stack ) | ||||
|   | ||||
| @@ -5,6 +5,7 @@ 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; | ||||
| @@ -76,7 +77,7 @@ public class PocketModem implements IPocketUpgrade | ||||
|                 modem.setLocation( entity.getEntityWorld(), entity.posX, entity.posY, entity.posZ ); | ||||
|             } | ||||
|  | ||||
|             access.setModemLight( modem.isActive() ); | ||||
|             access.setLight( modem.isActive() ? Colour.Red.ordinal() : Colour.Black.ordinal() ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| { | ||||
|     "parent": "item/generated", | ||||
|     "textures": { | ||||
|         "layer0": "computercraft:items/pocketComputerBlinkAdvanced" | ||||
|         "layer0": "computercraft:items/pocketComputerBlinkAdvanced", | ||||
|         "layer1": "computercraft:items/pocketComputerLight" | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,7 +0,0 @@ | ||||
| { | ||||
|     "parent": "item/generated", | ||||
|     "textures": { | ||||
|         "layer0": "computercraft:items/pocketComputerBlinkAdvanced", | ||||
|         "layer1": "computercraft:items/pocketComputerModemLight" | ||||
|     } | ||||
| } | ||||
| @@ -1,6 +1,7 @@ | ||||
| { | ||||
|     "parent": "item/generated", | ||||
|     "textures": { | ||||
|         "layer0": "computercraft:items/pocketComputerOnAdvanced" | ||||
|         "layer0": "computercraft:items/pocketComputerOnAdvanced", | ||||
|         "layer1": "computercraft:items/pocketComputerLight" | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,7 +0,0 @@ | ||||
| { | ||||
|     "parent": "item/generated", | ||||
|     "textures": { | ||||
|         "layer0": "computercraft:items/pocketComputerOnAdvanced", | ||||
|         "layer1": "computercraft:items/pocketComputerModemLight" | ||||
|     } | ||||
| } | ||||
| @@ -1,6 +1,7 @@ | ||||
| { | ||||
|     "parent": "item/generated", | ||||
|     "textures": { | ||||
|         "layer0": "computercraft:items/pocketComputerBlink" | ||||
|         "layer0": "computercraft:items/pocketComputerBlink", | ||||
|         "layer1": "computercraft:items/pocketComputerLight" | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,7 +0,0 @@ | ||||
| { | ||||
|     "parent": "item/generated", | ||||
|     "textures": { | ||||
|         "layer0": "computercraft:items/pocketComputerBlink", | ||||
|         "layer1": "computercraft:items/pocketComputerModemLight" | ||||
|     } | ||||
| } | ||||
| @@ -1,6 +1,7 @@ | ||||
| { | ||||
|     "parent": "item/generated", | ||||
|     "textures": { | ||||
|         "layer0": "computercraft:items/pocketComputerOn" | ||||
|         "layer0": "computercraft:items/pocketComputerOn", | ||||
|         "layer1": "computercraft:items/pocketComputerLight" | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,7 +0,0 @@ | ||||
| { | ||||
|     "parent": "item/generated", | ||||
|     "textures": { | ||||
|         "layer0": "computercraft:items/pocketComputerOn", | ||||
|         "layer1": "computercraft:items/pocketComputerModemLight" | ||||
|     } | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 246 B | 
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 242 B | 
		Reference in New Issue
	
	Block a user
	 SquidDev
					SquidDev