1.0.5
All checks were successful
Gulliver Reloaded/pipeline/head This commit looks good

Tweak Jumping Speed and Movement Speed
This commit is contained in:
TheBrokenRail 2020-03-27 12:51:54 -04:00
parent caf78d54ba
commit 6ebf8e9c2f
4 changed files with 23 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -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<Float> SCALE = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.FLOAT);
@Shadow
public abstract Map<StatusEffect, StatusEffectInstance> 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<Float> info) {
info.setReturnValue(info.getReturnValue() * (float) Math.pow(getScale(), 0.2f));
}
@Inject(at = @At("RETURN"), method = "getMovementSpeed()F", cancellable = true)
public void getMovementSpeed(CallbackInfoReturnable<Float> 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,10 +82,19 @@ public abstract class MixinLivingEntity implements ScaledEntity {
@Inject(at = @At("HEAD"), method = "tick")
public void tick(CallbackInfo info) {
if (!((LivingEntity) (Object) this).getEntityWorld().isClient()) {
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")
public void initDataTracker(CallbackInfo info) {
((LivingEntity) (Object) this).getDataTracker().startTracking(SCALE, 1f);

View File

@ -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<EntityPose, EntityDimensions> POSE_DIMENSIONS;
@Inject(at = @At("RETURN"), method = "getMovementSpeed()F", cancellable = true)
public void getMovementSpeed(CallbackInfoReturnable<Float> info) {
info.setReturnValue(info.getReturnValue() * ((ScaledEntity) this).getScale());
}
@Inject(at = @At("RETURN"), method = "getDimensions", cancellable = true)
public void getDimensions(EntityPose pose, CallbackInfoReturnable<EntityDimensions> info) {
info.setReturnValue(((ScaledEntity) this).scaleDimensions(info.getReturnValue()));