diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java index 282bb2bf2..7b7862cbb 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -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 );