diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-03-10 18:14:57 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-03-19 20:33:55 +0200 |
commit | 003d45abf038146b46133a02133e6c507825af80 (patch) | |
tree | 5c859bcb7573e95bbcd6d9b13b3ff1797801b31a /src | |
parent | c6374684225c3f4552479e3116ac9a0cc16f4009 (diff) | |
download | LibGui-003d45abf038146b46133a02133e6c507825af80.tar.gz LibGui-003d45abf038146b46133a02133e6c507825af80.tar.bz2 LibGui-003d45abf038146b46133a02133e6c507825af80.zip |
Add unmodifiable slots
(cherry picked from commit d654f037614438aaa198c1c3da49be989ae7bea7)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java | 18 | ||||
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java | 22 |
2 files changed, 34 insertions, 6 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java index 9301761..8846e17 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java @@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack; public class ValidatedSlot extends Slot { private final int slotNumber; + private boolean modifiable = true; public ValidatedSlot(Inventory inventoryIn, int index, int xPosition, int yPosition) { super(inventoryIn, index, xPosition, yPosition); @@ -16,12 +17,12 @@ public class ValidatedSlot extends Slot { @Override public boolean canInsert(ItemStack stack) { - return inventory.isValidInvStack(slotNumber, stack); + return modifiable && inventory.isValidInvStack(slotNumber, stack); } @Override public boolean canTakeItems(PlayerEntity player) { - return inventory.canPlayerUseInv(player); + return modifiable && inventory.canPlayerUseInv(player); } @Override @@ -39,7 +40,18 @@ public class ValidatedSlot extends Slot { return result; } - + + /** + * Returns true if the item in this slot can be modified by players. + */ + public boolean isModifiable() { + return modifiable; + } + + public void setModifiable(boolean modifiable) { + this.modifiable = modifiable; + } + public int getInventoryIndex() { return slotNumber; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java index f9918b0..3fa0427 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java @@ -10,17 +10,17 @@ import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.container.Slot; import net.minecraft.inventory.Inventory; public class WItemSlot extends WWidget { - private final List<Slot> peers = Lists.newArrayList(); + private final List<ValidatedSlot> peers = Lists.newArrayList(); private BackgroundPainter backgroundPainter; private Inventory inventory; private int startIndex = 0; private int slotsWide = 1; private int slotsHigh = 1; private boolean big = false; + private boolean modifiable = true; public WItemSlot(Inventory inventory, int startIndex, int slotsWide, int slotsHigh, boolean big, boolean ltr) { this.inventory = inventory; @@ -84,7 +84,22 @@ public class WItemSlot extends WWidget { public boolean isBigSlot() { return big; } - + + /** + * Returns true if the contents of this {@code WItemSlot} can be modified by players. + */ + public boolean isModifiable() { + return modifiable; + } + + public WItemSlot setModifiable(boolean modifiable) { + this.modifiable = modifiable; + for (ValidatedSlot peer : peers) { + peer.setModifiable(modifiable); + } + return this; + } + @Override public void createPeers(GuiDescription c) { super.createPeers(c); @@ -94,6 +109,7 @@ public class WItemSlot extends WWidget { for (int y = 0; y < slotsHigh; y++) { for (int x = 0; x < slotsWide; x++) { ValidatedSlot slot = new ValidatedSlot(inventory, index, this.getAbsoluteX() + (x * 18), this.getAbsoluteY() + (y * 18)); + slot.setModifiable(modifiable); peers.add(slot); c.addSlotPeer(slot); index++; |