Compare commits
2 Commits
c993621bdb
...
130b2db727
Author | SHA1 | Date | |
---|---|---|---|
130b2db727 | |||
16027c04d1 |
@ -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 {
|
public class AngleViewHandler {
|
||||||
|
|
||||||
private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
public static boolean PREVENT_HEAD_MOVEMENT = false;
|
||||||
|
|
||||||
public static void registerKeybindings() {
|
public static void registerKeybindings() {
|
||||||
for(Angle angle : Angle.values()) {
|
for(Angle angle : Angle.values()) {
|
||||||
@ -31,9 +32,14 @@ public class AngleViewHandler {
|
|||||||
player.setYaw(angle.yaw);
|
player.setYaw(angle.yaw);
|
||||||
player.setPitch(angle.pitch);
|
player.setPitch(angle.pitch);
|
||||||
|
|
||||||
|
PREVENT_HEAD_MOVEMENT = true;
|
||||||
|
|
||||||
scheduler.schedule(() -> {
|
scheduler.schedule(() -> {
|
||||||
if(player == null) return;
|
if(player == null) return;
|
||||||
|
PREVENT_HEAD_MOVEMENT = false;
|
||||||
player.setPitch(-90);
|
player.setPitch(-90);
|
||||||
|
PREVENT_HEAD_MOVEMENT = true;
|
||||||
|
scheduler.schedule(() -> PREVENT_HEAD_MOVEMENT = false, 1500, TimeUnit.MILLISECONDS);
|
||||||
}, 1500, TimeUnit.MILLISECONDS);
|
}, 1500, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"package": "wtf.hak.survivalfabric.mixin.client",
|
"package": "wtf.hak.survivalfabric.mixin.client",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"client": [
|
"client": [
|
||||||
|
"EntityMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
Reference in New Issue
Block a user