Search in sources :

Example 6 with INMSHandler

use of thpmc.vanilla_source.api.nms.INMSHandler in project VanillaSource by TheHollowPlanetMC.

the class ImplParallelWorld method sendMultiBlockUpdate.

@Override
public void sendMultiBlockUpdate(Set<BlockPosition3i> blocks) {
    INMSHandler nmsHandler = NMSManager.getNMSHandler();
    Set<Object> packets = nmsHandler.createMultiBlockChangePacket(this, blocks);
    for (Object packet : packets) {
        parallelUniverse.getResidents().forEach(player -> {
            if (worldName.equals(player.getBukkitPlayer().getWorld().getName()))
                nmsHandler.sendPacket(player.getBukkitPlayer(), packet);
        });
    }
}
Also used : INMSHandler(thpmc.vanilla_source.api.nms.INMSHandler)

Example 7 with INMSHandler

use of thpmc.vanilla_source.api.nms.INMSHandler in project VanillaSource 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.vanilla_source.api.nms.INMSHandler)

Example 8 with INMSHandler

use of thpmc.vanilla_source.api.nms.INMSHandler in project VanillaSource 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, ImplVSSettings.isUseCachedChunkPacket()), channelPromise);
        return;
    }
    if (nmsHandler.isLightUpdatePacket(packet) && ImplVSSettings.isRewriteLightPacket()) {
        super.write(channelHandlerContext, NMSManager.getLightUpdatePacketHandler().rewrite(packet, EnginePlayer, ImplVSSettings.isUseCachedChunkPacket()), channelPromise);
        return;
    }
    if (nmsHandler.isBlockChangePacket(packet)) {
        super.write(channelHandlerContext, NMSManager.getBlockChangePacketHandler().rewrite(packet, EnginePlayer, ImplVSSettings.isUseCachedChunkPacket()), channelPromise);
        return;
    }
    if (nmsHandler.isMultiBlockChangePacket(packet)) {
        super.write(channelHandlerContext, NMSManager.getMultiBlockChangePacketHandler().rewrite(packet, EnginePlayer, ImplVSSettings.isUseCachedChunkPacket()), channelPromise);
        return;
    }
    super.write(channelHandlerContext, packet, channelPromise);
}
Also used : INMSHandler(thpmc.vanilla_source.api.nms.INMSHandler)

Example 9 with INMSHandler

use of thpmc.vanilla_source.api.nms.INMSHandler in project VanillaSource by TheHollowPlanetMC.

the class PacketHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception {
    INMSHandler nmsHandler = NMSManager.getNMSHandler();
    if (nmsHandler.isFlyPacket(packet)) {
        super.channelRead(channelHandlerContext, NMSManager.getFlyPacketHandler().rewrite(packet, EnginePlayer, ImplVSSettings.isUseCachedChunkPacket()));
        return;
    }
    super.channelRead(channelHandlerContext, packet);
}
Also used : INMSHandler(thpmc.vanilla_source.api.nms.INMSHandler)

Example 10 with INMSHandler

use of thpmc.vanilla_source.api.nms.INMSHandler in project VanillaSource by TheHollowPlanetMC.

the class TestListener method onChat.

@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
    Player player = event.getPlayer();
    if (!event.getMessage().equals("spawn"))
        return;
    TaskHandler.runSync(() -> {
        Location location = player.getLocation();
        INMSHandler nmsHandler = VanillaSourceAPI.getInstance().getNMSHandler();
        GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "NPC");
        NMSEntityController entityPlayer = nmsHandler.createNMSEntityController(location.getWorld(), location.getX(), location.getY(), location.getZ(), EntityType.PLAYER, gameProfile);
        entityPlayer.setPositionRaw(location.getX(), location.getY(), location.getZ());
        CollideOption collideOption = new CollideOption(FluidCollisionMode.NEVER, true);
    /*
            collideOption.setCollideBlockFunction(engineBlock -> {
                return engineBlock.getMaterial() != Material.GLASS;
            });*/
    /*
            VanillaSourceAPI.getInstance().getTickRunnerPool().spawn(tickRunner -> {
                EnginePlayerEntity npc = new EnginePlayerEntity(tickRunner.getThreadLocalCache().getWorld(location.getWorld().getName()), (NMSEntityPlayer) entityPlayer, tickRunner, true);
                npc.getGoalSelector().registerGoal(0, new EntityFollowGoal(player));
                npc.setMovementCollideOption(collideOption);
                tickRunner.addEntity(npc);
            });*/
    });
}
Also used : Player(org.bukkit.entity.Player) GameProfile(com.mojang.authlib.GameProfile) CollideOption(thpmc.vanilla_source.api.util.collision.CollideOption) NMSEntityController(thpmc.vanilla_source.api.nms.entity.NMSEntityController) INMSHandler(thpmc.vanilla_source.api.nms.INMSHandler) EventHandler(org.bukkit.event.EventHandler)

Aggregations

INMSHandler (thpmc.vanilla_source.api.nms.INMSHandler)13 EngineBlock (thpmc.vanilla_source.api.world.block.EngineBlock)5 EngineChunk (thpmc.vanilla_source.api.world.cache.EngineChunk)4 Vector (org.bukkit.util.Vector)3 GameProfile (com.mojang.authlib.GameProfile)2 HashSet (java.util.HashSet)2 World (org.bukkit.World)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 NMSEntityController (thpmc.vanilla_source.api.nms.entity.NMSEntityController)2 ParallelWorld (thpmc.vanilla_source.api.world.parallel.ParallelWorld)2 ArrayList (java.util.ArrayList)1 Location (org.bukkit.Location)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 EngineEntity (thpmc.vanilla_source.api.entity.EngineEntity)1 EntityFollowGoal (thpmc.vanilla_source.api.entity.ai.navigation.goal.EntityFollowGoal)1 BlockPosition (thpmc.vanilla_source.api.entity.ai.pathfinding.BlockPosition)1 CollideOption (thpmc.vanilla_source.api.util.collision.CollideOption)1 EngineBoundingBox (thpmc.vanilla_source.api.util.collision.EngineBoundingBox)1