aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-11-26 18:25:29 +0200
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-11-26 18:25:29 +0200
commit50bcec28d59d04b9ec8ceead159df0e7c659491c (patch)
treedb6f7eee1a3d949ee9ae0e15f783d7291df59bc3
parent272837528c7bf23e7e289d46fb4510d06102cca7 (diff)
downloadLibGui-50bcec28d59d04b9ec8ceead159df0e7c659491c.tar.gz
LibGui-50bcec28d59d04b9ec8ceead159df0e7c659491c.tar.bz2
LibGui-50bcec28d59d04b9ec8ceead159df0e7c659491c.zip
Fix compilation issues, add support for tooltip components (also from data and widgets)
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java5
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java6
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java3
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java10
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java5
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java6
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java105
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java3
-rw-r--r--src/main/resources/mixins.libgui.accessors.json1
12 files changed, 126 insertions, 24 deletions
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java
index 69a0640..96ac123 100644
--- a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java
@@ -8,7 +8,6 @@ import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
-import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class GuiBlock extends BlockWithEntity {
@@ -24,8 +23,8 @@ public class GuiBlock extends BlockWithEntity {
}
@Override
- public BlockEntity createBlockEntity(BlockView var1) {
- return new GuiBlockEntity();
+ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
+ return new GuiBlockEntity(pos, state);
}
@Override
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java
index 6a9f741..82188d2 100644
--- a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java
@@ -1,5 +1,6 @@
package io.github.cottonmc.test;
+import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@@ -10,6 +11,7 @@ import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList;
+import net.minecraft.util.math.BlockPos;
import javax.annotation.Nullable;
@@ -18,8 +20,8 @@ public class GuiBlockEntity extends BlockEntity implements ImplementedInventory,
DefaultedList<ItemStack> items = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY);
- public GuiBlockEntity() {
- super(LibGuiTest.GUI_BLOCKENTITY_TYPE);
+ public GuiBlockEntity(BlockPos pos, BlockState state) {
+ super(LibGuiTest.GUI_BLOCKENTITY_TYPE, pos, state);
}
@Override
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java b/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java
index 8b567b7..17bfdaa 100644
--- a/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java
@@ -6,6 +6,7 @@ import java.nio.file.Path;
import java.util.Optional;
import net.fabricmc.api.ModInitializer;
+import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
@@ -35,7 +36,7 @@ public class LibGuiTest implements ModInitializer {
Registry.register(Registry.BLOCK, new Identifier(MODID, "gui"), GUI_BLOCK);
GUI_BLOCK_ITEM = new BlockItem(GUI_BLOCK, new Item.Settings().group(ItemGroup.MISC));
Registry.register(Registry.ITEM, new Identifier(MODID, "gui"), GUI_BLOCK_ITEM);
- GUI_BLOCKENTITY_TYPE = BlockEntityType.Builder.create(GuiBlockEntity::new, GUI_BLOCK).build(null);
+ GUI_BLOCKENTITY_TYPE = FabricBlockEntityTypeBuilder.create(GuiBlockEntity::new, GUI_BLOCK).build(null);
Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MODID, "gui"), GUI_BLOCKENTITY_TYPE);
GUI_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(new Identifier(MODID, "gui"), (int syncId, PlayerInventory inventory) -> {
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
index 85ad3cd..52b0e81 100644
--- a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
@@ -7,6 +7,7 @@ import io.github.cottonmc.cotton.gui.widget.TooltipBuilder;
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
import io.github.cottonmc.cotton.gui.widget.WLabel;
import io.github.cottonmc.cotton.gui.widget.WSlider;
+import io.github.cottonmc.cotton.gui.widget.WSprite;
import io.github.cottonmc.cotton.gui.widget.WTextField;
import io.github.cottonmc.cotton.gui.widget.WTiledSprite;
import io.github.cottonmc.cotton.gui.widget.WWidget;
@@ -19,12 +20,6 @@ import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
public class TestClientGui extends LightweightGuiDescription {
-
- @Environment(EnvType.CLIENT)
- public static final BackgroundPainter PANEL = (x, y, panel)->{
- ScreenDrawing.drawBeveledPanel(x-1, y-1, panel.getWidth()+2, panel.getHeight()+2);
- };
-
//private static final Identifier PORTAL1 = new Identifier("libgui-test:portal.png");
//private static final Identifier PORTAL2 = new Identifier("libgui-test:portal2.png");
@@ -36,10 +31,13 @@ public class TestClientGui extends LightweightGuiDescription {
WGridPanel root = new WGridPanel(22);
this.setRootPanel(root);
WLabel title = new WLabel(new LiteralText("Client Test Gui"), WLabel.DEFAULT_TEXT_COLOR) {
+ private final WWidget tooltipWidget = new WSprite(new Identifier("minecraft", "textures/block/cobblestone.png"));
+
@Environment(EnvType.CLIENT)
@Override
public void addTooltip(TooltipBuilder tooltip) {
tooltip.add(new LiteralText("Radical!"));
+ tooltip.add(tooltipWidget);
}
};
WTiledSprite wood = new WTiledSprite(
diff --git a/gradle.properties b/gradle.properties
index be7ce1c..84be842 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1G
# Dependencies
fabric_version=0.26.4+1.17
jankson_version=3.0.1+j1.2.0
- modmenu_version=1.14.6+build.31
+ modmenu_version=2.0.0-beta.1+build.2
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"
],