package jesse.keeblarcraft.mixin; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.entity.Entity; import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; @Mixin(targets = "net.minecraft.server.network.ServerPlayNetworkHandler$1") public abstract class PlayerEntityInteractionHandler implements PlayerInteractEntityC2SPacket.Handler { // Unsure what @Shadow is doing, but I'm sure fabric wiki can explain // @Shadow(aliases = "field_28963") @Final private ServerPlayNetworkHandler field_28963; // I assume this is just a bad named field which is the ServerPlayNetworkHandler // @Shadow(aliases = "field_28962") @Final private Entity field_28962; // I assume this is just a bad named field which is the Entity in question depending on the function // // Probably not required for a tool since this is hitting, but you would need to check this if you DID want to make a longer reaching sword or something. Attack is // // in PlayerEntity but this mixin targets the server handler because the server dictates hitting between stuff // @Inject(method = "attack()V", at = @At("HEAD"), require = 1, allow = 1, cancellable = true) // private void isActuallyInHitRange(final CallbackInfo callback) { // // All we are doing in this class is telling the 'attack' function to return false immediately if the two entities are not within a squared distance of each other. // // 100 hard coded because value of hit range is hard coded '10' in the ClientPlayerInteractionManagerMixin in the client section (10^2) // if (!(this.field_28963.player.squaredDistanceTo(this.field_28962) <= 100)) { // 10^2 becauses 10 blocks chosen in Client mixin // callback.cancel(); // } // } }