aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/plugin')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/HideIngredientsFromTagsPlugin.java48
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/InputMethodWatcher.java5
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java3
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java27
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java5
7 files changed, 77 insertions, 19 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java
index 7cb913ada..b0d66877a 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java
@@ -26,7 +26,7 @@ package me.shedaniel.rei.plugin.client;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Lifecycle;
-import dev.architectury.platform.Platform;
+import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.RoughlyEnoughItemsCoreClient;
@@ -65,8 +65,10 @@ import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryListener;
import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper;
import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler;
+import me.shedaniel.rei.plugin.client.runtime.InputMethodWatcher;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.TextComponent;
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/HideIngredientsFromTagsPlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/HideIngredientsFromTagsPlugin.java
index 8fc6dbe70..a32b2bb51 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/HideIngredientsFromTagsPlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/HideIngredientsFromTagsPlugin.java
@@ -38,16 +38,15 @@ import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.common.InternalLogger;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
-import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
-import net.minecraft.tags.TagKey;
import org.jetbrains.annotations.ApiStatus;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Objects;
/**
* A plugin to hide any ingredients from the <code>c:hidden_from_recipe_viewers</code> tag.
@@ -103,7 +102,44 @@ public class HideIngredientsFromTagsPlugin implements REIClientPlugin {
private Cache cache;
- private record Cache(EntryIngredient ingredient, LongSet hashes) {}
+ private static final class Cache {
+ private final EntryIngredient ingredient;
+ private final LongSet hashes;
+
+ private Cache(EntryIngredient ingredient, LongSet hashes) {
+ this.ingredient = ingredient;
+ this.hashes = hashes;
+ }
+
+ public EntryIngredient ingredient() {
+ return ingredient;
+ }
+
+ public LongSet hashes() {
+ return hashes;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) return true;
+ if (obj == null || obj.getClass() != this.getClass()) return false;
+ Cache that = (Cache) obj;
+ return Objects.equals(this.ingredient, that.ingredient) &&
+ Objects.equals(this.hashes, that.hashes);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ingredient, hashes);
+ }
+
+ @Override
+ public String toString() {
+ return "Cache[" +
+ "ingredient=" + ingredient + ", " +
+ "hashes=" + hashes + ']';
+ }
+ }
@Override
public FilteringRuleType<? extends FilteringRule<HideTagsFilteringRule.Cache>> getType() {
@@ -114,9 +150,9 @@ public class HideIngredientsFromTagsPlugin implements REIClientPlugin {
public Cache prepareCache(boolean async) {
try {
EntryIngredient ingredient = EntryIngredient.builder()
- .addAll(EntryIngredients.ofItemTag(TagKey.create(Registry.ITEM_REGISTRY, HIDDEN_TAG)))
- .addAll(EntryIngredients.ofItemTag(TagKey.create(Registry.BLOCK_REGISTRY, HIDDEN_TAG)))
- .addAll(EntryIngredients.ofFluidTag(TagKey.create(Registry.FLUID_REGISTRY, HIDDEN_TAG)))
+ .addAll(EntryIngredients.ofItemTag(HIDDEN_TAG))
+ .addAll(EntryIngredients.ofBlockTag(HIDDEN_TAG))
+ .addAll(EntryIngredients.ofFluidTag(HIDDEN_TAG))
.build();
LongSet hashes = new LongOpenHashSet();
for (EntryStack<?> stack : ingredient) {
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/InputMethodWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/InputMethodWatcher.java
index 1f6c9d4e4..d4a153fe6 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/InputMethodWatcher.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/InputMethodWatcher.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.plugin.client.runtime;
+import com.google.common.collect.ImmutableList;
import me.shedaniel.math.Color;
import me.shedaniel.math.Point;
import me.shedaniel.rei.api.client.config.ConfigManager;
@@ -71,7 +72,7 @@ public class InputMethodWatcher implements HintProvider {
}
}
if (match > 0) {
- return List.of(new TranslatableComponent("text.rei.input.methods.hint"),
+ return ImmutableList.of(new TranslatableComponent("text.rei.input.methods.hint"),
new TextComponent(" "), component);
}
}
@@ -92,7 +93,7 @@ public class InputMethodWatcher implements HintProvider {
@Override
public List<HintButton> getButtons() {
- return List.of(
+ return ImmutableList.of(
new HintButton(new TranslatableComponent("text.rei.hint.configure"), bounds -> {
MenuAccess access = ScreenOverlayImpl.getInstance().menuAccess();
access.openOrClose(CraftableFilterButtonWidget.FILTER_MENU_UUID, bounds.clone(),
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java
index 61b8a5db2..3fa092de1 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java
@@ -34,6 +34,7 @@ import me.shedaniel.rei.impl.client.search.argument.ArgumentCache;
import net.minecraft.Util;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.MutablePair;
import org.jetbrains.annotations.Nullable;
@@ -54,7 +55,7 @@ public class SearchFilterPrepareWatcher implements HintProvider {
if (Util.getEpochMillis() - cache.prepareStart < 100) return Collections.emptyList();
int prepareStageCurrent = cache.currentStep.step;
int prepareStageTotal = cache.currentStep.totalSteps;
- ArgumentCache.CurrentStep.Step currentStage = ArrayUtils.get(cache.currentStep.steps, prepareStageCurrent - 1);
+ ArgumentCache.CurrentStep.Step currentStage = prepareStageCurrent - 1 >= 0 && prepareStageCurrent - 1 < cache.currentStep.steps.length ? cache.currentStep.steps[prepareStageCurrent - 1] : null;
int currentStageCurrent = currentStage == null ? 0 : currentStage.stacks;
int currentStageTotal = currentStage == null ? 0 : currentStage.totalStacks;
double prepareStageProgress = prepareStageTotal == 0 ? 0 : prepareStageCurrent / (double) prepareStageTotal;
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java
index 4bb86ee53..0fc9ac881 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java
@@ -156,7 +156,9 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS
@Nullable
@Override
public FluidStack add(FluidStack o1, FluidStack o2) {
- return o1.copyWithAmount(o1.getAmount() + o2.getAmount());
+ FluidStack copy = o1.copy();
+ copy.setAmount(o1.getAmount().add(o2.getAmount()));
+ return copy;
}
@Override
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
index 7a2d1ffa5..6d24e61de 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
@@ -23,6 +23,7 @@
package me.shedaniel.rei.plugin.client.entry;
+import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Lighting;
@@ -30,9 +31,9 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import it.unimi.dsi.fastutil.objects.ReferenceSet;
+import me.shedaniel.architectury.hooks.ItemStackHooks;
import me.shedaniel.architectury.utils.Env;
import me.shedaniel.architectury.utils.EnvExecutor;
-import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.entry.renderer.AbstractEntryRenderer;
import me.shedaniel.rei.api.client.entry.renderer.BatchedEntryRenderer;
@@ -67,11 +68,10 @@ import net.minecraft.tags.TagContainer;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.level.block.Block;
import org.jetbrains.annotations.Nullable;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySerializer<ItemStack> {
@Environment(EnvType.CLIENT)
@@ -218,8 +218,23 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer
@Override
public Collection<ResourceLocation> getTagsFor(TagContainer tagContainer, EntryStack<ItemStack> entry, ItemStack value) {
TagCollection<Item> collection = tagContainer.getItems();
- dwadada
- return collection == null ? Collections.emptyList() : collection.getMatchingTags(value.getItem());
+ Collection<ResourceLocation> itemTags = collection == null ? Collections.emptyList() : collection.getMatchingTags(value.getItem());
+ if (value.getItem() instanceof BlockItem) {
+ TagCollection<Block> blocks = tagContainer.getBlocks();
+ Collection<ResourceLocation> blockTags = blocks == null ? Collections.emptyList() : blocks.getMatchingTags(((BlockItem) value.getItem()).getBlock());
+ return new AbstractCollection<ResourceLocation>() {
+ @Override
+ public Iterator<ResourceLocation> iterator() {
+ return Iterators.concat(itemTags.iterator(), blockTags.iterator());
+ }
+
+ @Override
+ public int size() {
+ return itemTags.size() + blockTags.size();
+ }
+ };
+ }
+ return itemTags;
}
@Environment(EnvType.CLIENT)
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java
index 2b3bfb1fa..03a011a17 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java
@@ -24,7 +24,7 @@
package me.shedaniel.rei.plugin.test;
import com.google.common.collect.ImmutableList;
-import dev.architectury.event.events.common.CommandRegistrationEvent;
+import me.shedaniel.architectury.event.events.CommandRegistrationEvent;
import me.shedaniel.rei.api.client.entry.filtering.FilteringRuleTypeRegistry;
import me.shedaniel.rei.api.client.entry.filtering.base.BasicFilteringRule;
import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
@@ -35,6 +35,7 @@ import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
+import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.common.InternalLogger;
import net.fabricmc.api.EnvType;
@@ -106,7 +107,7 @@ public class REITestPlugin implements REIClientPlugin {
if (i++ % 10 != 0)
continue;
registry.group(Registry.ITEM.getKey(item), new TextComponent(Registry.ITEM.getKey(item).toString()),
- stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.<ItemStack>castValue().is(item));
+ stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.<ItemStack>castValue().getItem() == item);
}
}