Search in sources :

Example 26 with CraftChunk

use of org.bukkit.craftbukkit.v1_13_R1.CraftChunk in project NotQuests by AlessioGr.

the class PacketInjector method spawnBeaconBeam.

public void spawnBeaconBeam(Player player, Location location) {
    // Prepare Data
    Connection connection = getConnection(getServerPlayer(player).connection);
    location = location.clone();
    BlockPos blockPos = new BlockPos(location.getX(), location.getY(), location.getZ());
    Chunk chunk = location.getChunk();
    CraftChunk craftChunk = (CraftChunk) chunk;
    LevelChunk levelChunk = craftChunk.getHandle();
    World world = location.getWorld();
    CraftWorld craftWorld = (CraftWorld) world;
    ServerLevel serverLevel = craftWorld.getHandle();
    // 
    BlockState blockState = location.getBlock().getState();
    blockState.setType(Material.BEACON);
    SectionPos sectionPos = SectionPos.of((int) location.getX(), (int) location.getY(), (int) location.getZ());
    ShortSet positions = ShortSet.of((short) 0);
    // PalettedContainer<BlockState> pcB = new PalettedContainer<>();
    // net.minecraft.world.level.block.state.BlockState[] presetBlockStates = serverLevel.chunkPacketBlockController.getPresetBlockStates(world, chunkPos, b0 << 4);
    // PalettedContainer<BlockState> datapaletteblock = new PalettedContainer<>(net.minecraft.world.level.block.Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES, presetBlockStates);
    LevelChunkSection section = levelChunk.getHighestSection();
    ClientboundSectionBlocksUpdatePacket clientboundSectionBlocksUpdatePacket = new ClientboundSectionBlocksUpdatePacket(sectionPos, positions, section, true);
    main.sendMessage(player, "<main>Sending packet...");
    connection.send(clientboundSectionBlocksUpdatePacket);
    main.sendMessage(player, "<success>Packet sent!");
// ClientboundBlockUpdatePacket clientboundBlockUpdatePacket = new ClientboundBlockUpdatePacket(blockPos, BlockState.);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Connection(net.minecraft.network.Connection) ClientboundSectionBlocksUpdatePacket(net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk) Chunk(org.bukkit.Chunk) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) World(org.bukkit.World) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) CraftBlockState(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState) BlockState(org.bukkit.block.BlockState) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) ShortSet(it.unimi.dsi.fastutil.shorts.ShortSet) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) SectionPos(net.minecraft.core.SectionPos) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk)

Example 27 with CraftChunk

use of org.bukkit.craftbukkit.v1_13_R1.CraftChunk in project Denizen by DenizenScript.

the class BlockHelperImpl method doRandomTick.

@Override
public void doRandomTick(Location location) {
    BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    LevelChunk nmsChunk = ((CraftChunk) location.getChunk()).getHandle();
    net.minecraft.world.level.block.state.BlockState nmsBlock = nmsChunk.getBlockState(pos);
    ServerLevel nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
    if (nmsBlock.isRandomlyTicking()) {
        nmsBlock.randomTick(nmsWorld, pos, nmsWorld.random);
    }
    try {
        // FluidState fluid = nmsBlock.getFluidState();
        // if (fluid.isRandomlyTicking()) {
        // fluid.animateTick(nmsWorld, pos, nmsWorld.random);
        // }
        Object fluid = BLOCKSTATEBASE_GETFLUIDSTATE.invoke(nmsBlock);
        if ((boolean) FLUIDSTATE_ISRANDOMLYTICKING.invoke(fluid)) {
            FLUIDSTATE_ANIMATETICK.invoke(fluid, nmsWorld, pos, nmsWorld.random);
        }
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_17_R1.CraftChunk)

Example 28 with CraftChunk

use of org.bukkit.craftbukkit.v1_13_R1.CraftChunk in project Denizen 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 29 with CraftChunk

use of org.bukkit.craftbukkit.v1_13_R1.CraftChunk in project Denizen by DenizenScript.

the class ChunkHelperImpl method getHeightMap.

@Override
public int[] getHeightMap(Chunk chunk) {
    Heightmap map = ((CraftChunk) chunk).getHandle().heightmaps.get(Heightmap.Types.MOTION_BLOCKING);
    int[] outputMap = new int[256];
    for (int x = 0; x < 16; x++) {
        for (int y = 0; y < 16; y++) {
            outputMap[x * 16 + y] = map.getFirstAvailable(x, y);
        }
    }
    return outputMap;
}
Also used : Heightmap(net.minecraft.world.level.levelgen.Heightmap) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk)

Example 30 with CraftChunk

use of org.bukkit.craftbukkit.v1_13_R1.CraftChunk in project Denizen by DenizenScript.

the class ChunkHelperImpl method setAllBiomes.

@Override
public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
    Holder<Biome> nmsBiome = ((BiomeNMSImpl) biome).biomeBase;
    LevelChunk nmsChunk = ((CraftChunk) chunk).getHandle();
    ChunkPos chunkcoordintpair = nmsChunk.getPos();
    int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());
    int j = QuartPos.fromBlock(chunkcoordintpair.getMinBlockZ());
    LevelHeightAccessor levelheightaccessor = nmsChunk.getHeightAccessorForGeneration();
    for (int k = levelheightaccessor.getMinSection(); k < levelheightaccessor.getMaxSection(); ++k) {
        LevelChunkSection chunksection = nmsChunk.getSection(nmsChunk.getSectionIndexFromSectionY(k));
        PalettedContainer<Holder<Biome>> datapaletteblock = chunksection.getBiomes();
        datapaletteblock.acquire();
        for (int l = 0; l < 4; ++l) {
            for (int i1 = 0; i1 < 4; ++i1) {
                for (int j1 = 0; j1 < 4; ++j1) {
                    datapaletteblock.getAndSetUnchecked(l, i1, j1, nmsBiome);
                }
            }
        }
        datapaletteblock.release();
    }
}
Also used : LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) Biome(net.minecraft.world.level.biome.Biome) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) Holder(net.minecraft.core.Holder) ChunkPos(net.minecraft.world.level.ChunkPos) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)

Aggregations

LevelChunk (net.minecraft.world.level.chunk.LevelChunk)15 Material (org.bukkit.Material)14 World (org.bukkit.World)12 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)11 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)11 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)11 Location (org.bukkit.Location)11 BlockPos (net.minecraft.core.BlockPos)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 CraftChunk (org.bukkit.craftbukkit.v1_17_R1.CraftChunk)9 WildLoadersPlugin (com.bgsoftware.wildloaders.WildLoadersPlugin)8 Hologram (com.bgsoftware.wildloaders.api.holograms.Hologram)8 ChunkLoader (com.bgsoftware.wildloaders.api.loaders.ChunkLoader)8 ChunkLoaderNPC (com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC)8 ITileEntityChunkLoader (com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader)8 WChunkLoader (com.bgsoftware.wildloaders.loaders.WChunkLoader)8 Collection (java.util.Collection)8 Collections (java.util.Collections)8 HashMap (java.util.HashMap)8