From 653a76d86b85b68a78d1dbea76ed790800cb09ff Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 5 Nov 2021 14:46:21 +0100 Subject: [PATCH] Added workaround for incompat with FallFlyingLib --- gradle.properties | 2 +- src/main/java/ru/betterend/BetterEnd.java | 1 + .../mixin/common/LivingEntityMixin.java | 92 ++++++++++++++++++- .../betterend/mixin/common/PlayerMixin.java | 10 +- 4 files changed, 98 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index b3428e44..9278e111 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.17.1 yarn_mappings=6 loader_version=0.12.4 # Mod Properties -mod_version=0.12.1-pre +mod_version=0.12.2 maven_group=ru.betterend archives_base_name=better-end diff --git a/src/main/java/ru/betterend/BetterEnd.java b/src/main/java/ru/betterend/BetterEnd.java index eca735f7..f4556a18 100644 --- a/src/main/java/ru/betterend/BetterEnd.java +++ b/src/main/java/ru/betterend/BetterEnd.java @@ -33,6 +33,7 @@ import ru.betterend.world.surface.SurfaceBuilders; public class BetterEnd implements ModInitializer { public static final String MOD_ID = "betterend"; public static final Logger LOGGER = new Logger(MOD_ID); + public static final boolean RUNS_FALL_FLYING_LIB = FabricLoader.getInstance().getModContainer("fallflyinglib").isPresent(); @Override public void onInitialize() { diff --git a/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java b/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java index 4351b962..403307a5 100644 --- a/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java @@ -3,6 +3,7 @@ package ru.betterend.mixin.common; import java.util.Collection; import net.minecraft.sounds.SoundEvent; +import net.minecraft.tags.EntityTypeTags; import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffect; @@ -22,6 +23,7 @@ import net.minecraft.world.item.ElytraItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -37,7 +39,7 @@ import ru.betterend.interfaces.MobEffectApplier; import ru.betterend.item.CrystaliteArmor; import ru.betterend.registry.EndAttributes; -@Mixin(value=LivingEntity.class, priority=2000) +@Mixin(value=LivingEntity.class, priority=200) public abstract class LivingEntityMixin extends Entity { public LivingEntityMixin(EntityType entityType, Level level) { @@ -112,9 +114,95 @@ public abstract class LivingEntityMixin extends Entity { } return value; } - + + // FlyFallingLib (part of Origin) redirected the call to updateFallFlying, + // so we inject our code before the actual call and cancel the execution if the player is still + // flying. That means we have to replicate all vanilla code that happens after the call to + // updateFallFlying. We do this in vanillaAfterUpdateFallFlying + @Inject(method="aiStep", cancellable = true, at=@At(value="INVOKE", target="Lnet/minecraft/world/entity/LivingEntity;updateFallFlying()V")) + private void be_updateFallFlying_originFix(CallbackInfo info) { + //run be_updateFallFlying instead + if (!BetterEnd.RUNS_FALL_FLYING_LIB) return; + + ItemStack itemStack = getItemBySlot(EquipmentSlot.CHEST); + if (!level.isClientSide && itemStack.getItem() instanceof FallFlyingItem) { + boolean isFlying = getSharedFlag(7); + if (isFlying && !onGround && !isPassenger() && !hasEffect(MobEffects.LEVITATION)) { + if (ElytraItem.isFlyEnabled(itemStack)) { + if ((fallFlyTicks + 1) % 20 == 0) { + itemStack.hurtAndBreak( + 1, + LivingEntity.class.cast(this), + livingEntity -> livingEntity.broadcastBreakEvent(EquipmentSlot.CHEST) + ); + } + isFlying = true; + } + else { + isFlying = false; + } + } + else { + isFlying = false; + } + setSharedFlag(7, isFlying); + if (isFlying) { + vanillaAfterUpdateFallFlying(); + info.cancel(); + } + } + + } + + @Shadow protected abstract void removeFrost(); + @Shadow protected abstract void tryAddFrost(); + @Shadow protected abstract void pushEntities(); + @Shadow protected abstract void checkAutoSpinAttack(AABB aABB, AABB aABB2); + @Shadow protected int autoSpinAttackTicks; + + private void vanillaAfterUpdateFallFlying(){ + LivingEntity self = (LivingEntity)(Object)this; + AABB aABB = this.getBoundingBox(); + self.travel(new Vec3(self.xxa, self.yya, self.zza)); + this.level.getProfiler().pop(); + this.level.getProfiler().push("freezing"); + boolean bl2 = this.getType().is(EntityTypeTags.FREEZE_HURTS_EXTRA_TYPES); + int o; + if (!this.level.isClientSide && !self.isDeadOrDying()) { + o = this.getTicksFrozen(); + if (this.isInPowderSnow && this.canFreeze()) { + this.setTicksFrozen(Math.min(this.getTicksRequiredToFreeze(), o + 1)); + } else { + this.setTicksFrozen(Math.max(0, o - 2)); + } + } + + this.removeFrost(); + this.tryAddFrost(); + if (!this.level.isClientSide && this.tickCount % 40 == 0 && this.isFullyFrozen() && this.canFreeze()) { + o = bl2 ? 5 : 1; + this.hurt(DamageSource.FREEZE, (float)o); + } + + this.level.getProfiler().pop(); + this.level.getProfiler().push("push"); + if (this.autoSpinAttackTicks > 0) { + --this.autoSpinAttackTicks; + this.checkAutoSpinAttack(aABB, this.getBoundingBox()); + } + + this.pushEntities(); + this.level.getProfiler().pop(); + if (!this.level.isClientSide && self.isSensitiveToWater() && this.isInWaterRainOrBubble()) { + this.hurt(DamageSource.DROWN, 1.0F); + } + } + @Inject(method = "updateFallFlying", at = @At("HEAD"), cancellable = true) private void be_updateFallFlying(CallbackInfo info) { + //run be_updateFallFlying_originFix instead? + if (BetterEnd.RUNS_FALL_FLYING_LIB) return; + ItemStack itemStack = getItemBySlot(EquipmentSlot.CHEST); if (!level.isClientSide && itemStack.getItem() instanceof FallFlyingItem) { boolean isFlying = getSharedFlag(7); diff --git a/src/main/java/ru/betterend/mixin/common/PlayerMixin.java b/src/main/java/ru/betterend/mixin/common/PlayerMixin.java index 992dd794..baa419f7 100644 --- a/src/main/java/ru/betterend/mixin/common/PlayerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/PlayerMixin.java @@ -1,5 +1,7 @@ package ru.betterend.mixin.common; +import java.util.Optional; + import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -24,9 +26,7 @@ import ru.bclib.util.MHelper; import ru.betterend.interfaces.FallFlyingItem; import ru.betterend.registry.EndBlocks; -import java.util.Optional; - -@Mixin(Player.class) +@Mixin(value=Player.class, priority=200) public abstract class PlayerMixin extends LivingEntity { protected PlayerMixin(EntityType entityType, Level level) { super(entityType, level); @@ -45,11 +45,13 @@ public abstract class PlayerMixin extends LivingEntity { @Inject(method = "tryToStartFallFlying", at = @At("HEAD"), cancellable = true) public void be_tryToStartFlying(CallbackInfoReturnable info) { - if (!onGround && !isFallFlying() && !isInWater() && !hasEffect(MobEffects.LEVITATION)) { + if (!onGround && !isFallFlying() && !isInWater() && !hasEffect(MobEffects.LEVITATION)) { ItemStack itemStack = getItemBySlot(EquipmentSlot.CHEST); if (itemStack.getItem() instanceof FallFlyingItem && ElytraItem.isFlyEnabled(itemStack)) { setSharedFlag(7, true); info.setReturnValue(true); + System.out.println("Started"); + info.cancel(); } } }