Skip to content

Commit

Permalink
Reach Distance buggy af
Browse files Browse the repository at this point in the history
  • Loading branch information
minheragon12345 committed Jan 1, 2024
1 parent 99a57a7 commit 5f93ddb
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

public class ManasCoreAttributeUtils {
public static double getEntityReachAddition(Player player) {
double range = player.getAttributeValue(ManasCoreAttributes.ENTITY_REACH.get());
return range == 0 ? 0 : range + (player.isCreative() ? 3 : 0);
return player.getAttributeValue(ManasCoreAttributes.ENTITY_REACH.get());
}

public static double getBlockReachAddition(Player player) {
double reach = player.getAttributeValue(ManasCoreAttributes.BLOCK_REACH.get());
return reach == 0 ? 0 : reach + (player.isCreative() ? 0.5 : 0);
return player.getAttributeValue(ManasCoreAttributes.BLOCK_REACH.get());
}

public static boolean cantHit(Player player, Entity entity, double padding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.world.entity.ai.attributes.RangedAttribute;

public class ManasCoreAttributes {
public static final RegistrySupplier<RangedAttribute> BLOCK_REACH = ManasCore.REGISTER.attribute("block_reach")
public static final RegistrySupplier<RangedAttribute> BLOCK_REACH = ManasCore.REGISTER.attribute("block_reach_addition")
.withDefaultValue(0)
.withMinimumValue(0)
.withMaximumValue(1024)
Expand All @@ -27,7 +27,7 @@ public class ManasCoreAttributes {
.applyToAll()
.syncable()
.end();
public static final RegistrySupplier<RangedAttribute> ENTITY_REACH = ManasCore.REGISTER.attribute("entity_reach")
public static final RegistrySupplier<RangedAttribute> ENTITY_REACH = ManasCore.REGISTER.attribute("entity_reach_addition")
.withDefaultValue(0)
.withMinimumValue(0)
.withMaximumValue(1024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ protected void jumpInLiquid(TagKey<Fluid> fluidTag, CallbackInfo ci) {
LivingEntity entity = (LivingEntity) (Object) this;
AttributeInstance instance = entity.getAttribute(ManasCoreAttributes.SWIM_SPEED.get());
if (instance == null) return;
entity.setDeltaMovement(entity.getDeltaMovement().add(0.0, 0.04 * instance.getValue(), 0.0));
entity.setDeltaMovement(entity.getDeltaMovement().add(0.0, 0.04 * instance.getValue() - 0.04, 0.0));
}

@Inject(method = "goDownInWater", at = @At("HEAD"))
protected void goDownInWater(CallbackInfo ci) {
LivingEntity entity = (LivingEntity) (Object) this;
AttributeInstance instance = entity.getAttribute(ManasCoreAttributes.SWIM_SPEED.get());
if (instance == null) return;
entity.setDeltaMovement(entity.getDeltaMovement().add(0.0, -0.04 * instance.getValue(), 0.0));
entity.setDeltaMovement(entity.getDeltaMovement().add(0.0, 0.04 - 0.04 * instance.getValue(), 0.0));
}

@ModifyArg(method = "travel", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/LivingEntity;moveRelative(FLnet/minecraft/world/phys/Vec3;)V"), index = 0)
target = "Lnet/minecraft/world/entity/LivingEntity;moveRelative(FLnet/minecraft/world/phys/Vec3;)V", ordinal = 0))
public float travel(float speed) {
LivingEntity entity = (LivingEntity) (Object) this;
AttributeInstance instance = entity.getAttribute(ManasCoreAttributes.SWIM_SPEED.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.state.BlockState;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand Down Expand Up @@ -38,10 +37,11 @@ private float getCritMultiplier(float multiplier) {
}

@Redirect(method = "attack", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/player/Player;distanceToSqr(Lnet/minecraft/world/entity/Entity;)D", opcode = Opcodes.GETSTATIC))
target = "Lnet/minecraft/world/entity/player/Player;distanceToSqr(Lnet/minecraft/world/entity/Entity;)D"))
private double getBlockInteractDistance(Player player, Entity entity) {
double reach = ManasCoreAttributeUtils.getBlockReachAddition(player);
return player.distanceToSqr(entity) - reach * reach;
double reach = ManasCoreAttributeUtils.getEntityReachAddition(player);
double reachSquared = reach * reach * (reach < 0 ? -1 : 1);
return player.distanceToSqr(entity) - reachSquared;
}

@Inject(method = "getDestroySpeed", at = @At("RETURN"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.objectweb.asm.Opcodes;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -12,17 +13,19 @@
@Mixin(ServerGamePacketListenerImpl.class)
public class MixinServerGamePacketListenerImpl {
@Shadow public ServerPlayer player;
@Redirect(method = "handleUseItemOn", at = @At(value = "FIELD",
target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;MAX_INTERACTION_DISTANCE:D", opcode = Opcodes.GETSTATIC))
private double getBlockInteractDistance() {
double reach = ManasCoreAttributeUtils.getBlockReachAddition(this.player) + Math.sqrt(ServerGamePacketListenerImpl.MAX_INTERACTION_DISTANCE);
return reach * reach;
@Redirect(method = "handleUseItemOn", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/phys/Vec3;distanceToSqr(Lnet/minecraft/world/phys/Vec3;)D"))
private double getBlockInteractDistancee(Vec3 instance, Vec3 vec) {
double reach = ManasCoreAttributeUtils.getBlockReachAddition(player);
double reachSquared = reach * reach * (reach < 0 ? -1 : 1);
return instance.distanceToSqr(vec) - reachSquared;
}

@Redirect(method = "handleInteract", at = @At(value = "FIELD",
target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;MAX_INTERACTION_DISTANCE:D", opcode = Opcodes.GETSTATIC))
private double getEntityInteractDistance() {
double reach = ManasCoreAttributeUtils.getEntityReachAddition(this.player) + Math.sqrt(ServerGamePacketListenerImpl.MAX_INTERACTION_DISTANCE);
return reach * reach;
@Redirect(method = "handleInteract", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/phys/AABB;distanceToSqr(Lnet/minecraft/world/phys/Vec3;)D"))
private double getEntityInteractDistance(AABB instance, Vec3 vec) {
double reach = ManasCoreAttributeUtils.getEntityReachAddition(player);
double reachSquared = reach * reach * (reach < 0 ? -1 : 1);
return instance.distanceToSqr(vec) - reachSquared;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.objectweb.asm.Opcodes;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -14,10 +13,11 @@
@Mixin(ServerPlayerGameMode.class)
public class MixinServerPlayerGameMode {
@Shadow @Final protected ServerPlayer player;
@Redirect(method = "handleBlockBreakAction", at = @At(value = "FIELD",
target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;MAX_INTERACTION_DISTANCE:D", opcode = Opcodes.GETSTATIC))
private double getReachDistance() {
double reach = ManasCoreAttributeUtils.getBlockReachAddition(player) + Math.sqrt(ServerGamePacketListenerImpl.MAX_INTERACTION_DISTANCE);
return reach * reach;
@Redirect(method = "handleBlockBreakAction", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/phys/Vec3;distanceToSqr(Lnet/minecraft/world/phys/Vec3;)D"))
private double getBlockInteractDistancee(Vec3 instance, Vec3 vec) {
double reach = ManasCoreAttributeUtils.getBlockReachAddition(player);
double reachSquared = reach * reach * (reach < 0 ? -1 : 1);
return instance.distanceToSqr(vec) - reachSquared;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,52 @@

import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
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.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(GameRenderer.class)
public class MixinGameRenderer {
@Shadow @Final Minecraft minecraft;
@Inject(method = "pick", at = @At(value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/world/phys/Vec3;add(DDD)Lnet/minecraft/world/phys/Vec3;", shift = At.Shift.AFTER))
private void getReachDistance(float partialTicks, CallbackInfo ci, @Local(ordinal = 0) double d, @Local(ordinal = 0) Vec3 vec3,
@Local(ordinal = 1) Vec3 vec32, @Local(ordinal = 2) LocalRef<Vec3> vec33) {
if (minecraft.player == null) return;
@ModifyArg(method = "pick", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/phys/AABB;expandTowards(Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/phys/AABB;"), index = 0)
private Vec3 getEntityReachDistance(Vec3 vector, @Local(ordinal = 0) double d) {
Player player = this.minecraft.player;
if (player == null) return vector;

double reach = ManasCoreAttributeUtils.getEntityReachAddition(minecraft.player);
if (minecraft.gameMode != null && minecraft.gameMode.hasFarPickRange()) {
if (minecraft.gameMode != null && minecraft.gameMode.hasFarPickRange() && minecraft.hitResult == null) {
double newD = d + reach;
vec33.set(vec3.add(vec32.x * newD, vec32.y * newD, vec32.z * newD));
return vector.scale(newD);
}
return vector;
}

@ModifyArg(method = "pick", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/phys/AABB;expandTowards(Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/phys/AABB;",
opcode = Opcodes.GETSTATIC), index = 0)
private Vec3 getEntityReachDistance(Vec3 vector, @Local(ordinal = 0) double d) {
target = "Lnet/minecraft/world/entity/projectile/ProjectileUtil;getEntityHitResult(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;D)Lnet/minecraft/world/phys/EntityHitResult;"),
index = 2)
private Vec3 getReacgDistance(Vec3 startVec, @Local(ordinal = 0) double d,
@Local(ordinal = 0) Vec3 vec3, @Local(ordinal = 1) Vec3 vec32) {
Player player = this.minecraft.player;
if (player == null) return vector;
if (player == null) return startVec;

double reach = ManasCoreAttributeUtils.getEntityReachAddition(minecraft.player);
if (minecraft.gameMode != null && minecraft.gameMode.hasFarPickRange() && minecraft.hitResult == null) {
double newD = d + reach;
return vector.scale(newD);
return vec3.add(vec32.x * newD, vec32.y * newD, vec32.z * newD);
}
return vector;
return startVec;
}

@ModifyArg(method = "pick", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/projectile/ProjectileUtil;getEntityHitResult(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;D)Lnet/minecraft/world/phys/EntityHitResult;",
opcode = Opcodes.GETSTATIC), index = 5)
target = "Lnet/minecraft/world/entity/projectile/ProjectileUtil;getEntityHitResult(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;D)Lnet/minecraft/world/phys/EntityHitResult;"), index = 5)
private double getEntityDistance(double distance, @Local(ordinal = 0) double d) {
Player player = this.minecraft.player;
if (player == null) return distance;
Expand All @@ -60,12 +61,12 @@ private double getEntityDistance(double distance, @Local(ordinal = 0) double d)
}

@Redirect(method = "pick", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/phys/Vec3;distanceToSqr(Lnet/minecraft/world/phys/Vec3;)D", ordinal = 1, opcode = Opcodes.GETSTATIC))
target = "Lnet/minecraft/world/phys/Vec3;distanceToSqr(Lnet/minecraft/world/phys/Vec3;)D", ordinal = 1))
private double getEntityReachDistance(Vec3 instance, Vec3 vec) {
Player player = this.minecraft.player;
if (player == null) return instance.distanceToSqr(vec);

double reach = ManasCoreAttributeUtils.getEntityReachAddition(player);
return instance.distanceToSqr(vec) - reach * reach;
double reachSquared = reach * reach * (reach < 0 ? -1 : 1);
return instance.distanceToSqr(vec) - reachSquared;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.client.gui.Gui;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -17,7 +16,7 @@ public class MixinGui {
@Shadow @Final
private Minecraft minecraft;
@Redirect(method = "renderCrosshair", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/Entity;isAlive()Z", opcode = Opcodes.GETSTATIC))
target = "Lnet/minecraft/world/entity/Entity;isAlive()Z"))
private boolean getEntityReachtDistance(Entity instance) {
Player player = this.minecraft.player;
if (player == null) return instance.isAlive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private void startAttack(CallbackInfoReturnable<Boolean> cir) {
return;
}

if(!(this.hitResult instanceof EntityHitResult entityHit)) return;
if(ManasCoreAttributeUtils.cantHit(player, entityHit.getEntity(), 3)) {
if (!(this.hitResult instanceof EntityHitResult entityHit)) return;
if (ManasCoreAttributeUtils.cantHit(player, entityHit.getEntity(), 3)) {
if (this.gameMode != null && this.gameMode.hasMissTime()) this.missTime = 10;
this.player.resetAttackStrengthTicker();
this.player.swing(InteractionHand.MAIN_HAND);
Expand Down

0 comments on commit 5f93ddb

Please sign in to comment.