net.minecraft.network.Packet Java Examples

The following examples show how to use net.minecraft.network.Packet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NoFall.java    From LiquidBounce with GNU General Public License v3.0 7 votes vote down vote up
@EventTarget
public void onPacket(final PacketEvent event) {
    final Packet<?> packet = event.getPacket();
    final String mode = modeValue.get();

    if (packet instanceof C03PacketPlayer) {
        final C03PacketPlayer playerPacket = (C03PacketPlayer) packet;

        if (mode.equalsIgnoreCase("SpoofGround"))
            playerPacket.onGround = true;

        if (mode.equalsIgnoreCase("NoGround"))
            playerPacket.onGround = false;

        if (mode.equalsIgnoreCase("Hypixel")
                && mc.thePlayer != null && mc.thePlayer.fallDistance > 1.5)
            playerPacket.onGround = mc.thePlayer.ticksExisted % 2 == 0;
    }
}
 
Example #2
Source File: RotationUtils.java    From LiquidBounce with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Handle packet
 *
 * @param event Packet Event
 */
@EventTarget
public void onPacket(final PacketEvent event) {
    final Packet<?> packet = event.getPacket();

    if(packet instanceof C03PacketPlayer) {
        final C03PacketPlayer packetPlayer = (C03PacketPlayer) packet;

        if(targetRotation != null && !keepCurrentRotation && (targetRotation.getYaw() != serverRotation.getYaw() || targetRotation.getPitch() != serverRotation.getPitch())) {
            packetPlayer.yaw = targetRotation.getYaw();
            packetPlayer.pitch = targetRotation.getPitch();
            packetPlayer.rotating = true;
        }

        if(packetPlayer.rotating) serverRotation = new Rotation(packetPlayer.yaw, packetPlayer.pitch);
    }
}
 
Example #3
Source File: Blink.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
@EventTarget
public void onPacket(PacketEvent event) {
    final Packet<?> packet = event.getPacket();

    if (mc.thePlayer == null || disableLogger)
        return;

    if (packet instanceof C03PacketPlayer) // Cancel all movement stuff
        event.cancelEvent();

    if (packet instanceof C03PacketPlayer.C04PacketPlayerPosition || packet instanceof C03PacketPlayer.C06PacketPlayerPosLook ||
            packet instanceof C08PacketPlayerBlockPlacement ||
            packet instanceof C0APacketAnimation ||
            packet instanceof C0BPacketEntityAction || packet instanceof C02PacketUseEntity) {
        event.cancelEvent();

        packets.add(packet);
    }
}
 
Example #4
Source File: WallClimb.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
@EventTarget
public void onPacket(final PacketEvent event) {
    final Packet<?> packet = event.getPacket();

    if(packet instanceof C03PacketPlayer) {
        final C03PacketPlayer packetPlayer = (C03PacketPlayer) packet;

        if(glitch) {
            final float yaw = (float) MovementUtils.getDirection();

            packetPlayer.x = packetPlayer.x - MathHelper.sin(yaw) * 0.00000001D;
            packetPlayer.z = packetPlayer.z + MathHelper.cos(yaw) * 0.00000001D;

            glitch = false;
        }
    }
}
 
Example #5
Source File: BlinkModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void sendPacket(EventSendPacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        final Packet packet = event.getPacket();

        if (Minecraft.getMinecraft().world == null || Minecraft.getMinecraft().isSingleplayer()) {
            return;
        }

        if (packet instanceof CPacketChatMessage || packet instanceof CPacketConfirmTeleport || packet instanceof CPacketKeepAlive || packet instanceof CPacketTabComplete || packet instanceof CPacketClientStatus) {
            return;
        }

        this.packets.add(packet);
        event.setCanceled(true);
    }
}
 
Example #6
Source File: BlinkModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDisable() {
    super.onDisable();
    if (Minecraft.getMinecraft().world != null) {
        if (this.entity != null) {
            Minecraft.getMinecraft().world.removeEntity(this.entity);
        }
        if (this.packets.size() > 0) {
            for (Packet packet : this.packets) {
                Minecraft.getMinecraft().player.connection.sendPacket(packet);
            }
            this.packets.clear();
        }
    }
}
 
Example #7
Source File: ClientConnectionMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At(value = "INVOKE",
	target = "Lnet/minecraft/network/ClientConnection;handlePacket(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;)V",
	ordinal = 0)},
	method = {
		"channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V"},
	cancellable = true)
private void onChannelRead0(ChannelHandlerContext channelHandlerContext,
	Packet<?> packet, CallbackInfo ci)
{
	PacketInputEvent event = new PacketInputEvent(packet);
	WurstClient.INSTANCE.getEventManager().fire(event);
	
	if(event.isCancelled())
		ci.cancel();
}
 
Example #8
Source File: ClientPlayNetworkHandlerMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {"sendPacket(Lnet/minecraft/network/Packet;)V"},
	cancellable = true)
private void onSendPacket(Packet<?> packet, CallbackInfo ci)
{
	PacketOutputEvent event = new PacketOutputEvent(packet);
	WurstClient.INSTANCE.getEventManager().fire(event);
	
	if(event.isCancelled())
		ci.cancel();
}
 
Example #9
Source File: MixinClientConnection.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("HEAD"), cancellable = true)
  public void send(Packet<?> packet_1, GenericFutureListener<? extends Future<? super Void>> genericFutureListener_1, CallbackInfo callback) {
  	if (packet_1 instanceof ChatMessageC2SPacket) {
	ChatMessageC2SPacket pack = (ChatMessageC2SPacket) packet_1;
	if (pack.getChatMessage().startsWith(CommandManager.prefix)) {
   		CommandManager.callCommand(pack.getChatMessage().substring(CommandManager.prefix.length()));
   		callback.cancel();
	}
}
  	
  	EventSendPacket event = new EventSendPacket(packet_1);
      BleachHack.eventBus.post(event);

      if (event.isCancelled()) callback.cancel();
  }
 
Example #10
Source File: HallowedTreasureChestEntity.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public Packet<?> createSpawnPacket() {
	PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer());
	
	packet.writeDouble(getX());
	packet.writeDouble(getY());
	packet.writeDouble(getZ());
	
	packet.writeBoolean(shouldReplace);
	packet.writeFloat(rotation);
	
	packet.writeInt(getEntityId());
	
	return ServerSidePacketRegistry.INSTANCE.toPacket(ENTITY_ID, packet);
}
 
Example #11
Source File: InventoryUtils.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@EventTarget
public void onPacket(final PacketEvent event) {
    final Packet packet = event.getPacket();

    if (packet instanceof C08PacketPlayerBlockPlacement)
        CLICK_TIMER.reset();
}
 
Example #12
Source File: AbstractProtocol.java    From multiconnect with MIT License 5 votes vote down vote up
protected static void insertAfter(List<PacketInfo<?>> list, Class<? extends Packet<?>> element, PacketInfo<?> toInsert) {
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i).getPacketClass() == element) {
            list.add(i + 1, toInsert);
            return;
        }
    }
    list.add(0, toInsert);
}
 
Example #13
Source File: NetworkManagerPatch.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This is our channelRead0 hook
 * It allows us to cancel processing incoming packets or modify the unencrypted data
 * @param packet
 * @param stage
 * @return
 */
public static boolean channelRead0Hook(Packet packet, EventStageable.EventStage stage) {
    if(packet != null) {
        final EventReceivePacket event = new EventReceivePacket(stage, packet);
        Seppuku.INSTANCE.getEventManager().dispatchEvent(event);

        return event.isCanceled();
    }

    return false;
}
 
Example #14
Source File: FreeCam.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@EventTarget
public void onPacket(PacketEvent event) {
    final Packet<?> packet = event.getPacket();

    if(packet instanceof C03PacketPlayer || packet instanceof C0BPacketEntityAction)
        event.cancelEvent();
}
 
Example #15
Source File: MixinThreadedAnvilChunkStorage.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "sendWatchPackets", at = @At("HEAD"))
private void fireWatchEvents(ServerPlayerEntity player, ChunkPos pos, Packet<?>[] packets, boolean withinMaxWatchDistance, boolean withinViewDistance, CallbackInfo callback) {
	if (withinViewDistance && !withinMaxWatchDistance) {
		ChunkWatchEvent.Watch event = new ChunkWatchEvent.Watch(player, pos, world);

		MinecraftForge.EVENT_BUS.post(event);
	}
}
 
Example #16
Source File: Teleport.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@EventTarget
public void onPacket(final PacketEvent event) {
    final Packet<?> packet = event.getPacket();

    if(disableLogger)
        return;

    if(packet instanceof C03PacketPlayer) {
        final C03PacketPlayer packetPlayer = (C03PacketPlayer) packet;

        switch(modeValue.get().toLowerCase()) {
            case "spoof":
                if(endPos == null)
                    break;

                packetPlayer.x = endPos.getX() + 0.5D;
                packetPlayer.y = endPos.getY() + 1;
                packetPlayer.z = endPos.getZ() + 0.5D;
                mc.thePlayer.setPosition(endPos.getX() + 0.5D, endPos.getY() + 1, endPos.getZ() + 0.5D);
                break;
            case "aac3.5.0":
                if(!flyTimer.hasTimePassed(60))
                    return;

                event.cancelEvent();

                if(!(packet instanceof C03PacketPlayer.C04PacketPlayerPosition) && !(packet instanceof C03PacketPlayer.C06PacketPlayerPosLook))
                    return;

                packets.add(packet);
                break;
        }
    }
}
 
Example #17
Source File: PatchworkPlayNetworkingMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Packet<?> getOpenContainerPacket(FMLPlayMessages.OpenContainer message) {
	PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());

	buf.writeByte(OPEN_CONTAINER);
	FMLPlayMessages.OpenContainer.encode(message, buf);

	return ServerSidePacketRegistry.INSTANCE.toPacket(IDENTIFIER, buf);
}
 
Example #18
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Consumer<Packet<?>> playerConsumer(final Supplier<ServerPlayerEntity> player) {
	return packet -> player.get().networkHandler.connection.send(packet);
}
 
Example #19
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Consumer<Packet<?>> playerListPointConsumer(final Supplier<TargetPoint> pointSupplier) {
	return packet -> {
		final TargetPoint point = pointSupplier.get();
		getServer().getPlayerManager().sendToAround(point.excluded, point.x, point.y, point.z, point.radius, point.dim, packet);
	};
}
 
Example #20
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public PacketDistributor(BiFunction<PacketDistributor<T>, Supplier<T>, Consumer<Packet<?>>> functor, NetworkDirection direction) {
	this.functor = functor;
	this.direction = direction;
}
 
Example #21
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Consumer<Packet<?>> playerListDimConsumer(final Supplier<DimensionType> dimensionType) {
	return packet -> getServer().getPlayerManager().sendToDimension(packet, dimensionType.get());
}
 
Example #22
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Consumer<Packet<?>> trackingEntityAndSelf(final Supplier<Entity> entitySupplier) {
	return packet -> {
		final Entity entity = entitySupplier.get();
		((ServerChunkManager) entity.getEntityWorld().getChunkManager()).sendToNearbyPlayers(entity, packet);
	};
}
 
Example #23
Source File: EventReadPacket.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
public void setPacket(Packet<?> packet) {
    this.packet = packet;
}
 
Example #24
Source File: PatchworkPlayNetworkingMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public Packet<?> getEntitySpawningPacket(Entity entity) {
	FMLPlayMessages.SpawnEntity message = new FMLPlayMessages.SpawnEntity(entity);
	PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());

	buf.writeByte(SPAWN_ENTITY);
	FMLPlayMessages.SpawnEntity.encode(message, buf);

	return ServerSidePacketRegistry.INSTANCE.toPacket(IDENTIFIER, buf);
}
 
Example #25
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Consumer<Packet<?>> playerListAll(final Supplier<Void> ignored) {
	return packet -> getServer().getPlayerManager().sendToAll(packet);
}
 
Example #26
Source File: EventSendPacket.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
public EventSendPacket(Packet<?> packet) {
    this.packet = packet;
}
 
Example #27
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Consumer<Packet<?>> connectionList(final Supplier<List<ClientConnection>> connections) {
	return packet -> connections.get().forEach(connection -> connection.send(packet));
}
 
Example #28
Source File: PacketDistributor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
PacketTarget(final Consumer<Packet<?>> packetConsumer, final PacketDistributor<?> distributor) {
	this.packetConsumer = packetConsumer;
	this.direction = distributor.direction;
}
 
Example #29
Source File: MixinNetworkManager.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true)
private void read(ChannelHandlerContext context, Packet<?> packet, CallbackInfo callback) {
    final PacketEvent event = new PacketEvent(packet);
    LiquidBounce.eventManager.callEvent(event);

    if(event.isCancelled())
        callback.cancel();
}
 
Example #30
Source File: EventSendPacket.java    From bleachhack-1.14 with GNU General Public License v3.0 4 votes vote down vote up
public Packet<?> getPacket() {
    return packet;
}