Search in sources :

Example 6 with ParallelChunk

use of thpmc.engine.api.world.parallel.ParallelChunk in project THP-Engine by TheHollowPlanetMC.

the class MultiBlockChangePacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    String worldName = EnginePlayer.getBukkitPlayer().getWorld().getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    try {
        SectionPosition aValue = (SectionPosition) a.get(packet);
        int chunkX = aValue.getX();
        int chunkZ = aValue.getZ();
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(aValue.getY());
        if (sectionTypeArray == null)
            return packet;
        short[] bValue = (short[]) b.get(packet);
        IBlockData[] cValueClone = ((IBlockData[]) c.get(packet)).clone();
        for (int i = 0; i < bValue.length; i++) {
            short coord = bValue[i];
            int x = coord >> 8;
            int y = coord & 0xF;
            int z = (coord >> 4) & 0xF;
            IBlockData iBlockData = (IBlockData) sectionTypeArray.getType(x, y, z);
            if (iBlockData != null) {
                cValueClone[i] = iBlockData;
            }
        }
        boolean dValue = d.getBoolean(packet);
        PacketPlayOutMultiBlockChange newPacket = new PacketPlayOutMultiBlockChange();
        a.set(newPacket, aValue);
        b.set(newPacket, bValue);
        c.set(newPacket, cValueClone);
        d.set(newPacket, dValue);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) SectionPosition(net.minecraft.server.v1_16_R3.SectionPosition) PacketPlayOutMultiBlockChange(net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.engine.util.SectionTypeArray) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse)

Example 7 with ParallelChunk

use of thpmc.engine.api.world.parallel.ParallelChunk in project THP-Engine by TheHollowPlanetMC.

the class ImplEnginePlayer method setUniverse.

@Override
public synchronized void setUniverse(@Nullable ParallelUniverse parallelUniverse) {
    if (currentUniverse == parallelUniverse)
        return;
    if (currentUniverse != null) {
        ((ImplParallelUniverse) currentUniverse).getPlayers().remove(this);
        ParallelWorld currentWorld = currentUniverse.getWorld(player.getWorld().getName());
        this.currentUniverse = parallelUniverse;
        int range = Bukkit.getViewDistance();
        int chunkX = player.getLocation().getBlockX() >> 4;
        int chunkZ = player.getLocation().getBlockZ() >> 4;
        for (int x = -range; x < range; x++) {
            for (int z = -range; z < range; z++) {
                ParallelChunk chunk = currentWorld.getChunk(chunkX + x, chunkZ + z);
                if (chunk == null)
                    continue;
                ((ImplParallelChunk) chunk).sendClearPacket(player);
            }
        }
    }
    if (parallelUniverse != null) {
        ((ImplParallelUniverse) parallelUniverse).getPlayers().add(this);
        ParallelWorld nextWorld = parallelUniverse.getWorld(player.getWorld().getName());
        this.currentUniverse = parallelUniverse;
        int range = Bukkit.getViewDistance();
        int chunkX = player.getLocation().getBlockX() >> 4;
        int chunkZ = player.getLocation().getBlockZ() >> 4;
        for (int x = -range; x < range; x++) {
            for (int z = -range; z < range; z++) {
                ParallelChunk chunk = nextWorld.getChunk(chunkX + x, chunkZ + z);
                if (chunk == null)
                    continue;
                chunk.sendUpdate(player);
            }
        }
    }
    this.currentUniverse = parallelUniverse;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk)

Example 8 with ParallelChunk

use of thpmc.engine.api.world.parallel.ParallelChunk in project THP-Engine by TheHollowPlanetMC.

the class ImplParallelWorld method getBlockLightLevel.

@Override
public int getBlockLightLevel(int blockX, int blockY, int blockZ) {
    int chunkX = blockX >> 4;
    int chunkZ = blockZ >> 4;
    long coord = ChunkUtil.getCoordinateKey(chunkX, chunkZ);
    ParallelChunk parallelChunk = chunkMap.get(coord);
    if (parallelChunk == null)
        return 0;
    return parallelChunk.getBlockLightLevel(blockX, blockY, blockZ);
}
Also used : ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk)

Example 9 with ParallelChunk

use of thpmc.engine.api.world.parallel.ParallelChunk in project THP-Engine by TheHollowPlanetMC.

the class ImplParallelWorld method removeSkyLight.

@Override
public void removeSkyLight(int blockX, int blockY, int blockZ) {
    int chunkX = blockX >> 4;
    int chunkZ = blockZ >> 4;
    long coord = ChunkUtil.getCoordinateKey(chunkX, chunkZ);
    ParallelChunk parallelChunk = chunkMap.get(coord);
    if (parallelChunk == null)
        return;
    parallelChunk.removeSkyLight(blockX, blockY, blockZ);
}
Also used : ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk)

Example 10 with ParallelChunk

use of thpmc.engine.api.world.parallel.ParallelChunk in project THP-Engine by TheHollowPlanetMC.

the class ImplParallelWorld method getSkyLightLevel.

@Override
public int getSkyLightLevel(int blockX, int blockY, int blockZ) {
    int chunkX = blockX >> 4;
    int chunkZ = blockZ >> 4;
    long coord = ChunkUtil.getCoordinateKey(chunkX, chunkZ);
    ParallelChunk parallelChunk = chunkMap.get(coord);
    if (parallelChunk == null)
        return 0;
    return parallelChunk.getSkyLightLevel(blockX, blockY, blockZ);
}
Also used : ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk)

Aggregations

ParallelChunk (thpmc.engine.api.world.parallel.ParallelChunk)26 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)10 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)6 SectionTypeArray (thpmc.engine.util.SectionTypeArray)6 Nullable (org.jetbrains.annotations.Nullable)5 SectionLevelArray (thpmc.engine.util.SectionLevelArray)5 World (org.bukkit.World)4 BlockData (org.bukkit.block.data.BlockData)3 java.util (java.util)2 List (java.util.List)2 Bukkit (org.bukkit.Bukkit)2 ChunkSnapshot (org.bukkit.ChunkSnapshot)2 CraftWorld (org.bukkit.craftbukkit.v1_15_R1.CraftWorld)2 CraftBlockData (org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)2 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)2 Player (org.bukkit.entity.Player)2 BlockPosition3i (thpmc.engine.util.BlockPosition3i)2 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)1 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)1 ChunkCoordIntPair (net.minecraft.server.v1_15_R1.ChunkCoordIntPair)1