From 4981f9c1d612f7a5e015dc9cdbc5c37292447603 Mon Sep 17 00:00:00 2001 From: deirn Date: Mon, 2 Aug 2021 12:36:21 +0700 Subject: [PATCH] don't show locked and not-yet-generated loot container inventory closes #26 --- .../badasintended/megane/impl/Minecraft.java | 51 ++++++++++++++++++- .../AccessorLootableContainerBlockEntity.java | 14 +++++ .../resources/megane-vanilla.mixins.json | 3 +- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/vanilla/java/badasintended/megane/impl/mixin/minecraft/AccessorLootableContainerBlockEntity.java diff --git a/src/vanilla/java/badasintended/megane/impl/Minecraft.java b/src/vanilla/java/badasintended/megane/impl/Minecraft.java index ebe7d0b..7585f3d 100644 --- a/src/vanilla/java/badasintended/megane/impl/Minecraft.java +++ b/src/vanilla/java/badasintended/megane/impl/Minecraft.java @@ -9,6 +9,7 @@ import badasintended.megane.api.registry.MeganeRegistrar; import badasintended.megane.impl.mixin.minecraft.AccessorAbstractFurnaceBlockEntity; import badasintended.megane.impl.mixin.minecraft.AccessorHorseBaseEntity; +import badasintended.megane.impl.mixin.minecraft.AccessorLootableContainerBlockEntity; import badasintended.megane.impl.util.A; import net.minecraft.block.Blocks; import net.minecraft.block.LeveledCauldronBlock; @@ -19,6 +20,8 @@ import net.minecraft.block.entity.EnderChestBlockEntity; import net.minecraft.block.entity.HopperBlockEntity; import net.minecraft.block.entity.JukeboxBlockEntity; +import net.minecraft.block.entity.LockableContainerBlockEntity; +import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.entity.passive.AbstractDonkeyEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.Fluids; @@ -100,7 +103,53 @@ public int size(EnderChestBlockEntity enderChestBlockEntity) { } }) - .inventory(BlockEntity.class, new InventoryProvider<>() { + .inventory(1100, LootableContainerBlockEntity.class, new InventoryProvider<>() { + private boolean generated; + + @Override + public boolean hasInventory(LootableContainerBlockEntity lootableContainerBlockEntity) { + generated = ((AccessorLootableContainerBlockEntity) lootableContainerBlockEntity).getLootTableId() == null; + return true; + } + + @Override + public int size(LootableContainerBlockEntity lootableContainerBlockEntity) { + return generated ? lootableContainerBlockEntity.size() : 0; + } + + @Override + public @NotNull ItemStack getStack(LootableContainerBlockEntity lootableContainerBlockEntity, int slot) { + return lootableContainerBlockEntity.getStack(slot); + } + }) + + .inventory(1200, LockableContainerBlockEntity.class, new InventoryProvider<>() { + private PlayerEntity player; + private boolean unlocked; + + @Override + public void setupContext(World world, PlayerEntity player) { + this.player = player; + } + + @Override + public boolean hasInventory(LockableContainerBlockEntity lockableContainerBlockEntity) { + unlocked = lockableContainerBlockEntity.checkUnlocked(player); + return true; + } + + @Override + public int size(LockableContainerBlockEntity lockableContainerBlockEntity) { + return unlocked ? lockableContainerBlockEntity.size() : 0; + } + + @Override + public @NotNull ItemStack getStack(LockableContainerBlockEntity lockableContainerBlockEntity, int slot) { + return lockableContainerBlockEntity.getStack(slot); + } + }) + + .inventory(1300, BlockEntity.class, new InventoryProvider<>() { World world; Inventory inventory; diff --git a/src/vanilla/java/badasintended/megane/impl/mixin/minecraft/AccessorLootableContainerBlockEntity.java b/src/vanilla/java/badasintended/megane/impl/mixin/minecraft/AccessorLootableContainerBlockEntity.java new file mode 100644 index 0000000..3ec0bbf --- /dev/null +++ b/src/vanilla/java/badasintended/megane/impl/mixin/minecraft/AccessorLootableContainerBlockEntity.java @@ -0,0 +1,14 @@ +package badasintended.megane.impl.mixin.minecraft; + +import net.minecraft.block.entity.LootableContainerBlockEntity; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(LootableContainerBlockEntity.class) +public interface AccessorLootableContainerBlockEntity { + + @Accessor + Identifier getLootTableId(); + +} diff --git a/src/vanilla/resources/megane-vanilla.mixins.json b/src/vanilla/resources/megane-vanilla.mixins.json index 972803d..df6c135 100644 --- a/src/vanilla/resources/megane-vanilla.mixins.json +++ b/src/vanilla/resources/megane-vanilla.mixins.json @@ -8,6 +8,7 @@ }, "mixins" : [ "AccessorAbstractFurnaceBlockEntity", - "AccessorHorseBaseEntity" + "AccessorHorseBaseEntity", + "AccessorLootableContainerBlockEntity" ] }