From e1809045a90f73c9c11f10982abec7d37e998360 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 9 May 2020 14:11:31 +0300
Subject: Docs
---
.../cotton/gui/CottonInventoryController.java | 3 +++
.../github/cottonmc/cotton/gui/EmptyInventory.java | 3 +++
.../github/cottonmc/cotton/gui/GuiDescription.java | 9 +++++++++
.../cotton/gui/widget/WAbstractSlider.java | 22 ++++++++++++++++++++++
4 files changed, 37 insertions(+)
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
index 2721ff3..21a1dcb 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
@@ -22,6 +22,9 @@ import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.world.World;
+/**
+ * A screen handler-based GUI description for GUIs with slots.
+ */
public class CottonInventoryController extends ScreenHandler implements GuiDescription {
protected Inventory blockInventory;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java b/src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java
index 84eee0f..7376c92 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/EmptyInventory.java
@@ -4,6 +4,9 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
+/**
+ * An empty inventory that cannot hold any items.
+ */
public class EmptyInventory implements Inventory {
public static final EmptyInventory INSTANCE = new EmptyInventory();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
index 3239179..a0b75cc 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
@@ -8,6 +8,15 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.screen.PropertyDelegate;
+/**
+ * A GUI description represents a GUI without depending on screens.
+ *
+ *
GUI descriptions contain the root panel and the property delegate of the GUI.
+ * They also manage the focused widget.
+ *
+ * @see io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
+ * @see CottonInventoryController
+ */
public interface GuiDescription {
public WPanel getRootPanel();
public int getTitleColor();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
index 3367b1d..17b88c1 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
@@ -348,6 +348,16 @@ public abstract class WAbstractSlider extends WWidget {
: (ch == GLFW.GLFW_KEY_RIGHT || ch == GLFW.GLFW_KEY_UP);
}
+ /**
+ * The direction enum represents all four directions a slider can face.
+ *
+ *
For example, a slider whose value grows towards the right faces right.
+ *
+ *
The default direction for vertical sliders is {@link #UP} and
+ * the one for horizontal sliders is {@link #RIGHT}.
+ *
+ * @since 2.0.0
+ */
public enum Direction {
UP(Axis.VERTICAL, false),
DOWN(Axis.VERTICAL, true),
@@ -362,10 +372,22 @@ public abstract class WAbstractSlider extends WWidget {
this.inverted = inverted;
}
+ /**
+ * Gets the direction's axis.
+ *
+ * @return the axis
+ */
public Axis getAxis() {
return axis;
}
+ /**
+ * Returns whether this slider is inverted.
+ *
+ *
An inverted slider will have reversed keyboard control.
+ *
+ * @return whether this slider is inverted
+ */
public boolean isInverted() {
return inverted;
}
--
cgit
From 7f9699a1a4714b89abbd9f5567d753f6a7967aff Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 9 May 2020 14:12:37 +0300
Subject: Make WLabel.getTextAt and WText.getTextAt public
---
src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java | 2 +-
src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
index 3889ac2..e14239a 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
@@ -101,7 +101,7 @@ public class WLabel extends WWidget {
@Environment(EnvType.CLIENT)
@Nullable
- private Text getTextAt(int x, int y) {
+ public Text getTextAt(int x, int y) {
if (isWithinBounds(x, y)) {
return MinecraftClient.getInstance().textRenderer.method_27527().method_27489(text, x);
}
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 094817c..94bb080 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
@@ -59,7 +59,7 @@ public class WText extends WWidget {
@Environment(EnvType.CLIENT)
@Nullable
- protected Text getTextAt(int x, int y) {
+ public Text getTextAt(int x, int y) {
TextRenderer font = MinecraftClient.getInstance().textRenderer;
int lineIndex = y / font.fontHeight;
--
cgit
From 64398d682a207aeb15009168746ee4c9861b5587 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 9 May 2020 14:24:36 +0300
Subject: Update to 20w19a
---
gradle.properties | 8 +++---
.../cotton/gui/client/CottonClientScreen.java | 2 +-
.../cotton/gui/client/CottonInventoryScreen.java | 2 +-
.../cottonmc/cotton/gui/client/ScreenDrawing.java | 30 +++++++++++-----------
.../github/cottonmc/cotton/gui/widget/WItem.java | 2 +-
.../github/cottonmc/cotton/gui/widget/WLabel.java | 2 +-
.../github/cottonmc/cotton/gui/widget/WText.java | 4 +--
.../cottonmc/cotton/gui/widget/WTextField.java | 6 ++---
8 files changed, 28 insertions(+), 28 deletions(-)
(limited to 'src/main/java/io')
diff --git a/gradle.properties b/gradle.properties
index b1db372..f8f383a 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
- minecraft_version=20w17a
- yarn_mappings=20w17a+build.4
+ minecraft_version=20w19a
+ yarn_mappings=20w19a+build.6
loader_version=0.8.2+build.194
# Mod Properties
- mod_version = 1.9.0
+ mod_version = 2.0.0
maven_group = io.github.cottonmc
archives_base_name = LibGui
# Dependencies
- fabric_version=0.6.2+build.327-1.16
+ fabric_version=0.10.7+build.344-1.16
jankson_version=2.0.1+j1.2.0
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
index 968cbba..d4ac04c 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
@@ -66,7 +66,7 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
}
if (getTitle() != null) {
- textRenderer.method_27528(matrices, getTitle(), left, top, description.getTitleColor());
+ textRenderer.draw(matrices, getTitle(), left, top, description.getTitleColor());
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
index a018173..1508110 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
@@ -198,7 +198,7 @@ public class CottonInventoryScreen extends
}
if (getTitle() != null) {
- textRenderer.method_27528(matrices, getTitle(), x, y, description.getTitleColor());
+ textRenderer.draw(matrices, getTitle(), x, y, description.getTitleColor());
}
}
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 786f2ee..5a3edd1 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
@@ -299,13 +299,13 @@ public class ScreenDrawing {
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(s);
int l = (width/2) - (wid/2);
MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(s);
int l = width - wid;
MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color);
}
@@ -328,19 +328,19 @@ public class ScreenDrawing {
public static void drawString(MatrixStack matrices, Text text, Alignment align, int x, int y, int width, int color) {
switch(align) {
case LEFT: {
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color);
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(text);
int l = (width/2) - (wid/2);
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(text);
int l = width - wid;
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color);
}
break;
}
@@ -364,13 +364,13 @@ public class ScreenDrawing {
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(s);
int l = (width/2) - (wid/2);
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(s);
int l = width - wid;
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color);
}
@@ -392,19 +392,19 @@ public class ScreenDrawing {
public static void drawStringWithShadow(MatrixStack matrices, Text text, Alignment align, int x, int y, int width, int color) {
switch(align) {
case LEFT: {
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x, y, color);
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(text);
int l = (width/2) - (wid/2);
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(text);
int l = width - wid;
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x+l, y, color);
}
break;
}
@@ -433,7 +433,7 @@ public class ScreenDrawing {
* @param color the text color
*/
public static void drawString(MatrixStack matrices, Text text, int x, int y, int color) {
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color);
}
public static int colorAtOpacity(int opaque, float opacity) {
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 c1e07e8..4bb89d8 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(mc.player, items.get(current), x + getWidth() / 2 - 9, y + getHeight() / 2 - 9);
+ renderer.renderGuiItem(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/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
index e14239a..d6d02d3 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
@@ -103,7 +103,7 @@ public class WLabel extends WWidget {
@Nullable
public Text getTextAt(int x, int y) {
if (isWithinBounds(x, y)) {
- return MinecraftClient.getInstance().textRenderer.method_27527().method_27489(text, x);
+ return MinecraftClient.getInstance().textRenderer.getTextHandler().trimToWidth(text, x);
}
return null;
}
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 94bb080..ccc3e83 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
@@ -54,7 +54,7 @@ public class WText extends WWidget {
@Environment(EnvType.CLIENT)
private void wrapLines() {
TextRenderer font = MinecraftClient.getInstance().textRenderer;
- wrappedLines = font.method_27527().method_27491(text, width, Style.field_24360, false);
+ wrappedLines = font.getTextHandler().wrapLines(text, width, Style.EMPTY);
}
@Environment(EnvType.CLIENT)
@@ -65,7 +65,7 @@ public class WText extends WWidget {
if (lineIndex >= 0 && lineIndex < wrappedLines.size()) {
Text line = wrappedLines.get(lineIndex);
- return font.method_27527().method_27489(line, x);
+ return font.getTextHandler().trimToWidth(line, x);
}
return null;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
index d6eadac..74129f5 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
@@ -322,7 +322,7 @@ public class WTextField extends WWidget {
int textColor = this.editable ? this.enabledColor : this.uneditableColor;
//TODO: Scroll offset
- String trimText = font.method_27523(this.text, this.width-OFFSET_X_TEXT);
+ String trimText = font.trimToWidth(this.text, this.width-OFFSET_X_TEXT);
boolean selection = (select!=-1);
boolean focused = this.isFocused(); //this.isFocused() && this.focusedTicks / 6 % 2 == 0 && boolean_1; //Blinks the cursor
@@ -677,7 +677,7 @@ public class WTextField extends WWidget {
TextRenderer font = MinecraftClient.getInstance().textRenderer;
int lastAdvance = 0;
for(int i=0; i
Date: Sat, 9 May 2020 14:30:34 +0300
Subject: Simplify getTextAt
---
src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java | 2 +-
src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
index d6d02d3..67bd55a 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
@@ -103,7 +103,7 @@ public class WLabel extends WWidget {
@Nullable
public Text getTextAt(int x, int y) {
if (isWithinBounds(x, y)) {
- return MinecraftClient.getInstance().textRenderer.getTextHandler().trimToWidth(text, x);
+ return MinecraftClient.getInstance().textRenderer.trimToWidth(text, x);
}
return null;
}
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 ccc3e83..2d3a5ec 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
@@ -65,7 +65,7 @@ public class WText extends WWidget {
if (lineIndex >= 0 && lineIndex < wrappedLines.size()) {
Text line = wrappedLines.get(lineIndex);
- return font.getTextHandler().trimToWidth(line, x);
+ return font.trimToWidth(line, x);
}
return null;
--
cgit
From 16eb60403814d787f3ef5512ecbb51b7001efd71 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 01:46:16 +0300
Subject: Update to 20w20b
---
gradle.properties | 12 ++++----
.../cotton/gui/client/CottonClientScreen.java | 2 +-
.../cotton/gui/client/CottonInventoryScreen.java | 2 +-
.../cottonmc/cotton/gui/client/ScreenDrawing.java | 32 +++++++++++-----------
.../github/cottonmc/cotton/gui/widget/WItem.java | 2 +-
.../github/cottonmc/cotton/gui/widget/WLabel.java | 2 +-
.../github/cottonmc/cotton/gui/widget/WText.java | 6 ++--
.../cottonmc/cotton/gui/widget/WTextField.java | 6 ++--
8 files changed, 31 insertions(+), 33 deletions(-)
(limited to 'src/main/java/io')
diff --git a/gradle.properties b/gradle.properties
index b1db372..3696bf2 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
- minecraft_version=20w17a
- yarn_mappings=20w17a+build.4
- loader_version=0.8.2+build.194
+ minecraft_version=20w20b
+ yarn_mappings=20w20b+build.7
+ loader_version=0.8.3+build.196
# Mod Properties
- mod_version = 1.9.0
+ mod_version = 1.9.1
maven_group = io.github.cottonmc
archives_base_name = LibGui
# Dependencies
- fabric_version=0.6.2+build.327-1.16
- jankson_version=2.0.1+j1.2.0
+ fabric_version=0.10.9+build.346-1.16
+ jankson_version=2.1.0+j1.2.0
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
index 05f3b68..6b53eae 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
@@ -66,7 +66,7 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
}
if (getTitle() != null) {
- textRenderer.method_27528(ScreenDrawing.matrices, getTitle(), left, top, description.getTitleColor());
+ textRenderer.draw(ScreenDrawing.matrices, getTitle(), left, top, description.getTitleColor());
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
index 5dca5f1..aa58b26 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
@@ -198,7 +198,7 @@ public class CottonInventoryScreen extends H
}
if (getTitle() != null) {
- textRenderer.method_27528(ScreenDrawing.matrices, getTitle(), x, y, description.getTitleColor());
+ textRenderer.draw(ScreenDrawing.matrices, getTitle(), x, y, description.getTitleColor());
}
}
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 199909f..1a485b5 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
@@ -315,13 +315,13 @@ public class ScreenDrawing {
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(s);
int l = (width/2) - (wid/2);
MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(s);
int l = width - wid;
MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color);
}
@@ -343,19 +343,19 @@ public class ScreenDrawing {
public static void drawString(Text text, Alignment align, int x, int y, int width, int color) {
switch(align) {
case LEFT: {
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color);
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(text);
int l = (width/2) - (wid/2);
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(text);
int l = width - wid;
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color);
}
break;
}
@@ -378,13 +378,13 @@ public class ScreenDrawing {
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(s);
int l = (width/2) - (wid/2);
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(s);
int l = width - wid;
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color);
}
@@ -405,19 +405,19 @@ public class ScreenDrawing {
public static void drawStringWithShadow(Text text, Alignment align, int x, int y, int width, int color) {
switch(align) {
case LEFT: {
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color);
}
break;
case CENTER: {
- int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(text);
int l = (width/2) - (wid/2);
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color);
}
break;
case RIGHT: {
- int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int wid = MinecraftClient.getInstance().textRenderer.getWidth(text);
int l = width - wid;
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x+l, y, color);
}
break;
}
@@ -444,7 +444,7 @@ public class ScreenDrawing {
* @param color the text color
*/
public static void drawString(Text text, int x, int y, int color) {
- MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color);
}
/**
@@ -453,7 +453,7 @@ public class ScreenDrawing {
@Deprecated
public static void drawCenteredWithShadow(String s, int x, int y, int color) {
TextRenderer render = MinecraftClient.getInstance().textRenderer;
- render.drawWithShadow(matrices, s, (float)(x - render.getStringWidth(s) / 2), (float)y, color);
+ render.drawWithShadow(matrices, s, (float)(x - render.getWidth(s) / 2), (float)y, color);
}
public static int colorAtOpacity(int opaque, float opacity) {
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 d3d91b0..5dc3775 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
@@ -60,7 +60,7 @@ public class WItem extends WWidget {
MinecraftClient mc = MinecraftClient.getInstance();
ItemRenderer renderer = mc.getItemRenderer();
renderer.zOffset = 100f;
- renderer.renderGuiItem(mc.player, items.get(current), getWidth() / 2 - 9, getHeight() / 2 - 9);
+ renderer.method_27951(mc.player, items.get(current), getWidth() / 2 - 9, getHeight() / 2 - 9);
renderer.zOffset = 0f;
RenderSystem.popMatrix();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
index 1ab42b1..1964675 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
@@ -103,7 +103,7 @@ public class WLabel extends WWidget {
@Nullable
private Text getTextAt(int x, int y) {
if (isWithinBounds(x, y)) {
- return MinecraftClient.getInstance().textRenderer.method_27527().method_27489(text, x);
+ return MinecraftClient.getInstance().textRenderer.trimToWidth(text, x);
}
return null;
}
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 2052379..721c007 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
@@ -9,8 +9,6 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.client.util.Texts;
-import net.minecraft.text.Style;
import net.minecraft.text.Text;
import javax.annotation.Nullable;
@@ -54,7 +52,7 @@ public class WText extends WWidget {
@Environment(EnvType.CLIENT)
private void wrapLines() {
TextRenderer font = MinecraftClient.getInstance().textRenderer;
- wrappedLines = font.method_27527().method_27491(text, width, Style.field_24360, false);
+ wrappedLines = font.wrapLines(text, width);
}
@Environment(EnvType.CLIENT)
@@ -65,7 +63,7 @@ public class WText extends WWidget {
if (lineIndex >= 0 && lineIndex < wrappedLines.size()) {
Text line = wrappedLines.get(lineIndex);
- return font.method_27527().method_27489(line, x);
+ return font.getTextHandler().trimToWidth(line, x);
}
return null;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
index 75e7628..e25e8d3 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
@@ -321,7 +321,7 @@ public class WTextField extends WWidget {
int textColor = this.editable ? this.enabledColor : this.uneditableColor;
//TODO: Scroll offset
- String trimText = font.method_27523(this.text, this.width-OFFSET_X_TEXT);
+ String trimText = font.trimToWidth(this.text, this.width-OFFSET_X_TEXT);
boolean selection = (select!=-1);
boolean focused = this.isFocused(); //this.isFocused() && this.focusedTicks / 6 % 2 == 0 && boolean_1; //Blinks the cursor
@@ -676,7 +676,7 @@ public class WTextField extends WWidget {
TextRenderer font = MinecraftClient.getInstance().textRenderer;
int lastAdvance = 0;
for(int i=0; i
Date: Sat, 16 May 2020 17:44:55 +0300
Subject: Delegate WItemSlot peer creation to an overrideable method
This allows users to tweak slot behaviour with custom slot classes :)
---
.../io/github/cottonmc/cotton/gui/widget/WItemSlot.java | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
(limited to 'src/main/java/io')
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 7af7b29..8d0cf94 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
@@ -111,7 +111,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));
+ ValidatedSlot slot = createSlotPeer(inventory, index, this.getAbsoluteX() + (x * 18), this.getAbsoluteY() + (y * 18));
slot.setModifiable(modifiable);
peers.add(slot);
c.addSlotPeer(slot);
@@ -119,6 +119,20 @@ public class WItemSlot extends WWidget {
}
}
}
+
+ /**
+ * 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) {
--
cgit
From 7a462ea318a433a1520a5a1a5804980552c0d0a7 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 17:54:22 +0300
Subject: Split item slot inserting and taking into different flags
---
.../github/cottonmc/cotton/gui/ValidatedSlot.java | 62 +++++++++++++++++---
.../cottonmc/cotton/gui/widget/WItemSlot.java | 68 +++++++++++++++++++---
2 files changed, 116 insertions(+), 14 deletions(-)
(limited to 'src/main/java/io')
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/widget/WItemSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java
index 8d0cf94..7d11881 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++;
--
cgit
From e4ee59927279e9a7e42fa249e573408e46dfc904 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 18:36:43 +0300
Subject: Docs
---
.../cotton/gui/CottonInventoryController.java | 36 ++++++++++++++++++++--
.../cottonmc/cotton/gui/widget/WItemSlot.java | 9 +++++-
.../cotton/gui/widget/WPlayerInvPanel.java | 16 ++++++++--
3 files changed, 55 insertions(+), 6 deletions(-)
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
index 21a1dcb..272d251 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
@@ -325,11 +325,31 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
this.propertyDelegate = delegate;
return this;
}
-
+
+ /**
+ * Creates a player inventory widget from this panel's {@linkplain #playerInventory player inventory}.
+ *
+ * @return the created inventory widget
+ */
public WPlayerInvPanel createPlayerInventoryPanel() {
return new WPlayerInvPanel(this.playerInventory);
}
-
+
+ /**
+ * Gets the block inventory at the context.
+ *
+ * If no inventory is found, returns {@link EmptyInventory#INSTANCE}.
+ *
+ *
Searches for these implementations in the following order:
+ *
+ * - Blocks implementing {@code InventoryProvider}
+ * - Block entities implementing {@code InventoryProvider}
+ * - Block entities implementing {@code Inventory}
+ *
+ *
+ * @param ctx the context
+ * @return the found inventory
+ */
public static Inventory getBlockInventory(ScreenHandlerContext ctx) {
return ctx.run((world, pos) -> {
BlockState state = world.getBlockState(pos);
@@ -357,7 +377,17 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
return EmptyInventory.INSTANCE;
}).orElse(EmptyInventory.INSTANCE);
}
-
+
+ /**
+ * Gets the property delegate at the context.
+ *
+ * If no property delegate is found, returns an empty property delegate with no properties.
+ *
+ *
Searches for blocks and block entities implementing {@link PropertyDelegateHolder}.
+ *
+ * @param ctx the context
+ * @return the found property delegate
+ */
public static PropertyDelegate getBlockPropertyDelegate(ScreenHandlerContext ctx) {
return ctx.run((world, pos) -> {
BlockState state = world.getBlockState(pos);
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 7e25cb1..06bac2e 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
@@ -61,7 +61,14 @@ public class WItemSlot extends WWidget {
return w;
}
-
+
+ /**
+ * Creates a 9x3 slot widget from the "main" part of a player inventory.
+ *
+ * @param inventory the player inventory
+ * @return the created slot widget
+ * @see WPlayerInvPanel
+ */
public static WItemSlot ofPlayerStorage(Inventory inventory) {
WItemSlot w = new WItemSlot();
w.inventory = inventory;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java
index 0fda576..47df88f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java
@@ -1,11 +1,16 @@
package io.github.cottonmc.cotton.gui.widget;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
import net.minecraft.entity.player.PlayerInventory;
+/**
+ * A player inventory widget that has a visually separate hotbar.
+ */
public class WPlayerInvPanel extends WPlainPanel {
- private WItemSlot inv;
- private WItemSlot hotbar;
+ private final WItemSlot inv;
+ private final WItemSlot hotbar;
public WPlayerInvPanel(PlayerInventory playerInventory) {
inv = WItemSlot.ofPlayerStorage(playerInventory);
@@ -14,6 +19,13 @@ public class WPlayerInvPanel extends WPlainPanel {
this.add(hotbar, 0, 58);
}
+ /**
+ * Sets the background painter of this inventory widget's slots.
+ *
+ * @param painter the new painter
+ * @return this panel
+ */
+ @Environment(EnvType.CLIENT)
@Override
public WPanel setBackgroundPainter(BackgroundPainter painter) {
super.setBackgroundPainter(null);
--
cgit
From 75df4f3494a027421fd3dbaf12c3aeebac85f3e8 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 18:38:55 +0300
Subject: Remove ltr parameter from WItemSlot's public constructor
---
src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/main/java/io')
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 06bac2e..585a807 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
@@ -24,7 +24,7 @@ public class WItemSlot extends WWidget {
private boolean insertingAllowed = true;
private boolean takingAllowed = true;
- public WItemSlot(Inventory inventory, int startIndex, int slotsWide, int slotsHigh, boolean big, boolean ltr) {
+ public WItemSlot(Inventory inventory, int startIndex, int slotsWide, int slotsHigh, boolean big) {
this.inventory = inventory;
this.startIndex = startIndex;
this.slotsWide = slotsWide;
--
cgit
From ce32233ed9a442b47456dddbefc06786cee7956c Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 18:39:49 +0300
Subject: Remove Lists.newArrayList usages
---
src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java | 5 ++---
src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 5 ++---
2 files changed, 4 insertions(+), 6 deletions(-)
(limited to 'src/main/java/io')
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 585a807..012cf16 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
@@ -1,9 +1,8 @@
package io.github.cottonmc.cotton.gui.widget;
+import java.util.ArrayList;
import java.util.List;
-import com.google.common.collect.Lists;
-
import io.github.cottonmc.cotton.gui.GuiDescription;
import io.github.cottonmc.cotton.gui.ValidatedSlot;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
@@ -14,7 +13,7 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.inventory.Inventory;
public class WItemSlot extends WWidget {
- private final List peers = Lists.newArrayList();
+ private final List peers = new ArrayList<>();
private BackgroundPainter backgroundPainter;
private Inventory inventory;
private int startIndex = 0;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
index fe32718..d01ec35 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
@@ -1,9 +1,8 @@
package io.github.cottonmc.cotton.gui.widget;
+import java.util.ArrayList;
import java.util.List;
-import com.google.common.collect.Lists;
-
import io.github.cottonmc.cotton.gui.GuiDescription;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import net.fabricmc.api.EnvType;
@@ -19,7 +18,7 @@ public abstract class WPanel extends WWidget {
*
* The list is mutable.
*/
- protected final List children = Lists.newArrayList();
+ protected final List children = new ArrayList<>();
@Environment(EnvType.CLIENT)
private BackgroundPainter backgroundPainter = null;
--
cgit
From 1251c42512ef376074eb4bdfaf7e496954cd5b0d Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 18:40:00 +0300
Subject: Fix typo in WPanel documentation
---
src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
index d01ec35..d1f0f4a 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java
@@ -10,7 +10,7 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.util.math.MatrixStack;
/**
- * Panels are widgets tthat contain other widgets.
+ * Panels are widgets that contain other widgets.
*/
public abstract class WPanel extends WWidget {
/**
--
cgit
From 084985537dae8106c262f5f8a5d3917df2f66ed3 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 18:46:02 +0300
Subject: WWidget + GuiDescription docs, improve "host is null" logging message
---
.../github/cottonmc/cotton/gui/GuiDescription.java | 2 +-
.../github/cottonmc/cotton/gui/widget/WWidget.java | 33 ++++++++++++++++++++--
2 files changed, 32 insertions(+), 3 deletions(-)
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
index a0b75cc..fec799b 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/GuiDescription.java
@@ -45,7 +45,7 @@ public interface GuiDescription {
@Nullable
public WWidget getFocus();
- /** Notifies this gui that the widget waants to acquire focus. */
+ /** Notifies this gui that the widget wants to acquire focus. */
public void requestFocus(WWidget widget);
/** Notifies this gui that the widget wants to give up its hold over focus. */
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
index cee18d5..656f24f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
@@ -4,13 +4,14 @@ import java.util.ArrayList;
import java.util.List;
import io.github.cottonmc.cotton.gui.GuiDescription;
-import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
@@ -18,15 +19,22 @@ import javax.annotation.Nullable;
* The base class for all widgets.
*/
public class WWidget {
+ private static final Logger LOGGER = LogManager.getLogger();
+
/**
* The containing panel of this widget.
* Can be null if this widget is the root panel or a HUD widget.
*/
@Nullable
protected WPanel parent;
+
+ /** The X coordinate of this widget relative to its parent. */
protected int x = 0;
+ /** The Y coordinate of this widget relative to its parent. */
protected int y = 0;
+ /** The width of this widget, defaults to 18 pixels. */
protected int width = 18;
+ /** The height of this widget, defaults to 18 pixels. */
protected int height = 18;
/**
@@ -245,23 +253,44 @@ public class WWidget {
public void onFocusLost() {
}
+ /**
+ * Tests whether this widget has focus.
+ *
+ * @return true if this widget widget has focus, false otherwise
+ * @see GuiDescription#isFocused(WWidget)
+ */
public boolean isFocused() {
if (host==null) return false;
return host.isFocused(this);
}
+ /**
+ * If this widget has a host, requests the focus from the host.
+ *
+ * @see GuiDescription#requestFocus(WWidget)
+ */
public void requestFocus() {
if (host!=null) {
host.requestFocus(this);
} else {
- System.out.println("host is null");
+ LOGGER.warn("Requesting focus for {}, but the host is null", this);
}
}
+ /**
+ * If this widget has a host, releases this widget's focus.
+ *
+ * @see GuiDescription#releaseFocus(WWidget)
+ */
public void releaseFocus() {
if (host!=null) host.releaseFocus(this);
}
+ /**
+ * Tests whether this widget can have the focus in the GUI.
+ *
+ * @return true if this widget can be focused, false otherwise
+ */
public boolean canFocus() {
return false;
}
--
cgit
From 66e331452061d1d102a6db055b7da4638335b06f Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 18:47:56 +0300
Subject: Remove unused StyleEntry class
---
.../io/github/cottonmc/cotton/gui/style/StyleEntry.java | 17 -----------------
1 file changed, 17 deletions(-)
delete mode 100644 src/main/java/io/github/cottonmc/cotton/gui/style/StyleEntry.java
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/style/StyleEntry.java b/src/main/java/io/github/cottonmc/cotton/gui/style/StyleEntry.java
deleted file mode 100644
index e7318a7..0000000
--- a/src/main/java/io/github/cottonmc/cotton/gui/style/StyleEntry.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package io.github.cottonmc.cotton.gui.style;
-
-import java.util.HashMap;
-
-import io.github.cottonmc.cotton.gui.widget.data.Color;
-
-public class StyleEntry {
- private String selector = "*";
- private HashMap customEntries = new HashMap<>();
-
- private Color foreground;
- private Color background;
-
- public Color getForeground() {
- return (foreground!=null) ? foreground : Color.WHITE;
- }
-}
--
cgit
From 319b74a2fb12126dd1906a389fa8c48af0af8d40 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 18:51:04 +0300
Subject: Rename BackgroundPainter.VANILLA_9PATCH to VANILLA, make it the
default
Also added FunctionalInterface to BackgroundPainter.
---
.../cotton/gui/client/BackgroundPainter.java | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java
index 70d8ba4..6badb54 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java
@@ -8,6 +8,7 @@ import net.minecraft.util.Identifier;
* Background painters are used to paint the background of a widget.
* The background painter instance of a widget can be changed to customize the look of a widget.
*/
+@FunctionalInterface
public interface BackgroundPainter {
/**
* Paint the specified panel to the screen.
@@ -17,30 +18,20 @@ public interface BackgroundPainter {
*/
public void paintBackground(int left, int top, WWidget panel);
-
/**
- * The {@code VANILLA} background painter draws a vanilla-like gui panel using {@link ScreenDrawing#drawGuiPanel(int, int, int, int)}.
- *
- * This background painter applies a padding of 8 pixels to all sides around the widget.
- *
- *
This background painter is the default painter for root panels.
- * * You can override {@link io.github.cottonmc.cotton.gui.GuiDescription#addPainters()} to customize the painter yourself.
- */
- public static BackgroundPainter VANILLA = (left, top, panel) -> {
- ScreenDrawing.drawGuiPanel(left-8, top-8, panel.getWidth()+16, panel.getHeight()+16);
- };
-
- /**
- * The {@code VANILLA_9PATCH} background painter draws a vanilla-like gui panel using {@linkplain NinePatch nine-patch textures}.
+ * The {@code VANILLA} background painter draws a vanilla-like gui panel using {@linkplain NinePatch nine-patch textures}.
*
*
This background painter uses {@code libgui:textures/widget/panel_light.png} as the light texture and
* {@code libgui:textures/widget/panel_dark.png} as the dark texture.
*
*
This background painter applies a padding of 8 pixels to all sides around the widget.
*
+ *
This background painter is the default painter for root panels.
+ * * You can override {@link io.github.cottonmc.cotton.gui.GuiDescription#addPainters()} to customize the painter yourself.
+ *
* @since 1.5.0
*/
- public static BackgroundPainter VANILLA_9PATCH = createLightDarkVariants(
+ public static BackgroundPainter VANILLA = createLightDarkVariants(
createNinePatch(new Identifier("libgui", "textures/widget/panel_light.png"), 8),
createNinePatch(new Identifier("libgui", "textures/widget/panel_dark.png"), 8)
);
--
cgit
From c30b2cbc144ca4aa7ee385e0422dadf017d7a916 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 18:55:14 +0300
Subject: Remove deprecated ValidatedSlot methods
---
.../github/cottonmc/cotton/gui/ValidatedSlot.java | 21 ---------------------
1 file changed, 21 deletions(-)
(limited to 'src/main/java/io')
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 2c6b5b2..8a50a45 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
@@ -42,27 +42,6 @@ public class ValidatedSlot extends Slot {
return result;
}
- /**
- * Returns true if the item in this slot can be modified by players.
- *
- * @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 insertingAllowed || takingAllowed;
- }
-
- /**
- * @deprecated Replaced with {@link #setInsertingAllowed(boolean)} and {@link #setTakingAllowed(boolean)}.
- */
- @Deprecated
- public void setModifiable(boolean modifiable) {
- this.insertingAllowed = modifiable;
- this.takingAllowed = modifiable;
- }
-
public int getInventoryIndex() {
return slotNumber;
}
--
cgit
From 49f8daea8780f79ebbec7fec8dacf0dff884329b Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 22:31:54 +0300
Subject: Add documentation for WListPanel constructor
---
src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'src/main/java/io')
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java
index 9416f95..876d43a 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java
@@ -54,6 +54,13 @@ public class WListPanel extends WClippedPanel {
protected WScrollBar scrollBar = new WScrollBar(Axis.VERTICAL);
private int lastScroll = -1;
+ /**
+ * Constructs a list panel.
+ *
+ * @param data the list data
+ * @param supplier the widget supplier that creates unconfigured widgets
+ * @param configurator the widget configurator that configures widgets to display the passed data
+ */
public WListPanel(List data, Supplier supplier, BiConsumer configurator) {
this.data = data;
this.supplier = supplier;
--
cgit
From 8ee43fdb284a4aa2fa3c25d6c7f6694b79ad391c Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 16 May 2020 22:35:15 +0300
Subject: Use logger instead of println in ValidatedSlot, improve ctor param
names
---
.../java/io/github/cottonmc/cotton/gui/ValidatedSlot.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
(limited to 'src/main/java/io')
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 8a50a45..1e9ee3c 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/ValidatedSlot.java
@@ -4,15 +4,18 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
public class ValidatedSlot extends Slot {
+ private static final Logger LOGGER = LogManager.getLogger();
private final int slotNumber;
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!");
+ public ValidatedSlot(Inventory inventory, int index, int x, int y) {
+ super(inventory, index, x, y);
+ if (inventory==null) throw new IllegalArgumentException("Can't make an itemslot from a null inventory!");
this.slotNumber = index;
}
@@ -29,13 +32,13 @@ public class ValidatedSlot extends Slot {
@Override
public ItemStack getStack() {
if (inventory==null) {
- System.out.println("Prevented null-inventory from WItemSlot with slot #: "+slotNumber);
+ LOGGER.warn("Prevented null-inventory from WItemSlot with slot #: {}", slotNumber);
return ItemStack.EMPTY;
}
ItemStack result = super.getStack();
if (result==null) {
- System.out.println("Prevented null-itemstack crash from: "+inventory.getClass().getCanonicalName());
+ LOGGER.warn("Prevented null-itemstack crash from: {}", inventory.getClass().getCanonicalName());
return ItemStack.EMPTY;
}
--
cgit
From 0c90421761cd68f1aef6c1972644cb560509e095 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Tue, 19 May 2020 23:00:31 +0300
Subject: Don't use client-only getStackForRender() in WItem
---
src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'src/main/java/io')
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 ffebe76..2572e83 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
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
@@ -107,7 +108,7 @@ public class WItem extends WWidget {
ImmutableList.Builder builder = ImmutableList.builder();
for (ItemConvertible item : tag.values()) {
- builder.add(item.asItem().getStackForRender());
+ builder.add(new ItemStack(item));
}
return builder.build();
--
cgit