PeripheralsPlusPlus icon indicating copy to clipboard operation
PeripheralsPlusPlus copied to clipboard

Pocket Peripheral API Feedback

Open SquidDev opened this issue 9 years ago • 5 comments

As requested from SquidDev-CC/CC-Tweaks#56 I'm going to give some feedback on the Pocket Peripheral API.

IPocketAccess

This isn't a requirement, but would be a bonus. Instead of passing around Entity and ItemStack instances everywhere it would be nice to have everything wrapped in an interface. It would look something like:

interface IPocketAccess {
  Entity getEntity(); // Gets the holding entity

  // Gets/sets the modem light on the pocket computer
  boolean getModemLight();
  void setModemLight(boolean value);

  // Same as `ITurtleAccess`. However this is specific for this upgrade.
  NBTTagCompound getUpgradeNBTData();
  void updateUpgradeNBTData();
}

This abstraction from the ItemStack means you don't have to manually set the modem NBT tag, or fiddle with other pocket internals. Personally I think that is cleaner, and means other people can implement tablets and implement this API without having to have identical internals.

It also means the peripheral container can create custom implementations of these and so each upgrade can have its own upgrade NBT tag.

Factories & #77

This is something I'd prefer to have, but adds another layer of complication, and is very different from how turtles implement it. So probably best to ignore.

Basically there would be two classes. IPocketUpgradeFactory. This implements information about the upgrade - adjectives, crafting item, id/string identifier and a method that creates the upgrade. IPocketUpgrade then provides methods that handle instance interaction - update, right click, and either implements or provides an instance of IPeripheral. This means you don't need to cast the IPeripheral instance in your update handler - because it is being called on the peripheral/upgrade itself instead.


What you have currently is very nice. I don't see any additional functionality/methods that need adding to it - though admittedly I'm not doing anything complicated with it. My only real complaint is having to fiddle directly with the ItemStack.

SquidDev avatar Jul 28 '15 13:07 SquidDev