CC: Tweaked

CC: Tweaked

57M Downloads

[Question]API PeripheralProvider

SirEndii opened this issue ยท 2 comments

commented

Hey, I want to be able to connect my block to a modem, but I have the problem that I can now connect every block in Minecraft to a modem.

image

Here's my code: https://hasteb.in/junixina.java

Thanks for any help

Useful information to include:

  • Minecraft version: 1.16.4
  • CC: Tweaked version: 1,94.0
commented

Your peripheral provider basically looks like this:

@NotNull
@Override
public LazyOptional<IPeripheral> getPeripheral(@NotNull World world, @NotNull BlockPos blockPos, @NotNull Direction direction) {
    return LazyOptional.of(() -> new AdvancedPeripheral("lightSensor"));
}

This doesn't contain any checks, which means it'll return an AdvancedPeripheral for every block, not just LightSensor. You probably want something like:

@NotNull
@Override
public LazyOptional<IPeripheral> getPeripheral(@NotNull World world, @NotNull BlockPos blockPos, @NotNull Direction direction) {
    BlockState block = world.getBlock(blockPos);
    return block.getBlock() instanceof LightSensor
      ? LazyOptional.of(() -> new AdvancedPeripheral("lightSensor"))
      : LazyOptional.empty();
}
commented

Thank you!