aboutsummaryrefslogtreecommitdiff
path: root/default-plugin/src/main/java/me/shedaniel/rei/plugin/client
diff options
context:
space:
mode:
Diffstat (limited to 'default-plugin/src/main/java/me/shedaniel/rei/plugin/client')
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java33
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java14
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ReferenceTagNodeWidget.java14
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagNodeWidget.java6
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/TagTreeWidget.java11
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java13
6 files changed, 41 insertions, 50 deletions
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
index 3500f4ce7..6280e533d 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
@@ -26,12 +26,12 @@ package me.shedaniel.rei.plugin.client;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-import dev.architectury.event.EventResult;
-import dev.architectury.networking.NetworkManager;
-import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import it.unimi.dsi.fastutil.objects.ReferenceSet;
+import me.shedaniel.architectury.event.EventResult;
+import me.shedaniel.architectury.mixin.FluidTagsAccessor;
+import me.shedaniel.architectury.networking.NetworkManager;
import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
@@ -86,8 +86,6 @@ import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
-import net.minecraft.tags.Tag;
-import net.minecraft.tags.TagCollection;
import net.minecraft.world.item.*;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
@@ -213,7 +211,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
}
private static EntryIngredient getTag(ResourceLocation tagId) {
- return EntryIngredients.ofItemTag(TagKey.create(Registry.ITEM_REGISTRY, tagId));
+ return EntryIngredients.ofItemTag(tagId);
}
@Override
@@ -229,17 +227,6 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
registry.registerRecipeFiller(UpgradeRecipe.class, RecipeType.SMITHING, DefaultSmithingDisplay::new);
registry.registerFiller(AnvilRecipe.class, DefaultAnvilDisplay::new);
registry.registerFiller(BrewingRecipe.class, DefaultBrewingDisplay::new);
- registry.registerFiller(TagKey.class, tagKey -> {
- if (tagKey.isFor(Registry.ITEM_REGISTRY)) {
- return DefaultTagDisplay.ofItems(tagKey);
- } else if (tagKey.isFor(Registry.BLOCK_REGISTRY)) {
- return DefaultTagDisplay.ofItems(tagKey);
- } else if (tagKey.isFor(Registry.FLUID_REGISTRY)) {
- return DefaultTagDisplay.ofFluids(tagKey);
- }
-
- return null;
- });
for (Map.Entry<Item, Integer> entry : AbstractFurnaceBlockEntity.getFuel().entrySet()) {
registry.add(new DefaultFuelDisplay(Collections.singletonList(EntryIngredients.of(entry.getKey())), Collections.emptyList(), entry.getValue()));
}
@@ -277,7 +264,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
DummyShovelItem.getPathBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> {
registry.add(new DefaultPathingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue().getBlock())));
});
- registry.add(new DefaultBeaconBaseDisplay(Collections.singletonList(EntryIngredients.ofItemTag(BlockTags.BEACON_BASE_BLOCKS)), Collections.emptyList()));
+ registry.add(new DefaultBeaconBaseDisplay(Collections.singletonList(EntryIngredients.ofBlockTag(BlockTags.BEACON_BASE_BLOCKS)), Collections.emptyList()));
registry.add(new DefaultBeaconPaymentDisplay(Collections.singletonList(EntryIngredients.ofItemTag(ItemTags.BEACON_PAYMENT_ITEMS)), Collections.emptyList()));
if (Platform.isFabric()) {
Set<Potion> potions = Sets.newLinkedHashSet();
@@ -312,8 +299,14 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
registerForgePotions(registry, this);
}
- for (Registry<?> reg : Registry.REGISTRY) {
- reg.getTags().forEach(tagPair -> registry.add(tagPair.getFirst()));
+ for (ResourceLocation tag : ItemTags.getAllTags().getAvailableTags()) {
+ registry.add(DefaultTagDisplay.ofItems(tag));
+ }
+ for (ResourceLocation tag : BlockTags.getAllTags().getAvailableTags()) {
+ registry.add(DefaultTagDisplay.ofBlocks(tag));
+ }
+ for (ResourceLocation tag : FluidTagsAccessor.getHelper().getAllTags().getAvailableTags()) {
+ registry.add(DefaultTagDisplay.ofFluids(tag));
}
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java
index d0312275b..eb5a1fed2 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java
@@ -46,7 +46,6 @@ import me.shedaniel.rei.plugin.common.displays.tag.TagNode;
import me.shedaniel.rei.plugin.common.displays.tag.TagNodes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
-import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
@@ -56,6 +55,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import java.util.function.Function;
public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, ?>> {
@@ -123,7 +123,7 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?,
TagNode<?>[] tagNode = new TagNode[]{null};
widgets.add(Widgets.withTranslate(Widgets.delegateWithBounds(() -> delegate[0]), 0, 0, 20));
- TagNodes.create(display.getKey(), dataResult -> {
+ TagNodes.create(display.getTagCollectionId(), display.getTagCollection(), display.getRegistry(), display.getKey(), dataResult -> {
if (dataResult.error().isPresent()) {
delegate[0] = Widgets.withBounds(Widgets.concat(
Widgets.createLabel(new Point(innerBounds.getCenterX(), innerBounds.getCenterY() - 8), new TextComponent("Failed to resolve tags!")),
@@ -132,9 +132,9 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?,
} else {
tagNode[0] = dataResult.result().get();
//noinspection rawtypes
- Function<? extends Holder<?>, ? extends EntryStack<?>> displayMapper = display.getMapper();
- Function<Holder<?>, EntryStack<?>> mapper = holder -> {
- EntryStack<?> stack = ((Function<Holder<?>, EntryStack<?>>) displayMapper).apply(holder);
+ Function<?, ? extends EntryStack<?>> displayMapper = display.getMapper();
+ Function<?, EntryStack<?>> mapper = value -> {
+ EntryStack<?> stack = ((Function<Object, EntryStack<?>>) displayMapper).apply(value);
if (stack.isEmpty()) {
return ClientEntryStacks.of(new AbstractRenderer() {
@Override
@@ -149,13 +149,13 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?,
@Override
@Nullable
public Tooltip getTooltip(TooltipContext context) {
- return Tooltip.create(context.getPoint(), new TextComponent(holder.unwrapKey().map(key -> key.location().toString()).orElse("null")));
+ return Tooltip.create(context.getPoint(), new TextComponent(Optional.ofNullable(stack.getIdentifier()).map(ResourceLocation::toString).orElse("null")));
}
});
}
return stack;
};
- delegate[0] = Widgets.overflowed(overflowBounds, Widgets.padded(16, new TagTreeWidget(tagNode[0], mapper, overflowBounds)));
+ delegate[0] = Widgets.overflowed(overflowBounds, Widgets.padded(16, new TagTreeWidget(display.getTagCollection(), tagNode[0], mapper, overflowBounds)));
}
});
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 337814c9e..70350b2b1 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
@@ -23,7 +23,6 @@
package me.shedaniel.rei.plugin.client.categories.tag;
-import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.widgets.Slot;
@@ -33,11 +32,11 @@ 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.Minecraft;
import net.minecraft.client.gui.components.events.GuiEventListener;
-import net.minecraft.client.renderer.GameRenderer;
-import net.minecraft.core.Holder;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.TagCollection;
import java.util.Collections;
import java.util.List;
@@ -50,7 +49,7 @@ public class ReferenceTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
private final Slot slot;
private final List<? extends GuiEventListener> children;
- public ReferenceTagNodeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) {
+ public ReferenceTagNodeWidget(TagCollection<S> tagCollection, TagNode<S> node, Function<S, EntryStack<T>> mapper, Rectangle overflowBounds) {
this.node = node;
this.overflowBounds = overflowBounds;
this.bounds = new Rectangle(0, 0, 24, 23);
@@ -58,7 +57,7 @@ public class ReferenceTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
.disableBackground()
.disableHighlight()
.disableTooltips()
- .entries(EntryIngredients.ofTag(node.getReference(), mapper));
+ .entries(EntryIngredients.ofTag(tagCollection, node.getReference(), mapper));
this.children = Collections.singletonList(this.slot);
}
@@ -70,13 +69,12 @@ public class ReferenceTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
@Override
public void render(PoseStack poses, int mouseX, int mouseY, float delta) {
if (this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), getBounds()))) {
- RenderSystem.setShader(GameRenderer::getPositionTexShader);
- RenderSystem.setShaderTexture(0, new ResourceLocation("textures/gui/advancements/widgets.png"));
+ Minecraft.getInstance().getTextureManager().bind(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(new TextComponent("#" + this.node.getReference().location().toString())).queue();
+ Tooltip.create(new TextComponent("#" + this.node.getReference().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 c1003e63c..b5fa00cb2 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
@@ -27,14 +27,14 @@ 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;
-import net.minecraft.core.Holder;
+import net.minecraft.tags.TagCollection;
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, Rectangle overflowBounds) {
+ static <S, T> TagNodeWidget<S, T> create(TagCollection<S> tagCollection, TagNode<S> node, Function<S, EntryStack<T>> mapper, Rectangle overflowBounds) {
if (node.getReference() != null) {
- return new ReferenceTagNodeWidget<>(node, mapper, overflowBounds);
+ return new ReferenceTagNodeWidget<>(tagCollection, node, mapper, overflowBounds);
} else if (node.getValue() != null) {
return new ValueTagNodeWidget<>(node, mapper, overflowBounds);
} else {
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 3733fbedf..cccfadb3d 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
@@ -30,11 +30,12 @@ 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;
-import net.minecraft.core.Holder;
+import net.minecraft.tags.TagCollection;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
public class TagTreeWidget<S, T> extends WidgetWithBounds {
@@ -45,13 +46,13 @@ public class TagTreeWidget<S, T> extends WidgetWithBounds {
private final List<TagTreeWidget<S, T>> childWidgets;
private final List<WidgetWithBounds> children;
- public TagTreeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) {
+ public TagTreeWidget(TagCollection<S> tagCollection, TagNode<S> node, Function<S, EntryStack<T>> mapper, Rectangle overflowBounds) {
this.node = node;
this.overflowBounds = overflowBounds;
- this.rootWidget = TagNodeWidget.create(node, mapper, overflowBounds);
+ this.rootWidget = TagNodeWidget.create(tagCollection, node, mapper, overflowBounds);
this.childWidgets = new ArrayList<>();
for (TagNode<S> childNode : node.children()) {
- TagTreeWidget<S, T> childWidget = new TagTreeWidget<>(childNode, mapper, overflowBounds);
+ TagTreeWidget<S, T> childWidget = new TagTreeWidget<>(tagCollection, childNode, mapper, overflowBounds);
childWidget.getBounds().y = rootWidget.getBounds().getMaxY() + 16;
this.childWidgets.add(childWidget);
}
@@ -61,7 +62,7 @@ public class TagTreeWidget<S, T> extends WidgetWithBounds {
childWidget.getBounds().x = rootWidget.getBounds().getCenterX() - childrenTotalWidth / 2 + x;
x += childWidget.getBounds().width + 6;
}
- this.children = Stream.concat(Stream.of(this.rootWidget), this.childWidgets.stream()).toList();
+ this.children = Stream.concat(Stream.of(this.rootWidget), this.childWidgets.stream()).collect(Collectors.toList());
this.bounds = new Rectangle(this.children.stream()
.map(WidgetWithBounds::getBounds)
.reduce(Rectangle::union)
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 f2daae995..214ec9a37 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
@@ -33,10 +33,9 @@ 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;
-import net.minecraft.core.Holder;
-import net.minecraft.core.HolderSet;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
@@ -48,9 +47,9 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
private final List<? extends GuiEventListener> children;
private final Rectangle overflowBounds;
- public ValueTagNodeWidget(TagNode<S> node, Function<Holder<S>, EntryStack<T>> mapper, Rectangle overflowBounds) {
+ public ValueTagNodeWidget(TagNode<S> node, Function<S, EntryStack<T>> mapper, Rectangle overflowBounds) {
this.overflowBounds = overflowBounds;
- HolderSet<S> holders = node.getValue();
+ Collection<S> holders = node.getValue();
int width = Math.min(4, holders.size());
int height = Math.max((int) Math.ceil(holders.size() * 1.0 / width), 1);
this.bounds = new Rectangle(0, 0, 16 * width + 12, 16 * height + 12);
@@ -61,7 +60,7 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
this.widgets = new ArrayList<>();
this.widgets.add(background);
this.widgets.add(slotBackground);
- for (Holder<S> holder : holders) {
+ for (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))
@@ -88,8 +87,8 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> {
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()))) {
+ if (!(widget instanceof WidgetWithBounds) ||
+ this.overflowBounds.intersects(MatrixUtils.transform(poses.last().pose(), ((WidgetWithBounds) widget).getBounds()))) {
widget.render(poses, mouse.x, mouse.y, delta);
}
}