Search in sources :

Example 1 with WorldEventS2CPacket

use of net.minecraft.network.packet.s2c.play.WorldEventS2CPacket in project meteor-rejects by AntiCope.

the class CoordLogger method onPacketReceive.

@EventHandler
private void onPacketReceive(PacketEvent.Receive event) {
    // Teleports
    if (event.packet instanceof EntityPositionS2CPacket) {
        EntityPositionS2CPacket packet = (EntityPositionS2CPacket) event.packet;
        try {
            Entity entity = mc.world.getEntityById(packet.getId());
            // Player teleport
            if (entity.getType().equals(EntityType.PLAYER) && players.get()) {
                Vec3d packetPosition = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
                Vec3d playerPosition = entity.getPos();
                if (playerPosition.distanceTo(packetPosition) >= minDistance.get()) {
                    info(formatMessage("Player '" + entity.getEntityName() + "' has teleported to ", packetPosition));
                }
            } else // World teleport
            if (entity.getType().equals(EntityType.WOLF) && wolves.get()) {
                Vec3d packetPosition = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
                Vec3d wolfPosition = entity.getPos();
                UUID ownerUuid = ((TameableEntity) entity).getOwnerUuid();
                if (ownerUuid != null && wolfPosition.distanceTo(packetPosition) >= minDistance.get()) {
                    info(formatMessage("Wolf has teleported to ", packetPosition));
                }
            }
        } catch (NullPointerException ignored) {
        }
    // World events
    } else if (event.packet instanceof WorldEventS2CPacket) {
        WorldEventS2CPacket worldEventS2CPacket = (WorldEventS2CPacket) event.packet;
        if (worldEventS2CPacket.isGlobal()) {
            // Min distance
            if (PlayerUtils.distanceTo(worldEventS2CPacket.getPos()) <= minDistance.get())
                return;
            switch(worldEventS2CPacket.getEventId()) {
                case 1023:
                    if (withers.get())
                        info(formatMessage("Wither spawned at ", worldEventS2CPacket.getPos()));
                    break;
                case 1038:
                    if (endPortals.get())
                        info(formatMessage("End portal opened at ", worldEventS2CPacket.getPos()));
                    break;
                case 1028:
                    if (enderDragons.get())
                        info(formatMessage("Ender dragon killed at ", worldEventS2CPacket.getPos()));
                    break;
                default:
                    if (otherEvents.get())
                        info(formatMessage("Unknown global event at ", worldEventS2CPacket.getPos()));
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TameableEntity(net.minecraft.entity.passive.TameableEntity) EntityPositionS2CPacket(net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket) WorldEventS2CPacket(net.minecraft.network.packet.s2c.play.WorldEventS2CPacket) UUID(java.util.UUID) Vec3d(net.minecraft.util.math.Vec3d) EventHandler(meteordevelopment.orbit.EventHandler)

Aggregations

UUID (java.util.UUID)1 EventHandler (meteordevelopment.orbit.EventHandler)1 Entity (net.minecraft.entity.Entity)1 TameableEntity (net.minecraft.entity.passive.TameableEntity)1 EntityPositionS2CPacket (net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket)1 WorldEventS2CPacket (net.minecraft.network.packet.s2c.play.WorldEventS2CPacket)1 Vec3d (net.minecraft.util.math.Vec3d)1