[unrelated] Mixins for brother reference
Some checks are pending
build / build (21) (push) Waiting to run
Some checks are pending
build / build (21) (push) Waiting to run
This commit is contained in:
parent
4c3e9c65aa
commit
79a4738bbc
@ -0,0 +1,17 @@
|
|||||||
|
package jesse.keeblarcraft.mixin;
|
||||||
|
|
||||||
|
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.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||||
|
|
||||||
|
@Mixin(ClientPlayerInteractionManager.class)
|
||||||
|
public abstract class ClientPlayerInteractionManagerMixin {
|
||||||
|
// This initial
|
||||||
|
@Inject(method = "getReachDistance()F", at = @At ("HEAD"), cancellable = true)
|
||||||
|
public void getReachDistance(CallbackInfoReturnable<Float> cir) {
|
||||||
|
cir.setReturnValue(10.0f);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package jesse.keeblarcraft.mixin;
|
||||||
|
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Constant;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
import net.minecraft.network.listener.ServerPlayPacketListener;
|
||||||
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
|
|
||||||
|
@Mixin(ServerPlayNetworkHandler.class)
|
||||||
|
public abstract class ServerPlayNetworkHandlerMixin implements ServerPlayPacketListener {
|
||||||
|
|
||||||
|
// Truth be told not required for a pickaxe or tool probably
|
||||||
|
@Redirect(
|
||||||
|
method = "onPlayerInteractEntity(Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket;)V",
|
||||||
|
at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC))
|
||||||
|
private double getActualAttackRange() {
|
||||||
|
return 100; // 10^2 becauses 10 blocks chosen in Client mixin
|
||||||
|
}
|
||||||
|
|
||||||
|
// Essentially replaces the 'MAX_BREAK_SQUARED_DISTANCE' value with the value we have in the function (100), or 10 blocks which bc 10^2
|
||||||
|
@Redirect(
|
||||||
|
method = "onPlayerInteractBlock(Lnet/minecraft/network/packet/c2s/play/PlayerInteractBlockC2SPacket;)V",
|
||||||
|
at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC))
|
||||||
|
private double getActualReachDistance() {
|
||||||
|
return 100; // 10^2 becauses 10 blocks chosen in Client mixin
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search '64' inside the same onPlayerInteractBlock, would also need to replace that value maybe. This is in the github reference for that block breaking
|
||||||
|
// im not 100% sure what this is doing. If it's squared then sqrt(64) = 8 blocks but I'm not sure what 8 would represent here.
|
||||||
|
@ModifyConstant(
|
||||||
|
method = "onPlayerInteractBlock(Lnet/minecraft/network/packet/c2s/play/PlayerInteractBlockC2SPacket;)V",
|
||||||
|
require = 1, allow = 1, constant = @Constant(doubleValue = 64.0))
|
||||||
|
private double getActualReachDistance(final double reachDistance) {
|
||||||
|
return 100; // 10^2 becauses 10 blocks chosen in Client mixin
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package jesse.keeblarcraft.mixin;
|
||||||
|
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
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.Redirect;
|
||||||
|
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||||
|
|
||||||
|
// This class is needed to validate the actual block breaking
|
||||||
|
@Mixin(ServerPlayerInteractionManager.class)
|
||||||
|
public abstract class ServerPlayerInteractionManagerMixin {
|
||||||
|
@Shadow @Final protected ServerPlayerEntity player;
|
||||||
|
|
||||||
|
@Redirect(
|
||||||
|
method = "processBlockBreakingAction",
|
||||||
|
at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC))
|
||||||
|
private double getActualReachDistance() {
|
||||||
|
return 100; // 10^2 becauses 10 blocks chosen in Client mixin
|
||||||
|
}
|
||||||
|
}
|
@ -4,9 +4,14 @@
|
|||||||
"package": "jesse.keeblarcraft.mixin",
|
"package": "jesse.keeblarcraft.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"PlayerMixin"
|
"PlayerMixin",
|
||||||
|
"ServerPlayNetworkHandlerMixin",
|
||||||
|
"PlayerEntityInteractionHandler",
|
||||||
|
"ServerPlayerInteractionManagerMixin"
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"ClientPlayerInteractionManagerMixin"
|
||||||
],
|
],
|
||||||
"client": [],
|
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user