Added workaround for incompat with FallFlyingLib

This commit is contained in:
Frank 2021-11-05 14:46:21 +01:00
parent f11e5d3e88
commit 653a76d86b
4 changed files with 98 additions and 7 deletions

View file

@ -6,7 +6,7 @@ minecraft_version=1.17.1
yarn_mappings=6 yarn_mappings=6
loader_version=0.12.4 loader_version=0.12.4
# Mod Properties # Mod Properties
mod_version=0.12.1-pre mod_version=0.12.2
maven_group=ru.betterend maven_group=ru.betterend
archives_base_name=better-end archives_base_name=better-end

View file

@ -33,6 +33,7 @@ import ru.betterend.world.surface.SurfaceBuilders;
public class BetterEnd implements ModInitializer { public class BetterEnd implements ModInitializer {
public static final String MOD_ID = "betterend"; public static final String MOD_ID = "betterend";
public static final Logger LOGGER = new Logger(MOD_ID); public static final Logger LOGGER = new Logger(MOD_ID);
public static final boolean RUNS_FALL_FLYING_LIB = FabricLoader.getInstance().getModContainer("fallflyinglib").isPresent();
@Override @Override
public void onInitialize() { public void onInitialize() {

View file

@ -3,6 +3,7 @@ package ru.betterend.mixin.common;
import java.util.Collection; import java.util.Collection;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.tags.EntityTypeTags;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffect; 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.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@ -37,7 +39,7 @@ import ru.betterend.interfaces.MobEffectApplier;
import ru.betterend.item.CrystaliteArmor; import ru.betterend.item.CrystaliteArmor;
import ru.betterend.registry.EndAttributes; import ru.betterend.registry.EndAttributes;
@Mixin(value=LivingEntity.class, priority=2000) @Mixin(value=LivingEntity.class, priority=200)
public abstract class LivingEntityMixin extends Entity { public abstract class LivingEntityMixin extends Entity {
public LivingEntityMixin(EntityType<?> entityType, Level level) { public LivingEntityMixin(EntityType<?> entityType, Level level) {
@ -112,9 +114,95 @@ public abstract class LivingEntityMixin extends Entity {
} }
return value; 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) @Inject(method = "updateFallFlying", at = @At("HEAD"), cancellable = true)
private void be_updateFallFlying(CallbackInfo info) { private void be_updateFallFlying(CallbackInfo info) {
//run be_updateFallFlying_originFix instead?
if (BetterEnd.RUNS_FALL_FLYING_LIB) return;
ItemStack itemStack = getItemBySlot(EquipmentSlot.CHEST); ItemStack itemStack = getItemBySlot(EquipmentSlot.CHEST);
if (!level.isClientSide && itemStack.getItem() instanceof FallFlyingItem) { if (!level.isClientSide && itemStack.getItem() instanceof FallFlyingItem) {
boolean isFlying = getSharedFlag(7); boolean isFlying = getSharedFlag(7);

View file

@ -1,5 +1,7 @@
package ru.betterend.mixin.common; package ru.betterend.mixin.common;
import java.util.Optional;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -24,9 +26,7 @@ import ru.bclib.util.MHelper;
import ru.betterend.interfaces.FallFlyingItem; import ru.betterend.interfaces.FallFlyingItem;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import java.util.Optional; @Mixin(value=Player.class, priority=200)
@Mixin(Player.class)
public abstract class PlayerMixin extends LivingEntity { public abstract class PlayerMixin extends LivingEntity {
protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level level) { protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level level) {
super(entityType, level); super(entityType, level);
@ -45,11 +45,13 @@ public abstract class PlayerMixin extends LivingEntity {
@Inject(method = "tryToStartFallFlying", at = @At("HEAD"), cancellable = true) @Inject(method = "tryToStartFallFlying", at = @At("HEAD"), cancellable = true)
public void be_tryToStartFlying(CallbackInfoReturnable<Boolean> info) { public void be_tryToStartFlying(CallbackInfoReturnable<Boolean> info) {
if (!onGround && !isFallFlying() && !isInWater() && !hasEffect(MobEffects.LEVITATION)) { if (!onGround && !isFallFlying() && !isInWater() && !hasEffect(MobEffects.LEVITATION)) {
ItemStack itemStack = getItemBySlot(EquipmentSlot.CHEST); ItemStack itemStack = getItemBySlot(EquipmentSlot.CHEST);
if (itemStack.getItem() instanceof FallFlyingItem && ElytraItem.isFlyEnabled(itemStack)) { if (itemStack.getItem() instanceof FallFlyingItem && ElytraItem.isFlyEnabled(itemStack)) {
setSharedFlag(7, true); setSharedFlag(7, true);
info.setReturnValue(true); info.setReturnValue(true);
System.out.println("Started");
info.cancel();
} }
} }
} }