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-10 18:14:57 +0200 |
commit | d654f037614438aaa198c1c3da49be989ae7bea7 (patch) | |
tree | 05af5e0e6e891ec198fe18d920473e2675455e21 /src/main/java | |
parent | f7bb83291dec390548765b51ce57516882362a29 (diff) | |
download | LibGui-d654f037614438aaa198c1c3da49be989ae7bea7.tar.gz LibGui-d654f037614438aaa198c1c3da49be989ae7bea7.tar.bz2 LibGui-d654f037614438aaa198c1c3da49be989ae7bea7.zip |
Add unmodifiable slots
Diffstat (limited to 'src/main/java')
-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++; |