From 0ad542236cc7cb09d87fafe39859f64d0475e120 Mon Sep 17 00:00:00 2001 From: gnembon Date: Thu, 7 May 2020 19:16:04 -0300 Subject: [PATCH 1/2] untested - creativeFlySpeed, creativeFlyDrag --- src/main/java/carpet/CarpetSettings.java | 14 ++++++++ .../LivingEntity_scarpetEventsMixin.java | 33 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index c8c82b04..e7c7a5f6 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -69,6 +69,7 @@ public class CarpetSettings ) public static int portalSurvivalDelay = 80; + private static class OneHourMaxDelayLimit extends Validator { @Override public Integer validate(ServerCommandSource source, ParsedRule currentRule, Integer newValue, String string) { return (newValue > 0 && newValue <= 72000) ? newValue : null; @@ -586,4 +587,17 @@ public class CarpetSettings category = {CREATIVE, CLIENT} ) public static boolean creativeNoClip = false; + + + @Rule( + desc = "Creative flying speed multiplier", + category = {CREATIVE, CLIENT} + ) + public static double creativeFlySpeed = 1.0f; + + @Rule( + desc = "Creative air drag", + category = {CREATIVE, CLIENT} + ) + public static double creativeFlyDrag = 0.91f; } diff --git a/src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java b/src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java index 456b9b74..5d30edac 100644 --- a/src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java +++ b/src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java @@ -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 cir) + { + if ((Object)this instanceof PlayerEntity) + { + PlayerEntity self = (PlayerEntity)(Object)(this); + if (self.abilities.flying && !onGround) + cir.setReturnValue(flyingSpeed* (float)CarpetSettings.creativeFlySpeed); + } + } } From d35769a3658cd37515ee84ff21e6e56495bec56e Mon Sep 17 00:00:00 2001 From: gnembon Date: Sun, 10 May 2020 00:50:02 -0300 Subject: [PATCH 2/2] specified conditions for creative fly controls --- src/main/java/carpet/CarpetSettings.java | 19 +++++++ .../mixins/LivingEntity_creativeFlyMixin.java | 50 +++++++++++++++++++ .../LivingEntity_scarpetEventsMixin.java | 27 ---------- src/main/resources/carpet.mixins.json | 3 +- 4 files changed, 71 insertions(+), 28 deletions(-) create mode 100644 src/main/java/carpet/mixins/LivingEntity_creativeFlyMixin.java diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index e7c7a5f6..fe099c00 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -584,6 +584,15 @@ public class CarpetSettings @Rule( desc = "Creative No Clip", + extra = { + "On servers it needs to be set on both ", + "client and server to function properly.", + "Has no effect when set on the server only", + "Can allow to phase through walls", + "if only set on the carpet client side", + "but requires some trapdoor magic to", + "allow the player to enter blocks" + }, category = {CREATIVE, CLIENT} ) public static boolean creativeNoClip = false; @@ -591,12 +600,22 @@ public class CarpetSettings @Rule( desc = "Creative flying speed multiplier", + extra = { + "Purely client side setting, meaning that", + "having it set on the decicated server has no effect", + "but this also means it will work on vanilla servers as well" + }, category = {CREATIVE, CLIENT} ) public static double creativeFlySpeed = 1.0f; @Rule( desc = "Creative air drag", + extra = { + "Purely client side setting, meaning that", + "having it set on the decicated server has no effect", + "but this also means it will work on vanilla servers as well" + }, category = {CREATIVE, CLIENT} ) public static double creativeFlyDrag = 0.91f; diff --git a/src/main/java/carpet/mixins/LivingEntity_creativeFlyMixin.java b/src/main/java/carpet/mixins/LivingEntity_creativeFlyMixin.java new file mode 100644 index 00000000..4d1410df --- /dev/null +++ b/src/main/java/carpet/mixins/LivingEntity_creativeFlyMixin.java @@ -0,0 +1,50 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +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.callback.CallbackInfoReturnable; + +@Mixin(LivingEntity.class) +public abstract class LivingEntity_creativeFlyMixin extends Entity +{ + @Shadow public float flyingSpeed; + + public LivingEntity_creativeFlyMixin(EntityType type, World world) + { + super(type, world); + } + + @ModifyConstant(method = "travel", constant = @Constant(floatValue = 0.91F), expect = 2) + private float drag(float original) + { + if (CarpetSettings.creativeFlyDrag != 0.91D && (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 cir) + { + if (CarpetSettings.creativeFlySpeed != 1.0D && (Object)this instanceof PlayerEntity) + { + PlayerEntity self = (PlayerEntity)(Object)(this); + if (self.abilities.flying && !onGround) + cir.setReturnValue(flyingSpeed* (float)CarpetSettings.creativeFlySpeed); + } + } +} diff --git a/src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java b/src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java index 5d30edac..57eeaa7a 100644 --- a/src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java +++ b/src/main/java/carpet/mixins/LivingEntity_scarpetEventsMixin.java @@ -28,8 +28,6 @@ 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); @@ -52,29 +50,4 @@ 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 cir) - { - if ((Object)this instanceof PlayerEntity) - { - PlayerEntity self = (PlayerEntity)(Object)(this); - if (self.abilities.flying && !onGround) - cir.setReturnValue(flyingSpeed* (float)CarpetSettings.creativeFlySpeed); - } - } } diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index f8e4b733..46ccfed2 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -159,7 +159,8 @@ "PistonHandler_movableTEMixin", "PlayerEntity_creativeNoClipMixin", "PistonBlockEntity_creativeNoClipMixin", - "BlockItem_creativeNoClipMixin" + "BlockItem_creativeNoClipMixin", + "LivingEntity_creativeFlyMixin" ], "client": [