Search in sources :

Example 41 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_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_18_R2.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk)

Example 42 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method removeLoader.

@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
    Location loaderLoc = chunkLoader.getLocation();
    World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
    long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
    TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
    if (tileEntityChunkLoader != null) {
        tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_8_R3::removeHologram);
        tileEntityChunkLoader.removed = true;
        world.tileEntityList.remove(tileEntityChunkLoader);
    }
    if (spawnParticle)
        world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
    for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
        Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
        chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            tileEntity.b(nbtTagCompound);
            nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
            tileEntity.a(nbtTagCompound);
        });
    }
}
Also used : ChunkLoader(com.bgsoftware.wildloaders.api.loaders.ChunkLoader) NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) HashMap(java.util.HashMap) IUpdatePlayerListBox(net.minecraft.server.v1_8_R3.IUpdatePlayerListBox) ArrayList(java.util.ArrayList) WChunkLoader(com.bgsoftware.wildloaders.loaders.WChunkLoader) Location(org.bukkit.Location) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) Map(java.util.Map) TileEntityMobSpawner(net.minecraft.server.v1_8_R3.TileEntityMobSpawner) WildLoadersPlugin(com.bgsoftware.wildloaders.WildLoadersPlugin) LongHash(org.bukkit.craftbukkit.v1_8_R3.util.LongHash) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) TileEntity(net.minecraft.server.v1_8_R3.TileEntity) Hologram(com.bgsoftware.wildloaders.api.holograms.Hologram) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) NBTTagLong(net.minecraft.server.v1_8_R3.NBTTagLong) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Collection(java.util.Collection) UUID(java.util.UUID) Block(net.minecraft.server.v1_8_R3.Block) World(net.minecraft.server.v1_8_R3.World) List(java.util.List) Chunk(net.minecraft.server.v1_8_R3.Chunk) ChunkLoaderNPC(com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) Collections(java.util.Collections) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) World(net.minecraft.server.v1_8_R3.World) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Chunk(net.minecraft.server.v1_8_R3.Chunk) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_8_R3.TileEntityMobSpawner) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Location(org.bukkit.Location)

Example 43 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_7_R4 method removeLoader.

@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
    Location loaderLoc = chunkLoader.getLocation();
    World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    int x = loaderLoc.getBlockX(), y = loaderLoc.getBlockY(), z = loaderLoc.getBlockZ();
    long tileEntityLong = LongHash.toLong(x >> 4, z >> 4);
    TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
    if (tileEntityChunkLoader != null) {
        tileEntityChunkLoader.removed = true;
        world.tileEntityList.remove(tileEntityChunkLoader);
    }
    if (spawnParticle)
        world.a(null, 2001, x, y, z, Block.getId(world.getType(x, y, z)) + (world.getData(x, y, z) << 12));
    for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
        Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
        // noinspection unchecked
        chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            ((TileEntity) tileEntity).b(nbtTagCompound);
            nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
            ((TileEntity) tileEntity).a(nbtTagCompound);
        });
    }
}
Also used : ChunkLoader(com.bgsoftware.wildloaders.api.loaders.ChunkLoader) IUpdatePlayerListBox(net.minecraft.server.v1_7_R4.IUpdatePlayerListBox) NBTTagString(net.minecraft.server.v1_7_R4.NBTTagString) HashMap(java.util.HashMap) TileEntity(net.minecraft.server.v1_7_R4.TileEntity) LongHash(org.bukkit.craftbukkit.v1_7_R4.util.LongHash) WChunkLoader(com.bgsoftware.wildloaders.loaders.WChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_7_R4.TileEntityMobSpawner) Location(org.bukkit.Location) Map(java.util.Map) WildLoadersPlugin(com.bgsoftware.wildloaders.WildLoadersPlugin) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) CraftChunk(org.bukkit.craftbukkit.v1_7_R4.CraftChunk) NBTTagList(net.minecraft.server.v1_7_R4.NBTTagList) CraftWorld(org.bukkit.craftbukkit.v1_7_R4.CraftWorld) Hologram(com.bgsoftware.wildloaders.api.holograms.Hologram) NBTTagLong(net.minecraft.server.v1_7_R4.NBTTagLong) Collection(java.util.Collection) UUID(java.util.UUID) NBTTagCompound(net.minecraft.server.v1_7_R4.NBTTagCompound) Block(net.minecraft.server.v1_7_R4.Block) Chunk(net.minecraft.server.v1_7_R4.Chunk) ItemStack(net.minecraft.server.v1_7_R4.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack) ChunkLoaderNPC(com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC) World(net.minecraft.server.v1_7_R4.World) Collections(java.util.Collections) NBTTagCompound(net.minecraft.server.v1_7_R4.NBTTagCompound) CraftWorld(org.bukkit.craftbukkit.v1_7_R4.CraftWorld) World(net.minecraft.server.v1_7_R4.World) CraftChunk(org.bukkit.craftbukkit.v1_7_R4.CraftChunk) Chunk(net.minecraft.server.v1_7_R4.Chunk) TileEntity(net.minecraft.server.v1_7_R4.TileEntity) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_7_R4.TileEntityMobSpawner) CraftWorld(org.bukkit.craftbukkit.v1_7_R4.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_7_R4.CraftChunk) Location(org.bukkit.Location)

Example 44 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_7_R4 method createLoader.

@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
    Location loaderLoc = chunkLoader.getLocation();
    World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    int x = loaderLoc.getBlockX(), y = loaderLoc.getBlockY(), z = loaderLoc.getBlockZ();
    TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, x, y, z);
    // noinspection unchecked
    world.tileEntityList.add(tileEntityChunkLoader);
    for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
        Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
        // noinspection unchecked
        chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            ((TileEntity) tileEntity).b(nbtTagCompound);
            nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
            ((TileEntity) tileEntity).a(nbtTagCompound);
        });
    }
    return tileEntityChunkLoader;
}
Also used : ChunkLoader(com.bgsoftware.wildloaders.api.loaders.ChunkLoader) IUpdatePlayerListBox(net.minecraft.server.v1_7_R4.IUpdatePlayerListBox) NBTTagString(net.minecraft.server.v1_7_R4.NBTTagString) HashMap(java.util.HashMap) TileEntity(net.minecraft.server.v1_7_R4.TileEntity) LongHash(org.bukkit.craftbukkit.v1_7_R4.util.LongHash) WChunkLoader(com.bgsoftware.wildloaders.loaders.WChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_7_R4.TileEntityMobSpawner) Location(org.bukkit.Location) Map(java.util.Map) WildLoadersPlugin(com.bgsoftware.wildloaders.WildLoadersPlugin) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) CraftChunk(org.bukkit.craftbukkit.v1_7_R4.CraftChunk) NBTTagList(net.minecraft.server.v1_7_R4.NBTTagList) CraftWorld(org.bukkit.craftbukkit.v1_7_R4.CraftWorld) Hologram(com.bgsoftware.wildloaders.api.holograms.Hologram) NBTTagLong(net.minecraft.server.v1_7_R4.NBTTagLong) Collection(java.util.Collection) UUID(java.util.UUID) NBTTagCompound(net.minecraft.server.v1_7_R4.NBTTagCompound) Block(net.minecraft.server.v1_7_R4.Block) Chunk(net.minecraft.server.v1_7_R4.Chunk) ItemStack(net.minecraft.server.v1_7_R4.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack) ChunkLoaderNPC(com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC) World(net.minecraft.server.v1_7_R4.World) Collections(java.util.Collections) NBTTagCompound(net.minecraft.server.v1_7_R4.NBTTagCompound) CraftWorld(org.bukkit.craftbukkit.v1_7_R4.CraftWorld) World(net.minecraft.server.v1_7_R4.World) CraftChunk(org.bukkit.craftbukkit.v1_7_R4.CraftChunk) Chunk(net.minecraft.server.v1_7_R4.Chunk) TileEntity(net.minecraft.server.v1_7_R4.TileEntity) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_7_R4.TileEntityMobSpawner) CraftWorld(org.bukkit.craftbukkit.v1_7_R4.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_7_R4.CraftChunk) Location(org.bukkit.Location)

Example 45 with CraftChunk

use of org.bukkit.craftbukkit.v1_17_R1.CraftChunk in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method createLoader.

@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
    Location loaderLoc = chunkLoader.getLocation();
    World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
    TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
    world.tileEntityListTick.add(tileEntityChunkLoader);
    for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
        Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
        chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            tileEntity.save(nbtTagCompound);
            nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
            try {
                compoundLoadMethod.invoke(tileEntity, nbtTagCompound);
            } catch (Throwable ex) {
                tileEntity.a(nbtTagCompound);
            }
        });
    }
    return tileEntityChunkLoader;
}
Also used : ChunkLoader(com.bgsoftware.wildloaders.api.loaders.ChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_12_R1.TileEntityMobSpawner) Block(net.minecraft.server.v1_12_R1.Block) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) HashMap(java.util.HashMap) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ArrayList(java.util.ArrayList) WChunkLoader(com.bgsoftware.wildloaders.loaders.WChunkLoader) TileEntity(net.minecraft.server.v1_12_R1.TileEntity) Chunk(net.minecraft.server.v1_12_R1.Chunk) World(net.minecraft.server.v1_12_R1.World) Location(org.bukkit.Location) NBTTagLong(net.minecraft.server.v1_12_R1.NBTTagLong) Map(java.util.Map) WildLoadersPlugin(com.bgsoftware.wildloaders.WildLoadersPlugin) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) Method(java.lang.reflect.Method) Hologram(com.bgsoftware.wildloaders.api.holograms.Hologram) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) LongHash(org.bukkit.craftbukkit.v1_12_R1.util.LongHash) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) Collection(java.util.Collection) UUID(java.util.UUID) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) ITickable(net.minecraft.server.v1_12_R1.ITickable) ChunkLoaderNPC(com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC) Collections(java.util.Collections) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) World(net.minecraft.server.v1_12_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) Chunk(net.minecraft.server.v1_12_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_12_R1.TileEntityMobSpawner) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) Location(org.bukkit.Location)

Aggregations

LevelChunk (net.minecraft.world.level.chunk.LevelChunk)17 Material (org.bukkit.Material)15 World (org.bukkit.World)13 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)12 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)12 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)12 BlockPos (net.minecraft.core.BlockPos)11 Location (org.bukkit.Location)11 ArrayList (java.util.ArrayList)9 List (java.util.List)9 CraftChunk (org.bukkit.craftbukkit.v1_17_R1.CraftChunk)9 CraftChunk (org.bukkit.craftbukkit.v1_18_R2.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