1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-15 03:35:42 +00:00

Expand IPocketAccess.getLight/setLight to use RGB colours

This allows us to restore the modem light to its original colour.
This commit is contained in:
SquidDev 2017-05-14 14:22:20 +01:00
parent 6426255bd4
commit a6b870dfbb
6 changed files with 34 additions and 25 deletions

View File

@ -23,26 +23,22 @@ public interface IPocketAccess
Entity getEntity(); Entity getEntity();
/** /**
* Get the colour of the pocket computer's light. * Get the colour of this pocket computer's light as a RGB number.
* *
* See {@link #setLight(int)} for the values this may return. * @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.
* @return The colour of the pocket computer's light.
* @see #setLight(int) * @see #setLight(int)
*/ */
int getLight(); 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 * @param colour The colour this modem's light will be changed to. This should be a RGB colour between
* {@link <a href="http://www.computercraft.info/wiki/Colors_(API)#Colors">The colors API</a>} - so 0 being black, * {@code 0x000000} and {@code 0xFFFFFF} or -1 to reset to the default colour.
* 1 representing red, 2 representing green all the way up to 15 for white.
*
* @param value The colour the light should have.
* @see #getLight() * @see #getLight()
*/ */
void setLight( int value ); void setLight( int colour );
/** /**
* Get the upgrade-specific NBT. * Get the upgrade-specific NBT.

View File

@ -127,7 +127,7 @@ public interface ITurtleAccess
void setColour( int colour ); void setColour( int colour );
/** /**
* Set the colour of the turtle to a RGB number. * Get the colour of this turtle as a RGB number.
* *
* @return The colour this turtle is. This will be a RGB colour between {@code 0x000000} and {@code 0xFFFFFF} or * @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. * -1 if it has no colour.

View File

@ -192,8 +192,8 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
{ {
if( layout != 1 ) return 0xFFFFFF; if( layout != 1 ) return 0xFFFFFF;
Colour colour = Colour.fromInt( ComputerCraft.Items.pocketComputer.getLightState( stack ) ); int colour = ComputerCraft.Items.pocketComputer.getLightState( stack );
return colour == null ? Colour.Black.getHex() : colour.getHex(); return colour == -1 ? Colour.Black.getHex() : colour;
} }
}, ComputerCraft.Items.pocketComputer ); }, ComputerCraft.Items.pocketComputer );

View File

@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -40,19 +41,32 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public int getLight() public int getLight()
{ {
int value = getUserData().getInteger( "modemLight" ); NBTTagCompound tag = getUserData();
return value >= 0 && value <= 15 ? value : 0; if( tag.hasKey( "modemLight", Constants.NBT.TAG_ANY_NUMERIC ) )
{
return tag.getInteger( "modemLight" );
}
else
{
return -1;
}
} }
@Override @Override
public void setLight( int value ) public void setLight( int colour )
{ {
if( value < 0 || value > 15 ) throw new IllegalArgumentException( "Colour out of bounds" );
NBTTagCompound tag = getUserData(); NBTTagCompound tag = getUserData();
if( tag.getInteger( "modemLight" ) != value ) if( colour >= 0 && colour <= 0xFFFFFF )
{ {
tag.setInteger( "modemLight", value ); 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(); updateUserData();
} }
} }

View File

@ -457,12 +457,12 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia
if( computer != null && computer.isOn() ) if( computer != null && computer.isOn() )
{ {
NBTTagCompound computerNBT = computer.getUserData(); NBTTagCompound computerNBT = computer.getUserData();
if( computerNBT != null ) if( computerNBT != null && computerNBT.hasKey( "modemLight", Constants.NBT.TAG_ANY_NUMERIC ) )
{ {
return computerNBT.getInteger( "modemLight" ); return computerNBT.getInteger( "modemLight" );
} }
} }
return 0; return -1;
} }
public IPocketUpgrade getUpgrade( ItemStack stack ) public IPocketUpgrade getUpgrade( ItemStack stack )

View File

@ -5,7 +5,6 @@ import dan200.computercraft.api.pocket.IPocketAccess;
import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.peripheral.PeripheralType; import dan200.computercraft.shared.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory; import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -77,7 +76,7 @@ public class PocketModem implements IPocketUpgrade
modem.setLocation( entity.getEntityWorld(), entity.posX, entity.posY, entity.posZ ); 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 );
} }
} }