From 3ecfadc3ab1ad336438a8079b64b0a2bdc72a5a7 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> 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