Search in sources :

Example 16 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project Movecraft by APDevTeam.

the class IWorldHandler method moveTileEntity.

private void moveTileEntity(@NotNull World nativeWorld, @NotNull BlockPosition newPosition, @NotNull TileEntity tile) {
    Chunk chunk = nativeWorld.getChunkAtWorldCoords(newPosition);
    tile.invalidateBlockCache();
    tile.setLocation(nativeWorld, newPosition);
    if (nativeWorld.captureBlockStates) {
        tile.setLocation(nativeWorld, newPosition);
        nativeWorld.capturedTileEntities.put(newPosition, tile);
        return;
    }
    chunk.tileEntities.put(newPosition, tile);
}
Also used : Chunk(net.minecraft.server.v1_16_R3.Chunk)

Example 17 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project Movecraft by APDevTeam.

the class IWorldHandler method moveTileEntity.

private void moveTileEntity(@NotNull World nativeWorld, @NotNull BlockPosition newPosition, @NotNull TileEntity tile) {
    Chunk chunk = nativeWorld.getChunkAtWorldCoords(newPosition);
    tile.invalidateBlockCache();
    tile.setWorld(nativeWorld);
    tile.setPosition(newPosition);
    if (nativeWorld.captureBlockStates) {
        tile.setWorld(nativeWorld);
        tile.setPosition(newPosition);
        nativeWorld.capturedTileEntities.put(newPosition, tile);
        return;
    }
    chunk.tileEntities.put(newPosition, tile);
}
Also used : Chunk(net.minecraft.server.v1_14_R1.Chunk)

Example 18 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project TheAPI by TheDevTec.

the class v1_8_R3 method setBlock.

@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.server.v1_8_R3.Chunk c = (net.minecraft.server.v1_8_R3.Chunk) chunk;
    ChunkSection sc = c.getSections()[y >> 4];
    if (sc == null) {
        c.getSections()[y >> 4] = sc = new ChunkSection(y >> 4 << 4, true);
    }
    BlockPosition pos = new BlockPosition(x, y, z);
    // REMOVE TILE ENTITY
    c.tileEntities.remove(pos);
    sc.setType(x & 15, y & 15, z & 15, (IBlockData) IblockData);
    // ADD TILE ENTITY
    if (IblockData instanceof IContainer) {
        TileEntity ent = ((IContainer) IblockData).a(c.world, 0);
        c.tileEntities.put(pos, ent);
        Object packet = ent.getUpdatePacket();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : TileEntity(net.minecraft.server.v1_8_R3.TileEntity) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) IContainer(net.minecraft.server.v1_8_R3.IContainer) ChunkSection(net.minecraft.server.v1_8_R3.ChunkSection)

Example 19 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project TheAPI by TheDevTec.

the class v1_8_R3 method getChunk.

@Override
public Object getChunk(World world, int x, int z) {
    WorldServer sworld = ((CraftWorld) world).getHandle();
    net.minecraft.server.v1_8_R3.Chunk loaded = ((ChunkProviderServer) sworld.N()).getChunkIfLoaded(x, z);
    if (loaded == null) {
        // load
        try {
            net.minecraft.server.v1_8_R3.Chunk chunk;
            chunk = ((IChunkLoader) Ref.get(((ChunkProviderServer) sworld.N()), chunkLoader)).a(sworld, x, z);
            if (chunk != null) {
                chunk.setLastSaved(sworld.getTime());
                if (((ChunkProviderServer) sworld.N()).chunkProvider != null) {
                    ((ChunkProviderServer) sworld.N()).chunkProvider.recreateStructures(chunk, x, z);
                }
            }
            if (chunk != null) {
                ((ChunkProviderServer) sworld.N()).chunks.put(ChunkCoordIntPair.a(x, z), chunk);
                postToMainThread(() -> {
                    chunk.addEntities();
                });
                loaded = chunk;
            }
        } catch (Exception e) {
        }
    }
    if (loaded == null) {
        // generate new chunk
        ChunkRegionLoader loader = null;
        if ((IChunkLoader) Ref.get(((ChunkProviderServer) sworld.N()), chunkLoader) instanceof ChunkRegionLoader) {
            loader = (ChunkRegionLoader) Ref.get(((ChunkProviderServer) sworld.N()), chunkLoader);
        }
        if (loader != null && loader.chunkExists(sworld, x, z)) {
            loaded = ChunkIOExecutor.syncChunkLoad(sworld, loader, (ChunkProviderServer) sworld.N(), x, z);
        } else {
            loaded = ((ChunkProviderServer) sworld.N()).originalGetChunkAt(x, z);
        }
        loaded = ((ChunkProviderServer) sworld.N()).chunkProvider.getOrCreateChunk(x, z);
        ((ChunkProviderServer) sworld.N()).chunks.put(ChunkCoordIntPair.a(x, z), loaded);
    }
    return loaded;
}
Also used : ChunkProviderServer(net.minecraft.server.v1_8_R3.ChunkProviderServer) WorldServer(net.minecraft.server.v1_8_R3.WorldServer) ChunkRegionLoader(net.minecraft.server.v1_8_R3.ChunkRegionLoader) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld)

Example 20 with Chunk

use of net.minecraft.server.v1_8_R3.Chunk in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method spawnExistingEntity.

@Override
public void spawnExistingEntity(LivingEntity entity, SpawnReason spawnReason, boolean bypassSpawnEvent) {
    Location location = entity.getLocation();
    World world = location.getWorld();
    if (world == null)
        throw new IllegalArgumentException("Entity is not in a loaded world");
    if (bypassSpawnEvent) {
        IChunkAccess ichunkaccess = ((CraftWorld) world).getHandle().getChunkAt(MathHelper.floor(entity.getLocation().getX() / 16.0D), MathHelper.floor(entity.getLocation().getZ() / 16.0D), ChunkStatus.FULL, false);
        if (!(ichunkaccess instanceof Chunk))
            return;
        ichunkaccess.a(((CraftEntity) entity).getHandle());
        ((CraftWorld) world).getHandle().addEntityChunk(((CraftEntity) entity).getHandle());
    } else {
        ((CraftWorld) world).addEntity(((CraftEntity) entity).getHandle(), spawnReason);
    }
}
Also used : IChunkAccess(net.minecraft.server.v1_16_R3.IChunkAccess) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Chunk(net.minecraft.server.v1_16_R3.Chunk) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)13 ArrayList (java.util.ArrayList)11 List (java.util.List)11 HashMap (java.util.HashMap)10 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 Map (java.util.Map)8 UUID (java.util.UUID)8 Chunk (net.minecraft.server.v1_16_R3.Chunk)8 CraftChunk (org.bukkit.craftbukkit.v1_8_R3.CraftChunk)7 BlockPosition (net.minecraft.server.v1_8_R3.BlockPosition)6 Chunk (net.minecraft.server.v1_15_R1.Chunk)4 IBlockData (net.minecraft.server.v1_8_R3.IBlockData)4 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)4