1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-05-31 05:34:13 +00:00

Fix syncing of colour between PocketBrain and item

- Actually set colour when constructing the brain.
 - Sync it back after crafting, much like we do for upgrades (see
   dcc74e15c7ab88e5ec7bb4c83ca00d49c074b615) for more details.

We should take a proper look at this on 1.21.4 and make these methods
main-thread only, so we can sync immediately.

Fixes #2157
This commit is contained in:
Jonathan Coates 2025-03-20 18:54:06 +00:00
parent 7c1e8e1951
commit 0e1e8a72d3
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 11 additions and 6 deletions

View File

@ -44,11 +44,12 @@ public final class PocketBrain implements IPocketAccess {
private int colour = -1; private int colour = -1;
private int lightColour = -1; private int lightColour = -1;
public PocketBrain(PocketHolder holder, @Nullable UpgradeData<IPocketUpgrade> upgrade, ServerComputer.Properties properties) { public PocketBrain(PocketHolder holder, @Nullable UpgradeData<IPocketUpgrade> upgrade, int colour, ServerComputer.Properties properties) {
this.computer = new PocketServerComputer(this, holder, properties); this.computer = new PocketServerComputer(this, holder, properties);
this.holder = holder; this.holder = holder;
this.position = holder.pos(); this.position = holder.pos();
this.upgrade = UpgradeData.copyOf(upgrade); this.upgrade = UpgradeData.copyOf(upgrade);
this.colour = colour;
invalidatePeripheral(); invalidatePeripheral();
} }

View File

@ -272,7 +272,7 @@ public class PocketComputerItem extends Item implements IComputerItem, IColoured
} }
var brain = new PocketBrain( var brain = new PocketBrain(
holder, getUpgradeWithData(stack), holder, getUpgradeWithData(stack), getColour(stack),
ServerComputer.properties(getComputerID(stack), getFamily()).label(getLabel(stack)) ServerComputer.properties(getComputerID(stack), getFamily()).label(getLabel(stack))
); );
var computer = brain.computer(); var computer = brain.computer();
@ -314,10 +314,14 @@ public class PocketComputerItem extends Item implements IComputerItem, IColoured
// item. However, if we've just crafted the computer with an upgrade, we should sync the other way, and update // item. However, if we've just crafted the computer with an upgrade, we should sync the other way, and update
// the computer. // the computer.
var server = level.getServer(); var server = level.getServer();
if (server != null) { if (server == null) return;
var computer = getServerComputer(server, stack);
if (computer != null) computer.getBrain().setUpgrade(getUpgradeWithData(stack)); var computer = getServerComputer(server, stack);
} if (computer == null) return;
var brain = computer.getBrain();
brain.setUpgrade(getUpgradeWithData(stack));
brain.setColour(getColour(stack));
} }
// IComputerItem implementation // IComputerItem implementation