Search in sources :

Example 1 with ResourceLocation

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

the class Handler method getBiomeAt.

@Override
public BiomeNMS getBiomeAt(Block block) {
    // Based on CraftWorld source
    ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
    Biome biome = level.getNoiseBiome(block.getX() >> 2, block.getY() >> 2, block.getZ() >> 2);
    ResourceLocation key = level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome);
    String keyText = key.getNamespace().equals("minecraft") ? key.getPath() : key.toString();
    return new BiomeNMSImpl(level, keyText);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Biome(net.minecraft.world.level.biome.Biome) ResourceLocation(net.minecraft.resources.ResourceLocation) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)

Example 2 with ResourceLocation

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

the class AdvancementHelperImpl method unregister.

@Override
public void unregister(com.denizenscript.denizen.nms.util.Advancement advancement) {
    if (advancement.temporary || !advancement.registered) {
        return;
    }
    Map<ResourceLocation, Advancement> advancements = getAdvancementDataWorld().advancements.advancements;
    ResourceLocation key = asResourceLocation(advancement.key);
    Advancement nms = advancements.get(key);
    if (advancement.parent == null) {
        Set<Advancement> roots = ReflectionHelper.getFieldValue(AdvancementList.class, ReflectionMappingsInfo.AdvancementList_roots, getAdvancementDataWorld().advancements);
        roots.remove(nms);
    } else {
        Set<Advancement> branches = ReflectionHelper.getFieldValue(AdvancementList.class, ReflectionMappingsInfo.AdvancementList_tasks, getAdvancementDataWorld().advancements);
        branches.remove(nms);
    }
    advancements.remove(key);
    advancement.registered = false;
    ((CraftServer) Bukkit.getServer()).getHandle().sendAll(new ClientboundUpdateAdvancementsPacket(false, Collections.emptySet(), Collections.singleton(key), Collections.emptyMap()), (net.minecraft.world.entity.player.Player) null);
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 3 with ResourceLocation

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

the class Handler method getBiomeAt.

@Override
public BiomeNMS getBiomeAt(Block block) {
    // Based on CraftWorld source
    ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
    Biome biome = level.getNoiseBiome(block.getX() >> 2, block.getY() >> 2, block.getZ() >> 2);
    ResourceLocation key = level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome);
    String keyText = key.getNamespace().equals("minecraft") ? key.getPath() : key.toString();
    return new BiomeNMSImpl(level, keyText);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Biome(net.minecraft.world.level.biome.Biome) ResourceLocation(net.minecraft.resources.ResourceLocation) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)

Example 4 with ResourceLocation

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

the class AdvancementHelperImpl method unregister.

@Override
public void unregister(com.denizenscript.denizen.nms.util.Advancement advancement) {
    if (advancement.temporary || !advancement.registered) {
        return;
    }
    Map<ResourceLocation, Advancement> advancements = getAdvancementDataWorld().advancements.advancements;
    ResourceLocation key = asResourceLocation(advancement.key);
    Advancement nms = advancements.get(key);
    if (advancement.parent == null) {
        Set<Advancement> roots = ReflectionHelper.getFieldValue(AdvancementList.class, ReflectionMappingsInfo.AdvancementList_roots, getAdvancementDataWorld().advancements);
        roots.remove(nms);
    } else {
        Set<Advancement> branches = ReflectionHelper.getFieldValue(AdvancementList.class, ReflectionMappingsInfo.AdvancementList_tasks, getAdvancementDataWorld().advancements);
        branches.remove(nms);
    }
    advancements.remove(key);
    advancement.registered = false;
    ((CraftServer) Bukkit.getServer()).getHandle().broadcastAll(new ClientboundUpdateAdvancementsPacket(false, Collections.emptySet(), Collections.singleton(key), Collections.emptyMap()), (net.minecraft.world.entity.player.Player) null);
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 5 with ResourceLocation

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

the class EntityHelperImpl method getDiscoveredRecipes.

public List<String> getDiscoveredRecipes(Player player) {
    try {
        ServerRecipeBook book = ((CraftPlayer) player).getHandle().getRecipeBook();
        Set<ResourceLocation> set = (Set<ResourceLocation>) RECIPE_BOOK_DISCOVERED_SET.get(book);
        List<String> output = new ArrayList<>();
        for (ResourceLocation key : set) {
            output.add(key.toString());
        }
        return output;
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
    return null;
}
Also used : ServerRecipeBook(net.minecraft.stats.ServerRecipeBook) ResourceLocation(net.minecraft.resources.ResourceLocation)

Aggregations

ResourceLocation (net.minecraft.resources.ResourceLocation)28 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)6 CraftServer (org.bukkit.craftbukkit.v1_17_R1.CraftServer)4 CraftServer (org.bukkit.craftbukkit.v1_18_R1.CraftServer)4 BlockPos (net.minecraft.core.BlockPos)2 ClientboundUpdateAdvancementsPacket (net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 ServerRecipeBook (net.minecraft.stats.ServerRecipeBook)2 DamageSource (net.minecraft.world.damagesource.DamageSource)2 Entity (net.minecraft.world.entity.Entity)2 EquipmentSlot (net.minecraft.world.entity.EquipmentSlot)2 LivingEntity (net.minecraft.world.entity.LivingEntity)2 MobType (net.minecraft.world.entity.MobType)2 Biome (net.minecraft.world.level.biome.Biome)2 NamespacedKey (org.bukkit.NamespacedKey)2 Enchantment (org.bukkit.enchantments.Enchantment)2 Recipe (org.bukkit.inventory.Recipe)2 ShapedRecipe (org.bukkit.inventory.ShapedRecipe)2 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)1 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)1