net.minecraft.network.play.server.SPacketPlayerPosLook Java Examples

The following examples show how to use net.minecraft.network.play.server.SPacketPlayerPosLook. 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: FlightModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void recievePacket(EventReceivePacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        if (this.mode.getValue() == Mode.PACKET) {
            if (event.getPacket() instanceof SPacketPlayerPosLook) {
                final SPacketPlayerPosLook packet = (SPacketPlayerPosLook) event.getPacket();
                if (Minecraft.getMinecraft().player.isEntityAlive() && Minecraft.getMinecraft().world.isBlockLoaded(new BlockPos(Minecraft.getMinecraft().player.posX, Minecraft.getMinecraft().player.posY, Minecraft.getMinecraft().player.posZ)) && !(Minecraft.getMinecraft().currentScreen instanceof GuiDownloadTerrain)) {
                    if (this.teleportId <= 0) {
                        this.teleportId = packet.getTeleportId();
                    } else {
                        event.setCanceled(true);
                    }
                }
            }
        }
    }
}
 
Example #2
Source File: PositionRotationManager.java    From ForgeHax with MIT License 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPacketReceived(PacketEvent.Incoming.Pre event) {
  if (!enabled.get()) return;

  if(event.getPacket() instanceof SPacketPlayerPosLook) {
    // when the server sets the rotation we use that instead
    final SPacketPlayerPosLook packet = event.getPacket();
    
    float pitch = packet.getPitch();
    float yaw = packet.getYaw();
    
    Angle va = gState.getClientAngles();
    
    if(packet.getFlags().contains(EnumFlags.X_ROT))
      pitch += va.getPitch();
    
    if(packet.getFlags().contains(EnumFlags.Y_ROT))
      yaw += va.getYaw();
    
    gState.setServerAngles(pitch, yaw);
    gState.setInitialized(true);
  }
}
 
Example #3
Source File: FlyMod.java    From ForgeHax with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onOutgoingPacketSent(PacketEvent.Incoming.Pre event) {
  if (event.getPacket() instanceof SPacketPlayerPosLook) {
    SPacketPlayerPosLook packet = event.getPacket();
    try {
      ObfuscationReflectionHelper.setPrivateValue(
          SPacketPlayerPosLook.class,
          packet,
          MC.player.rotationYaw,
          "yaw",
          "field_148936_d",
          "d");
      ObfuscationReflectionHelper.setPrivateValue(
          SPacketPlayerPosLook.class,
          packet,
          MC.player.rotationPitch,
          "pitch",
          "field_148937_e",
          "e");
    } catch (Exception e) {
    }
  }
}
 
Example #4
Source File: NoRotateModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void receivePacket(EventReceivePacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        if (event.getPacket() instanceof SPacketPlayerPosLook) {
            final SPacketPlayerPosLook packet = (SPacketPlayerPosLook) event.getPacket();
            if(Minecraft.getMinecraft().player != null) {
                packet.yaw = Minecraft.getMinecraft().player.rotationYaw;
                packet.pitch = Minecraft.getMinecraft().player.rotationPitch;
            }
        }
    }
}
 
Example #5
Source File: FreecamMod.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPacketReceived(PacketEvent.Incoming.Pre event) {
  if (originalPlayer == null || getLocalPlayer() == null) {
    return;
  }
  
  if (event.getPacket() instanceof SPacketPlayerPosLook) {
    SPacketPlayerPosLook packet = event.getPacket();
    pos = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
    angle = Angle.degrees(packet.getPitch(), packet.getYaw());
    event.setCanceled(true);
  }
}
 
Example #6
Source File: NoRotate.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPacketReceived(PacketEvent.Incoming.Pre event) {
  if (event.getPacket() instanceof SPacketPlayerPosLook) {
    SPacketPlayerPosLook packet = event.getPacket();
    if (getLocalPlayer() != null) {
      Angle angle = LocalPlayerUtils.getViewAngles();
      
      packet.getFlags().removeAll(Arrays.asList(EnumFlags.X_ROT, EnumFlags.Y_ROT));
      
      FastReflection.Fields.SPacketPlayer_yaw.set(packet, angle.getYaw());
      FastReflection.Fields.SPacketPlayer_pitch.set(packet, angle.getPitch());
    }
  }
}
 
Example #7
Source File: VanillaFlyMod.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPacketRecieving(PacketEvent.Incoming.Pre event) {
  EntityPlayer player = getLocalPlayer();
  if (isNull(player)) {
    return;
  }

  if (!antiGround.get() || !(event.getPacket() instanceof SPacketPlayerPosLook)
      || !player.capabilities.isFlying) {
    return;
  }
  
  SPacketPlayerPosLook packet = event.getPacket();
  
  double oldY = player.posY;
  player.setPosition(
      Fields.SPacketPlayer_x.get(packet),
      Fields.SPacketPlayer_y.get(packet),
      Fields.SPacketPlayer_z.get(packet)
  );
  
  /*
   * This needs a little explanation, as I had a little trouble wrapping my head around it myself.
   * Basically, we're trying to find a new position that's as close to the original height as possible.
   * That way, if you're, for example, spoofing and the server rubberbands you back, you don't go back to the ground.
   * This tries to find the lowest block above the spot the server teleported you to, and teleport you right to that.
   * If the lowest block is below where you were before, it just teleports you to where you were before.
   * This allows VanillaFly to be slightly more usable on servers like Constantiam that like to teleport you in place
   * to hopefully disable fly hacks. Well, sorry guys, this fly hack is smarter than that.
   */
  AxisAlignedBB range = player.getEntityBoundingBox()
      .expand(0, 256 - player.height - player.posY, 0).contract(0, player.height, 0);
  List<AxisAlignedBB> collisionBoxes = player.world.getCollisionBoxes(player, range);
  AtomicReference<Double> newY = new AtomicReference<>(256D);
  collisionBoxes.forEach(box -> newY.set(Math.min(newY.get(), box.minY - player.height)));
  
  Fields.SPacketPlayer_y.set(packet, Math.min(oldY, newY.get()));
}
 
Example #8
Source File: MixinNetHandlerPlayServer.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
/**
 * Fixes things such that when mods try to teleport players into the ship space, VS will either
 * redirect the teleport or block it. Looking at you SimpleTeleporters mod >:/
 */
@Inject(method = "setPlayerLocation(DDDFFLjava/util/Set;)V", at = @At("HEAD"), cancellable = true)
public void onSetPlayerLocation(double x, double y, double z, float yaw, float pitch,
    Set<SPacketPlayerPosLook.EnumFlags> relativeSet, CallbackInfo callbackInfo) {
    if (!redirectingSetPlayerLocation) {
        BlockPos pos = new BlockPos(x, y, z);
        // If the player is being teleported to ship space then we have to stop it.
        if (PhysicsChunkManager.isLikelyShipChunk(pos.getX() >> 4, pos.getZ() >> 4)) {
            callbackInfo.cancel();
            redirectingSetPlayerLocation = true;
            World world = player.getEntityWorld();
            Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysicsObject(world, pos);
            if (physicsObject.isPresent()) {
                Vector tpPos = new Vector(x, y, z);
                physicsObject.get()
                    .getShipTransformationManager()
                    .getCurrentTickTransform()
                    .transform(tpPos, TransformType.SUBSPACE_TO_GLOBAL);
                // Now call this again with the transformed position.
                // player.sendMessage(new TextComponentString("Transformed the player tp from <"
                // + x + ":" + y + ":" + z + "> to" + tpPos));
                thisAsNetHandler
                    .setPlayerLocation(tpPos.X, tpPos.Y, tpPos.Z, yaw, pitch, relativeSet);
            } else {
                player.sendMessage(new TextComponentString(
                    "Tried teleporting you to an unloaded ship; teleportation canceled."));
            }
            redirectingSetPlayerLocation = false;
        }
    }
}