|
| 1 | +// |
| 2 | +// Source code recreated from a .class file by IntelliJ IDEA |
| 3 | +// (powered by FernFlower decompiler) |
| 4 | +// |
| 5 | + |
| 6 | +package generations.gg.generations.core.generationscore.common.world.container.slots; |
| 7 | + |
| 8 | +import earth.terrarium.common_storage_lib.resources.item.ItemResource; |
| 9 | +import earth.terrarium.common_storage_lib.storage.base.CommonStorage; |
| 10 | +import earth.terrarium.common_storage_lib.storage.base.StorageSlot; |
| 11 | +import earth.terrarium.common_storage_lib.storage.base.UpdateManager; |
| 12 | +import earth.terrarium.common_storage_lib.storage.util.ModifiableItemSlot; |
| 13 | +import net.minecraft.world.Container; |
| 14 | +import net.minecraft.world.SimpleContainer; |
| 15 | +import net.minecraft.world.entity.player.Player; |
| 16 | +import net.minecraft.world.inventory.Slot; |
| 17 | +import net.minecraft.world.item.ItemStack; |
| 18 | +import org.jetbrains.annotations.NotNull; |
| 19 | + |
| 20 | +public class MenuStorageSlot extends Slot { |
| 21 | + public static final Container EMPTY = new SimpleContainer(0); |
| 22 | + private final StorageSlot<ItemResource> storageSlot; |
| 23 | + private final ModifiableItemSlot modifiable; |
| 24 | + |
| 25 | + private ItemStack cached = null; |
| 26 | + |
| 27 | + public MenuStorageSlot(CommonStorage<ItemResource> storage, int slotIndex, int x, int y) { |
| 28 | + super(EMPTY, slotIndex, x, y); |
| 29 | + this.storageSlot = storage.get(slotIndex); |
| 30 | + StorageSlot var6 = this.storageSlot; |
| 31 | + if (var6 instanceof ModifiableItemSlot slot) { |
| 32 | + this.modifiable = slot; |
| 33 | + cached = modifiable.toItemStack(); |
| 34 | + } else { |
| 35 | + throw new UnsupportedOperationException("Cannot create MenuStorageSlot from non-modifiable slot"); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + public boolean mayPlace(ItemStack stack) { |
| 40 | + return stack.isEmpty() ? false : this.storageSlot.isResourceValid(ItemResource.of(stack)); |
| 41 | + } |
| 42 | + |
| 43 | + public @NotNull ItemStack getItem() { |
| 44 | + return cached; |
| 45 | + } |
| 46 | + |
| 47 | + public void set(ItemStack stack) { |
| 48 | + this.modifiable.set(stack); |
| 49 | + cached = stack; |
| 50 | + } |
| 51 | + |
| 52 | + public void onQuickCraft(ItemStack oldStackIn, ItemStack newStackIn) { |
| 53 | + } |
| 54 | + |
| 55 | + public int getMaxStackSize() { |
| 56 | + return (int)this.storageSlot.getLimit((ItemResource)this.storageSlot.getResource()); |
| 57 | + } |
| 58 | + |
| 59 | + public int getMaxStackSize(ItemStack stack) { |
| 60 | + return this.modifiable.getMaxAllowed(ItemResource.of(stack)); |
| 61 | + } |
| 62 | + |
| 63 | + public boolean mayPickup(Player playerIn) { |
| 64 | + return !this.modifiable.isEmpty(); |
| 65 | + } |
| 66 | + |
| 67 | + public @NotNull ItemStack remove(int amount) { |
| 68 | + ItemResource resource = (ItemResource)this.storageSlot.getResource(); |
| 69 | + long extract = this.storageSlot.extract(resource, (long)amount, false); |
| 70 | + var itemStack = extract > 0L ? resource.toStack((int)extract) : ItemStack.EMPTY; |
| 71 | + |
| 72 | + cached = modifiable.toItemStack(); |
| 73 | + |
| 74 | + return itemStack; |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | + public void setChanged() { |
| 79 | + super.setChanged(); |
| 80 | + UpdateManager.batch(new Object[]{this.storageSlot}); |
| 81 | + } |
| 82 | +} |
0 commit comments