use of thpmc.engine.util.SectionLevelArray in project THP-Engine by TheHollowPlanetMC.
the class ImplParallelChunk method getBlockLightLevel.
@Override
public int getBlockLightLevel(int blockX, int blockY, int blockZ) {
int sectionIndex = ChunkUtil.getSectionIndex(blockY);
SectionLevelArray sectionLevelArray = blockLightArrays[sectionIndex];
if (sectionLevelArray == null)
return 0;
return sectionLevelArray.getLevel(blockX & 0xF, blockY & 0xF, blockZ & 0xF);
}
use of thpmc.engine.util.SectionLevelArray in project THP-Engine by TheHollowPlanetMC.
the class ImplParallelChunk method createSkyLightSectionLevelArrayIfAbsent.
public SectionLevelArray createSkyLightSectionLevelArrayIfAbsent(int sectionY) {
int sectionIndex = ChunkUtil.getSectionIndex(sectionY << 4);
SectionLevelArray sectionLevelArray = skyLightArrays[sectionIndex];
if (sectionLevelArray == null) {
sectionLevelArray = new SectionLevelArray();
skyLightArrays[sectionIndex] = sectionLevelArray;
}
return sectionLevelArray;
}
use of thpmc.engine.util.SectionLevelArray in project THP-Engine by TheHollowPlanetMC.
the class ImplParallelChunk method setBlockLightLevel.
@Override
public void setBlockLightLevel(int blockX, int blockY, int blockZ, int level) {
int sectionIndex = ChunkUtil.getSectionIndex(blockY);
SectionLevelArray sectionLevelArray = blockLightArrays[sectionIndex];
if (sectionLevelArray == null) {
sectionLevelArray = new SectionLevelArray();
blockLightArrays[sectionIndex] = sectionLevelArray;
}
sectionLevelArray.setLevel(blockX & 0xF, blockY & 0xF, blockZ & 0xF, (byte) level);
lightUpdatePacketCache = null;
}
use of thpmc.engine.util.SectionLevelArray in project THP-Engine by TheHollowPlanetMC.
the class ImplParallelUniverse method addDiffs.
@Override
public void addDiffs(ParallelUniverse universe) {
int indexStart = NMSManager.isHigher_v1_18_R1() ? -4 : 0;
int indexEnd = NMSManager.isHigher_v1_18_R1() ? 20 : 16;
for (ParallelWorld diffWorld : universe.getAllWorld()) {
for (ParallelChunk diffChunk : diffWorld.getAllChunk()) {
for (int i = indexStart; i < indexEnd; i++) {
ParallelWorld thisWorld = null;
ParallelChunk thisChunk = null;
SectionTypeArray sectionTypeArray = diffChunk.getSectionTypeArray(i);
if (sectionTypeArray != null) {
thisWorld = this.getWorld(diffWorld.getName());
thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
SectionTypeArray thisType = ((ImplParallelChunk) thisChunk).createSectionTypeArrayIfAbsent(i);
sectionTypeArray.threadsafeIteration(thisType::setType);
}
SectionLevelArray blockLightLevelArray = diffChunk.getBlockLightSectionLevelArray(i);
if (blockLightLevelArray != null) {
if (thisWorld == null)
thisWorld = this.getWorld(diffWorld.getName());
if (thisChunk == null)
thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
SectionLevelArray thisLevel = ((ImplParallelChunk) thisChunk).createBlockLightSectionLevelArrayIfAbsent(i);
blockLightLevelArray.threadsafeIteration(thisLevel::setLevel);
}
SectionLevelArray skyLightLevelArray = diffChunk.getSkyLightSectionLevelArray(i);
if (skyLightLevelArray != null) {
if (thisWorld == null)
thisWorld = this.getWorld(diffWorld.getName());
if (thisChunk == null)
thisChunk = ((ImplParallelWorld) thisWorld).createChunkIfAbsent(diffChunk.getChunkX(), diffChunk.getChunkZ());
SectionLevelArray thisLevel = ((ImplParallelChunk) thisChunk).createSkyLightSectionLevelArrayIfAbsent(i);
skyLightLevelArray.threadsafeIteration(thisLevel::setLevel);
}
}
}
}
for (EnginePlayer EnginePlayer : this.getResidents()) {
((ImplEnginePlayer) EnginePlayer).setUniverseRaw(null);
EnginePlayer.setUniverse(this);
}
}
use of thpmc.engine.util.SectionLevelArray 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);
boolean iFlag = i.getBoolean(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);
i.set(newPacket, iFlag);
if (cacheSetting)
parallelChunk.setLightUpdatePacketCache(newPacket);
return newPacket;
} catch (Exception e) {
e.printStackTrace();
}
return packet;
}
Aggregations