diff --git a/CHANGELOG.md b/CHANGELOG.md index 17c93ac..e8b9299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Containers remaining open by vanished players in certain conditions + ## [1.5.6] - 2024-06-20 ### Added - Prevent advancement progress config option diff --git a/src/main/java/me/drex/vanish/mixin/ContainerOpenersCountMixin.java b/src/main/java/me/drex/vanish/mixin/ContainerOpenersCountMixin.java new file mode 100644 index 0000000..a8d00a6 --- /dev/null +++ b/src/main/java/me/drex/vanish/mixin/ContainerOpenersCountMixin.java @@ -0,0 +1,24 @@ +package me.drex.vanish.mixin; + +import me.drex.vanish.api.VanishAPI; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.entity.ContainerOpenersCounter; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +import java.util.function.Predicate; + +@Mixin(ContainerOpenersCounter.class) +public class ContainerOpenersCountMixin { + @ModifyArg( + method = "getPlayersWithContainerOpen", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;getEntities(Lnet/minecraft/world/level/entity/EntityTypeTest;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;"), + index = 2 + ) + private Predicate vanish_excludeVanished(Predicate predicate) { + return predicate.and(player -> !VanishAPI.isVanished(player)); + } +} diff --git a/src/main/resources/vanish.mixins.json b/src/main/resources/vanish.mixins.json index 855e279..237cfe5 100644 --- a/src/main/resources/vanish.mixins.json +++ b/src/main/resources/vanish.mixins.json @@ -10,6 +10,7 @@ "mixins": [ "CommandSourceStackMixin", "ContainerMixin", + "ContainerOpenersCountMixin", "EntityGetterMixin", "EntityMixin", "EntitySelectorMixin",