diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index c4f1446a..1f6d824a 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,7 +587,39 @@ 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; + + + @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 456b9b74..57eeaa7a 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 diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index a88cc7d2..22094f70 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -160,7 +160,8 @@ "PistonHandler_movableTEMixin", "PlayerEntity_creativeNoClipMixin", "PistonBlockEntity_creativeNoClipMixin", - "BlockItem_creativeNoClipMixin" + "BlockItem_creativeNoClipMixin", + "LivingEntity_creativeFlyMixin" ], "client": [