Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fix, Urgent: Fix soft-overwrite preventing other mods' mobs from despawning with special conditions. #907

Merged
merged 2 commits into from
Jul 21, 2024

Conversation

ByThePowerOfScience
Copy link
Contributor

Replaces a soft-overwrite Inject with a ModifyArg that does the same thing and doesn't prevent other Mixins targeting this method from firing.

Replace soft-overwrite Inject with compatible ModifyArg so we don't stop every other mob from despawning if we encounter an error.
@ByThePowerOfScience ByThePowerOfScience changed the title Fix grave incompatibility with other mods Minor fix, Urgent: Fix soft-overwrite preventing other mods' mobs from despawning with special conditions. Jul 18, 2024
@StewStrong StewStrong merged commit e8120ae into ValkyrienSkies:1.18.x/main Jul 21, 2024
5 checks passed
@StewStrong
Copy link
Member

StewStrong commented Jul 21, 2024

This code crashes when I try running it

@ByThePowerOfScience
Copy link
Contributor Author

This code crashes when I try running it

I'll take a look, it's possible I got the args wrong.

@StewStrong
Copy link
Member

I think this would work, tho I havent tested it

package org.valkyrienskies.mod.mixin.feature.shipyard_entities;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.entity.EntitySectionStorage;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.valkyrienskies.mod.mixinducks.world.OfLevel;

@Mixin(PersistentEntitySectionManager.class)
public abstract class MixinPersistentEntitySectionManager implements OfLevel {
    @Shadow
    @Final
    EntitySectionStorage<Entity> sectionStorage;

    @Unique
    private Level valkyrienskies$level;

    @Override
    public Level getLevel() {
        return valkyrienskies$level;
    }

    @Override
    public void setLevel(final Level level) {
        this.valkyrienskies$level = level;
        ((OfLevel) this.sectionStorage).setLevel(level);
    }

    /**
     * This fixes this function randomly crashing. I'm not sure why but the removeIf() function is buggy
     */
    @ModifyArg(
        method = "processUnloads",
        at = @At(
            target = "Lit/unimi/dsi/fastutil/longs/LongSet;removeIf(Ljava/uti l/function/LongPredicate;)Z",
            value = "INVOKE"
        )
    )
    private java.util.function.LongPredicate processUnloads_catchException(
        final java.util.function.LongPredicate par1) {
        return (l) -> {
            try {
                return par1.test(l);
            } catch (final Exception e) {
                e.printStackTrace();
                return false;
            }
        };
    }
}

StewStrong added a commit that referenced this pull request Jul 21, 2024
@StewStrong
Copy link
Member

I merged the updated fix in dcba513

@ByThePowerOfScience ByThePowerOfScience deleted the patch-2 branch July 21, 2024 23:59
@ByThePowerOfScience
Copy link
Contributor Author

Nevermind, I misunderstood the problem removeIf was having. The function itself is running into a NPE, not something in the predicate.

In that case, do what SmoothChunkLoading does and mix into tick's call of processUnloads and wrap it with a WrapOperation handler. I'll do it in the morning.

xiewuzhiying pushed a commit to xiewuzhiying/Valkyrien-Skies-2 that referenced this pull request Aug 28, 2024
…m despawning with special conditions. (ValkyrienSkies#907)

* Update MixinPersistentEntitySectionManager.java

Replace soft-overwrite Inject with compatible ModifyArg so we don't stop every other mob from despawning if we encounter an error.

* Update MixinPersistentEntitySectionManager.java

Rename method
xiewuzhiying pushed a commit to xiewuzhiying/Valkyrien-Skies-2 that referenced this pull request Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants