feat: sync rotation type (aka MovementSync, MoveFix)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package me.alpha432.oyvey.event.impl.entity.player;
|
||||
|
||||
public class TravelEvent {
|
||||
public static class Post extends TickEvent { }
|
||||
|
||||
public static class Pre extends TickEvent { }
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package me.alpha432.oyvey.manager;
|
||||
|
||||
import me.alpha432.oyvey.event.Stage;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.TickEvent;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.TravelEvent;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.UpdateWalkingPlayerEvent;
|
||||
import me.alpha432.oyvey.event.system.Subscribe;
|
||||
import me.alpha432.oyvey.util.models.Angles;
|
||||
@@ -8,11 +10,9 @@ import me.alpha432.oyvey.util.traits.Util;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
// TODO movement sync
|
||||
public class RotationManager implements Util {
|
||||
private final List<Callback> callbacks = new ArrayList<>();
|
||||
|
||||
@@ -20,11 +20,39 @@ public class RotationManager implements Util {
|
||||
private Angles renderSnapshot, renderSnapshot0;
|
||||
|
||||
private Angles snapshot;
|
||||
private Angles travelSnapshot;
|
||||
|
||||
public RotationManager() {
|
||||
EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Subscribe(priority = 1000)
|
||||
public void onTickPre(TickEvent.Pre event) {
|
||||
executeCallbacks(callback -> callback.type() == Type.SYNC);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onTravelPre(TravelEvent.Pre event) {
|
||||
if (callbacks.isEmpty())
|
||||
return;
|
||||
|
||||
Callback highest = callbacks.stream().max(Comparator.comparing(Callback::priority)).orElseThrow();
|
||||
if (highest.type() == Type.SYNC) {
|
||||
travelSnapshot = new Angles(mc.player.getYRot(), mc.player.getXRot());
|
||||
mc.player.setYRot(highest.angles().yRot());
|
||||
mc.player.setXRot(highest.angles().xRot());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onTravelPost(TravelEvent.Post event) {
|
||||
if (travelSnapshot != null) {
|
||||
mc.player.setYRot(travelSnapshot.yRot());
|
||||
mc.player.setXRot(travelSnapshot.xRot());
|
||||
travelSnapshot = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onUpdateWalking(UpdateWalkingPlayerEvent event) {
|
||||
if (event.getStage() == Stage.PRE) {
|
||||
@@ -40,16 +68,22 @@ public class RotationManager implements Util {
|
||||
mc.player.setYRot(highest.angles().yRot());
|
||||
mc.player.setXRot(highest.angles().xRot());
|
||||
} else if (snapshot != null) {
|
||||
for (Callback callback : callbacks) {
|
||||
callback.execute();
|
||||
}
|
||||
callbacks.clear();
|
||||
executeCallbacks(callback -> callback.type() == Type.MOTION);
|
||||
|
||||
mc.player.setYRot(snapshot.yRot());
|
||||
mc.player.setXRot(snapshot.xRot());
|
||||
snapshot = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void sync(Angles angles, Runnable runnable) {
|
||||
sync(angles, 0, runnable);
|
||||
}
|
||||
|
||||
public void sync(Angles angles, int priority, Runnable runnable) {
|
||||
request(Type.SYNC, angles, priority, runnable);
|
||||
}
|
||||
|
||||
public void motion(Angles angles, Runnable runnable) {
|
||||
motion(angles, 0, runnable);
|
||||
}
|
||||
@@ -70,7 +104,7 @@ public class RotationManager implements Util {
|
||||
);
|
||||
}
|
||||
|
||||
public void silent(float yaw, float pitch) {
|
||||
public void sendDuplicate(float yaw, float pitch) {
|
||||
mc.player.positionReminder = 20;
|
||||
mc.player.yRotLast = yaw;
|
||||
mc.player.xRotLast = pitch;
|
||||
@@ -84,13 +118,23 @@ public class RotationManager implements Util {
|
||||
private void request(Type type, Angles angles, int priority, Runnable runnable) {
|
||||
Callback callback = new Callback(type, angles, priority, runnable);
|
||||
if (type == Type.SILENT) {
|
||||
silent(angles.yRot(), angles.xRot());
|
||||
sendDuplicate(angles.yRot(), angles.xRot());
|
||||
callback.execute();
|
||||
} else {
|
||||
callbacks.add(callback);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeCallbacks(Predicate<Callback> filter) {
|
||||
callbacks.removeIf(callback -> {
|
||||
if (filter.test(callback)) {
|
||||
callback.execute();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateRenderSnapshot(Angles angles, boolean update) {
|
||||
this.renderSnapshot0 = this.renderSnapshot;
|
||||
this.renderSnapshot = angles;
|
||||
@@ -112,6 +156,7 @@ public class RotationManager implements Util {
|
||||
|
||||
public enum Type {
|
||||
MOTION,
|
||||
SYNC,
|
||||
SILENT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.alpha432.oyvey.mixin.entity;
|
||||
|
||||
import me.alpha432.oyvey.event.impl.entity.player.TravelEvent;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS;
|
||||
import static me.alpha432.oyvey.util.traits.Util.isLocalPlayer;
|
||||
|
||||
@Mixin(AbstractClientPlayer.class)
|
||||
public class MixinAbstractClientPlayer {
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void travelPreHook(CallbackInfo ci) {
|
||||
if (isLocalPlayer(this)) {
|
||||
EVENT_BUS.post(new TravelEvent.Pre());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("TAIL"))
|
||||
private void travelPostHook(CallbackInfo ci) {
|
||||
if (isLocalPlayer(this)) {
|
||||
EVENT_BUS.post(new TravelEvent.Post());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,8 @@ import net.minecraft.client.Minecraft;
|
||||
public interface Util {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
EventBus EVENT_BUS = new EventBus();
|
||||
|
||||
static boolean isLocalPlayer(Object o) {
|
||||
return o == mc.player;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
"network.MixinConnection"
|
||||
],
|
||||
"client": [
|
||||
"entity.MixinAbstractClientPlayer",
|
||||
"entity.MixinClientPlayerEntity",
|
||||
"input.MixinKeyboardHandler",
|
||||
"input.MixinMouseHandler",
|
||||
"network.MixinClientPacketListener",
|
||||
"render.MixinAvatarRenderer",
|
||||
"render.MixinChatComponent",
|
||||
"render.MixinLevelRenderer",
|
||||
"render.MixinDeltaTrackerTimer",
|
||||
"render.MixinLevelRenderer",
|
||||
"render.gui.MixinCommandSuggestions",
|
||||
"render.gui.MixinGui"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user