-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
57 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 25 additions & 18 deletions
43
src/main/java/carpet/mixins/ServerPlayerGameMode_antiCheatMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,39 @@ | ||
package carpet.mixins; | ||
|
||
import carpet.CarpetSettings; | ||
import com.mojang.authlib.GameProfile; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.level.ServerPlayerGameMode; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(value = ServerPlayerGameMode.class, priority = 69420) // not that important for carpet | ||
public class ServerPlayerGameMode_antiCheatMixin | ||
@Mixin(value = ServerPlayer.class) | ||
public abstract class ServerPlayerGameMode_antiCheatMixin extends Player | ||
{ | ||
// that shoudn't've been a constant at the first place | ||
// resolves problems with mobs using reach entity attributes. | ||
public ServerPlayerGameMode_antiCheatMixin(final Level level, final BlockPos blockPos, final float f, final GameProfile gameProfile) | ||
{ | ||
super(level, blockPos, f, gameProfile); | ||
} | ||
|
||
@Inject(method = "canInteractWithBlock", at = @At("HEAD"), cancellable = true) | ||
private void canInteractLongRangeBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir) | ||
{ | ||
double maxRange = blockInteractionRange() + 1.0; | ||
maxRange = maxRange * maxRange; | ||
if (CarpetSettings.antiCheatDisabled && maxRange < 1024 && getEyePosition().distanceToSqr(Vec3.atCenterOf(pos)) < 1024) cir.setReturnValue(true); | ||
} | ||
|
||
@Redirect(method = "handleBlockBreakAction", at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/server/level/ServerPlayer;getEyePosition()Lnet/minecraft/world/phys/Vec3;" | ||
)) | ||
private Vec3 getEyePos(ServerPlayer instance, | ||
final BlockPos pos, final ServerboundPlayerActionPacket.Action action, final Direction direction, final int maxBuildHeight, final int sequence) | ||
@Inject(method = "canInteractWithEntity", at = @At("HEAD"), cancellable = true) | ||
private void canInteractLongRangeEntity(AABB aabb, CallbackInfoReturnable<Boolean> cir) | ||
{ | ||
if (CarpetSettings.antiCheatDisabled && | ||
instance.getEyePosition().distanceToSqr(Vec3.atCenterOf(pos)) < 1024 | ||
) return Vec3.atCenterOf(pos); | ||
return instance.getEyePosition(); | ||
double maxRange = entityInteractionRange() + 1.0; | ||
maxRange = maxRange * maxRange; | ||
if (CarpetSettings.antiCheatDisabled && maxRange < 1024 && aabb.distanceToSqr(getEyePosition()) < 1024) cir.setReturnValue(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters