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;
}
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);
}
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);
}
}
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();
}
}
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);
}
}
}
Aggregations