Being able to use generic peripherals alongside non-generic peripherals
Quezler opened this issue ยท 7 comments
Basically just a way to bring some attention to TeamPneumatic/pnc-repressurized#1034
That mod adds peripheral methods to some of its blocks, but the inventory/fluid methods don't get bound because of it.
Creating this here in the hope that people have tried to figure this out before, and have knowledge of clean ways to do it.
More context can be found in the linked issue, this description is just the bare minimum summary of what the issue entails.
There's a fair bit of historical baggage in PNC which is in big need of ... modernising.
Got some pointers to using the generic peripheral system?
There's a fair bit of historical baggage in PNC which is in big need of ... modernising.
Yeah, I very much sympathise! I think a lot of computer mod integration is also originally written to support OC and CC, which definitely makes things easier from the implementers side but more awkward from the consumer's side. Which is fair - computer mods is (rightfully!) not the most important thing.
Probably should talk with fnuecke about some common API, so we can avoid this when OC2 is stable!
Got some pointers to using the generic peripheral system?
Basically you implement GenericPeripheral
and add static classes to that method which target a specific type. So for instance, AbstractAirHandlingBlockEntity
would look something like:
public class AbstractAirHandlingBlockEntityMethods implements GenericPeripheral {
@Override
public ResourceLocation id() {
return new ResourceLocation( MOD_ID, "air_handling" );
}
@LuaFunction(mainThread = true)
public static float getPressure(AbstractAirHandlingBlockEntity self, Optional<Direction> direction) {
if (!direction.isPresent()) {
return airHandler.getPressure();
} else {
LazyOptional<IAirHandlerMachine> cap = getCapability(PNCCapabilities.AIR_HANDLER_MACHINE_CAPABILITY, direction.get());
return cap.map(IAirHandler::getPressure).orElse(0f);
}
}
@LuaFunction
public static float getMinWorkingPressure(AbstractAirHandlingBlockEntity self) { return self.getMinWorkingPressure(); }
// Etc...
}
Then register that class with ComputerCraftAPI.registerGenericSource
. I'm happy to have a go at a PR if that'd be helpful, though obviously no obligation to merge it if you think it's worse!
Thanks! Actually looks pretty straightforward; I'll have a play and see how easy it is to adapt to it...
Great. Feel free to ask if you've got any questions or complaints, happy to make some changes to the API if there's any awkward areas with it.
Closing this, as for now I want to keep explicitly provided peripherals and generic peripherals separate.
The recommended way to do this is just to use the generic peripheral system to implement one's peripheral too.
However, it looks like PneumaticCraft have reimplemented their own Lua-method system on top of CC's ๐, so that's probably not an option.
#1093 as an some idea?
But in general, ye, this is pain sometimes. I just copy-pasting peripherals