Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LocalPlayer.class)
public abstract class MixinLocalPlayer extends AbstractClientPlayer {
Expand All @@ -59,24 +60,24 @@ private void removeSneakingConditions(CallbackInfo ci) { // Allows sneaking whil
}
}

@Redirect(method = "moveTowardsClosestSpace", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;suffocatesAt(Lnet/minecraft/core/BlockPos;)Z", ordinal = 0))
private boolean checkCenterBlockSpace(LocalPlayer instance, BlockPos pos) {
@Redirect(method = "moveTowardsClosestSpace", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;suffocatesAt(Lnet/minecraft/core/BlockPos;)Z", ordinal = 1))
private boolean checkNeighborBlockSpace(LocalPlayer instance, BlockPos pos) {
if (ViaFabricPlus.api().targetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) {
final BlockPos oldPos = pos.atY(Mth.floor(this.getBoundingBox().minY + 0.5));
return !this.freeAt(oldPos) || (!this.isSwimming() && !this.freeAt(oldPos.above()));
return !this.viaFabricPlus$doesNotSuffocate(pos);
} else {
return this.suffocatesAt(pos);
}
}

@Redirect(method = "moveTowardsClosestSpace", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;suffocatesAt(Lnet/minecraft/core/BlockPos;)Z", ordinal = 1))
private boolean checkNeighborBlockSpace(LocalPlayer instance, BlockPos pos) {
@Inject(method = "suffocatesAt", at = @At("HEAD"), cancellable = true)
private void swimmingSuffocateCheck(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if (ViaFabricPlus.api().targetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) {
final BlockPos oldPos = pos.atY(Mth.floor(this.getBoundingBox().minY + 0.5));
return !this.freeAt(oldPos) || !this.freeAt(oldPos.above());
} else {
return this.suffocatesAt(pos);
cir.setReturnValue(this.isSwimming() ? !this.freeAt(pos) : !this.viaFabricPlus$doesNotSuffocate(pos));
}
}

@Unique
private boolean viaFabricPlus$doesNotSuffocate(final BlockPos pos) {
return this.freeAt(pos) && !this.level().getBlockState(pos.above()).isRedstoneConductor(this.level(), pos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public MixinLocalPlayer(ClientLevel level, GameProfile gameProfile) {
super(level, gameProfile);
}

@Redirect(method = "moveTowardsClosestSpace", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;getY()D"))
private double offsetCollisionY(LocalPlayer instance) {
if (ViaFabricPlus.api().targetVersion().olderThanOrEqualTo(ProtocolVersion.v1_16_1)) {
return instance.getY() + 0.5D;
} else {
return instance.getY();
}
}

@Redirect(method = "suffocatesAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;collidesWithSuffocatingBlock(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;)Z"))
private boolean useIntervalYCheck(Level instance, Entity entity, AABB aabb, @Local(argsOnly = true) BlockPos pos) {
if (ViaFabricPlus.api().targetVersion().olderThanOrEqualTo(ProtocolVersion.v1_16_1)) {
Expand Down
Loading