Switch to using entity-reach-attributes for changing the player's reach distance. Closes #82

This commit is contained in:
Sollace 2022-12-06 22:52:24 +00:00
parent ff3156b600
commit e1195256c6
10 changed files with 14 additions and 109 deletions

View file

@ -31,6 +31,12 @@ repositories {
name = 'modmenu'
url = 'https://maven.terraformersmc.com/releases'
}
maven {
url "https://maven.jamieswhiteshirt.com/libs-release"
content {
includeGroup "com.jamieswhiteshirt"
}
}
maven {
name = 'minelp'
url = 'https://repo.minelittlepony-mod.com/maven/snapshot'
@ -60,6 +66,9 @@ dependencies {
modApi "com.minelittlepony:kirin:${project.kirin_version}"
include "com.minelittlepony:kirin:${project.kirin_version}"
modApi "com.jamieswhiteshirt:reach-entity-attributes:${project.reach_attributes_version}"
include "com.jamieswhiteshirt:reach-entity-attributes:${project.reach_attributes_version}"
modCompileOnly("com.terraformersmc:modmenu:${project.modmenu_version}")
// implementation 'org.jetbrains:intellij-fernflower:1.2.1.16'
modCompileOnly("net.caffienemc.sodium:sodium-fabric-mc1.19.2:0.4.4+build.18")

View file

@ -18,3 +18,4 @@ org.gradle.daemon=false
modmenu_version=4.0.6
minelp_version=4.6.2-beta.1
kirin_version=1.12.0-beta.4
reach_attributes_version=2.3.0

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.entity;
import java.util.ArrayList;
import java.util.List;
import com.jamieswhiteshirt.reachentityattributes.ReachEntityAttributes;
import com.minelittlepony.unicopia.Unicopia;
import net.minecraft.entity.attribute.ClampedEntityAttribute;
@ -12,7 +13,8 @@ import net.minecraft.util.registry.Registry;
public interface UEntityAttributes {
List<EntityAttribute> REGISTRY = new ArrayList<>();
EntityAttribute EXTENDED_REACH_DISTANCE = register("pegasus.reach", new ClampedEntityAttribute("player.reachDistance", 0, 0, 10).setTracked(true));
EntityAttribute EXTENDED_REACH_DISTANCE = ReachEntityAttributes.REACH;
EntityAttribute EXTENDED_ATTACK_DISTANCE = ReachEntityAttributes.ATTACK_RANGE;
EntityAttribute EXTRA_MINING_SPEED = register("earth.mining_speed", new ClampedEntityAttribute("player.miningSpeed", 1, 0, 5).setTracked(true));
EntityAttribute ENTITY_GRAVTY_MODIFIER = register("player.gravity", (new EntityAttribute("player.gravityModifier", 1) {}).setTracked(true));

View file

@ -123,7 +123,6 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
}
public static void registerAttributes(DefaultAttributeContainer.Builder builder) {
builder.add(UEntityAttributes.EXTENDED_REACH_DISTANCE);
builder.add(UEntityAttributes.EXTRA_MINING_SPEED);
builder.add(UEntityAttributes.ENTITY_GRAVTY_MODIFIER);
}
@ -266,10 +265,6 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
return gravity;
}
public float getExtendedReach() {
return (float)entity.getAttributeInstance(UEntityAttributes.EXTENDED_REACH_DISTANCE).getValue();
}
public float getBlockBreakingSpeed() {
return (float)entity.getAttributeInstance(UEntityAttributes.EXTRA_MINING_SPEED).getValue();
}

View file

@ -27,6 +27,7 @@ public class PolearmItem extends SwordItem {
ImmutableMultimap.Builder<EntityAttribute, EntityAttributeModifier> builder = ImmutableMultimap.builder();
builder.putAll(super.getAttributeModifiers(EquipmentSlot.MAINHAND));
builder.put(UEntityAttributes.EXTENDED_REACH_DISTANCE, new EntityAttributeModifier(ATTACK_RANGE_MODIFIER_ID, "Weapon modifier", attackRange, EntityAttributeModifier.Operation.ADDITION));
builder.put(UEntityAttributes.EXTENDED_ATTACK_DISTANCE, new EntityAttributeModifier(ATTACK_RANGE_MODIFIER_ID, "Weapon modifier", attackRange, EntityAttributeModifier.Operation.ADDITION));
attributeModifiers = builder.build();
}

View file

@ -1,28 +0,0 @@
package com.minelittlepony.unicopia.mixin;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.server.network.*;
@Mixin(ServerPlayNetworkHandler.class)
abstract class MixinReachDistanceFix {
@Redirect(
method = {
"onPlayerInteractBlock",
"onPlayerInteractEntity"
},
at = @At(
value = "FIELD",
target = "net/minecraft/server/network/ServerPlayNetworkHandler.MAX_BREAK_SQUARED_DISTANCE:D",
opcode = Opcodes.GETSTATIC
),
require = 0
)
private double bgetMaxBreakSquaredDistance() {
double reach = 6 + Pony.of(((ServerPlayNetworkHandler)(Object)this).getPlayer()).getExtendedReach();
return reach * reach;
}
}

View file

@ -1,31 +0,0 @@
package com.minelittlepony.unicopia.mixin;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.server.network.*;
@Mixin(ServerPlayerInteractionManager.class)
abstract class MixinServerPlayerInteractionManager {
@Accessor
public abstract ServerPlayerEntity getPlayer();
@Redirect(
method = "processBlockBreakingAction",
at = @At(
value = "FIELD",
target = "net/minecraft/server/network/ServerPlayNetworkHandler.MAX_BREAK_SQUARED_DISTANCE:D",
opcode = Opcodes.GETSTATIC
),
require = 0
)
private double bgetMaxBreakSquaredDistance() {
double reach = 6 + Pony.of(getPlayer()).getExtendedReach();
return reach * reach;
}
}

View file

@ -1,30 +0,0 @@
package com.minelittlepony.unicopia.mixin.client;
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 com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerInteractionManager;
@Mixin(ClientPlayerInteractionManager.class)
abstract class MixinClientPlayerInteractionManager {
@Inject(method = "getReachDistance()F", at = @At("RETURN"), cancellable = true)
private void onGetReachDistance(CallbackInfoReturnable<Float> info) {
Pony player = Pony.of(MinecraftClient.getInstance().player);
if (player != null) {
info.setReturnValue(player.getExtendedReach() + info.getReturnValueF());
}
}
@Inject(method = "hasExtendedReach", at = @At("HEAD"), cancellable = true)
private void onHasExtendedReach(CallbackInfoReturnable<Boolean> info) {
if (!info.getReturnValueZ() && Pony.of(MinecraftClient.getInstance().player).getExtendedReach() > 0) {
info.setReturnValue(true);
}
}
}

View file

@ -24,17 +24,6 @@ abstract class MixinGameRenderer implements AutoCloseable, SynchronousResourceRe
@Shadow
private @Final MinecraftClient client;
@ModifyConstant(
method = "updateTargetedEntity",
constant = @Constant(doubleValue = 6),
require = 0
/* This injection is only here to fix reach distance in creative. If it fails, another mod is probably doing the same thing as us. */
// TODO: Find a better way of doing this
)
private double onUpdateTargetedEntity(double initial) {
return Math.max(initial, client.interactionManager.getReachDistance());
}
@Inject(method = "getFov(Lnet/minecraft/client/render/Camera;FZ)D",
at = @At("RETURN"),
cancellable = true)

View file

@ -25,9 +25,7 @@
"MixinPlayerEntity",
"MixinPowderSnowBlock",
"MixinProjectileEntity",
"MixinReachDistanceFix",
"MixinServerPlayerEntity",
"MixinServerPlayerInteractionManager",
"MixinServerPlayNetworkHandler",
"MixinServerWorld",
"MixinSheepEntity",
@ -47,7 +45,6 @@
"client.MixinAnimalModel",
"client.MixinArmorFeatureRenderer",
"client.MixinCamera",
"client.MixinClientPlayerInteractionManager",
"client.MixinEntityRenderDispatcher",
"client.MixinGameRenderer",
"client.MixinInGameHud",