mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 20:20:30 +00:00
Preserve on-state of pocket computers
This is far less robust than block-based computers, but I don't think it needs to be. Fixes #1097 Or closes? Unclear - I'm counting this as a bug.
This commit is contained in:
parent
2efad38f53
commit
ab22726883
@ -50,6 +50,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
private static final String NBT_UPGRADE = "Upgrade";
|
||||
private static final String NBT_UPGRADE_INFO = "UpgradeInfo";
|
||||
public static final String NBT_LIGHT = "Light";
|
||||
private static final String NBT_ON = "On";
|
||||
|
||||
private static final String NBT_INSTANCE = "Instanceid";
|
||||
private static final String NBT_SESSION = "SessionId";
|
||||
@ -108,6 +109,13 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
setLabel( stack, label );
|
||||
}
|
||||
|
||||
boolean on = computer.isOn();
|
||||
if( on != isMarkedOn( stack ) )
|
||||
{
|
||||
changed = true;
|
||||
stack.getOrCreateTag().putBoolean( NBT_ON, on );
|
||||
}
|
||||
|
||||
// Update pocket upgrade
|
||||
if( upgrade != null ) upgrade.update( computer, computer.getPeripheral( ComputerSide.BACK ) );
|
||||
|
||||
@ -250,6 +258,10 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
computer.updateValues( entity, stack, getUpgrade( stack ) );
|
||||
computer.addAPI( new PocketAPI( computer ) );
|
||||
ComputerCraft.serverComputerRegistry.add( instanceID, computer );
|
||||
|
||||
// Only turn on when initially creating the computer, rather than each tick.
|
||||
if( isMarkedOn( stack ) && entity instanceof PlayerEntity ) computer.turnOn();
|
||||
|
||||
if( inventory != null ) inventory.setChanged();
|
||||
}
|
||||
computer.setWorld( world );
|
||||
@ -365,6 +377,12 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
stack.getOrCreateTag().putInt( NBT_SESSION, sessionID );
|
||||
}
|
||||
|
||||
private static boolean isMarkedOn( @Nonnull ItemStack stack )
|
||||
{
|
||||
CompoundNBT nbt = stack.getTag();
|
||||
return nbt != null && nbt.getBoolean( NBT_ON );
|
||||
}
|
||||
|
||||
public static ComputerState getState( @Nonnull ItemStack stack )
|
||||
{
|
||||
ClientComputer computer = getClientComputer( stack );
|
||||
|
Loading…
Reference in New Issue
Block a user