Skip to content

Commit

Permalink
don't show locked and not-yet-generated loot container inventory
Browse files Browse the repository at this point in the history
closes #26
  • Loading branch information
deirn committed Aug 2, 2021
1 parent 1379bb3 commit 4981f9c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
51 changes: 50 additions & 1 deletion src/vanilla/java/badasintended/megane/impl/Minecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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();

}
3 changes: 2 additions & 1 deletion src/vanilla/resources/megane-vanilla.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"mixins" : [
"AccessorAbstractFurnaceBlockEntity",
"AccessorHorseBaseEntity"
"AccessorHorseBaseEntity",
"AccessorLootableContainerBlockEntity"
]
}

0 comments on commit 4981f9c

Please sign in to comment.