aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-16 17:54:22 +0300
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-16 17:57:12 +0300
commitc3af40657ffb6a8377713aff5592cd756d19ba4c (patch)
treeaedf614ee6a0bb8a8f0424ae8c891ba4cc425d10
parent5f099b105c448d4685ffb96faa95b10c06c31f28 (diff)
downloadLibGui-c3af40657ffb6a8377713aff5592cd756d19ba4c.tar.gz
LibGui-c3af40657ffb6a8377713aff5592cd756d19ba4c.tar.bz2
LibGui-c3af40657ffb6a8377713aff5592cd756d19ba4c.zip
Split item slot inserting and taking into different flags
(cherry picked from commit 7a462ea318a433a1520a5a1a5804980552c0d0a7)
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java62
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java68
2 files changed, 116 insertions, 14 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 7e116d2..2075840 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
@@ -7,8 +7,9 @@ import net.minecraft.item.ItemStack;
public class ValidatedSlot extends Slot {
private final int slotNumber;
- private boolean modifiable = true;
-
+ private boolean insertingAllowed = true;
+ private boolean takingAllowed = true;
+
public ValidatedSlot(Inventory inventoryIn, int index, int xPosition, int yPosition) {
super(inventoryIn, index, xPosition, yPosition);
if (inventoryIn==null) throw new IllegalArgumentException("Can't make an itemslot from a null inventory!");
@@ -17,12 +18,12 @@ public class ValidatedSlot extends Slot {
@Override
public boolean canInsert(ItemStack stack) {
- return modifiable && inventory.isValidInvStack(slotNumber, stack);
+ return insertingAllowed && inventory.isValidInvStack(slotNumber, stack);
}
@Override
public boolean canTakeItems(PlayerEntity player) {
- return modifiable && inventory.canPlayerUseInv(player);
+ return takingAllowed && inventory.canPlayerUseInv(player);
}
@Override
@@ -44,18 +45,65 @@ public class ValidatedSlot extends Slot {
/**
* Returns true if the item in this slot can be modified by players.
*
- * @return true if this slot is modifiable
+ * @return true if items can be inserted into or taken from this slot widget, false otherwise
* @since 1.8.0
+ * @deprecated Replaced with {@link #isInsertingAllowed()} and {@link #isTakingAllowed()}.
*/
+ @Deprecated
public boolean isModifiable() {
- return modifiable;
+ return insertingAllowed || takingAllowed;
}
+ /**
+ * @deprecated Replaced with {@link #setInsertingAllowed(boolean)} and {@link #setTakingAllowed(boolean)}.
+ */
+ @Deprecated
public void setModifiable(boolean modifiable) {
- this.modifiable = modifiable;
+ this.insertingAllowed = modifiable;
+ this.takingAllowed = modifiable;
}
public int getInventoryIndex() {
return slotNumber;
}
+
+ /**
+ * Returns whether items can be inserted into this slot.
+ *
+ * @return true if items can be inserted, false otherwise
+ * @since 1.10.0
+ */
+ public boolean isInsertingAllowed() {
+ return insertingAllowed;
+ }
+
+ /**
+ * Sets whether inserting items into this slot is allowed.
+ *
+ * @param insertingAllowed true if items can be inserted, false otherwise
+ * @since 1.10.0
+ */
+ public void setInsertingAllowed(boolean insertingAllowed) {
+ this.insertingAllowed = insertingAllowed;
+ }
+
+ /**
+ * Returns whether items can be taken from this slot.
+ *
+ * @return true if items can be taken, false otherwise
+ * @since 1.10.0
+ */
+ public boolean isTakingAllowed() {
+ return takingAllowed;
+ }
+
+ /**
+ * Sets whether taking items from this slot is allowed.
+ *
+ * @param takingAllowed true if items can be taken, false otherwise
+ * @since 1.10.0
+ */
+ public void setTakingAllowed(boolean takingAllowed) {
+ this.takingAllowed = takingAllowed;
+ }
} \ No newline at end of file
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 c6f0282..9823173 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
@@ -20,8 +20,9 @@ public class WItemSlot extends WWidget {
private int slotsWide = 1;
private int slotsHigh = 1;
private boolean big = false;
- private boolean modifiable = true;
-
+ private boolean insertingAllowed = true;
+ private boolean takingAllowed = true;
+
public WItemSlot(Inventory inventory, int startIndex, int slotsWide, int slotsHigh, boolean big, boolean ltr) {
this.inventory = inventory;
this.startIndex = startIndex;
@@ -88,17 +89,69 @@ public class WItemSlot extends WWidget {
/**
* Returns true if the contents of this {@code WItemSlot} can be modified by players.
*
- * @return true if this slot is modifiable
+ * @return true if items can be inserted into or taken from this slot widget, false otherwise
* @since 1.8.0
*/
public boolean isModifiable() {
- return modifiable;
+ return takingAllowed || insertingAllowed;
}
public WItemSlot setModifiable(boolean modifiable) {
- this.modifiable = modifiable;
+ this.insertingAllowed = modifiable;
+ this.takingAllowed = modifiable;
+ for (ValidatedSlot peer : peers) {
+ peer.setInsertingAllowed(modifiable);
+ peer.setTakingAllowed(modifiable);
+ }
+ return this;
+ }
+
+ /**
+ * Returns whether items can be inserted into this slot.
+ *
+ * @return true if items can be inserted, false otherwise
+ * @since 1.10.0
+ */
+ public boolean isInsertingAllowed() {
+ return insertingAllowed;
+ }
+
+ /**
+ * Sets whether inserting items into this slot is allowed.
+ *
+ * @param insertingAllowed true if items can be inserted, false otherwise
+ * @return this slot widget
+ * @since 1.10.0
+ */
+ public WItemSlot setInsertingAllowed(boolean insertingAllowed) {
+ this.insertingAllowed = insertingAllowed;
+ for (ValidatedSlot peer : peers) {
+ peer.setInsertingAllowed(insertingAllowed);
+ }
+ return this;
+ }
+
+ /**
+ * Returns whether items can be taken from this slot.
+ *
+ * @return true if items can be taken, false otherwise
+ * @since 1.10.0
+ */
+ public boolean isTakingAllowed() {
+ return takingAllowed;
+ }
+
+ /**
+ * Sets whether taking items from this slot is allowed.
+ *
+ * @param takingAllowed true if items can be taken, false otherwise
+ * @return this slot widget
+ * @since 1.10.0
+ */
+ public WItemSlot setTakingAllowed(boolean takingAllowed) {
+ this.takingAllowed = takingAllowed;
for (ValidatedSlot peer : peers) {
- peer.setModifiable(modifiable);
+ peer.setTakingAllowed(takingAllowed);
}
return this;
}
@@ -112,7 +165,8 @@ public class WItemSlot extends WWidget {
for (int y = 0; y < slotsHigh; y++) {
for (int x = 0; x < slotsWide; x++) {
ValidatedSlot slot = createSlotPeer(inventory, index, this.getAbsoluteX() + (x * 18), this.getAbsoluteY() + (y * 18));
- slot.setModifiable(modifiable);
+ slot.setInsertingAllowed(insertingAllowed);
+ slot.setTakingAllowed(takingAllowed);
peers.add(slot);
c.addSlotPeer(slot);
index++;