Search in sources :

Example 1 with Heightmap

use of net.minecraft.world.gen.Heightmap 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 2 with Heightmap

use of net.minecraft.world.gen.Heightmap 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 3 with Heightmap

use of net.minecraft.world.gen.Heightmap 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)

Example 4 with Heightmap

use of net.minecraft.world.gen.Heightmap in project Shrines by Silverminer007.

the class StructureUtils method getHeight.

public static int getHeight(ChunkGenerator cG, BlockPos pos, MutableBoundingBox mbb, Random rand) {
    Category biome = cG.getBiomeSource().getNoiseBiome(pos.getX(), pos.getY(), pos.getZ()).getBiomeCategory();
    if (biome == Category.NETHER) {
        int i = randomIntInclusive(rand, 32, 100);
        List<BlockPos> list1 = ImmutableList.of(new BlockPos(mbb.x0, 0, mbb.z0), new BlockPos(mbb.x1, 0, mbb.z0), new BlockPos(mbb.x0, 0, mbb.z1), new BlockPos(mbb.x1, 0, mbb.z1));
        List<IBlockReader> list = list1.stream().map((pos1) -> {
            return cG.getBaseColumn(pos1.getX(), pos1.getZ());
        }).collect(Collectors.toList());
        Heightmap.Type heightmap$type = Heightmap.Type.WORLD_SURFACE_WG;
        BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable();
        int k;
        for (k = i; k > 15; --k) {
            int l = 0;
            blockpos$mutable.set(0, k, 0);
            for (IBlockReader iblockreader : list) {
                BlockState blockstate = iblockreader.getBlockState(blockpos$mutable);
                if (blockstate != null && heightmap$type.isOpaque().test(blockstate)) {
                    ++l;
                    if (l == 3) {
                        return k;
                    }
                }
            }
        }
        return k;
    } else if (biome == Category.THEEND) {
        int i1 = cG.getFirstOccupiedHeight(mbb.x0, mbb.z0, Heightmap.Type.WORLD_SURFACE_WG);
        int j1 = cG.getFirstOccupiedHeight(mbb.x0, mbb.z1, Heightmap.Type.WORLD_SURFACE_WG);
        int k1 = cG.getFirstOccupiedHeight(mbb.x1, mbb.z0, Heightmap.Type.WORLD_SURFACE_WG);
        int l1 = cG.getFirstOccupiedHeight(mbb.x1, mbb.z1, Heightmap.Type.WORLD_SURFACE_WG);
        return Math.min(Math.min(i1, j1), Math.min(k1, l1));
    } else {
        return getAverageHeight(pos, cG, Math.max(mbb.getXSpan(), Math.max(mbb.getYSpan(), mbb.getZSpan())) / 16);
    }
}
Also used : AbstractStructure(com.silverminer.shrines.structures.AbstractStructure) MutableBoundingBox(net.minecraft.util.math.MutableBoundingBox) NewStructureInit(com.silverminer.shrines.init.NewStructureInit) Category(net.minecraft.world.biome.Biome.Category) ChunkGenerator(net.minecraft.world.gen.ChunkGenerator) NoFeatureConfig(net.minecraft.world.gen.feature.NoFeatureConfig) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.block.Blocks) ArrayList(java.util.ArrayList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) IBlockReader(net.minecraft.world.IBlockReader) ImmutableList(com.google.common.collect.ImmutableList) Utils(com.silverminer.shrines.utils.custom_structures.Utils) BlockState(net.minecraft.block.BlockState) LogManager(org.apache.logging.log4j.LogManager) IStructureConfig(com.silverminer.shrines.config.IStructureConfig) Heightmap(net.minecraft.world.gen.Heightmap) Heightmap(net.minecraft.world.gen.Heightmap) Category(net.minecraft.world.biome.Biome.Category) BlockState(net.minecraft.block.BlockState) IBlockReader(net.minecraft.world.IBlockReader) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with Heightmap

use of net.minecraft.world.gen.Heightmap in project LoliServer by Loli-Server.

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

Heightmap (net.minecraft.world.gen.Heightmap)5 PalettedContainer (net.minecraft.util.palette.PalettedContainer)4 BiomeContainer (net.minecraft.world.biome.BiomeContainer)4 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 ChunkSection (net.minecraft.world.chunk.ChunkSection)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 ImmutableList (com.google.common.collect.ImmutableList)1 IStructureConfig (com.silverminer.shrines.config.IStructureConfig)1 NewStructureInit (com.silverminer.shrines.init.NewStructureInit)1 AbstractStructure (com.silverminer.shrines.structures.AbstractStructure)1 Utils (com.silverminer.shrines.utils.custom_structures.Utils)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1