use of thpmc.engine.api.world.parallel.ParallelUniverse 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);
}
use of thpmc.engine.api.world.parallel.ParallelUniverse in project THP-Engine 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;
}
use of thpmc.engine.api.world.parallel.ParallelUniverse in project THP-Engine by TheHollowPlanetMC.
the class LightUpdatePacketHandler 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.getCachedLightUpdatePacket();
if (cachedPacket != null)
return cachedPacket;
int cValue = c.getInt(packet);
int dValue = d.getInt(packet);
int eValue = e.getInt(packet);
int fValue = f.getInt(packet);
Deque<byte[]> gValue = new ArrayDeque<>((List<byte[]>) g.get(packet));
Deque<byte[]> hValue = new ArrayDeque<>((List<byte[]>) h.get(packet));
int newC = 0;
int newD = 0;
int newE = 0;
int newF = 0;
List<byte[]> newG = new ArrayList<>();
List<byte[]> newH = new ArrayList<>();
boolean edited = false;
for (int index = 0; index < 18; index++) {
int sectionIndex = index - 1;
int cSectionBit = cValue & (1 << index);
newC |= cSectionBit;
newE |= eValue & (1 << index);
int dSectionBit = dValue & (1 << index);
newD |= dSectionBit;
newF |= fValue & (1 << index);
if (index == 0 || index == 17) {
if (cSectionBit != 0) {
newG.add(gValue.removeFirst());
}
if (dSectionBit != 0) {
newH.add(hValue.removeFirst());
}
continue;
}
SectionLevelArray skyLevelArray = parallelChunk.getSkyLightSectionLevelArray(sectionIndex);
SectionLevelArray blockLevelArray = parallelChunk.getBlockLightSectionLevelArray(sectionIndex);
if (skyLevelArray == null) {
if (cSectionBit != 0) {
newG.add(gValue.removeFirst());
}
} else {
if (cSectionBit == 0) {
NibbleArray nibbleArray = new NibbleArray();
boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newG.add(nibbleArray.asBytes());
if (notEmpty) {
newC |= 1 << index;
newE &= ~(1 << index);
} else {
newE |= 1 << index;
}
} else {
NibbleArray nibbleArray = new NibbleArray(gValue.removeFirst().clone());
boolean notEmpty = skyLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newG.add(nibbleArray.asBytes());
if (notEmpty) {
newE &= ~(1 << index);
}
}
}
if (blockLevelArray == null) {
if (dSectionBit != 0) {
newH.add(hValue.removeFirst());
}
} else {
if (dSectionBit == 0) {
NibbleArray nibbleArray = new NibbleArray();
boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newH.add(nibbleArray.asBytes());
if (notEmpty) {
newD |= 1 << index;
newF &= ~(1 << index);
} else {
newF |= 1 << index;
}
} else {
NibbleArray nibbleArray = new NibbleArray(hValue.removeFirst().clone());
boolean notEmpty = blockLevelArray.threadsafeIteration(nibbleArray::a);
if (notEmpty)
edited = true;
newH.add(nibbleArray.asBytes());
if (notEmpty) {
newF &= ~(1 << index);
}
}
}
}
if (!edited)
return packet;
PacketPlayOutLightUpdate newPacket = new PacketPlayOutLightUpdate();
a.set(newPacket, chunkX);
b.set(newPacket, chunkZ);
c.set(newPacket, newC);
d.set(newPacket, newD);
e.set(newPacket, newE);
f.set(newPacket, newF);
g.set(newPacket, newG);
h.set(newPacket, newH);
if (cacheSetting)
parallelChunk.setLightUpdatePacketCache(newPacket);
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
use of thpmc.engine.api.world.parallel.ParallelUniverse 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 {
ChunkCoordIntPair aValue = (ChunkCoordIntPair) a.get(packet);
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] bValue = (PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[]) b.get(packet);
int chunkX = aValue.x;
int chunkZ = aValue.z;
ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
if (parallelChunk == null)
return packet;
PacketPlayOutMultiBlockChange newPacket = new PacketPlayOutMultiBlockChange();
a.set(newPacket, aValue);
int length = bValue.length;
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] newInfo = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[length];
for (int index = 0; index < length; index++) {
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo info = bValue[index];
BlockPosition bp = info.a();
BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
if (blockData == null) {
newInfo[index] = info;
} else {
newInfo[index] = newPacket.new MultiBlockChangeInfo(info.b(), ((CraftBlockData) blockData).getState());
}
}
b.set(newPacket, newInfo);
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
use of thpmc.engine.api.world.parallel.ParallelUniverse 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