aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-16 18:21:51 +0300
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-16 18:21:51 +0300
commit6193eed0443598782e053e3d14f1e5bcdbe81485 (patch)
tree739174fb18fe98f4781b6a5b5b5c3791a5379c40 /src/main/java
parentcc0e892fcdb8d6e536801717cae60c2fe5b1ccd5 (diff)
parentac32967bf67360bab33908ccb54d2d9e947db25d (diff)
downloadLibGui-6193eed0443598782e053e3d14f1e5bcdbe81485.tar.gz
LibGui-6193eed0443598782e053e3d14f1e5bcdbe81485.tar.bz2
LibGui-6193eed0443598782e053e3d14f1e5bcdbe81485.zip
Merge branch 'master' into unstable/2.0
# Conflicts: # gradle.properties # src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java # src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java # src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java # src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java # src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java62
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java8
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java84
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java3
5 files changed, 137 insertions, 22 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 cce4cfe..2c6b5b2 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.screen.slot.Slot;
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.isValid(slotNumber, stack);
+ return insertingAllowed && inventory.isValid(slotNumber, stack);
}
@Override
public boolean canTakeItems(PlayerEntity player) {
- return modifiable && inventory.canPlayerUse(player);
+ return takingAllowed && inventory.canPlayerUse(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/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
index 5a3edd1..770b1d6 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
@@ -332,13 +332,13 @@ public class ScreenDrawing {
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(text);
int l = (width/2) - (wid/2);
MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(text);
int l = width - wid;
MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color);
}
@@ -396,13 +396,13 @@ public class ScreenDrawing {
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(text);
int l = (width/2) - (wid/2);
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(text);
int l = width - wid;
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x+l, y, color);
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java
index 4bb89d8..ffebe76 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java
@@ -59,7 +59,7 @@ public class WItem extends WWidget {
MinecraftClient mc = MinecraftClient.getInstance();
ItemRenderer renderer = mc.getItemRenderer();
renderer.zOffset = 100f;
- renderer.renderGuiItem(items.get(current), x + getWidth() / 2 - 9, y + getHeight() / 2 - 9);
+ renderer.method_27951(mc.player, items.get(current), x + getWidth() / 2 - 9, y + getHeight() / 2 - 9);
renderer.zOffset = 0f;
}
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 96814aa..7e25cb1 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
@@ -21,8 +21,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;
@@ -89,17 +90,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.setModifiable(modifiable);
+ 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.setTakingAllowed(takingAllowed);
}
return this;
}
@@ -112,14 +165,29 @@ 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);
+ ValidatedSlot slot = createSlotPeer(inventory, index, this.getAbsoluteX() + (x * 18), this.getAbsoluteY() + (y * 18));
+ slot.setInsertingAllowed(insertingAllowed);
+ slot.setTakingAllowed(takingAllowed);
peers.add(slot);
c.addSlotPeer(slot);
index++;
}
}
}
+
+ /**
+ * Creates a slot peer for this slot widget.
+ *
+ * @param inventory the slot inventory
+ * @param index the index in the inventory
+ * @param x the X coordinate
+ * @param y the Y coordinate
+ * @return the created slot instance
+ * @since 1.11.0
+ */
+ protected ValidatedSlot createSlotPeer(Inventory inventory, int index, int x, int y) {
+ return new ValidatedSlot(inventory, index, x, y);
+ }
@Environment(EnvType.CLIENT)
public void setBackgroundPainter(BackgroundPainter painter) {
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
index 2d3a5ec..ebd8e03 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
@@ -10,7 +10,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.text.Style;
import net.minecraft.text.Text;
import javax.annotation.Nullable;
@@ -54,7 +53,7 @@ public class WText extends WWidget {
@Environment(EnvType.CLIENT)
private void wrapLines() {
TextRenderer font = MinecraftClient.getInstance().textRenderer;
- wrappedLines = font.getTextHandler().wrapLines(text, width, Style.EMPTY);
+ wrappedLines = font.wrapLines(text, width);
}
@Environment(EnvType.CLIENT)