diff options
6 files changed, 142 insertions, 27 deletions
diff --git a/gradle.properties b/gradle.properties index f8f383a..e4903dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=20w19a - yarn_mappings=20w19a+build.6 - 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 = 2.0.0 @@ -13,5 +13,5 @@ org.gradle.jvmargs=-Xmx1G archives_base_name = LibGui # Dependencies - fabric_version=0.10.7+build.344-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/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) |