Search in sources :

Example 1 with BlockPosition3i

use of thpmc.vanilla_source.util.BlockPosition3i in project VanillaSource by TheHollowPlanetMC.

the class PacketManager method createMultiBlockChangePacket.

public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
    Map<ChunkPosition, Set<BlockPosition3i>> chunkMap = new HashMap<>();
    for (BlockPosition3i bp : blocks) {
        chunkMap.computeIfAbsent(new ChunkPosition(bp.getX(), bp.getZ()), cp -> new HashSet<>()).add(bp);
    }
    Set<Object> packets = new HashSet<>();
    for (Map.Entry<ChunkPosition, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
        ChunkPosition chunkPosition = entry.getKey();
        Set<BlockPosition3i> bps = entry.getValue();
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkPosition.x, chunkPosition.z);
        if (parallelChunk == null)
            continue;
        PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
        List<PacketPlayOutMultiBlockChange.MultiBlockChangeInfo> infoList = new ArrayList<>();
        for (BlockPosition3i bp : bps) {
            BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
            if (blockData == null)
                continue;
            short loc = (short) ((bp.getX() & 0xF) << 12 | (bp.getZ() & 0xF) << 8 | bp.getY());
            infoList.add(packet.new MultiBlockChangeInfo(loc, ((CraftBlockData) blockData).getState()));
        }
        PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] array = infoList.toArray(new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[infoList.size()]);
        try {
            MultiBlockChangePacketHandler.a.set(packet, new ChunkCoordIntPair(chunkPosition.x, chunkPosition.z));
            MultiBlockChangePacketHandler.b.set(packet, array);
            packets.add(packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packets;
}
Also used : ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) java.util(java.util) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld) BlockData(org.bukkit.block.data.BlockData) ChunkPosition(thpmc.vanilla_source.util.ChunkPosition) ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) SectionLevelArray(thpmc.vanilla_source.util.SectionLevelArray) Player(org.bukkit.entity.Player) MultiBlockChangePacketHandler(thpmc.vanilla_source.nms.v1_15_R1.MultiBlockChangePacketHandler) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) Nullable(org.jetbrains.annotations.Nullable) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) NMSHandler(thpmc.vanilla_source.nms.v1_15_R1.NMSHandler) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockChangePacketHandler(thpmc.vanilla_source.nms.v1_15_R1.BlockChangePacketHandler) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) Bukkit(org.bukkit.Bukkit) ChunkPosition(thpmc.vanilla_source.util.ChunkPosition) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Example 2 with BlockPosition3i

use of thpmc.vanilla_source.util.BlockPosition3i 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 3 with BlockPosition3i

use of thpmc.vanilla_source.util.BlockPosition3i in project VanillaSource by TheHollowPlanetMC.

the class StructureData method setBlockData.

/**
 * ブロックの状態を記録
 * @param baseLocation
 * @param blocks
 */
public void setBlockData(Location baseLocation, List<Block> blocks) {
    for (Block block : blocks) {
        BlockPosition3i relative = new BlockPosition3i(block.getX() - baseLocation.getBlockX(), block.getY() - baseLocation.getBlockY(), block.getZ() - baseLocation.getBlockZ());
        BlockData blockData = block.getBlockData();
        int blockLightLevel = block.getLightFromBlocks();
        this.blockDataMap.put(relative, blockData);
        this.blockLightLevelMap.put(relative, blockLightLevel);
    }
}
Also used : BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData)

Example 4 with BlockPosition3i

use of thpmc.vanilla_source.util.BlockPosition3i in project VanillaSource by TheHollowPlanetMC.

the class ImplStructureData method saveData.

/**
 * ymlファイルへ書き込み
 */
public void saveData() {
    File file = new File("plugins/VanillaSource/structure_data", name + ".yml");
    FileConfiguration yml = new YamlConfiguration();
    List<String> lines = new ArrayList<>();
    for (Map.Entry<BlockPosition3i, BlockData> entry : this.blockDataMap.entrySet()) {
        BlockPosition3i relative = entry.getKey();
        try {
            Object iBlockData = NMSManager.getNMSHandler().getIBlockData(entry.getValue());
            int id = NMSManager.getNMSHandler().getCombinedIdByIBlockData(iBlockData);
            String line = relative.getX() + ", " + relative.getY() + ", " + relative.getZ() + ", " + id;
            lines.add(line);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    yml.set("blocks", lines);
    List<String> lines2 = new ArrayList<>();
    for (Map.Entry<BlockPosition3i, Integer> entry : this.blockLightLevelMap.entrySet()) {
        BlockPosition3i relative = entry.getKey();
        int lightLevel = entry.getValue();
        String line = relative.getX() + ", " + relative.getY() + ", " + relative.getZ() + ", " + lightLevel;
        lines2.add(line);
    }
    yml.set("block-lights", lines2);
    try {
        yml.save(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) IOException(java.io.IOException) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) BlockData(org.bukkit.block.data.BlockData) File(java.io.File) Map(java.util.Map)

Example 5 with BlockPosition3i

use of thpmc.vanilla_source.util.BlockPosition3i in project VanillaSource by TheHollowPlanetMC.

the class ImplStructureData method loadData.

/**
 * ymlファイルから読み込み
 */
public void loadData() {
    this.blockDataMap.clear();
    File file = new File("plugins/VanillaSource/structure_data", name + ".yml");
    createFile(file);
    FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
    List<String> lines = yml.getStringList("blocks");
    // x, y, z, CombinedId
    for (String line : lines) {
        line = line.replace(" ", "");
        String[] args = line.split(",");
        int x = Integer.parseInt(args[0]);
        int y = Integer.parseInt(args[1]);
        int z = Integer.parseInt(args[2]);
        BlockPosition3i relative = new BlockPosition3i(x, y, z);
        int id = Integer.parseInt(args[3]);
        Object iBlockData = NMSManager.getNMSHandler().getIBlockDataByCombinedId(id);
        this.blockDataMap.put(relative, NMSManager.getNMSHandler().getBukkitBlockData(iBlockData));
    }
    if (yml.contains("block-lights")) {
        lines = yml.getStringList("block-lights");
        // x, y, z, lightLevel
        for (String line : lines) {
            line = line.replace(" ", "");
            String[] args = line.split(",");
            int x = Integer.parseInt(args[0]);
            int y = Integer.parseInt(args[1]);
            int z = Integer.parseInt(args[2]);
            BlockPosition3i relative = new BlockPosition3i(x, y, z);
            int lightLevel = Integer.parseInt(args[3]);
            this.blockLightLevelMap.put(relative, lightLevel);
        }
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) File(java.io.File)

Aggregations

BlockPosition3i (thpmc.vanilla_source.util.BlockPosition3i)7 BlockData (org.bukkit.block.data.BlockData)5 ParallelWorld (thpmc.vanilla_source.api.world.parallel.ParallelWorld)4 Block (org.bukkit.block.Block)3 File (java.io.File)2 java.util (java.util)2 Bukkit (org.bukkit.Bukkit)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 Player (org.bukkit.entity.Player)2 Nullable (org.jetbrains.annotations.Nullable)2 ParallelChunk (thpmc.vanilla_source.api.world.parallel.ParallelChunk)2 ParallelUniverse (thpmc.vanilla_source.api.world.parallel.ParallelUniverse)2 SectionLevelArray (thpmc.vanilla_source.util.SectionLevelArray)2 SectionTypeArray (thpmc.vanilla_source.util.SectionTypeArray)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)1 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1