use of thpmc.engine.api.world.parallel.ParallelWorld 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;
}
use of thpmc.engine.api.world.parallel.ParallelWorld in project THP-Engine 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;
}
use of thpmc.engine.api.world.parallel.ParallelWorld in project THP-Engine 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;
}
use of thpmc.engine.api.world.parallel.ParallelWorld in project THP-Engine 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.engine.api.world.parallel.ParallelWorld in project THP-Engine 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;
}
Aggregations