Search in sources :

Example 6 with ParallelWorld

use of thpmc.vanilla_source.api.world.parallel.ParallelWorld in project VanillaSource by TheHollowPlanetMC.

the class ImplParallelUniverse method addDiffs.

@Override
public void addDiffs(ParallelUniverse universe) {
    int indexStart = NMSManager.isHigher_v1_18_R1() ? -4 : 0;
    int indexEnd = NMSManager.isHigher_v1_18_R1() ? 20 : 16;
    for (ParallelWorld diffWorld : universe.getAllWorld()) {
        for (ParallelChunk diffChunk : diffWorld.getAllChunk()) {
            for (int i = indexStart; i < indexEnd; i++) {
                ParallelWorld thisWorld = null;
                ParallelChunk thisChunk = null;
                SectionTypeArray sectionTypeArray = diffChunk.getSectionTypeArray(i);
                if (sectionTypeArray != null) {
                    thisWorld = this.getWorld(diffWorld.getName());
                    thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
                    SectionTypeArray thisType = ((ImplParallelChunk) thisChunk).createSectionTypeArrayIfAbsent(i);
                    sectionTypeArray.threadsafeIteration(thisType::setType);
                }
                SectionLevelArray blockLightLevelArray = diffChunk.getBlockLightSectionLevelArray(i);
                if (blockLightLevelArray != null) {
                    if (thisWorld == null)
                        thisWorld = this.getWorld(diffWorld.getName());
                    if (thisChunk == null)
                        thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
                    SectionLevelArray thisLevel = ((ImplParallelChunk) thisChunk).createBlockLightSectionLevelArrayIfAbsent(i);
                    blockLightLevelArray.threadsafeIteration(thisLevel::setLevel);
                }
                SectionLevelArray skyLightLevelArray = diffChunk.getSkyLightSectionLevelArray(i);
                if (skyLightLevelArray != null) {
                    if (thisWorld == null)
                        thisWorld = this.getWorld(diffWorld.getName());
                    if (thisChunk == null)
                        thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
                    SectionLevelArray thisLevel = ((ImplParallelChunk) thisChunk).createSkyLightSectionLevelArrayIfAbsent(i);
                    skyLightLevelArray.threadsafeIteration(thisLevel::setLevel);
                }
            }
        }
    }
    for (EnginePlayer EnginePlayer : this.getResidents()) {
        ((ImplEnginePlayer) EnginePlayer).setUniverseRaw(null);
        EnginePlayer.setUniverse(this);
    }
}
Also used : ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) EnginePlayer(thpmc.vanilla_source.api.player.EnginePlayer) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) SectionLevelArray(thpmc.vanilla_source.util.SectionLevelArray)

Example 7 with ParallelWorld

use of thpmc.vanilla_source.api.world.parallel.ParallelWorld in project VanillaSource by TheHollowPlanetMC.

the class ParallelStructure method clearStructureData.

/**
 * 適用されている構造物データを消去します
 * @param EnginePlayer 構造物を変化させて見せるプレイヤー
 * @param chunkUpdate チャンクアップデートのパケットを送信するかどうか
 */
public void clearStructureData(EnginePlayer EnginePlayer, boolean chunkUpdate) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return;
    Set<Block> blocks = dataMap.get(universe.getName());
    if (blocks == null)
        return;
    ParallelWorld parallelWorld = universe.getWorld(Objects.requireNonNull(baseLocation.getWorld()).getName());
    for (Block block : blocks) {
        parallelWorld.removeBlockData(block.getX(), block.getY(), block.getZ());
    }
    Set<BlockPosition3i> blockPosition3iSet = new HashSet<>();
    blocks.forEach(block -> blockPosition3iSet.add(new BlockPosition3i(block.getX(), block.getY(), block.getZ())));
    parallelWorld.sendMultiBlockUpdate(blockPosition3iSet);
}
Also used : ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) ParallelUniverse(thpmc.vanilla_source.api.world.parallel.ParallelUniverse) Block(org.bukkit.block.Block)

Example 8 with ParallelWorld

use of thpmc.vanilla_source.api.world.parallel.ParallelWorld in project VanillaSource by TheHollowPlanetMC.

the class BlockChangePacketHandler 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 {
        PacketPlayOutBlockChange blockChange = (PacketPlayOutBlockChange) packet;
        BlockPosition bp = (BlockPosition) a.get(blockChange);
        BlockData blockData = parallelWorld.getBlockData(bp.getX(), bp.getY(), bp.getZ());
        if (blockData == null)
            return packet;
        PacketPlayOutBlockChange newPacket = new PacketPlayOutBlockChange();
        a.set(newPacket, bp);
        newPacket.block = ((CraftBlockData) blockData).getState();
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) BlockPosition(net.minecraft.server.v1_15_R1.BlockPosition) ParallelUniverse(thpmc.vanilla_source.api.world.parallel.ParallelUniverse) PacketPlayOutBlockChange(net.minecraft.server.v1_15_R1.PacketPlayOutBlockChange) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Example 9 with ParallelWorld

use of thpmc.vanilla_source.api.world.parallel.ParallelWorld in project VanillaSource 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.vanilla_source.api.world.parallel.ParallelWorld) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk)

Example 10 with ParallelWorld

use of thpmc.vanilla_source.api.world.parallel.ParallelWorld in project VanillaSource by TheHollowPlanetMC.

the class FlyPacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    World world = EnginePlayer.getBukkitPlayer().getWorld();
    String worldName = world.getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    EntityPlayer entityPlayer = ((CraftPlayer) EnginePlayer.getBukkitPlayer()).getHandle();
    int x = NumberConversions.floor(entityPlayer.locX());
    int y = NumberConversions.floor(entityPlayer.locY());
    int z = NumberConversions.floor(entityPlayer.locZ());
    int downY = y - 1;
    downY = Math.max(0, downY);
    if (parallelWorld.hasBlockData(x, y, z) || parallelWorld.hasBlockData(x, downY, z)) {
        try {
            PlayerConnection playerConnection = entityPlayer.playerConnection;
            C.set(playerConnection, 0);
            E.set(playerConnection, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packet;
}
Also used : ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) ParallelUniverse(thpmc.vanilla_source.api.world.parallel.ParallelUniverse) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) World(org.bukkit.World) ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) PlayerConnection(net.minecraft.server.v1_15_R1.PlayerConnection)

Aggregations

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