Merge branch 'master' into 1.21.4
All checks were successful
build / build (push) Successful in 1m8s
All checks were successful
build / build (push) Successful in 1m8s
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
package wtf.hak.survivalfabric.mixin.client;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
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 wtf.hak.survivalfabric.teleportation.AngleViewHandler;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public abstract class EntityMixin {
|
||||
|
||||
@Inject(method = "setYaw", at = @At("HEAD"), cancellable = true)
|
||||
private void preventYawChange(float yaw, CallbackInfo ci) {
|
||||
if((Object) this instanceof ClientPlayerEntity player) {
|
||||
if(player.isMainPlayer() && AngleViewHandler.PREVENT_HEAD_MOVEMENT) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "setPitch", at = @At("HEAD"), cancellable = true)
|
||||
private void preventPitchChange(float pitch, CallbackInfo ci) {
|
||||
if((Object) this instanceof ClientPlayerEntity player) {
|
||||
if(player.isMainPlayer() && AngleViewHandler.PREVENT_HEAD_MOVEMENT) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public class AngleViewHandler {
|
||||
|
||||
private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
public static boolean PREVENT_HEAD_MOVEMENT = false;
|
||||
|
||||
public static void registerKeybindings() {
|
||||
for(Angle angle : Angle.values()) {
|
||||
@ -31,9 +32,14 @@ public class AngleViewHandler {
|
||||
player.setYaw(angle.yaw);
|
||||
player.setPitch(angle.pitch);
|
||||
|
||||
PREVENT_HEAD_MOVEMENT = true;
|
||||
|
||||
scheduler.schedule(() -> {
|
||||
if(player == null) return;
|
||||
PREVENT_HEAD_MOVEMENT = false;
|
||||
player.setPitch(-90);
|
||||
PREVENT_HEAD_MOVEMENT = true;
|
||||
scheduler.schedule(() -> PREVENT_HEAD_MOVEMENT = false, 1500, TimeUnit.MILLISECONDS);
|
||||
}, 1500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
});
|
||||
|
@ -3,6 +3,7 @@
|
||||
"package": "wtf.hak.survivalfabric.mixin.client",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"client": [
|
||||
"EntityMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
Reference in New Issue
Block a user