Search in sources :

Example 1 with BlockPosition3i

use of thpmc.engine.util.BlockPosition3i in project THP-Engine by TheHollowPlanetMC.

the class ImplStructureData method loadData.

/**
 * ymlファイルから読み込み
 */
public void loadData() {
    this.blockDataMap.clear();
    File file = new File("plugins/THP-Engine/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.engine.util.BlockPosition3i) File(java.io.File)

Example 2 with BlockPosition3i

use of thpmc.engine.util.BlockPosition3i in project THP-Engine 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.engine.api.world.parallel.ParallelWorld) BlockPosition3i(thpmc.engine.util.BlockPosition3i) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData)

Example 3 with BlockPosition3i

use of thpmc.engine.util.BlockPosition3i in project THP-Engine by TheHollowPlanetMC.

the class PacketManager method createMultiBlockChangePacket.

public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
    Map<BlockPosition3i, Set<BlockPosition3i>> chunkMap = new HashMap<>();
    for (BlockPosition3i bp : blocks) {
        chunkMap.computeIfAbsent(new BlockPosition3i(bp.getX() >> 4, bp.getY() >> 4, bp.getZ() >> 4), cp -> new HashSet<>()).add(bp);
    }
    Set<Object> packets = new HashSet<>();
    for (Map.Entry<BlockPosition3i, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
        BlockPosition3i sectionPosition = entry.getKey();
        Set<BlockPosition3i> bps = entry.getValue();
        ParallelChunk parallelChunk = parallelWorld.getChunk(sectionPosition.getX(), sectionPosition.getZ());
        if (parallelChunk == null)
            continue;
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionPosition.getY());
        if (sectionTypeArray == null)
            continue;
        List<Short> coordList = new ArrayList<>();
        List<IBlockData> dataList = new ArrayList<>();
        for (BlockPosition3i bp : bps) {
            IBlockData iBlockData = (IBlockData) sectionTypeArray.getType(bp.getX() & 0xF, bp.getY() & 0xF, bp.getZ() & 0xF);
            if (iBlockData == null)
                continue;
            coordList.add((short) ((bp.getX() & 0xF) << 8 | (bp.getZ() & 0xF) << 4 | bp.getY() & 0xF));
            dataList.add(iBlockData);
        }
        short[] coordArray = new short[coordList.size()];
        IBlockData[] dataArray = new IBlockData[dataList.size()];
        for (int i = 0; i < coordList.size(); i++) {
            coordArray[i] = coordList.get(i);
            dataArray[i] = dataList.get(i);
        }
        try {
            PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
            MultiBlockChangePacketHandler.a.set(packet, SectionPosition.a(sectionPosition.getX(), sectionPosition.getY(), sectionPosition.getZ()));
            MultiBlockChangePacketHandler.b.set(packet, coordArray);
            MultiBlockChangePacketHandler.c.set(packet, dataArray);
            MultiBlockChangePacketHandler.d.setBoolean(packet, true);
            packets.add(packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packets;
}
Also used : java.util(java.util) BlockData(org.bukkit.block.data.BlockData) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Player(org.bukkit.entity.Player) SectionTypeArray(thpmc.engine.util.SectionTypeArray) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) Nullable(org.jetbrains.annotations.Nullable) BlockChangePacketHandler(thpmc.engine.nms.v1_16_R3.BlockChangePacketHandler) NMSHandler(thpmc.engine.nms.v1_16_R3.NMSHandler) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) BlockPosition3i(thpmc.engine.util.BlockPosition3i) SectionLevelArray(thpmc.engine.util.SectionLevelArray) MultiBlockChangePacketHandler(thpmc.engine.nms.v1_16_R3.MultiBlockChangePacketHandler) Bukkit(org.bukkit.Bukkit) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.engine.util.SectionTypeArray) BlockPosition3i(thpmc.engine.util.BlockPosition3i)

Example 4 with BlockPosition3i

use of thpmc.engine.util.BlockPosition3i in project THP-Engine 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.engine.util.BlockPosition3i) Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData)

Example 5 with BlockPosition3i

use of thpmc.engine.util.BlockPosition3i in project THP-Engine by TheHollowPlanetMC.

the class ImplStructureData method saveData.

/**
 * ymlファイルへ書き込み
 */
public void saveData() {
    File file = new File("plugins/Parallel/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.engine.util.BlockPosition3i) BlockData(org.bukkit.block.data.BlockData) File(java.io.File) Map(java.util.Map)

Aggregations

BlockPosition3i (thpmc.engine.util.BlockPosition3i)7 BlockData (org.bukkit.block.data.BlockData)5 ParallelWorld (thpmc.engine.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.engine.api.world.parallel.ParallelChunk)2 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)2 SectionLevelArray (thpmc.engine.util.SectionLevelArray)2 SectionTypeArray (thpmc.engine.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