untested - creativeFlySpeed, creativeFlyDrag

This commit is contained in:
gnembon committed 2020-05-07 19:16:04 -03:00
1 parent 983f24a87d
commit 0ad542236c
2 files changed
+47

No files matched your search

@@ -1,5 +1,6 @@
package carpet.mixins;
import carpet.CarpetSettings;
import carpet.fakes.EntityInterface;
import carpet.fakes.LivingEntityInterface;
import carpet.script.EntityEventsGroup;
@@ -7,12 +8,17 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
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.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LivingEntity.class)
public abstract class LivingEntity_scarpetEventsMixin extends Entity implements LivingEntityInterface
@@ -22,6 +28,8 @@ public abstract class LivingEntity_scarpetEventsMixin extends Entity implements
@Shadow protected boolean jumping;
@Shadow public float flyingSpeed;
public LivingEntity_scarpetEventsMixin(EntityType<?> type, World world)
{
super(type, world);
@@ -44,4 +52,29 @@ public abstract class LivingEntity_scarpetEventsMixin extends Entity implements
{
return jumping;
}
@ModifyConstant(method = "travel", constant = @Constant(floatValue = 0.91F), expect = 2)
private float drag(float original)
{
if ((Object)this instanceof PlayerEntity)
{
PlayerEntity self = (PlayerEntity)(Object)(this);
if (self.abilities.flying && !onGround)
return (float)CarpetSettings.creativeFlyDrag;
}
return original;
}
@Inject(method = "getMovementSpeed(F)F", at = @At("HEAD"), cancellable = true)
private void flyingAltSpeed(float slipperiness, CallbackInfoReturnable<Float> cir)
{
if ((Object)this instanceof PlayerEntity)
{
PlayerEntity self = (PlayerEntity)(Object)(this);
if (self.abilities.flying && !onGround)
cir.setReturnValue(flyingSpeed* (float)CarpetSettings.creativeFlySpeed);
}
}
}