use of org.spongepowered.api.block.entity.NameableBlockEntity in project SpongeCommon by SpongePowered.
the class ServerLocationData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ServerLocation.class).create(Keys.BIOME_TEMPERATURE).get(h -> {
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h);
final Biome biome = world.getBiome(pos);
return (double) biome.getBaseTemperature();
}).create(Keys.BLOCK_LIGHT).get(h -> {
final Level world = (Level) h.world();
return world.getBrightness(LightLayer.BLOCK, VecHelper.toBlockPos(h));
}).create(Keys.BLOCK_TEMPERATURE).get(h -> {
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h);
final Biome biome = world.getBiome(pos);
return (double) biome.getTemperature(pos);
}).create(Keys.SKY_LIGHT).get(h -> {
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h);
return world.getBrightness(LightLayer.SKY, pos);
}).create(Keys.IS_FULL_BLOCK).get(h -> {
final BlockState block = (BlockState) h.block();
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h.position());
return block.isSolidRender(world, pos);
}).create(Keys.IS_INDIRECTLY_POWERED).get(h -> {
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h);
return world.getBestNeighborSignal(pos) > 0;
}).create(Keys.DISPLAY_NAME).get(h -> SpongeAdventure.asAdventure(((Nameable) h.blockEntity().get()).getDisplayName())).supports(h -> h.blockEntity().isPresent() && h.blockEntity().get() instanceof NameableBlockEntity).create(Keys.CUSTOM_NAME).get(h -> {
final BlockEntity blockEntity = h.blockEntity().get();
return ((Nameable) blockEntity).hasCustomName() ? SpongeAdventure.asAdventure(((Nameable) blockEntity).getCustomName()) : null;
}).set((h, v) -> (((CustomNameableBridge) h.blockEntity().get())).bridge$setCustomDisplayName(SpongeAdventure.asVanilla(v))).delete(h -> (((CustomNameableBridge) h.blockEntity().get())).bridge$setCustomDisplayName(null)).supports(h -> h.blockEntity().isPresent() && h.blockEntity().get() instanceof NameableBlockEntity).create(Keys.CREATOR).get(h -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$getBlockCreatorUUID(VecHelper.toBlockPos(h.blockPosition())).orElse(null)).set((h, v) -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$setBlockCreator(VecHelper.toBlockPos(h.blockPosition()), v)).delete(h -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$setBlockCreator(VecHelper.toBlockPos(h.blockPosition()), null)).create(Keys.NOTIFIER).get(h -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$getBlockNotifierUUID(VecHelper.toBlockPos(h.blockPosition())).orElse(null)).set((h, v) -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$setBlockNotifier(VecHelper.toBlockPos(h.blockPosition()), v)).delete(h -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$setBlockNotifier(VecHelper.toBlockPos(h.blockPosition()), null));
}
Aggregations