use of net.minecraft.network.play.client.CPacketPlayer in project Wurst-MC-1.12 by Wurst-Imperium.
the class BlinkMod method onSentPacket.
@Override
public void onSentPacket(PacketOutputEvent event) {
if (!(event.getPacket() instanceof CPacketPlayer))
return;
event.cancel();
CPacketPlayer packet = (CPacketPlayer) event.getPacket();
CPacketPlayer prevPacket = packets.peekLast();
if (prevPacket != null && packet.isOnGround() == prevPacket.isOnGround() && packet.getYaw(-1) == prevPacket.getYaw(-1) && packet.getPitch(-1) == prevPacket.getPitch(-1) && packet.getX(-1) == prevPacket.getX(-1) && packet.getY(-1) == prevPacket.getY(-1) && packet.getZ(-1) == prevPacket.getZ(-1))
return;
packets.addLast(packet);
}
use of net.minecraft.network.play.client.CPacketPlayer in project Wurst-MC-1.12 by Wurst-Imperium.
the class JesusMod method onSentPacket.
@Override
public void onSentPacket(PacketOutputEvent event) {
// check packet type
if (!(event.getPacket() instanceof CPacketPlayer))
return;
CPacketPlayer packet = (CPacketPlayer) event.getPacket();
// check if packet contains a position
if (!(packet instanceof CPacketPlayer.Position || packet instanceof CPacketPlayer.PositionRotation))
return;
// check inWater
if (WMinecraft.getPlayer().isInWater())
return;
// check fall distance
if (WMinecraft.getPlayer().fallDistance > 3F)
return;
if (!isOverLiquid())
return;
// if not actually moving, cancel packet
if (WMinecraft.getPlayer().movementInput == null) {
event.cancel();
return;
}
// wait for timer
packetTimer++;
if (packetTimer < 4)
return;
// cancel old packet
event.cancel();
// get position
double x = packet.getX(0);
double y = packet.getY(0);
double z = packet.getZ(0);
// offset y
if (WMinecraft.getPlayer().ticksExisted % 2 == 0)
y -= 0.05;
else
y += 0.05;
// create new packet
Packet newPacket;
if (packet instanceof CPacketPlayer.Position)
newPacket = new CPacketPlayer.Position(x, y, z, true);
else
newPacket = new CPacketPlayer.PositionRotation(x, y, z, packet.getYaw(0), packet.getPitch(0), true);
// send new packet
WConnection.sendPacketBypass(newPacket);
}
use of net.minecraft.network.play.client.CPacketPlayer in project SpongeCommon by SpongePowered.
the class MixinNetHandlerPlayServer method throwMoveEvent.
/**
* @author gabizou - June 22nd, 2016
* @reason Sponge has to throw the movement events before we consider moving the player and there's
* no clear way to go about it with the target position being null and the last position update checks.
* @param packetIn
*/
@Redirect(method = "processPlayer", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/EntityPlayerMP;queuedEndExit:Z"))
private boolean throwMoveEvent(EntityPlayerMP playerMP, CPacketPlayer packetIn) {
if (!playerMP.queuedEndExit) {
// We don't fire an event to avoid confusing plugins.
if (!packetIn.moving && !packetIn.rotating) {
return playerMP.queuedEndExit;
}
// Sponge Start - Movement event
Player player = (Player) this.player;
IMixinEntityPlayerMP mixinPlayer = (IMixinEntityPlayerMP) this.player;
Vector3d fromrot = player.getRotation();
// If Sponge used the player's current location, the delta might never be triggered which could be exploited
Location<World> from = player.getLocation();
if (this.lastMoveLocation != null) {
from = this.lastMoveLocation;
}
Vector3d torot = new Vector3d(packetIn.pitch, packetIn.yaw, 0);
Location<World> to = new Location<>(player.getWorld(), packetIn.x, packetIn.y, packetIn.z);
// Minecraft sends a 0, 0, 0 position when rotation only update occurs, this needs to be recognized and corrected
boolean rotationOnly = !packetIn.moving && packetIn.rotating;
if (rotationOnly) {
// Correct the to location so it's not misrepresented to plugins, only when player rotates without moving
// In this case it's only a rotation update, which isn't related to the to location
from = player.getLocation();
to = from;
}
// Minecraft does the same with rotation when it's only a positional update
boolean positionOnly = packetIn.moving && !packetIn.rotating;
if (positionOnly) {
// Correct the new rotation to match the old rotation
torot = fromrot;
}
((IMixinEntityPlayerMP) this.player).setVelocityOverride(to.getPosition().sub(from.getPosition()));
double deltaSquared = to.getPosition().distanceSquared(from.getPosition());
double deltaAngleSquared = fromrot.distanceSquared(torot);
// eventually it would be nice to not have them
if (deltaSquared > ((1f / 16) * (1f / 16)) || deltaAngleSquared > (.15f * .15f)) {
Transform<World> fromTransform = player.getTransform().setLocation(from).setRotation(fromrot);
Transform<World> toTransform = player.getTransform().setLocation(to).setRotation(torot);
Sponge.getCauseStackManager().pushCause(player);
MoveEntityEvent event = SpongeEventFactory.createMoveEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), fromTransform, toTransform, player);
SpongeImpl.postEvent(event);
Sponge.getCauseStackManager().popCause();
if (event.isCancelled()) {
mixinPlayer.setLocationAndAngles(fromTransform);
this.lastMoveLocation = from;
((IMixinEntityPlayerMP) this.player).setVelocityOverride(null);
return true;
} else if (!event.getToTransform().equals(toTransform)) {
mixinPlayer.setLocationAndAngles(event.getToTransform());
this.lastMoveLocation = event.getToTransform().getLocation();
((IMixinEntityPlayerMP) this.player).setVelocityOverride(null);
return true;
} else if (!from.equals(player.getLocation()) && this.justTeleported) {
this.lastMoveLocation = player.getLocation();
// Prevent teleports during the move event from causing odd behaviors
this.justTeleported = false;
((IMixinEntityPlayerMP) this.player).setVelocityOverride(null);
return true;
} else {
this.lastMoveLocation = event.getToTransform().getLocation();
}
this.resendLatestResourcePackRequest();
}
}
return playerMP.queuedEndExit;
}
use of net.minecraft.network.play.client.CPacketPlayer in project SpongeCommon by SpongePowered.
the class PacketUtil method onProcessPacket.
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
public static void onProcessPacket(Packet packetIn, INetHandler netHandler) {
if (netHandler instanceof NetHandlerPlayServer) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
EntityPlayerMP packetPlayer = ((NetHandlerPlayServer) netHandler).player;
Sponge.getCauseStackManager().pushCause(packetPlayer);
// If true, logic was handled in Pre so return
if (firePreEvents(packetIn, packetPlayer)) {
return;
}
boolean ignoreCreative = false;
// } else
if (creativeCheck(packetIn, packetPlayer)) {
long packetDiff = System.currentTimeMillis() - lastInventoryOpenPacketTimeStamp;
// If the time between packets is small enough, mark the current packet to be ignored for our event handler.
if (packetDiff < 100) {
ignoreCreative = true;
}
}
// Don't process movement capture logic if player hasn't moved
boolean ignoreMovementCapture = false;
if (packetIn instanceof CPacketPlayer) {
CPacketPlayer movingPacket = ((CPacketPlayer) packetIn);
if (movingPacket instanceof CPacketPlayer.Rotation) {
ignoreMovementCapture = true;
} else if (packetPlayer.posX == movingPacket.x && packetPlayer.posY == movingPacket.y && packetPlayer.posZ == movingPacket.z) {
ignoreMovementCapture = true;
}
}
if (ignoreMovementCapture || (packetIn instanceof CPacketClientSettings)) {
packetIn.processPacket(netHandler);
} else {
final ItemStackSnapshot cursor = ItemStackUtil.snapshotOf(packetPlayer.inventory.getItemStack());
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
IPhaseState<? extends PacketContext<?>> packetState = TrackingPhases.PACKET.getStateForPacket(packetIn);
if (packetState == null) {
throw new IllegalArgumentException("Found a null packet phase for packet: " + packetIn.getClass());
}
PhaseContext<?> context = EMPTY;
if (!TrackingPhases.PACKET.isPacketInvalid(packetIn, packetPlayer, packetState)) {
context = packetState.createPhaseContext().source(packetPlayer).packetPlayer(packetPlayer).packet(packetIn).cursor(cursor).ignoreCreative(ignoreCreative);
TrackingPhases.PACKET.populateContext(packetIn, packetPlayer, packetState, context);
context.owner((Player) packetPlayer);
context.notifier((Player) packetPlayer);
}
try (PhaseContext<?> packetContext = context.buildAndSwitch()) {
packetIn.processPacket(netHandler);
}
if (packetIn instanceof CPacketClientStatus) {
// update the reference of player
packetPlayer = ((NetHandlerPlayServer) netHandler).player;
}
((IMixinEntityPlayerMP) packetPlayer).setPacketItem(ItemStack.EMPTY);
}
}
} else {
// client
packetIn.processPacket(netHandler);
}
}
use of net.minecraft.network.play.client.CPacketPlayer in project Wurst-MC-1.12 by Wurst-Imperium.
the class JetpackMod method onUpdate.
@Override
public void onUpdate() {
if (mc.gameSettings.keyBindJump.pressed)
WMinecraft.getPlayer().jump();
if (flightKickBypass != null && flightKickBypass.isChecked()) {
updateMS();
updateFlyHeight();
WConnection.sendPacket(new CPacketPlayer(true));
if (flyHeight <= 290 && hasTimePassedM(500) || flyHeight > 290 && hasTimePassedM(100)) {
goToGround();
updateLastMS();
}
}
}
Aggregations