-
Greetings |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It seems you just need to register a PeripheralCapability for the block on neoforge, or add to PeripheralLookup on fabric. I'm not sure if this is possible to do with the generic peripheral system, I would assume not? |
Beta Was this translation helpful? Give feedback.
-
Yeaaaaah. Block support for generic peripherals is one of the things I want to look at as part of the 1.21.5 changes, as we half need this for #1890. Whether this happens or not ... remains to been seen. I think the interface I'm probably thinking of right now is something like: interface BlockPeripheralTarget {
ServerLevel level();
BlockPos pos();
BlockState state();
@Nullable BlockEntity blockEntity();
@Nullable Direction side();
} Then peripherals look something like: final class NoteBlockPeripheral implements GenericPeripheral {
@LuaFunction(mainThread = true)
public void playNote(BlockPeripheralTarget block) {
// ...
}
} However, this requires a way to select what block(s) to apply to this peripheral to. The easiest way to do that is just have a class NoteBlockPeripheral implements GenericPeripheral {
public boolean canApply(Object target) {
return target instanceof BlockPeripheralTarget block && block.state().block() == Blocks.NOTE_BLOCK;
}
// ...
} However, I'm a little wary of the performance implications with this with a lot of providers registered. Maybe it's not actually that bad in practice though, something to measure. For now though, as @tehgreatdoge, you can just use capabilities — those do now support blocks. That's mostly why |
Beta Was this translation helpful? Give feedback.
Yeaaaaah. Block support for generic peripherals is one of the things I want to look at as part of the 1.21.5 changes, as we half need this for #1890. Whether this happens or not ... remains to been seen.
I think the interface I'm probably thinking of right now is something like:
Then peripherals look something like:
However, this requires a way to select what…