Skip to content

Commit

Permalink
Allow sneaking inside blocks/vehicles in <= 1.13.2
Browse files Browse the repository at this point in the history
Closes #506
  • Loading branch information
FlorianMichael committed Aug 15, 2024
1 parent 84b3a95 commit 2ce5975
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.network.packet.Packet;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -76,6 +75,8 @@ public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {
@Shadow
public abstract void setClientPermissionLevel(int clientPermissionLevel);

@Shadow private boolean inSneakingPose;

@WrapWithCondition(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;jump()V"))
private boolean dontJumpBeforeFlying(ClientPlayerEntity instance) {
return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_5);
Expand Down Expand Up @@ -184,9 +185,11 @@ private boolean dontAllowSneakingWhileSwimming(ClientPlayerEntity instance) {
return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_14_1) && instance.isSwimming();
}

@Redirect(method = "tickMovement", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerAbilities;flying:Z", ordinal = 0))
private boolean allowSneakingWhileFlying(PlayerAbilities instance) {
return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_13_2) && instance.flying;
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getAttributeValue(Lnet/minecraft/registry/entry/RegistryEntry;)D"))
private void removeSneakingConditions(CallbackInfo ci) { // Allows sneaking while flying, inside blocks and vehicles
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) {
this.inSneakingPose = this.isSneaking() && !this.isSleeping();
}
}

@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isTouchingWater()Z"))
Expand Down

0 comments on commit 2ce5975

Please sign in to comment.