Search in sources :

Example 6 with INMSHandler

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);
}
Also used : EngineChunk(thpmc.engine.api.world.cache.EngineChunk) EngineBlock(thpmc.engine.api.world.block.EngineBlock) INMSHandler(thpmc.engine.api.nms.INMSHandler)

Example 7 with INMSHandler

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);
}
Also used : INMSHandler(thpmc.engine.api.nms.INMSHandler)

Example 8 with INMSHandler

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);
        });
    });
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) World(org.bukkit.World) INMSHandler(thpmc.engine.api.nms.INMSHandler)

Example 9 with INMSHandler

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);
        });
    }
}
Also used : INMSHandler(thpmc.engine.api.nms.INMSHandler)

Example 10 with INMSHandler

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);
}
Also used : EngineBlock(thpmc.engine.api.world.block.EngineBlock) Vector(org.bukkit.util.Vector) EngineBoundingBox(thpmc.engine.api.util.collision.EngineBoundingBox) INMSHandler(thpmc.engine.api.nms.INMSHandler) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

INMSHandler (thpmc.engine.api.nms.INMSHandler)15 EngineBlock (thpmc.engine.api.world.block.EngineBlock)5 Player (org.bukkit.entity.Player)4 NMSEntityPlayer (thpmc.engine.api.nms.entity.NMSEntityPlayer)4 EngineChunk (thpmc.engine.api.world.cache.EngineChunk)4 Vector (org.bukkit.util.Vector)3 EnginePlayer (thpmc.engine.api.player.EnginePlayer)3 HashSet (java.util.HashSet)2 Location (org.bukkit.Location)2 World (org.bukkit.World)2 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)2 GameProfile (com.mojang.authlib.GameProfile)1 ArrayList (java.util.ArrayList)1 EventHandler (org.bukkit.event.EventHandler)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 EnginePlayerEntity (thpmc.engine.api.entity.EnginePlayerEntity)1 EntityFollowGoal (thpmc.engine.api.entity.ai.navigation.goal.EntityFollowGoal)1 BlockPosition (thpmc.engine.api.entity.ai.pathfinding.BlockPosition)1 NMSEntity (thpmc.engine.api.nms.entity.NMSEntity)1