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(-) 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(-) 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(-) 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 ac32967bf67360bab33908ccb54d2d9e947db25d Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sat, 16 May 2020 18:02:48 +0300 Subject: Bump version to 1.11.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3696bf2..0a7e564 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.8.3+build.196 # Mod Properties - mod_version = 1.9.1 + mod_version = 1.11.0 maven_group = io.github.cottonmc archives_base_name = LibGui -- cgit