Search in sources :

Example 1 with BiomeContainer

use of net.minecraft.world.biome.BiomeContainer in project FastAsyncWorldEdit by IntellectualSites.

the class ForgeWorld method setBiome.

@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
    checkNotNull(position);
    checkNotNull(biome);
    IChunk chunk = getWorld().getChunk(position.getBlockX() >> 4, position.getBlockZ() >> 4, ChunkStatus.FULL, false);
    BiomeContainer container = chunk == null ? null : chunk.getBiomes();
    if (chunk == null || container == null) {
        return false;
    }
    // Temporary, while biome setting is 2D only
    for (int i = 0; i < BiomeMath.VERTICAL_BIT_MASK; i++) {
        int idx = BiomeMath.computeBiomeIndex(position.getX(), i, position.getZ());
        container.biomes[idx] = ForgeAdapter.adapt(biome);
    }
    chunk.setModified(true);
    return true;
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) BiomeContainer(net.minecraft.world.biome.BiomeContainer)

Example 2 with BiomeContainer

use of net.minecraft.world.biome.BiomeContainer in project LoliServer by Loli-Server.

the class CustomChunkGenerator method buildSurfaceAndBedrock.

@Override
public void buildSurfaceAndBedrock(WorldGenRegion p_225551_1_, IChunk p_225551_2_) {
    // Call the bukkit ChunkGenerator before structure generation so correct biome information is available.
    int x = p_225551_2_.getPos().x;
    int z = p_225551_2_.getPos().z;
    random.setSeed((long) x * 341873128712L + (long) z * 132897987541L);
    // Get default biome data for chunk
    CustomBiomeGrid biomegrid = new CustomBiomeGrid(new BiomeContainer(world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), p_225551_2_.getPos(), this.getBiomeSource()));
    ChunkData data;
    if (generator.isParallelCapable()) {
        data = generator.generateChunkData(this.world.getWorld(), random, x, z, biomegrid);
    } else {
        synchronized (this) {
            data = generator.generateChunkData(this.world.getWorld(), random, x, z, biomegrid);
        }
    }
    Preconditions.checkArgument(data instanceof CraftChunkData, "Plugins must use createChunkData(World) rather than implementing ChunkData: %s", data);
    CraftChunkData craftData = (CraftChunkData) data;
    ChunkSection[] sections = craftData.getRawChunkData();
    ChunkSection[] csect = p_225551_2_.getSections();
    int scnt = Math.min(csect.length, sections.length);
    // Loop through returned sections
    for (int sec = 0; sec < scnt; sec++) {
        if (sections[sec] == null) {
            continue;
        }
        ChunkSection section = sections[sec];
        csect[sec] = section;
    }
    // Set biome grid
    ((ChunkPrimer) p_225551_2_).setBiomes(biomegrid.biome);
    if (craftData.getTiles() != null) {
        for (BlockPos pos : craftData.getTiles()) {
            int tx = pos.getX();
            int ty = pos.getY();
            int tz = pos.getZ();
            Block block = craftData.getTypeId(tx, ty, tz).getBlock();
            if (block.isEntityBlock()) {
                TileEntity tile = ((ITileEntityProvider) block).newBlockEntity(world);
                p_225551_2_.setBlockEntity(new BlockPos((x << 4) + tx, ty, (z << 4) + tz), tile);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ChunkData(org.bukkit.generator.ChunkGenerator.ChunkData) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) Block(net.minecraft.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) BlockPos(net.minecraft.util.math.BlockPos) ChunkSection(net.minecraft.world.chunk.ChunkSection) BiomeContainer(net.minecraft.world.biome.BiomeContainer) ChunkPrimer(net.minecraft.world.chunk.ChunkPrimer)

Example 3 with BiomeContainer

use of net.minecraft.world.biome.BiomeContainer in project LoliServer by Loli-Server.

the class CraftChunk method getChunkSnapshot.

@Override
public ChunkSnapshot getChunkSnapshot(boolean includeMaxBlockY, boolean includeBiome, boolean includeBiomeTempRain) {
    net.minecraft.world.chunk.Chunk chunk = getHandle();
    ChunkSection[] cs = chunk.getSections();
    PalettedContainer[] sectionBlockIDs = new PalettedContainer[cs.length];
    byte[][] sectionSkyLights = new byte[cs.length][];
    byte[][] sectionEmitLights = new byte[cs.length][];
    boolean[] sectionEmpty = new boolean[cs.length];
    for (int i = 0; i < cs.length; i++) {
        if (cs[i] == null) {
            // Section is empty?
            sectionBlockIDs[i] = emptyBlockIDs;
            sectionSkyLights[i] = emptyLight;
            sectionEmitLights[i] = emptyLight;
            sectionEmpty[i] = true;
        } else {
            // Not empty
            CompoundNBT data = new CompoundNBT();
            cs[i].getStates().write(data, "Palette", "BlockStates");
            // TODO: snapshot whole ChunkSection
            PalettedContainer blockids = new PalettedContainer<net.minecraft.block.BlockState>(ChunkSection.GLOBAL_BLOCKSTATE_PALETTE, net.minecraft.block.Block.BLOCK_STATE_REGISTRY, NBTUtil::readBlockState, NBTUtil::writeBlockState, Blocks.AIR.defaultBlockState());
            blockids.read(data.getList("Palette", CraftMagicNumbers.NBT.TAG_COMPOUND), data.getLongArray("BlockStates"));
            sectionBlockIDs[i] = blockids;
            WorldLightManager lightengine = chunk.level.getChunkSource().getLightEngine();
            NibbleArray skyLightArray = lightengine.getLayerListener(LightType.SKY).getDataLayerData(SectionPos.of(x, i, z));
            if (skyLightArray == null) {
                sectionSkyLights[i] = emptyLight;
            } else {
                sectionSkyLights[i] = new byte[2048];
                System.arraycopy(skyLightArray.getData(), 0, sectionSkyLights[i], 0, 2048);
            }
            NibbleArray emitLightArray = lightengine.getLayerListener(LightType.BLOCK).getDataLayerData(SectionPos.of(x, i, z));
            if (emitLightArray == null) {
                sectionEmitLights[i] = emptyLight;
            } else {
                sectionEmitLights[i] = new byte[2048];
                System.arraycopy(emitLightArray.getData(), 0, sectionEmitLights[i], 0, 2048);
            }
        }
    }
    Heightmap hmap = null;
    if (includeMaxBlockY) {
        hmap = new Heightmap(null, Heightmap.Type.MOTION_BLOCKING);
        hmap.setRawData(chunk.heightmaps.get(Heightmap.Type.MOTION_BLOCKING).getRawData());
    }
    BiomeContainer biome = null;
    if (includeBiome || includeBiomeTempRain) {
        biome = chunk.getBiomes();
    }
    World world = getWorld();
    return new CraftChunkSnapshot(getX(), getZ(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, biome);
}
Also used : Heightmap(net.minecraft.world.gen.Heightmap) CompoundNBT(net.minecraft.nbt.CompoundNBT) NBTUtil(net.minecraft.nbt.NBTUtil) ServerWorld(net.minecraft.world.server.ServerWorld) World(org.bukkit.World) NibbleArray(net.minecraft.world.chunk.NibbleArray) WorldLightManager(net.minecraft.world.lighting.WorldLightManager) ChunkSection(net.minecraft.world.chunk.ChunkSection) BiomeContainer(net.minecraft.world.biome.BiomeContainer) PalettedContainer(net.minecraft.util.palette.PalettedContainer)

Example 4 with BiomeContainer

use of net.minecraft.world.biome.BiomeContainer in project Magma-1.16.x by magmafoundation.

the class CraftChunk method getChunkSnapshot.

@Override
public ChunkSnapshot getChunkSnapshot(boolean includeMaxBlockY, boolean includeBiome, boolean includeBiomeTempRain) {
    net.minecraft.world.chunk.Chunk chunk = getHandle();
    ChunkSection[] cs = chunk.getSections();
    PalettedContainer[] sectionBlockIDs = new PalettedContainer[cs.length];
    byte[][] sectionSkyLights = new byte[cs.length][];
    byte[][] sectionEmitLights = new byte[cs.length][];
    boolean[] sectionEmpty = new boolean[cs.length];
    for (int i = 0; i < cs.length; i++) {
        if (cs[i] == null) {
            // Section is empty?
            sectionBlockIDs[i] = emptyBlockIDs;
            sectionSkyLights[i] = emptyLight;
            sectionEmitLights[i] = emptyLight;
            sectionEmpty[i] = true;
        } else {
            // Not empty
            CompoundNBT data = new CompoundNBT();
            cs[i].getStates().write(data, "Palette", "BlockStates");
            // TODO: snapshot whole ChunkSection
            PalettedContainer blockids = new PalettedContainer<net.minecraft.block.BlockState>(ChunkSection.GLOBAL_BLOCKSTATE_PALETTE, net.minecraft.block.Block.BLOCK_STATE_REGISTRY, NBTUtil::readBlockState, NBTUtil::writeBlockState, Blocks.AIR.defaultBlockState());
            blockids.read(data.getList("Palette", CraftMagicNumbers.NBT.TAG_COMPOUND), data.getLongArray("BlockStates"));
            sectionBlockIDs[i] = blockids;
            WorldLightManager lightengine = chunk.level.getChunkSource().getLightEngine();
            NibbleArray skyLightArray = lightengine.getLayerListener(LightType.SKY).getDataLayerData(SectionPos.of(x, i, z));
            if (skyLightArray == null) {
                sectionSkyLights[i] = emptyLight;
            } else {
                sectionSkyLights[i] = new byte[2048];
                System.arraycopy(skyLightArray.getData(), 0, sectionSkyLights[i], 0, 2048);
            }
            NibbleArray emitLightArray = lightengine.getLayerListener(LightType.BLOCK).getDataLayerData(SectionPos.of(x, i, z));
            if (emitLightArray == null) {
                sectionEmitLights[i] = emptyLight;
            } else {
                sectionEmitLights[i] = new byte[2048];
                System.arraycopy(emitLightArray.getData(), 0, sectionEmitLights[i], 0, 2048);
            }
        }
    }
    Heightmap hmap = null;
    if (includeMaxBlockY) {
        hmap = new Heightmap(null, Heightmap.Type.MOTION_BLOCKING);
        hmap.setRawData(chunk.heightmaps.get(Heightmap.Type.MOTION_BLOCKING).getRawData());
    }
    BiomeContainer biome = null;
    if (includeBiome || includeBiomeTempRain) {
        biome = chunk.getBiomes();
    }
    World world = getWorld();
    return new CraftChunkSnapshot(getX(), getZ(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, biome);
}
Also used : Heightmap(net.minecraft.world.gen.Heightmap) CompoundNBT(net.minecraft.nbt.CompoundNBT) NBTUtil(net.minecraft.nbt.NBTUtil) ServerWorld(net.minecraft.world.server.ServerWorld) World(org.bukkit.World) NibbleArray(net.minecraft.world.chunk.NibbleArray) WorldLightManager(net.minecraft.world.lighting.WorldLightManager) ChunkSection(net.minecraft.world.chunk.ChunkSection) BiomeContainer(net.minecraft.world.biome.BiomeContainer) PalettedContainer(net.minecraft.util.palette.PalettedContainer)

Example 5 with BiomeContainer

use of net.minecraft.world.biome.BiomeContainer in project Magma-1.16.x by magmafoundation.

the class CraftChunk method getEmptyChunkSnapshot.

public static ChunkSnapshot getEmptyChunkSnapshot(int x, int z, CraftWorld world, boolean includeBiome, boolean includeBiomeTempRain) {
    BiomeContainer biome = null;
    if (includeBiome || includeBiomeTempRain) {
        BiomeProvider wcm = world.getHandle().getChunkSource().getGenerator().getBiomeSource();
        biome = new BiomeContainer(world.getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), new ChunkPos(x, z), wcm);
    }
    /* Fill with empty data */
    int hSection = world.getMaxHeight() >> 4;
    PalettedContainer[] blockIDs = new PalettedContainer[hSection];
    byte[][] skyLight = new byte[hSection][];
    byte[][] emitLight = new byte[hSection][];
    boolean[] empty = new boolean[hSection];
    for (int i = 0; i < hSection; i++) {
        blockIDs[i] = emptyBlockIDs;
        skyLight[i] = emptyLight;
        emitLight[i] = emptyLight;
        empty[i] = true;
    }
    return new CraftChunkSnapshot(x, z, world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new Heightmap(null, Heightmap.Type.MOTION_BLOCKING), biome);
}
Also used : BiomeProvider(net.minecraft.world.biome.provider.BiomeProvider) Heightmap(net.minecraft.world.gen.Heightmap) ChunkPos(net.minecraft.util.math.ChunkPos) BiomeContainer(net.minecraft.world.biome.BiomeContainer) PalettedContainer(net.minecraft.util.palette.PalettedContainer)

Aggregations

BiomeContainer (net.minecraft.world.biome.BiomeContainer)6 PalettedContainer (net.minecraft.util.palette.PalettedContainer)4 Heightmap (net.minecraft.world.gen.Heightmap)4 ChunkSection (net.minecraft.world.chunk.ChunkSection)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 NBTUtil (net.minecraft.nbt.NBTUtil)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 BiomeProvider (net.minecraft.world.biome.provider.BiomeProvider)2 NibbleArray (net.minecraft.world.chunk.NibbleArray)2 WorldLightManager (net.minecraft.world.lighting.WorldLightManager)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 World (org.bukkit.World)2 Block (net.minecraft.block.Block)1 ITileEntityProvider (net.minecraft.block.ITileEntityProvider)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPrimer (net.minecraft.world.chunk.ChunkPrimer)1 IChunk (net.minecraft.world.chunk.IChunk)1 CraftBlock (org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock)1 ChunkData (org.bukkit.generator.ChunkGenerator.ChunkData)1