aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/plugin/test
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2024-10-26 16:55:52 +0800
committershedaniel <daniel@shedaniel.me>2024-10-26 16:55:57 +0800
commitddb48e2032d1986709cad973067693eec3118504 (patch)
treee7905130008c67767d2ad2a4d72f49ba4df7e6e3 /runtime/src/main/java/me/shedaniel/rei/plugin/test
parenteaf9236e3da2adafcea204778ecc0072e70d0aa5 (diff)
downloadRoughlyEnoughItems-ddb48e2032d1986709cad973067693eec3118504.tar.gz
RoughlyEnoughItems-ddb48e2032d1986709cad973067693eec3118504.tar.bz2
RoughlyEnoughItems-ddb48e2032d1986709cad973067693eec3118504.zip
Update to 1.21.2 (Please read Primer)
https://hackmd.io/@shedaniel/rei17_primer
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/plugin/test')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestCommonPlugin.java62
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java36
2 files changed, 62 insertions, 36 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestCommonPlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestCommonPlugin.java
new file mode 100644
index 000000000..d928b969b
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestCommonPlugin.java
@@ -0,0 +1,62 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.test;
+
+import dev.architectury.event.events.common.CommandRegistrationEvent;
+import me.shedaniel.rei.api.common.display.Display;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
+import me.shedaniel.rei.api.common.plugins.REICommonPlugin;
+import me.shedaniel.rei.api.common.registry.display.ServerDisplayRegistry;
+import me.shedaniel.rei.api.common.util.EntryStacks;
+import net.minecraft.commands.Commands;
+import net.minecraft.commands.arguments.item.ItemArgument;
+import net.minecraft.commands.arguments.item.ItemInput;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.world.item.Item;
+
+public class REITestCommonPlugin implements REICommonPlugin {
+ public REITestCommonPlugin() {
+ CommandRegistrationEvent.EVENT.register((dispatcher, registry, selection) -> {
+ dispatcher.register(Commands.literal("rei_server_test_add_displays")
+ .then(Commands.argument("item", ItemArgument.item(registry))
+ .executes(context -> {
+ try {
+ Class<?> displayClass = Class.forName("me.shedaniel.rei.plugin.common.displays.DefaultPathingDisplay");
+ Display display = (Display) displayClass.getDeclaredConstructor(EntryStack.class, EntryStack.class)
+ .newInstance(EntryStacks.of(context.getArgument("item", ItemInput.class).getItem()), EntryStacks.of(context.getArgument("item", ItemInput.class).getItem()));
+ ServerDisplayRegistry.getInstance().add(display);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ return 0;
+ })));
+ });
+ }
+
+ @Override
+ public void registerItemComparators(ItemComparatorRegistry registry) {
+ registry.registerComponents(BuiltInRegistries.ITEM.stream().toArray(Item[]::new));
+ }
+}
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 bca2e6537..cc248df83 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
@@ -23,18 +23,14 @@
package me.shedaniel.rei.plugin.test;
-import com.google.common.collect.ImmutableList;
import dev.architectury.event.events.common.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;
-import me.shedaniel.rei.api.client.favorites.FavoriteEntryType;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry;
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.plugins.PluginManager;
import me.shedaniel.rei.api.common.registry.ReloadStage;
@@ -42,7 +38,6 @@ 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.client.Minecraft;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.item.ItemArgument;
import net.minecraft.commands.arguments.item.ItemInput;
@@ -51,9 +46,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
-import net.minecraft.world.item.Items;
import net.minecraft.world.item.component.CustomData;
-import net.minecraft.world.level.GameType;
import org.jetbrains.annotations.TestOnly;
import java.util.Random;
@@ -94,12 +87,6 @@ public class REITestPlugin implements REIClientPlugin {
for (Item item : BuiltInRegistries.ITEM) {
EntryStack<ItemStack> base = EntryStacks.of(item);
registry.addEntriesAfter(base, IntStream.range(0, times).mapToObj(value -> transformStack(EntryStacks.of(item))).collect(Collectors.toList()));
- try {
- for (ItemStack stack : registry.appendStacksForItem(item)) {
- registry.addEntries(IntStream.range(0, times).mapToObj(value -> transformStack(EntryStacks.of(stack))).collect(Collectors.toList()));
- }
- } catch (Exception ignored) {
- }
}
}
@@ -127,11 +114,6 @@ public class REITestPlugin implements REIClientPlugin {
});
}
- @Override
- public void registerItemComparators(ItemComparatorRegistry registry) {
- registry.registerComponents(BuiltInRegistries.ITEM.stream().toArray(Item[]::new));
- }
-
public EntryStack<ItemStack> transformStack(EntryStack<ItemStack> stack) {
CustomData data = stack.getValue().getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).update(tag -> {
tag.putInt("Whatever", random.nextInt(Integer.MAX_VALUE));
@@ -139,22 +121,4 @@ public class REITestPlugin implements REIClientPlugin {
stack.getValue().set(DataComponents.CUSTOM_DATA, data);
return stack;
}
-
- @Override
- public void registerFavorites(FavoriteEntryType.Registry registry) {
- registry.registerSystemFavorites(() -> {
- GameType mode = Minecraft.getInstance().gameMode.getPlayerMode();
- switch (mode) {
- case SURVIVAL:
- return ImmutableList.of(FavoriteEntry.fromEntryStack(EntryStacks.of(Items.STONE)));
- case CREATIVE:
- return ImmutableList.of(FavoriteEntry.fromEntryStack(EntryStacks.of(Items.PACKED_ICE)));
- case ADVENTURE:
- return ImmutableList.of(FavoriteEntry.fromEntryStack(EntryStacks.of(Items.ANVIL)));
- case SPECTATOR:
- default:
- return ImmutableList.of();
- }
- });
- }
}