Search in sources :

Example 1 with ResourceKey

use of net.minecraft.resources.ResourceKey in project Denizen-For-Bukkit by DenizenScript.

the class Handler method getBiomes.

@Override
public List<BiomeNMS> getBiomes(World world) {
    ServerLevel level = ((CraftWorld) world).getHandle();
    ArrayList<BiomeNMS> output = new ArrayList<>();
    for (Map.Entry<ResourceKey<Biome>, Biome> pair : level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).entrySet()) {
        output.add(new BiomeNMSImpl(level, pair.getKey().location().toString()));
    }
    return output;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Biome(net.minecraft.world.level.biome.Biome) ArrayList(java.util.ArrayList) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) Map(java.util.Map) ResourceKey(net.minecraft.resources.ResourceKey) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)

Example 2 with ResourceKey

use of net.minecraft.resources.ResourceKey in project SpongeCommon by SpongePowered.

the class CompassItemData method register.

static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(ItemStack.class).create(Keys.LODESTONE).get(stack -> {
        if (CompassItem.isLodestoneCompass(stack)) {
            final CompoundTag tag = stack.getOrCreateTag();
            final Optional<ResourceKey<Level>> dimension = CompassItem.getLodestoneDimension(tag);
            if (dimension.isPresent()) {
                return ServerLocation.of((ServerWorld) SpongeCommon.server().getLevel(dimension.get()), VecHelper.toVector3d(NbtUtils.readBlockPos(tag.getCompound("LodestonePos"))));
            }
        }
        return null;
    }).set((stack, location) -> {
        final CompoundTag tag = stack.getOrCreateTag();
        tag.put("LodestonePos", NbtUtils.writeBlockPos(VecHelper.toBlockPos(location)));
        Level.RESOURCE_KEY_CODEC.encodeStart(NbtOps.INSTANCE, ((net.minecraft.server.level.ServerLevel) location.world()).dimension()).resultOrPartial(SpongeCommon.logger()::error).ifPresent(dimension -> tag.put("LodestoneDimension", dimension));
        tag.putBoolean("LodestoneTracked", true);
    }).delete(stack -> {
        final CompoundTag tag = stack.getTag();
        if (tag != null) {
            tag.remove("LodestoneDimension");
            tag.remove("LodestonePos");
            tag.remove("LodestoneTracked");
        }
    });
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) NbtUtils(net.minecraft.nbt.NbtUtils) SpongeCommon(org.spongepowered.common.SpongeCommon) NbtOps(net.minecraft.nbt.NbtOps) ResourceKey(net.minecraft.resources.ResourceKey) CompassItem(net.minecraft.world.item.CompassItem) Keys(org.spongepowered.api.data.Keys) CompoundTag(net.minecraft.nbt.CompoundTag) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) VecHelper(org.spongepowered.common.util.VecHelper) Optional(java.util.Optional) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) ServerLocation(org.spongepowered.api.world.server.ServerLocation) CompoundTag(net.minecraft.nbt.CompoundTag) ResourceKey(net.minecraft.resources.ResourceKey)

Example 3 with ResourceKey

use of net.minecraft.resources.ResourceKey in project Denizen-For-Bukkit by DenizenScript.

the class Handler method getBiomes.

@Override
public List<BiomeNMS> getBiomes(World world) {
    ServerLevel level = ((CraftWorld) world).getHandle();
    ArrayList<BiomeNMS> output = new ArrayList<>();
    for (Map.Entry<ResourceKey<Biome>, Biome> pair : level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).entrySet()) {
        output.add(new BiomeNMSImpl(level, pair.getKey().location().toString()));
    }
    return output;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Biome(net.minecraft.world.level.biome.Biome) ArrayList(java.util.ArrayList) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) Map(java.util.Map) ResourceKey(net.minecraft.resources.ResourceKey) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)

Aggregations

ResourceKey (net.minecraft.resources.ResourceKey)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 Biome (net.minecraft.world.level.biome.Biome)2 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)1 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)1 Optional (java.util.Optional)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 NbtOps (net.minecraft.nbt.NbtOps)1 NbtUtils (net.minecraft.nbt.NbtUtils)1 CompassItem (net.minecraft.world.item.CompassItem)1 ItemStack (net.minecraft.world.item.ItemStack)1 Level (net.minecraft.world.level.Level)1 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1 Keys (org.spongepowered.api.data.Keys)1 ServerLocation (org.spongepowered.api.world.server.ServerLocation)1 ServerWorld (org.spongepowered.api.world.server.ServerWorld)1 SpongeCommon (org.spongepowered.common.SpongeCommon)1