diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-11-26 18:25:29 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-11-26 18:25:29 +0200 |
commit | 50bcec28d59d04b9ec8ceead159df0e7c659491c (patch) | |
tree | db6f7eee1a3d949ee9ae0e15f783d7291df59bc3 /src | |
parent | 272837528c7bf23e7e289d46fb4510d06102cca7 (diff) | |
download | LibGui-50bcec28d59d04b9ec8ceead159df0e7c659491c.tar.gz LibGui-50bcec28d59d04b9ec8ceead159df0e7c659491c.tar.bz2 LibGui-50bcec28d59d04b9ec8ceead159df0e7c659491c.zip |
Fix compilation issues, add support for tooltip components (also from data and widgets)
Diffstat (limited to 'src')
7 files changed, 113 insertions, 11 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java index f7803f6..293852d 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -158,7 +158,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio /** WILL MODIFY toInsert! Returns true if anything was inserted. */ private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) { ItemStack curSlotStack = slot.getStack(); - if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack) && slot.canInsert(toInsert)) { + if (!curSlotStack.isEmpty() && ItemStack.method_31577(toInsert, curSlotStack) && slot.canInsert(toInsert)) { int combinedAmount = curSlotStack.getCount() + toInsert.getCount(); int maxAmount = Math.min(toInsert.getMaxCount(), slot.getMaxItemCount()); if (combinedAmount <= maxAmount) { 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 6ae53d0..6b21af7 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 @@ -42,7 +42,7 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl * @param title the screen title */ public CottonInventoryScreen(T description, PlayerEntity player, Text title) { - super(description, player.inventory, title); + super(description, player.getInventory(), title); this.description = description; width = 18*9; height = 18*9; 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 f31a046..daaaf2f 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 @@ -5,6 +5,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; @@ -131,7 +132,7 @@ public class ScreenDrawing { RenderSystem.enableBlend(); //GlStateManager.disableTexture2D(); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); - buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE); //I thought GL_QUADS was deprecated but okay, sure. + buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE); //I thought GL_QUADS was deprecated but okay, sure. buffer.vertex(x, y + height, 0).color(r, g, b, opacity).texture(u1, v2).next(); buffer.vertex(x + width, y + height, 0).color(r, g, b, opacity).texture(u2, v2).next(); buffer.vertex(x + width, y, 0).color(r, g, b, opacity).texture(u2, v1).next(); @@ -191,7 +192,7 @@ public class ScreenDrawing { RenderSystem.enableBlend(); RenderSystem.disableTexture(); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); - buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR); //I thought GL_QUADS was deprecated but okay, sure. + buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); //I thought GL_QUADS was deprecated but okay, sure. buffer.vertex(left, top + height, 0.0D).color(r, g, b, a).next(); buffer.vertex(left + width, top + height, 0.0D).color(r, g, b, a).next(); buffer.vertex(left + width, top, 0.0D).color(r, g, b, a).next(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java index e7c7ece..bf9d7b3 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java @@ -8,12 +8,6 @@ import io.github.prospector.modmenu.api.ConfigScreenFactory; import io.github.prospector.modmenu.api.ModMenuApi; public class ModMenuSupport implements ModMenuApi { - - @Override - public String getModId() { - return LibGuiClient.MODID; - } - @Override public ConfigScreenFactory<?> getModConfigScreenFactory() { return screen -> new CottonClientScreen(new TranslatableText("options.libgui.libgui_settings"), new ConfigGui(screen)) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java index 4997bb2..05c5c02 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java @@ -2,12 +2,19 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.tooltip.TooltipComponent; +import net.minecraft.client.item.TooltipData; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.texture.TextureManager; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * A builder for widget tooltips. @@ -27,8 +34,10 @@ public final class TooltipBuilder { * * @param lines the lines * @return this builder + * @throws NullPointerException if the lines are null */ public TooltipBuilder add(Text... lines) { + Objects.requireNonNull(lines, "lines"); for (Text line : lines) { components.add(TooltipComponent.createOrderedTextTooltipComponent(line.asOrderedText())); } @@ -41,12 +50,108 @@ public final class TooltipBuilder { * * @param lines the lines * @return this builder + * @throws NullPointerException if the lines are null */ public TooltipBuilder add(OrderedText... lines) { + Objects.requireNonNull(lines, "lines"); for (OrderedText line : lines) { components.add(TooltipComponent.createOrderedTextTooltipComponent(line)); } return this; } + + /** + * Adds the components to this builder. + * + * @param components the components + * @return this builder + * @throws NullPointerException if the components are null + * @since 4.0.0 + */ + public TooltipBuilder add(TooltipComponent... components) { + Objects.requireNonNull(components, "components"); + this.components.addAll(Arrays.asList(components)); + + return this; + } + + /** + * Adds a tooltip component created from tooltip data to this builder. + * + * @param tooltipData the data + * @return this builder + * @throws NullPointerException if the data is null + * @since 4.0.0 + */ + public TooltipBuilder add(TooltipData tooltipData) { + Objects.requireNonNull(tooltipData, "tooltipData"); + components.add(TooltipComponent.createTooltipComponent(tooltipData)); + + return this; + } + + /** + * Adds the widget to this builder. + * + * <p>Tooltip widgets should usually be cached inside the widget they are created in. + * + * @param widget the widget + * @return this builder + * @throws NullPointerException if the widget is null + * @since 4.0.0 + */ + public TooltipBuilder add(WWidget widget) { + Objects.requireNonNull(widget, "widget"); + components.add(new WidgetTooltipComponent(widget)); + + return this; + } + + /** + * Adds the widget to this builder and resizes it if resizeable. + * + * <p>Tooltip widgets should usually be cached inside the widget they are created in. + * + * @param widget the widget + * @param width the new width + * @param height the new height + * @return this builder + * @throws NullPointerException if the widget is null + * @since 4.0.0 + */ + public TooltipBuilder add(WWidget widget, int width, int height) { + Objects.requireNonNull(widget, "widget"); + components.add(new WidgetTooltipComponent(widget)); + + if (widget.canResize()) { + widget.setSize(width, height); + } + + return this; + } + + private static class WidgetTooltipComponent implements TooltipComponent { + private final WWidget widget; + + WidgetTooltipComponent(WWidget widget) { + this.widget = widget; + } + + @Override + public int getWidth(TextRenderer textRenderer) { + return widget.getWidth(); + } + + @Override + public int getHeight() { + return widget.getHeight(); + } + + @Override + public void drawItems(TextRenderer textRenderer, int x, int y, MatrixStack matrices, ItemRenderer itemRenderer, int z, TextureManager textureManager) { + widget.paint(matrices, x, y, /* mouse coords: nowhere in sight */ -x, -y); + widget.tick(); // Screens are ticked every time they're rendered, so why not tooltip widgets? + } + } } 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 8ff03cf..9ea064f 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 @@ -9,6 +9,7 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.LiteralText; @@ -407,7 +408,7 @@ public class WTextField extends WWidget { RenderSystem.disableTexture(); RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); - bufferBuilder_1.begin(GL11.GL_QUADS, VertexFormats.POSITION); + bufferBuilder_1.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); bufferBuilder_1.vertex(x, y+height, 0.0D).next(); bufferBuilder_1.vertex(x+width, y+height, 0.0D).next(); bufferBuilder_1.vertex(x+width, y, 0.0D).next(); diff --git a/src/main/resources/mixins.libgui.accessors.json b/src/main/resources/mixins.libgui.accessors.json index 9ec55f2..03d0946 100644 --- a/src/main/resources/mixins.libgui.accessors.json +++ b/src/main/resources/mixins.libgui.accessors.json @@ -5,6 +5,7 @@ "required": true, "mixins": [ + "ScreenAccessor", "SlotAccessor" ], |