Search in sources :

Example 11 with ParallelUniverse

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

the class MapChunkPacketHandler 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);
    try {
        int chunkX = a.getInt(packet);
        int chunkZ = b.getInt(packet);
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        Object cachedPacket = parallelChunk.getCachedMapChunkPacket();
        if (cachedPacket != null)
            return cachedPacket;
        ChunkSnapshot chunkSnapshot = AsyncWorldCache.getChunkCache(worldName, chunkX, chunkZ);
        if (chunkSnapshot == null)
            return packet;
        DataPaletteBlock<IBlockData>[] cachedDataBlocks = (DataPaletteBlock<IBlockData>[]) blockids.get(chunkSnapshot);
        ChunkSection[] chunkSections = new ChunkSection[16];
        int nonEmptyChunkSections = 0;
        boolean edited = false;
        for (int index = 0; index < 16; index++) {
            ChunkSection chunkSection = Chunk.a;
            SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(index);
            if (sectionTypeArray != null) {
                DataPaletteBlock<IBlockData> cachedBlockData = cachedDataBlocks[index];
                if (cachedBlockData != null) {
                    final short[] nonEmptyTemp = { 0 };
                    cachedBlockData.a((iBlockData, i) -> {
                        Fluid fluid = iBlockData.getFluid();
                        if (!iBlockData.isAir()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                        if (!fluid.isEmpty()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                    });
                    short nonEmpty = nonEmptyTemp[0];
                    chunkSection = new ChunkSection(index << 4, nonEmpty, (short) 0, (short) 0);
                    NBTTagCompound data = new NBTTagCompound();
                    cachedBlockData.a(data, "Palette", "BlockStates");
                    DataPaletteBlock<IBlockData> blocks = chunkSection.getBlocks();
                    blocks.a(data.getList("Palette", 10), data.getLongArray("BlockStates"));
                }
                if (chunkSection == Chunk.a)
                    chunkSection = new ChunkSection(index << 4);
                ChunkSection finalChunkSection = chunkSection;
                boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
                    finalChunkSection.setType(x, y, z, (IBlockData) iBlockData);
                });
                if (notEmpty)
                    edited = true;
            } else {
                if (!chunkSnapshot.isSectionEmpty(index)) {
                    DataPaletteBlock<IBlockData> dataPaletteBlock = cachedDataBlocks[index];
                    final short[] nonEmptyTemp = { 0 };
                    dataPaletteBlock.a((iBlockData, i) -> {
                        Fluid fluid = iBlockData.getFluid();
                        if (!iBlockData.isAir()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                        if (!fluid.isEmpty()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                    });
                    short nonEmpty = nonEmptyTemp[0];
                    chunkSection = new ChunkSection(index << 4, nonEmpty, (short) 0, (short) 0);
                    blockIds.set(chunkSection, dataPaletteBlock);
                }
            }
            if (chunkSection != Chunk.a)
                nonEmptyChunkSections |= (1 << index);
            chunkSections[index] = chunkSection;
        }
        if (!edited)
            return packet;
        Chunk chunk = new Chunk(((CraftWorld) world).getHandle(), new ChunkCoordIntPair(chunkX, chunkZ), null, ChunkConverter.a, TickListEmpty.b(), TickListEmpty.b(), 0L, chunkSections, null);
        int cValue = c.getInt(packet);
        PacketPlayOutMapChunk newPacket = new PacketPlayOutMapChunk(chunk, nonEmptyChunkSections | cValue);
        NBTTagCompound dValue = (NBTTagCompound) d.get(packet);
        BiomeStorage eValue = (BiomeStorage) e.get(packet);
        List<NBTTagCompound> gValue = (List<NBTTagCompound>) g.get(packet);
        boolean hValue = h.getBoolean(packet);
        d.set(newPacket, dValue);
        e.set(newPacket, eValue);
        g.set(newPacket, gValue);
        h.set(newPacket, hValue || nonEmptyChunkSections == 65535);
        if (cacheSetting)
            parallelChunk.setMapChunkPacketCache(newPacket);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) ChunkSnapshot(org.bukkit.ChunkSnapshot) CraftChunkSnapshot(org.bukkit.craftbukkit.v1_15_R1.CraftChunkSnapshot) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld) ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) World(org.bukkit.World) List(java.util.List) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) ParallelUniverse(thpmc.vanilla_source.api.world.parallel.ParallelUniverse)

Example 12 with ParallelUniverse

use of thpmc.vanilla_source.api.world.parallel.ParallelUniverse 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_16_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) World(org.bukkit.World) ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) PlayerConnection(net.minecraft.server.v1_16_R3.PlayerConnection)

Example 13 with ParallelUniverse

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

the class MapChunkPacketHandler 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);
    try {
        int chunkX = a.getInt(packet);
        int chunkZ = b.getInt(packet);
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        Object cachedPacket = parallelChunk.getCachedMapChunkPacket();
        if (cachedPacket != null)
            return cachedPacket;
        ChunkSnapshot chunkSnapshot = AsyncWorldCache.getChunkCache(worldName, chunkX, chunkZ);
        if (chunkSnapshot == null)
            return packet;
        DataPaletteBlock<IBlockData>[] cachedDataBlocks = (DataPaletteBlock<IBlockData>[]) blockids.get(chunkSnapshot);
        ChunkSection[] chunkSections = new ChunkSection[16];
        int nonEmptyChunkSections = 0;
        boolean edited = false;
        for (int index = 0; index < 16; index++) {
            ChunkSection chunkSection = Chunk.a;
            SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(index);
            if (sectionTypeArray != null) {
                DataPaletteBlock<IBlockData> cachedBlockData = cachedDataBlocks[index];
                if (cachedBlockData != null) {
                    final short[] nonEmptyTemp = { 0 };
                    cachedBlockData.a((iBlockData, i) -> {
                        Fluid fluid = iBlockData.getFluid();
                        if (!iBlockData.isAir()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                        if (!fluid.isEmpty()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                    });
                    short nonEmpty = nonEmptyTemp[0];
                    chunkSection = new ChunkSection(index << 4, nonEmpty, (short) 0, (short) 0);
                    NBTTagCompound data = new NBTTagCompound();
                    cachedBlockData.a(data, "Palette", "BlockStates");
                    DataPaletteBlock<IBlockData> blocks = chunkSection.getBlocks();
                    blocks.a(data.getList("Palette", 10), data.getLongArray("BlockStates"));
                }
                if (chunkSection == Chunk.a)
                    chunkSection = new ChunkSection(index << 4);
                ChunkSection finalChunkSection = chunkSection;
                boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
                    finalChunkSection.setType(x, y, z, (IBlockData) iBlockData);
                });
                if (notEmpty)
                    edited = true;
            } else {
                if (!chunkSnapshot.isSectionEmpty(index)) {
                    DataPaletteBlock<IBlockData> dataPaletteBlock = cachedDataBlocks[index];
                    final short[] nonEmptyTemp = { 0 };
                    dataPaletteBlock.a((iBlockData, i) -> {
                        Fluid fluid = iBlockData.getFluid();
                        if (!iBlockData.isAir()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                        if (!fluid.isEmpty()) {
                            nonEmptyTemp[0] = (short) (nonEmptyTemp[0] + i);
                        }
                    });
                    short nonEmpty = nonEmptyTemp[0];
                    chunkSection = new ChunkSection(index << 4, nonEmpty, (short) 0, (short) 0);
                    blockIds.set(chunkSection, dataPaletteBlock);
                }
            }
            if (chunkSection != Chunk.a)
                nonEmptyChunkSections |= (1 << index);
            chunkSections[index] = chunkSection;
        }
        if (!edited)
            return packet;
        Chunk chunk = new Chunk(((CraftWorld) world).getHandle(), new ChunkCoordIntPair(chunkX, chunkZ), null, ChunkConverter.a, TickListEmpty.b(), TickListEmpty.b(), 0L, chunkSections, null);
        int cValue = c.getInt(packet);
        PacketPlayOutMapChunk newPacket = new PacketPlayOutMapChunk(chunk, nonEmptyChunkSections | cValue);
        NBTTagCompound dValue = (NBTTagCompound) d.get(packet);
        Object eValue = e.get(packet);
        List<NBTTagCompound> gValue = (List<NBTTagCompound>) g.get(packet);
        boolean hValue = h.getBoolean(packet);
        d.set(newPacket, dValue);
        e.set(newPacket, eValue);
        g.set(newPacket, gValue);
        h.set(newPacket, hValue || nonEmptyChunkSections == 65535);
        if (cacheSetting)
            parallelChunk.setMapChunkPacketCache(newPacket);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) ChunkSnapshot(org.bukkit.ChunkSnapshot) CraftChunkSnapshot(org.bukkit.craftbukkit.v1_16_R3.CraftChunkSnapshot) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) World(org.bukkit.World) List(java.util.List) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) ParallelUniverse(thpmc.vanilla_source.api.world.parallel.ParallelUniverse)

Example 14 with ParallelUniverse

use of thpmc.vanilla_source.api.world.parallel.ParallelUniverse in project VanillaSource 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.vanilla_source.api.world.parallel.ParallelWorld) SectionPosition(net.minecraft.server.v1_16_R3.SectionPosition) PacketPlayOutMultiBlockChange(net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) ParallelUniverse(thpmc.vanilla_source.api.world.parallel.ParallelUniverse)

Example 15 with ParallelUniverse

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

the class ParallelStructure method setStructureData.

/**
 * この構造物を指定された構造物データを適応して特定のプレイヤーへ見せる
 * @param EnginePlayer 構造物を変化させて見せるプレイヤー
 * @param implStructureData 構造物データ
 */
public void setStructureData(EnginePlayer EnginePlayer, ImplStructureData implStructureData, @Nullable UpdatePacketType type) {
    clearStructureData(EnginePlayer, false);
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return;
    ParallelWorld parallelWorld = universe.getWorld(Objects.requireNonNull(baseLocation.getWorld()).getName());
    Set<Block> blocks = new HashSet<>();
    Set<BlockPosition3i> updateBlocks = new HashSet<>();
    for (Map.Entry<BlockPosition3i, BlockData> entry : implStructureData.getBlockDataMap().entrySet()) {
        BlockPosition3i relative = entry.getKey();
        Block block = getBaseLocation().add(relative.getX(), relative.getY(), relative.getZ()).getBlock();
        parallelWorld.setBlockData(block.getX(), block.getY(), block.getZ(), entry.getValue());
        blocks.add(block);
        updateBlocks.add(new BlockPosition3i(block.getX(), block.getY(), block.getZ()));
    }
    for (Map.Entry<BlockPosition3i, Integer> entry : implStructureData.getBlockLightLevelMap().entrySet()) {
        BlockPosition3i relative = entry.getKey();
        Block block = getBaseLocation().add(relative.getX(), relative.getY(), relative.getZ()).getBlock();
        parallelWorld.setBlockLightLevel(block.getX(), block.getY(), block.getZ(), entry.getValue());
        blocks.add(block);
        updateBlocks.add(new BlockPosition3i(block.getX(), block.getY(), block.getZ()));
    }
    dataMap.put(universe.getName(), blocks);
    parallelWorld.sendMultiBlockUpdate(updateBlocks);
}
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) BlockData(org.bukkit.block.data.BlockData)

Aggregations

ParallelUniverse (thpmc.vanilla_source.api.world.parallel.ParallelUniverse)16 ParallelWorld (thpmc.vanilla_source.api.world.parallel.ParallelWorld)12 World (org.bukkit.World)7 ParallelChunk (thpmc.vanilla_source.api.world.parallel.ParallelChunk)6 BlockData (org.bukkit.block.data.BlockData)4 Player (org.bukkit.entity.Player)3 EnginePlayer (thpmc.vanilla_source.api.player.EnginePlayer)3 SectionTypeArray (thpmc.vanilla_source.util.SectionTypeArray)3 List (java.util.List)2 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)2 ChunkSnapshot (org.bukkit.ChunkSnapshot)2 Block (org.bukkit.block.Block)2 CraftBlockData (org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)2 VanillaSourceAPI (thpmc.vanilla_source.api.VanillaSourceAPI)2 BlockPosition3i (thpmc.vanilla_source.util.BlockPosition3i)2 SectionLevelArray (thpmc.vanilla_source.util.SectionLevelArray)2 be4rjp.artgui.button (be4rjp.artgui.button)1 Artist (be4rjp.artgui.frame.Artist)1 ArtMenu (be4rjp.artgui.menu.ArtMenu)1 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1