Search in sources :

Example 1 with CraftChunk

use of org.bukkit.craftbukkit.v1_12_R1.CraftChunk in project Ublisk by Derkades.

the class PlayerInteract method staffTool.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW)
public void staffTool(PlayerInteractEvent event) {
    ItemStack itemInHand = event.getPlayer().getInventory().getItemInMainHand();
    if (itemInHand.getType() != Material.COAL_ORE || event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    Player player = event.getPlayer();
    String itemName = itemInHand.getItemMeta().getDisplayName();
    final Block block = event.getClickedBlock();
    event.setCancelled(true);
    if (itemName == null) {
        sendStaffToolInfoMessage(player);
        return;
    }
    if (itemName.contains("farmland")) {
        block.setType(Material.SOIL);
        block.setData((byte) 7);
        Location loc = block.getLocation();
        Block wheat = new Location(Var.WORLD, loc.getX(), loc.getY() + 1, loc.getZ()).getBlock();
        wheat.setType(Material.CROPS);
        wheat.setData((byte) 7);
    } else if (itemName.contains("invis")) {
        block.setData((byte) 0);
        block.setType(Material.PISTON_MOVING_PIECE);
        event.getPlayer().sendMessage("Placed invisible block. To remove invisible block, type /u rinv while standing inside an invisible block.");
    } else if (itemName.contains("coal")) {
        block.setType(Material.GLASS);
        new URunnable() {

            public void run() {
                block.setType(Material.COAL_ORE);
            }
        }.runLater(1 * 20);
    } else if (itemName.contains("lighting")) {
        Chunk chunk = ((CraftChunk) block.getChunk()).getHandle();
        chunk.initLighting();
    } else {
        sendStaffToolInfoMessage(player);
    }
}
Also used : URunnable(xyz.derkades.ublisk.utils.URunnable) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) ItemStack(org.bukkit.inventory.ItemStack) Chunk(net.minecraft.server.v1_12_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 2 with CraftChunk

use of org.bukkit.craftbukkit.v1_12_R1.CraftChunk in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelperImpl method doRandomTick.

@Override
public void doRandomTick(Location location) {
    BlockPosition pos = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    Chunk nmsChunk = ((CraftChunk) location.getChunk()).getHandle();
    IBlockData nmsBlock = nmsChunk.getType(pos);
    WorldServer nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
    if (nmsBlock.isTicking()) {
        nmsBlock.b(nmsWorld, pos, nmsWorld.random);
    }
    Fluid fluid = nmsBlock.getFluid();
    if (fluid.f()) {
        fluid.b(nmsWorld, pos, nmsWorld.random);
    }
}
Also used : CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk)

Example 3 with CraftChunk

use of org.bukkit.craftbukkit.v1_12_R1.CraftChunk in project Denizen-For-Bukkit 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 4 with CraftChunk

use of org.bukkit.craftbukkit.v1_12_R1.CraftChunk in project Denizen-For-Bukkit 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_R1.CraftChunk)

Example 5 with CraftChunk

use of org.bukkit.craftbukkit.v1_12_R1.CraftChunk 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)

Aggregations

LevelChunk (net.minecraft.world.level.chunk.LevelChunk)4 CraftChunk (org.bukkit.craftbukkit.v1_17_R1.CraftChunk)3 CraftChunk (org.bukkit.craftbukkit.v1_18_R1.CraftChunk)3 BlockPos (net.minecraft.core.BlockPos)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 Biome (net.minecraft.world.level.biome.Biome)2 Heightmap (net.minecraft.world.level.levelgen.Heightmap)2 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)1 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)1 Chunk (net.minecraft.server.v1_12_R1.Chunk)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)1 ChunkBiomeContainer (net.minecraft.world.level.chunk.ChunkBiomeContainer)1 LevelChunkSection (net.minecraft.world.level.chunk.LevelChunkSection)1 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 CraftChunk (org.bukkit.craftbukkit.v1_12_R1.CraftChunk)1 CraftChunk (org.bukkit.craftbukkit.v1_16_R3.CraftChunk)1 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)1 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1