Search in sources :

Example 1 with Biome

use of net.minecraft.world.level.biome.Biome 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 Biome

use of net.minecraft.world.level.biome.Biome 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 3 with Biome

use of net.minecraft.world.level.biome.Biome 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 Biome

use of net.minecraft.world.level.biome.Biome in project Denizen-For-Bukkit by DenizenScript.

the class ChunkHelperImpl method setAllBiomes.

@Override
public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
    Biome nmsBiome = ((BiomeNMSImpl) biome).biomeBase;
    LevelChunk nmsChunk = ((CraftChunk) chunk).getHandle();
    ChunkBiomeContainer biomeContainer = nmsChunk.getBiomes();
    for (int x = 0; x < 4; x++) {
        for (int y = 0; y < 64; y++) {
            for (int z = 0; z < 4; z++) {
                biomeContainer.setBiome(x, y, z, nmsBiome);
            }
        }
    }
    nmsChunk.markUnsaved();
}
Also used : Biome(net.minecraft.world.level.biome.Biome) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) CraftChunk(org.bukkit.craftbukkit.v1_17_R1.CraftChunk) ChunkBiomeContainer(net.minecraft.world.level.chunk.ChunkBiomeContainer) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)

Example 5 with Biome

use of net.minecraft.world.level.biome.Biome in project Denizen-For-Bukkit by DenizenScript.

the class FakeBlockHelper method handleMapChunkPacket.

public static ClientboundLevelChunkWithLightPacket handleMapChunkPacket(World world, ClientboundLevelChunkWithLightPacket originalPacket, int chunkX, int chunkZ, List<FakeBlock> blocks) {
    try {
        ClientboundLevelChunkWithLightPacket duplicateCorePacket = new ClientboundLevelChunkWithLightPacket(DenizenNetworkManagerImpl.copyPacket(originalPacket));
        copyPacketPaperPatch(duplicateCorePacket, originalPacket);
        FriendlyByteBuf copier = new FriendlyByteBuf(Unpooled.buffer());
        originalPacket.getChunkData().write(copier);
        ClientboundLevelChunkPacketData packet = new ClientboundLevelChunkPacketData(copier, chunkX, chunkZ);
        FriendlyByteBuf serial = originalPacket.getChunkData().getReadBuffer();
        FriendlyByteBuf outputSerial = new FriendlyByteBuf(Unpooled.buffer(serial.readableBytes()));
        List blockEntities = new ArrayList((List) CHUNKDATA_BLOCK_ENTITIES.get(originalPacket.getChunkData()));
        CHUNKDATA_BLOCK_ENTITIES.set(packet, blockEntities);
        ListIterator iterator = blockEntities.listIterator();
        while (iterator.hasNext()) {
            Object blockEnt = iterator.next();
            int xz = CHUNKDATA_BLOCKENTITYINFO_PACKEDXZ.getInt(blockEnt);
            int y = CHUNKDATA_BLOCKENTITYINFO_Y.getInt(blockEnt);
            int x = (chunkX << 4) + ((xz >> 4) & 15);
            int z = (chunkZ << 4) + (xz & 15);
            for (FakeBlock block : blocks) {
                LocationTag loc = block.location;
                if (loc.getBlockX() == x && loc.getBlockY() == y && loc.getBlockZ() == z && block.material != null) {
                    iterator.remove();
                    break;
                }
            }
        }
        int worldMinY = world.getMinHeight();
        int worldMaxY = world.getMaxHeight();
        int minChunkY = worldMinY >> 4;
        int maxChunkY = worldMaxY >> 4;
        Registry<Biome> biomeRegistry = ((CraftWorld) world).getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
        for (int y = minChunkY; y < maxChunkY; y++) {
            int blockCount = serial.readShort();
            // reflected constructors as workaround for spigot remapper bug - Mojang "IdMap" became Spigot "IRegistry" but should be "Registry"
            PalettedContainer<BlockState> states = (PalettedContainer<BlockState>) PALETTEDCONTAINER_CTOR.newInstance(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES);
            states.read(serial);
            PalettedContainer<Biome> biomes = (PalettedContainer<Biome>) PALETTEDCONTAINER_CTOR.newInstance(biomeRegistry, biomeRegistry.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES);
            biomes.read(serial);
            if (anyBlocksInSection(blocks, y)) {
                int minY = y << 4;
                int maxY = (y << 4) + 16;
                for (FakeBlock block : blocks) {
                    int blockY = block.location.getBlockY();
                    if (blockY >= minY && blockY < maxY && block.material != null) {
                        int blockX = block.location.getBlockX();
                        int blockZ = block.location.getBlockZ();
                        blockX -= (blockX >> 4) * 16;
                        blockY -= (blockY >> 4) * 16;
                        blockZ -= (blockZ >> 4) * 16;
                        BlockState oldState = states.get(blockX, blockY, blockZ);
                        BlockState newState = getNMSState(block);
                        if (oldState.isAir() && !newState.isAir()) {
                            blockCount++;
                        } else if (newState.isAir() && !oldState.isAir()) {
                            blockCount--;
                        }
                        states.set(blockX, blockY, blockZ, newState);
                    }
                }
            }
            outputSerial.writeShort(blockCount);
            states.write(outputSerial);
            biomes.write(outputSerial);
        }
        byte[] outputBytes = outputSerial.array();
        CHUNKDATA_BUFFER_SETTER.invoke(packet, outputBytes);
        CHUNKPACKET_CHUNKDATA_SETTER.invoke(duplicateCorePacket, packet);
        return duplicateCorePacket;
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
    return null;
}
Also used : ClientboundLevelChunkWithLightPacket(net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ClientboundLevelChunkPacketData(net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData) ArrayList(java.util.ArrayList) FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) ListIterator(java.util.ListIterator) LocationTag(com.denizenscript.denizen.objects.LocationTag) Biome(net.minecraft.world.level.biome.Biome) BlockState(net.minecraft.world.level.block.state.BlockState) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) PalettedContainer(net.minecraft.world.level.chunk.PalettedContainer)

Aggregations

Biome (net.minecraft.world.level.biome.Biome)7 ServerLevel (net.minecraft.server.level.ServerLevel)4 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)3 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)3 ArrayList (java.util.ArrayList)3 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)3 Map (java.util.Map)2 ResourceKey (net.minecraft.resources.ResourceKey)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)2 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)2 LocationTag (com.denizenscript.denizen.objects.LocationTag)1 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)1 ClientboundLevelChunkPacketData (net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData)1 ClientboundLevelChunkWithLightPacket (net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)1