Search in sources :

Example 1 with NameableBlockEntity

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));
}
Also used : Nameable(net.minecraft.world.Nameable) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) BlockState(net.minecraft.world.level.block.state.BlockState) NameableBlockEntity(org.spongepowered.api.block.entity.NameableBlockEntity) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) Biome(net.minecraft.world.level.biome.Biome) Keys(org.spongepowered.api.data.Keys) BlockPos(net.minecraft.core.BlockPos) Nameable(net.minecraft.world.Nameable) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) VecHelper(org.spongepowered.common.util.VecHelper) LightLayer(net.minecraft.world.level.LightLayer) Level(net.minecraft.world.level.Level) ServerLocation(org.spongepowered.api.world.server.ServerLocation) CustomNameableBridge(org.spongepowered.common.bridge.CustomNameableBridge) CustomNameableBridge(org.spongepowered.common.bridge.CustomNameableBridge) Biome(net.minecraft.world.level.biome.Biome) BlockState(net.minecraft.world.level.block.state.BlockState) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) NameableBlockEntity(org.spongepowered.api.block.entity.NameableBlockEntity) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) NameableBlockEntity(org.spongepowered.api.block.entity.NameableBlockEntity)

Aggregations

BlockPos (net.minecraft.core.BlockPos)1 Nameable (net.minecraft.world.Nameable)1 Level (net.minecraft.world.level.Level)1 LightLayer (net.minecraft.world.level.LightLayer)1 Biome (net.minecraft.world.level.biome.Biome)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)1 NameableBlockEntity (org.spongepowered.api.block.entity.NameableBlockEntity)1 Keys (org.spongepowered.api.data.Keys)1 ServerLocation (org.spongepowered.api.world.server.ServerLocation)1 SpongeAdventure (org.spongepowered.common.adventure.SpongeAdventure)1 CustomNameableBridge (org.spongepowered.common.bridge.CustomNameableBridge)1 LevelChunkBridge (org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 VecHelper (org.spongepowered.common.util.VecHelper)1