Unmodifiable because I said so. Use your own crafting grid.
*/ -class ContainerSlotCraftingResult extends ContainerSlotUninteractable { +public class ContentCraftingResult extends ContentViewOnly { - ContainerSlotCraftingResult(@NotNull ServerPlayer holder) { + public ContentCraftingResult(@NotNull ServerPlayer holder) { super(holder); } @@ -26,11 +27,11 @@ public ItemStack get() { } @Override - public Slot asMenuSlot(Container container, int index, int x, int y) { - return new SlotUninteractable(container, index, x, y) { + public Slot asSlot(Container container, int slot, int x, int y) { + return new SlotViewOnly(container, slot, x, y) { @Override - ItemStack getOrDefault() { - if (!ContainerSlotCrafting.isAvailable(holder)) { + public ItemStack getOrDefault() { + if (!ContentCrafting.isAvailable(holder)) { return Placeholders.survivalOnly(holder); } InventoryMenu inventoryMenu = holder.inventoryMenu; diff --git a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotCursor.java b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentCursor.java similarity index 86% rename from internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotCursor.java rename to internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentCursor.java index 33b83df6..19694fda 100644 --- a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotCursor.java +++ b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentCursor.java @@ -1,5 +1,6 @@ -package com.lishid.openinv.internal.v1_21_R1.inventory; +package com.lishid.openinv.internal.v1_21_R1.inventory.slot; +import com.lishid.openinv.internal.v1_21_R1.inventory.Placeholders; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Player; @@ -11,11 +12,11 @@ /** * A slot wrapping the active menu's cursor. Unavailable when not online in a survival mode. */ -class ContainerSlotCursor implements ContainerSlot { +public class ContentCursor implements Content { private @NotNull ServerPlayer holder; - ContainerSlotCursor(@NotNull ServerPlayer holder) { + public ContentCursor(@NotNull ServerPlayer holder) { this.holder = holder; } @@ -66,8 +67,8 @@ private boolean isAvailable() { } @Override - public Slot asMenuSlot(Container container, int index, int x, int y) { - return new SlotCursor(container, index, x, y); + public Slot asSlot(Container container, int slot, int x, int y) { + return new SlotCursor(container, slot, x, y); } @Override @@ -76,14 +77,14 @@ public InventoryType.SlotType getSlotType() { return InventoryType.SlotType.OUTSIDE; } - class SlotCursor extends MenuSlotPlaceholder { + public class SlotCursor extends SlotPlaceholder { private SlotCursor(Container container, int index, int x, int y) { super(container, index, x, y); } @Override - ItemStack getOrDefault() { + public ItemStack getOrDefault() { if (!isAvailable()) { return Placeholders.survivalOnly(holder); } diff --git a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotDrop.java b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentDrop.java similarity index 78% rename from internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotDrop.java rename to internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentDrop.java index e7fb80c5..45594a06 100644 --- a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotDrop.java +++ b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentDrop.java @@ -1,5 +1,6 @@ -package com.lishid.openinv.internal.v1_21_R1.inventory; +package com.lishid.openinv.internal.v1_21_R1.inventory.slot; +import com.lishid.openinv.internal.v1_21_R1.inventory.Placeholders; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Container; import net.minecraft.world.inventory.Slot; @@ -10,11 +11,11 @@ /** * A fake slot used to drop items. Unavailable offline. */ -class ContainerSlotDrop implements ContainerSlot { +public class ContentDrop implements Content { private ServerPlayer holder; - ContainerSlotDrop(@NotNull ServerPlayer holder) { + public ContentDrop(@NotNull ServerPlayer holder) { this.holder = holder; } @@ -44,8 +45,8 @@ public void set(ItemStack itemStack) { } @Override - public Slot asMenuSlot(Container container, int index, int x, int y) { - return new SlotDrop(container, index, x, y); + public Slot asSlot(Container container, int slot, int x, int y) { + return new SlotDrop(container, slot, x, y); } @Override @@ -54,14 +55,14 @@ public InventoryType.SlotType getSlotType() { return InventoryType.SlotType.OUTSIDE; } - class SlotDrop extends MenuSlotPlaceholder { + public class SlotDrop extends SlotPlaceholder { private SlotDrop(Container container, int index, int x, int y) { super(container, index, x, y); } @Override - ItemStack getOrDefault() { + public ItemStack getOrDefault() { return holder.connection != null && !holder.connection.isDisconnected() ? Placeholders.drop : Placeholders.blockedOffline; diff --git a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotEquipment.java b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentEquipment.java similarity index 73% rename from internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotEquipment.java rename to internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentEquipment.java index 99f8b39d..2ba44873 100644 --- a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotEquipment.java +++ b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentEquipment.java @@ -1,5 +1,6 @@ -package com.lishid.openinv.internal.v1_21_R1.inventory; +package com.lishid.openinv.internal.v1_21_R1.inventory.slot; +import com.lishid.openinv.internal.v1_21_R1.inventory.Placeholders; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Container; import net.minecraft.world.entity.EquipmentSlot; @@ -11,12 +12,12 @@ /** * A slot for equipment that displays placeholders if empty. */ -class ContainerSlotEquipment extends ContainerSlotList { +public class ContentEquipment extends ContentList { private final ItemStack placeholder; private final EquipmentSlot equipmentSlot; - ContainerSlotEquipment(ServerPlayer holder, int index, EquipmentSlot equipmentSlot) { + public ContentEquipment(ServerPlayer holder, int index, EquipmentSlot equipmentSlot) { super(holder, index, InventoryType.SlotType.ARMOR); placeholder = switch (equipmentSlot) { case HEAD -> Placeholders.emptyHelmet; @@ -34,11 +35,11 @@ public void setHolder(@NotNull ServerPlayer holder) { } @Override - public Slot asMenuSlot(Container container, int index, int x, int y) { - return new SlotEquipment(container, index, x, y); + public Slot asSlot(Container container, int slot, int x, int y) { + return new SlotEquipment(container, slot, x, y); } - class SlotEquipment extends MenuSlotPlaceholder { + public class SlotEquipment extends SlotPlaceholder { private ServerPlayer viewer; @@ -47,7 +48,7 @@ class SlotEquipment extends MenuSlotPlaceholder { } @Override - ItemStack getOrDefault() { + public ItemStack getOrDefault() { ItemStack itemStack = getItem(); if (!itemStack.isEmpty()) { return itemStack; @@ -55,11 +56,11 @@ ItemStack getOrDefault() { return placeholder; } - EquipmentSlot getEquipmentSlot() { + public EquipmentSlot getEquipmentSlot() { return equipmentSlot; } - void onlyEquipmentFor(ServerPlayer viewer) { + public void onlyEquipmentFor(ServerPlayer viewer) { this.viewer = viewer; } diff --git a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotList.java b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentList.java similarity index 75% rename from internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotList.java rename to internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentList.java index 15c0e069..980c0b12 100644 --- a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/ContainerSlotList.java +++ b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/ContentList.java @@ -1,4 +1,4 @@ -package com.lishid.openinv.internal.v1_21_R1.inventory; +package com.lishid.openinv.internal.v1_21_R1.inventory.slot; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Container; @@ -12,13 +12,13 @@ /** * A normal slot backed by an item list. */ -abstract class ContainerSlotList implements ContainerSlot { +public abstract class ContentList implements Content { private final int index; private final InventoryType.SlotType slotType; - ListUsed to prevent plugins (particularly sorting plugins) from adding placeholders to inventories.
*/ -abstract class MenuSlotPlaceholder extends Slot { +public abstract class SlotPlaceholder extends Slot { - MenuSlotPlaceholder(Container container, int index, int x, int y) { + public SlotPlaceholder(Container container, int index, int x, int y) { super(container, index, x, y); } - abstract ItemStack getOrDefault(); + public abstract ItemStack getOrDefault(); } diff --git a/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/SlotViewOnly.java b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/SlotViewOnly.java new file mode 100644 index 00000000..5fa9edd5 --- /dev/null +++ b/internal/v1_21_R1/src/main/java/com/lishid/openinv/internal/v1_21_R1/inventory/slot/SlotViewOnly.java @@ -0,0 +1,151 @@ +package com.lishid.openinv.internal.v1_21_R1.inventory.slot; + +import com.lishid.openinv.internal.v1_21_R1.inventory.Placeholders; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +/** + * A view-only {@link Slot}. "Blank" by default, but can wrap another slot to display its content. + */ +public class SlotViewOnly extends SlotPlaceholder { + + public static @NotNull SlotViewOnly wrap(@NotNull Slot wrapped) { + SlotViewOnly wrapper; + if (wrapped instanceof SlotPlaceholder placeholder) { + wrapper = new SlotViewOnly(wrapped.container, wrapped.slot, wrapped.x, wrapped.y) { + @Override + public ItemStack getOrDefault() { + return placeholder.getOrDefault(); + } + }; + } else { + wrapper = new SlotViewOnly(wrapped.container, wrapped.slot, wrapped.x, wrapped.y) { + @Override + public ItemStack getOrDefault() { + return wrapped.getItem(); + } + }; + } + wrapper.index = wrapped.index; + return wrapper; + } + + public SlotViewOnly(Container container, int index, int x, int y) { + super(container, index, x, y); + } + + @Override + public ItemStack getOrDefault() { + return Placeholders.notSlot; + } + + @Override + public void onQuickCraft(ItemStack var0, ItemStack var1) { + } + + @Override + public void onTake(Player var0, ItemStack var1) { + } + + @Override + public boolean mayPlace(ItemStack var0) { + return false; + } + + @Override + public ItemStack getItem() { + return ItemStack.EMPTY; + } + + @Override + public boolean hasItem() { + return false; + } + + @Override + public void setByPlayer(ItemStack newStack) { + } + + @Override + public void setByPlayer(ItemStack newStack, ItemStack oldStack) { + } + + @Override + public void set(ItemStack var0) { + } + + @Override + public void setChanged() { + } + + @Override + public int getMaxStackSize() { + return 0; + } + + @Override + public int getMaxStackSize(ItemStack itemStack) { + return 0; + } + + @Override + public ItemStack remove(int amount) { + return ItemStack.EMPTY; + } + + @Override + public boolean mayPickup(Player var0) { + return false; + } + + @Override + public boolean isActive() { + return false; + } + + @Override + public Optional