aboutsummaryrefslogtreecommitdiff
path: root/default-plugin
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-07-06 17:34:35 +0800
committershedaniel <daniel@shedaniel.me>2022-07-06 17:38:32 +0800
commitcef0556a9fd2fb145e1d33102d5f3fc89781db26 (patch)
tree8e2ba23f2e68ea418c6db38c95982bda74b6d301 /default-plugin
parent132818b186c11339f3ae7b73aab209ec85329293 (diff)
downloadRoughlyEnoughItems-cef0556a9fd2fb145e1d33102d5f3fc89781db26.tar.gz
RoughlyEnoughItems-cef0556a9fd2fb145e1d33102d5f3fc89781db26.tar.bz2
RoughlyEnoughItems-cef0556a9fd2fb145e1d33102d5f3fc89781db26.zip
Fix #963
Diffstat (limited to 'default-plugin')
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java19
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java7
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java14
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreesWidget.java48
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java33
5 files changed, 49 insertions, 72 deletions
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java
index 06a8267c3..5418e895d 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java
@@ -29,6 +29,7 @@ import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.Slot;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
+import me.shedaniel.rei.api.client.util.MatrixUtils;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.plugin.common.displays.tag.TagNode;
@@ -44,12 +45,14 @@ import java.util.function.Function;
public class ReferenceTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
private final TagNode<S> node;
+ private final Rectangle overflowBounds;
private final Rectangle bounds;
private final Slot slot;
private final List<? extends GuiEventListener> children;
- public ReferenceTagNodeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper) {
+ public ReferenceTagNodeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) {
this.node = node;
+ this.overflowBounds = overflowBounds;
this.bounds = new Rectangle(0, 0, 24, 23);
this.slot = Widgets.createSlot(new Rectangle(0, 0, 18, 18))
.disableBackground()
@@ -66,13 +69,15 @@ public class ReferenceTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
@Override
public void render(PoseStack poses, int mouseX, int mouseY, float delta) {
- RenderSystem.setShader(GameRenderer::getPositionTexShader);
- RenderSystem.setShaderTexture(0, new ResourceLocation("textures/gui/advancements/widgets.png"));
- this.blit(poses, bounds.x, bounds.y, 1, 128 + 27, 24, 24);
- this.slot.getBounds().setLocation(bounds.getCenterX() - this.slot.getBounds().getWidth() / 2, bounds.y + (bounds.height - this.slot.getBounds().getHeight()) / 2 + 1);
- this.slot.render(poses, mouseX, mouseY, delta);
- if (this.containsMouse(mouseX, mouseY)) {
+ if (this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), getBounds()))) {
+ RenderSystem.setShader(GameRenderer::getPositionTexShader);
+ RenderSystem.setShaderTexture(0, new ResourceLocation("textures/gui/advancements/widgets.png"));
+ this.blit(poses, bounds.x, bounds.y, 1, 128 + 27, 24, 24);
+ this.slot.getBounds().setLocation(bounds.getCenterX() - this.slot.getBounds().getWidth() / 2, bounds.y + (bounds.height - this.slot.getBounds().getHeight()) / 2 + 1);
+ this.slot.render(poses, mouseX, mouseY, delta);
+ if (this.containsMouse(mouseX, mouseY)) {
Tooltip.create(Component.literal("#" + this.node.getReference().location().toString())).queue();
+ }
}
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java
index 9f2216935..9fbd7734b 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.plugin.client.categories.tag;
+import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.plugin.common.displays.tag.TagNode;
@@ -31,11 +32,11 @@ import net.minecraft.core.Holder;
import java.util.function.Function;
public abstract class TagNodeWidget<S, T> extends WidgetWithBounds {
- static <S, T> TagNodeWidget<S, T> create(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper) {
+ static <S, T> TagNodeWidget<S, T> create(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) {
if (node.getReference() != null) {
- return new ReferenceTagNodeWidget<>(node, mapper);
+ return new ReferenceTagNodeWidget<>(node, mapper, overflowBounds);
} else if (node.getValue() != null) {
- return new ValueTagNodeWidget<>(node, mapper);
+ return new ValueTagNodeWidget<>(node, mapper, overflowBounds);
} else {
throw new IllegalArgumentException("TagNode has no value or reference");
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java
index f544d4d7f..6a8e6affa 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java
@@ -24,9 +24,9 @@
package me.shedaniel.rei.plugin.client.categories.tag;
import com.mojang.blaze3d.vertex.PoseStack;
-import me.shedaniel.math.Color;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
+import me.shedaniel.rei.api.client.util.MatrixUtils;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.plugin.common.displays.tag.TagNode;
import net.minecraft.client.gui.components.events.GuiEventListener;
@@ -40,16 +40,18 @@ import java.util.stream.Stream;
public class TagTreeWidget<S, T> extends WidgetWithBounds {
private final Rectangle bounds;
private final TagNode<S> node;
+ private final Rectangle overflowBounds;
private final TagNodeWidget<S, T> rootWidget;
private final List<TagTreeWidget<S, T>> childWidgets;
private final List<WidgetWithBounds> children;
- public TagTreeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper) {
+ public TagTreeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) {
this.node = node;
- this.rootWidget = TagNodeWidget.create(node, mapper);
+ this.overflowBounds = overflowBounds;
+ this.rootWidget = TagNodeWidget.create(node, mapper, overflowBounds);
this.childWidgets = new ArrayList<>();
for (TagNode<S> childNode : node.children()) {
- TagTreeWidget<S, T> childWidget = new TagTreeWidget<>(childNode, mapper);
+ TagTreeWidget<S, T> childWidget = new TagTreeWidget<>(childNode, mapper, overflowBounds);
childWidget.getBounds().y = rootWidget.getBounds().getMaxY() + 16;
this.childWidgets.add(childWidget);
}
@@ -89,7 +91,9 @@ public class TagTreeWidget<S, T> extends WidgetWithBounds {
rootWidget.getBounds().getMaxY() + 6, rootWidget.getBounds().getMaxY() + 16, 0xFFFFFFFF);
childWidget.getBounds().setLocation(getBounds().getCenterX() - childrenTotalWidth / 2 + x,
this.rootWidget.getBounds().getMaxY() + 16);
- childWidget.render(poses, mouseX, mouseY, delta);
+ if (this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), childWidget.getBounds()))) {
+ childWidget.render(poses, mouseX, mouseY, delta);
+ }
x += childWidget.getBounds().width + 6;
}
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreesWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreesWidget.java
deleted file mode 100644
index bfa0a0e56..000000000
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreesWidget.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * This file is licensed under the MIT License, part of Roughly Enough Items.
- * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package me.shedaniel.rei.plugin.client.categories.tag;
-
-import com.mojang.blaze3d.vertex.PoseStack;
-import me.shedaniel.math.Rectangle;
-import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
-import net.minecraft.client.gui.components.events.GuiEventListener;
-
-import java.util.List;
-
-public class TagTreesWidget extends WidgetWithBounds {
- @Override
- public Rectangle getBounds() {
- return null;
- }
-
- @Override
- public void render(PoseStack poses, int mouseX, int mouseY, float delta) {
-
- }
-
- @Override
- public List<? extends GuiEventListener> children() {
- return null;
- }
-}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java
index e0d91e258..5936e1842 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java
@@ -26,15 +26,15 @@ package me.shedaniel.rei.plugin.client.categories.tag;
import com.google.common.base.Predicates;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
+import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.*;
+import me.shedaniel.rei.api.client.util.MatrixUtils;
import me.shedaniel.rei.api.common.entry.EntryStack;
-import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.plugin.common.displays.tag.TagNode;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
-import net.minecraft.util.Mth;
import java.util.ArrayList;
import java.util.Collections;
@@ -43,10 +43,13 @@ import java.util.function.Function;
public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
private final Rectangle bounds;
+ private final List<Widget> widgets;
private final WidgetWithBounds widget;
private final List<? extends GuiEventListener> children;
+ private final Rectangle overflowBounds;
- public ValueTagNodeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper) {
+ public ValueTagNodeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) {
+ this.overflowBounds = overflowBounds;
HolderSet<S> holders = node.getValue();
int width = Math.min(4, holders.size());
int height = Math.max((int) Math.ceil(holders.size() * 1.0 / width), 1);
@@ -55,19 +58,19 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
.rendering(Predicates.alwaysTrue());
Panel slotBackground = Widgets.createSlotBase(new Rectangle(5, 5, 16 * width + 2, 16 * height + 2));
int i = 0;
- List<Widget> widgets = new ArrayList<>();
- widgets.add(background);
- widgets.add(slotBackground);
+ this.widgets = new ArrayList<>();
+ this.widgets.add(background);
+ this.widgets.add(slotBackground);
for (Holder<S> holder : holders) {
int x = i % width;
int y = i / width;
Slot slot = Widgets.createSlot(new Rectangle(x * 16 + 5, y * 16 + 5, 18, 18))
.entry(mapper.apply(holder))
.disableBackground();
- widgets.add(slot);
+ this.widgets.add(slot);
i++;
}
- this.widget = Widgets.withTranslate(Widgets.concat(widgets),
+ this.widget = Widgets.withTranslate(Widgets.concat(this.widgets),
$ -> Matrix4f.createTranslateMatrix(getBounds().x, getBounds().y, 0));
this.children = Collections.singletonList(this.widget);
}
@@ -79,7 +82,19 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
@Override
public void render(PoseStack poses, int mouseX, int mouseY, float delta) {
- this.widget.render(poses, mouseX, mouseY, delta);
+ Rectangle bounds = getBounds();
+ if (this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), bounds))) {
+ poses.pushPose();
+ poses.translate(bounds.x, bounds.y, 0);
+ Point mouse = new Point(mouseX - bounds.x, mouseY - bounds.y);
+ for (Widget widget : this.widgets) {
+ if (!(widget instanceof WidgetWithBounds withBounds) ||
+ this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), withBounds.getBounds()))) {
+ widget.render(poses, mouse.x, mouse.y, delta);
+ }
+ }
+ poses.popPose();
+ }
}
@Override