From 6ebf8e9c2f4828a1a72ccd50648a650c71a647e1 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 27 Mar 2020 12:51:54 -0400 Subject: [PATCH] 1.0.5 Tweak Jumping Speed and Movement Speed --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- .../mixin/MixinLivingEntity.java | 26 ++++++++++++++----- .../mixin/MixinPlayerEntity.java | 13 ---------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3f4042..4f0885c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +**1.0.5** +* Tweak Jumping Speed and Movement Speed + **1.0.4** * Scale Fall Damage and Reach Distance By Size * Namespace Lang diff --git a/gradle.properties b/gradle.properties index b890927..a33f0f3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G fabric_loader_version = 0.7.8+build.189 # Mod Properties - mod_version = 1.0.4 + mod_version = 1.0.5 maven_group = com.thebrokenrail archives_base_name = gulliver-reloaded diff --git a/src/main/java/com/thebrokenrail/gulliverreloaded/mixin/MixinLivingEntity.java b/src/main/java/com/thebrokenrail/gulliverreloaded/mixin/MixinLivingEntity.java index e355e4b..53b9f1a 100644 --- a/src/main/java/com/thebrokenrail/gulliverreloaded/mixin/MixinLivingEntity.java +++ b/src/main/java/com/thebrokenrail/gulliverreloaded/mixin/MixinLivingEntity.java @@ -5,6 +5,10 @@ import com.thebrokenrail.gulliverreloaded.ScaledEntity; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityPose; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.attribute.EntityAttribute; +import net.minecraft.entity.attribute.EntityAttributeInstance; +import net.minecraft.entity.attribute.EntityAttributeModifier; +import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; @@ -18,15 +22,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Map; +import java.util.UUID; @SuppressWarnings("unused") @Mixin(LivingEntity.class) public abstract class MixinLivingEntity implements ScaledEntity { + private static final UUID SCALED_SPEED_ID = UUID.fromString("c5267238-6a78-4257-ae83-a2a5e34c1128"); private static final TrackedData SCALE = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.FLOAT); @Shadow public abstract Map getActiveStatusEffects(); + @Shadow public abstract EntityAttributeInstance getAttributeInstance(EntityAttribute attribute); + @Override public float getScale() { return ((LivingEntity) (Object) this).getDataTracker().get(SCALE); @@ -61,12 +69,7 @@ public abstract class MixinLivingEntity implements ScaledEntity { @Inject(at = @At("RETURN"), method = "getJumpVelocity", cancellable = true) public void getJumpVelocity(CallbackInfoReturnable info) { - info.setReturnValue(info.getReturnValue() * (float) Math.pow(getScale(), 0.2f)); - } - - @Inject(at = @At("RETURN"), method = "getMovementSpeed()F", cancellable = true) - public void getMovementSpeed(CallbackInfoReturnable info) { - info.setReturnValue(info.getReturnValue() * (float) Math.pow(getScale(), 0.2f)); + info.setReturnValue(info.getReturnValue() * (float) Math.pow(getScale(), 0.4f)); } @Inject(at = @At("RETURN"), method = "getEyeHeight", cancellable = true) @@ -79,8 +82,17 @@ public abstract class MixinLivingEntity implements ScaledEntity { @Inject(at = @At("HEAD"), method = "tick") public void tick(CallbackInfo info) { if (!((LivingEntity) (Object) this).getEntityWorld().isClient()) { - ((LivingEntity) (Object) this).getDataTracker().set(SCALE, computeScale()); + float scale = computeScale(); + if (((LivingEntity) (Object) this).getDataTracker().get(SCALE) != scale) { + ((LivingEntity) (Object) this).getDataTracker().set(SCALE, computeScale()); + } } + + EntityAttributeInstance speedAttribute = getAttributeInstance(EntityAttributes.MOVEMENT_SPEED); + if (speedAttribute.getModifier(SCALED_SPEED_ID) != null) { + speedAttribute.removeModifier(SCALED_SPEED_ID); + } + speedAttribute.addModifier((new EntityAttributeModifier(SCALED_SPEED_ID, "Scaled speed multiplier", getScale() - 1, EntityAttributeModifier.Operation.MULTIPLY_TOTAL)).setSerialize(false)); } @Inject(at = @At("RETURN"), method = "initDataTracker") diff --git a/src/main/java/com/thebrokenrail/gulliverreloaded/mixin/MixinPlayerEntity.java b/src/main/java/com/thebrokenrail/gulliverreloaded/mixin/MixinPlayerEntity.java index e10a7d3..50b6996 100644 --- a/src/main/java/com/thebrokenrail/gulliverreloaded/mixin/MixinPlayerEntity.java +++ b/src/main/java/com/thebrokenrail/gulliverreloaded/mixin/MixinPlayerEntity.java @@ -4,27 +4,14 @@ import com.thebrokenrail.gulliverreloaded.ScaledEntity; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityPose; import net.minecraft.entity.player.PlayerEntity; -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.CallbackInfoReturnable; -import java.util.Map; - @SuppressWarnings("unused") @Mixin(PlayerEntity.class) public abstract class MixinPlayerEntity { - @Shadow - @Final - private static Map POSE_DIMENSIONS; - - @Inject(at = @At("RETURN"), method = "getMovementSpeed()F", cancellable = true) - public void getMovementSpeed(CallbackInfoReturnable info) { - info.setReturnValue(info.getReturnValue() * ((ScaledEntity) this).getScale()); - } - @Inject(at = @At("RETURN"), method = "getDimensions", cancellable = true) public void getDimensions(EntityPose pose, CallbackInfoReturnable info) { info.setReturnValue(((ScaledEntity) this).scaleDimensions(info.getReturnValue()));