diff --git a/.github/DEVELOPER_API.md b/.github/DEVELOPER_API.md
index 2e854891..b8205fd0 100644
--- a/.github/DEVELOPER_API.md
+++ b/.github/DEVELOPER_API.md
@@ -11,7 +11,7 @@ public class ViaFabricPlusExampleAddon implements ClientModInitializer {
}
}
```
-#### ViaFabricPlus has 8 events at the moment:
+#### ViaFabricPlus has 7 events at the moment:
| Callback class name | Description |
|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ChangeProtocolVersionCallback | Called when the user changes the target version in the screen, or if you connect to a server for which a specific version has been selected, you disconnect, the event for the actual version is also called. |
@@ -20,11 +20,10 @@ public class ViaFabricPlusExampleAddon implements ClientModInitializer {
| InitializeSettingsCallback | Called after the default setting groups are loaded and before the setting config is loaded |
| LoadClassicProtocolExtensionCallback | Called when the classic server sends the protocol extensions (only in **c0.30 CPE**) |
| PreLoadCallback | Called before everything (Pre-pre load) |
-| SkipIdlePacketCallback | Called as soon as the idle packet is skipped in the <= 1.8 |
| ViaLoadingBaseBuilderCallback | Called when Via* is initialized |
### General API
-#### Get the release version of an material:
+#### Get the release version of a material:
```java
final ProtocolRange range = ItemReleaseVersionDefinition.INSTANCE.getItemMap().get(Items.WRITABLE_BOOK); // If an item does not appear in the item map, it has always existed
diff --git a/src/main/java/de/florianmichael/viafabricplus/base/event/SkipIdlePacketCallback.java b/src/main/java/de/florianmichael/viafabricplus/base/event/SkipIdlePacketCallback.java
deleted file mode 100644
index 2d247c6d..00000000
--- a/src/main/java/de/florianmichael/viafabricplus/base/event/SkipIdlePacketCallback.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
- * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package de.florianmichael.viafabricplus.base.event;
-
-import net.fabricmc.fabric.api.event.Event;
-import net.fabricmc.fabric.api.event.EventFactory;
-
-public interface SkipIdlePacketCallback {
-
- Event EVENT = EventFactory.createArrayBacked(SkipIdlePacketCallback.class, listeners -> () -> {
- for (SkipIdlePacketCallback listener : listeners) {
- listener.onSkipIdlePacket();
- }
- });
-
- void onSkipIdlePacket();
-}
diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java
index cd0ff138..e01383cd 100644
--- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java
+++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java
@@ -19,22 +19,18 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
import com.mojang.authlib.GameProfile;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
-import de.florianmichael.viafabricplus.definition.v1_8.ArmorPointCalculation;
-import de.florianmichael.viafabricplus.base.event.SkipIdlePacketCallback;
-import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity;
import de.florianmichael.viafabricplus.base.settings.groups.DebugSettings;
+import de.florianmichael.viafabricplus.definition.v1_8.ArmorPointCalculation;
+import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity;
import de.florianmichael.viafabricplus.base.settings.groups.VisualSettings;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.input.Input;
import net.minecraft.client.network.AbstractClientPlayerEntity;
-import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
-import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper;
-import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -51,28 +47,17 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity
@Shadow
public Input input;
- @Shadow
- private float lastYaw;
- @Shadow
- private float lastPitch;
- @Shadow
- @Final
- public ClientPlayNetworkHandler networkHandler;
- @Shadow
- private boolean autoJumpEnabled;
+
@Shadow
@Final
protected MinecraftClient client;
+
@Shadow
private boolean lastOnGround;
+
@Shadow
private int ticksSinceLastPositionPacketSent;
- @Shadow
- private double lastX;
- @Shadow
- private double lastBaseY;
- @Shadow
- private double lastZ;
+
@Unique
private boolean viafabricplus_areSwingCanceledThisTick = false;
@@ -80,62 +65,38 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity
super(world, profile);
}
- @Shadow
- protected abstract boolean isCamera();
-
@Shadow protected abstract void sendSprintingPacket();
- @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isCamera()Z"))
- public boolean fixMovement(ClientPlayerEntity instance) {
- if (this.isCamera()) {
- boolean bl4;
- double d = this.getX() - this.lastX;
- double e = this.getY() - this.lastBaseY;
- double f = this.getZ() - this.lastZ;
- double g = this.getYaw() - this.lastYaw;
- double h = this.getPitch() - this.lastPitch;
- if (ProtocolHack.getTargetVersion().isNewerThan(ProtocolVersion.v1_8)) {
- ++this.ticksSinceLastPositionPacketSent;
- }
- double n = MathHelper.square(2.05E-4);
- if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_18_2)) {
- n = 9.0E-4D;
- }
- boolean bl3 = MathHelper.squaredMagnitude(d, e, f) > n || this.ticksSinceLastPositionPacketSent >= 20;
- bl4 = g != 0.0 || h != 0.0;
- if (this.hasVehicle()) {
- Vec3d vec3d = this.getVelocity();
- this.networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(vec3d.x, -999.0, vec3d.z, this.getYaw(), this.getPitch(), this.onGround));
- bl3 = false;
- } else if (bl3 && bl4) {
- this.networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(this.getX(), this.getY(), this.getZ(), this.getYaw(), this.getPitch(), this.onGround));
- } else if (bl3) {
- this.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(this.getX(), this.getY(), this.getZ(), this.onGround));
- } else if (bl4) {
- this.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(this.getYaw(), this.getPitch(), this.onGround));
- } else if ((this.lastOnGround != this.onGround && !DebugSettings.INSTANCE.sendIdlePacket.getValue()) || DebugSettings.INSTANCE.sendIdlePacket.getValue()) {
- this.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(this.onGround));
- } else {
- SkipIdlePacketCallback.EVENT.invoker().onSkipIdlePacket();
- }
- if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
- ++this.ticksSinceLastPositionPacketSent;
- }
-
- if (bl3) {
- this.lastX = this.getX();
- this.lastBaseY = this.getY();
- this.lastZ = this.getZ();
- this.ticksSinceLastPositionPacketSent = 0;
- }
- if (bl4) {
- this.lastYaw = this.getYaw();
- this.lastPitch = this.getPitch();
- }
- this.lastOnGround = this.onGround;
- this.autoJumpEnabled = this.client.options.getAutoJump().getValue();
+ @Redirect(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;square(D)D"))
+ public double changeMagnitude(double n) {
+ if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_18_2)) {
+ n = 9.0E-4D;
}
- return false;
+ return MathHelper.square(n);
+ }
+
+ @Redirect(method = "sendMovementPackets", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerEntity;ticksSinceLastPositionPacketSent:I", ordinal = 0))
+ public int revertLastPositionPacketSentIncrementor(ClientPlayerEntity instance) {
+ // Mixin calls the redirector and sets the original field to the return value of the redirector + 1, therefore the -1 results, so we truncate the + 1 again and the field does not change
+ if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
+ return ticksSinceLastPositionPacketSent - 1;
+ }
+ return ticksSinceLastPositionPacketSent;
+ }
+
+ @Inject(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z"))
+ public void incrementLastPositionPacketSentCounter(CallbackInfo ci) {
+ if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
+ ++this.ticksSinceLastPositionPacketSent;
+ }
+ }
+
+ @Redirect(method = "sendMovementPackets", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerEntity;lastOnGround:Z", ordinal = 0))
+ public boolean sendIdlePacket(ClientPlayerEntity instance) {
+ if (DebugSettings.INSTANCE.sendIdlePacket.getValue()) {
+ return !onGround;
+ }
+ return lastOnGround;
}
@Inject(method = "swingHand", at = @At("HEAD"), cancellable = true)