Peripherals++

Peripherals++

359k Downloads

Turtle Upgrade Peripherals

theoriginalbit opened this issue ยท 1 comments

commented

You can't cache the peripherals in your upgrades. #createPeripheral(ITurtleAccess, TurtleSide) shouldn't retain the new instance like you've done in PeripheralXP and the likes. Doing so will mean all Turtles share the same peripheral, which can really cause problems, especially if it is location dependent! When you need the IPeripheral back in #update(ITurtleAccess, TurtleSide), you can do

@Override
public void update(ITurtleAccess access, TurtleSide side) {
  IPeripheral periph = access.getPeripheral(side);
  if (periph instanceof PeripheralXP) {
    PeripheralXP xp = (PeripheralXP) periph;
    // do what you need here
  }
}
commented

Makes sense, thanks so much for taking the time to help me out!