use of thpmc.engine.api.nms.INMSHandler in project THP-Engine by TheHollowPlanetMC.
the class NodeData method canStand.
public static boolean canStand(EngineWorld world, int blockX, int blockY, int blockZ, CollideOption collideOption) {
EngineChunk chunk = world.getChunkAt(blockX >> 4, blockZ >> 4);
if (chunk == null)
return false;
Object nmsBlockData1 = chunk.getNMSBlockData(blockX, blockY, blockZ);
Object nmsBlockData2 = chunk.getNMSBlockData(blockX, blockY + 1, blockZ);
Object nmsBlockData3 = chunk.getNMSBlockData(blockX, blockY - 1, blockZ);
Function<EngineBlock, Boolean> collideBlockFunction = collideOption.getCollideBlockFunction();
if (collideBlockFunction != null) {
if (nmsBlockData1 != null) {
if (!collideBlockFunction.apply(new EngineBlock(world, chunk, blockX, blockY, blockZ, nmsBlockData1))) {
nmsBlockData1 = null;
}
}
if (nmsBlockData2 != null) {
if (!collideBlockFunction.apply(new EngineBlock(world, chunk, blockX, blockY + 1, blockZ, nmsBlockData2))) {
nmsBlockData2 = null;
}
}
if (nmsBlockData3 != null) {
if (!collideBlockFunction.apply(new EngineBlock(world, chunk, blockX, blockY - 1, blockZ, nmsBlockData3))) {
nmsBlockData3 = null;
}
}
}
INMSHandler nmsHandler = THPEngineAPI.getInstance().getNMSHandler();
boolean traversable;
if (nmsBlockData1 == null && nmsBlockData2 == null) {
traversable = true;
} else if (nmsBlockData1 == null) {
traversable = !nmsHandler.hasCollision(new EngineBlock(world, chunk, blockX, blockY + 1, blockZ, nmsBlockData2), collideOption);
} else if (nmsBlockData2 == null) {
traversable = !nmsHandler.hasCollision(new EngineBlock(world, chunk, blockX, blockY, blockZ, nmsBlockData1), collideOption);
} else {
traversable = !nmsHandler.hasCollision(new EngineBlock(world, chunk, blockX, blockY, blockZ, nmsBlockData1), collideOption) && !nmsHandler.hasCollision(new EngineBlock(world, chunk, blockX, blockY + 1, blockZ, nmsBlockData2), collideOption);
}
if (!traversable)
return false;
if (nmsBlockData3 == null)
return false;
return nmsHandler.hasCollision(new EngineBlock(world, chunk, blockX, blockY - 1, blockZ, nmsBlockData3), collideOption);
}
use of thpmc.engine.api.nms.INMSHandler in project THP-Engine by TheHollowPlanetMC.
the class PacketHandler method write.
@Override
public void write(ChannelHandlerContext channelHandlerContext, Object packet, ChannelPromise channelPromise) throws Exception {
INMSHandler nmsHandler = NMSManager.getNMSHandler();
if (nmsHandler.isMapChunkPacket(packet)) {
super.write(channelHandlerContext, NMSManager.getMapChunkPacketHandler().rewrite(packet, EnginePlayer, ImplTHPESettings.isUseCachedChunkPacket()), channelPromise);
return;
}
if (nmsHandler.isLightUpdatePacket(packet) && ImplTHPESettings.isRewriteLightPacket()) {
super.write(channelHandlerContext, NMSManager.getLightUpdatePacketHandler().rewrite(packet, EnginePlayer, ImplTHPESettings.isUseCachedChunkPacket()), channelPromise);
return;
}
if (nmsHandler.isBlockChangePacket(packet)) {
super.write(channelHandlerContext, NMSManager.getBlockChangePacketHandler().rewrite(packet, EnginePlayer, ImplTHPESettings.isUseCachedChunkPacket()), channelPromise);
return;
}
if (nmsHandler.isMultiBlockChangePacket(packet)) {
super.write(channelHandlerContext, NMSManager.getMultiBlockChangePacketHandler().rewrite(packet, EnginePlayer, ImplTHPESettings.isUseCachedChunkPacket()), channelPromise);
return;
}
super.write(channelHandlerContext, packet, channelPromise);
}
use of thpmc.engine.api.nms.INMSHandler in project THP-Engine by TheHollowPlanetMC.
the class ImplParallelChunk method sendClearPacket.
public void sendClearPacket(Player player) {
INMSHandler nmsHandler = NMSManager.getNMSHandler();
TaskHandler.runSync(() -> {
World world = Bukkit.getWorld(getWorld().getName());
if (world == null)
return;
TaskHandler.runWorldSync(world, () -> {
nmsHandler.sendClearChunkMultiBlockChangePacketAtPrimaryThread(player, this);
});
});
}
use of thpmc.engine.api.nms.INMSHandler in project THP-Engine by TheHollowPlanetMC.
the class ImplParallelWorld method sendBlockUpdate.
@Override
public void sendBlockUpdate(int blockX, int blockY, int blockZ) {
INMSHandler nmsHandler = NMSManager.getNMSHandler();
Object packet = nmsHandler.createBlockChangePacket(this, blockX, blockY, blockZ);
if (packet != null) {
parallelUniverse.getResidents().forEach(player -> {
if (worldName.equals(player.getBukkitPlayer().getWorld().getName()))
nmsHandler.sendPacket(player.getBukkitPlayer(), packet);
});
}
}
use of thpmc.engine.api.nms.INMSHandler in project THP-Engine by TheHollowPlanetMC.
the class EngineWorld method rayTraceBlocksForShortRange.
@Nullable
default EngineRayTraceResult rayTraceBlocksForShortRange(@NotNull Vector startPosition, @NotNull Vector direction, double distance, @NotNull CollideOption collideOption) {
Vector movement = direction.clone().normalize().multiply(distance);
Vector endPosition = startPosition.clone().add(movement);
// collect block collisions
EngineBoundingBox region = new EngineBoundingBox(startPosition.getX(), startPosition.getY(), startPosition.getZ(), endPosition.getX(), endPosition.getY(), endPosition.getZ()).expandForMovement(movement);
region.expand(collideOption.getBoundingBoxGrow());
region.expand(16);
Set<EngineBoundingBox> boxList = new HashSet<>();
// get block collisions
int startX = NumberConversions.floor(region.getMinX());
int startY = NumberConversions.floor(region.getMinY());
int startZ = NumberConversions.floor(region.getMinZ());
int endX = NumberConversions.floor(region.getMaxX());
int endY = NumberConversions.floor(region.getMaxY());
int endZ = NumberConversions.floor(region.getMaxZ());
INMSHandler nmsHandler = THPEngineAPI.getInstance().getNMSHandler();
EngineChunk chunk = null;
for (int x = startX; x < endX; x++) {
for (int y = startY; y < endY; y++) {
for (int z = startZ; z < endZ; z++) {
int chunkX = x >> 4;
int chunkZ = z >> 4;
// get chunk cache
if (chunk == null) {
chunk = this.getChunkAt(chunkX, chunkZ);
} else if (chunk.getChunkX() != chunkX || chunk.getChunkZ() != chunkZ) {
chunk = this.getChunkAt(chunkX, chunkZ);
}
if (chunk == null) {
boxList.add(EngineBoundingBox.getBoundingBoxForUnloadChunk(chunkX, chunkZ));
continue;
}
// get nms block from cache
Object iBlockData = chunk.getNMSBlockData(x, y, z);
if (iBlockData == null) {
continue;
}
EngineBlock engineBlock = new EngineBlock(this, chunk, x, y, z, iBlockData);
// collect block collisions
nmsHandler.collectBlockCollisions(engineBlock, boxList, collideOption);
}
}
}
// perform raytrace
return rayTraceForCollisionList(startPosition, direction, distance, boxList, collideOption);
}
Aggregations