aboutsummaryrefslogtreecommitdiff
path: root/default-plugin/src/main/java/me
diff options
context:
space:
mode:
Diffstat (limited to 'default-plugin/src/main/java/me')
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java55
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ArmorDyeRecipeFiller.java9
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/BookCloningRecipeFiller.java18
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java6
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ShieldDecorationRecipeFiller.java25
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/TippedArrowRecipeFiller.java20
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java39
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java9
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java29
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java6
10 files changed, 100 insertions, 116 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 6702ec975..a651dbc4d 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
@@ -24,6 +24,7 @@
package me.shedaniel.rei.plugin.client;
import com.google.common.collect.*;
+import com.google.gson.internal.LinkedTreeMap;
import dev.architectury.event.EventResult;
import dev.architectury.networking.NetworkManager;
import dev.architectury.platform.Platform;
@@ -80,7 +81,9 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.inventory.*;
import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener;
+import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
+import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
@@ -92,7 +95,7 @@ import net.minecraft.world.inventory.*;
import net.minecraft.world.item.*;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
-import net.minecraft.world.item.alchemy.PotionUtils;
+import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.item.enchantment.EnchantmentInstance;
import net.minecraft.world.level.GameType;
@@ -359,31 +362,35 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
registry.add(new DefaultOxidationScrapingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue())));
});
if (Platform.isFabric()) {
- Set<Potion> potions = Sets.newLinkedHashSet();
- for (Ingredient container : PotionBrewing.ALLOWED_CONTAINERS) {
- for (PotionBrewing.Mix<Potion> mix : PotionBrewing.POTION_MIXES) {
- Potion from = mix.from;
- Ingredient ingredient = mix.ingredient;
- Potion to = mix.to;
+ Set<Holder<Potion>> potions = Collections.newSetFromMap(new LinkedTreeMap<>(Comparator.comparing(Holder::getRegisteredName), false));
+ PotionBrewing brewing = Minecraft.getInstance().level.potionBrewing();
+ for (Ingredient container : brewing.containers) {
+ for (PotionBrewing.Mix<Potion> mix : brewing.potionMixes) {
+ Holder<Potion> from = mix.from();
+ Ingredient ingredient = mix.ingredient();
+ Holder<Potion> to = mix.to();
Ingredient base = Ingredient.of(Arrays.stream(container.getItems())
.map(ItemStack::copy)
- .map(stack -> PotionUtils.setPotion(stack, from)));
+ .peek(stack -> stack.set(DataComponents.POTION_CONTENTS, new PotionContents(from))));
ItemStack output = Arrays.stream(container.getItems())
.map(ItemStack::copy)
- .map(stack -> PotionUtils.setPotion(stack, to))
+ .peek(stack -> stack.set(DataComponents.POTION_CONTENTS, new PotionContents(to)))
.findFirst().orElse(ItemStack.EMPTY);
registerBrewingRecipe(base, ingredient, output);
potions.add(from);
potions.add(to);
}
}
- for (Potion potion : potions) {
- for (PotionBrewing.Mix<Item> mix : PotionBrewing.CONTAINER_MIXES) {
- Item from = mix.from;
- Ingredient ingredient = mix.ingredient;
- Item to = mix.to;
- Ingredient base = Ingredient.of(PotionUtils.setPotion(new ItemStack(from), potion));
- ItemStack output = PotionUtils.setPotion(new ItemStack(to), potion);
+ for (Holder<Potion> potion : potions) {
+ for (PotionBrewing.Mix<Item> mix : brewing.containerMixes) {
+ Holder<Item> from = mix.from();
+ Ingredient ingredient = mix.ingredient();
+ Holder<Item> to = mix.to();
+ ItemStack baseStack = new ItemStack(from);
+ baseStack.set(DataComponents.POTION_CONTENTS, new PotionContents(potion));
+ Ingredient base = Ingredient.of(baseStack);
+ ItemStack output = new ItemStack(to);
+ output.set(DataComponents.POTION_CONTENTS, new PotionContents(potion));
registerBrewingRecipe(base, ingredient, output);
}
}
@@ -399,8 +406,8 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
Tier tier = tieredItem.getTier();
repairMaterialBase = EntryIngredients.ofIngredient(tier.getRepairIngredient());
} else if (item instanceof ArmorItem armorItem) {
- ArmorMaterial material = armorItem.getMaterial();
- repairMaterialBase = EntryIngredients.ofIngredient(material.getRepairIngredient());
+ Holder<ArmorMaterial> material = armorItem.getMaterial();
+ repairMaterialBase = EntryIngredients.ofIngredient(material.value().repairIngredient().get());
} else if (item instanceof ShieldItem shieldItem) {
repairMaterialBase = EntryIngredients.ofItemTag(ItemTags.PLANKS);
repairMaterialBase.filter(s -> shieldItem.isValidRepairItem(stack, s.castValue()));
@@ -411,7 +418,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
if (repairMaterialBase == null || repairMaterialBase.isEmpty()) continue;
for (int[] i = {1}; i[0] <= 4; i[0]++) {
ItemStack baseStack = item.getDefaultInstance();
- int toRepair = i[0] == 4 ? item.getMaxDamage() : baseStack.getMaxDamage() / 4 * i[0];
+ int toRepair = i[0] == 4 ? baseStack.getMaxDamage() : baseStack.getMaxDamage() / 4 * i[0];
baseStack.setDamageValue(toRepair);
EntryIngredient repairMaterial = repairMaterialBase.map(s -> {
EntryStack<?> newStack = s.copy();
@@ -457,7 +464,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
}
protected void registerForgePotions(DisplayRegistry registry, BuiltinClientPlugin clientPlugin) {
-
+
}
@Override
@@ -520,8 +527,8 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
}
public static class DummyShovelItem extends ShovelItem {
- public DummyShovelItem(Tier tier, float f, float g, Properties properties) {
- super(tier, f, g, properties);
+ public DummyShovelItem(Tier tier, Properties properties) {
+ super(tier, properties);
}
public static Map<Block, BlockState> getPathBlocksMap() {
@@ -530,8 +537,8 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
}
public static class DummyAxeItem extends AxeItem {
- public DummyAxeItem(Tier tier, float f, float g, Properties properties) {
- super(tier, f, g, properties);
+ public DummyAxeItem(Tier tier, Properties properties) {
+ super(tier, properties);
}
public static Map<Block, Block> getStrippedBlocksMap() {
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ArmorDyeRecipeFiller.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ArmorDyeRecipeFiller.java
index 73aa38bb5..39315bab8 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ArmorDyeRecipeFiller.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ArmorDyeRecipeFiller.java
@@ -29,10 +29,11 @@ import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay;
+import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.DyeItem;
-import net.minecraft.world.item.DyeableLeatherItem;
import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.component.DyedItemColor;
import net.minecraft.world.item.crafting.ArmorDyeRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
@@ -45,7 +46,7 @@ public class ArmorDyeRecipeFiller implements CraftingRecipeFiller<ArmorDyeRecipe
@Override
public Collection<Display> apply(RecipeHolder<ArmorDyeRecipe> recipe) {
List<Display> displays = new ArrayList<>();
- List<EntryStack<?>> toDye = EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getValueType() == ItemStack.class && entry.<ItemStack>castValue().getItem() instanceof DyeableLeatherItem).toList();
+ List<EntryStack<?>> toDye = EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getValueType() == ItemStack.class && entry.<ItemStack>castValue().is(ItemTags.DYEABLE)).toList();
DyeColor[] colors = DyeColor.values();
for (EntryStack<?> armor : toDye) {
@@ -53,7 +54,7 @@ public class ArmorDyeRecipeFiller implements CraftingRecipeFiller<ArmorDyeRecipe
for (DyeColor color : colors) {
ItemStack output = armorStack.copy();
DyeItem dyeItem = DyeItem.byColor(color);
- output = DyeableLeatherItem.dyeArmor(output, List.of(dyeItem));
+ output = DyedItemColor.applyDyes(output, List.of(dyeItem));
displays.add(new DefaultCustomShapelessDisplay(recipe,
List.of(EntryIngredient.of(armor.copy()),
EntryIngredients.of(dyeItem)),
@@ -72,7 +73,7 @@ public class ArmorDyeRecipeFiller implements CraftingRecipeFiller<ArmorDyeRecipe
inputs.add(EntryIngredients.of(dyeItem));
}
ItemStack output = armorStack.copy();
- output = DyeableLeatherItem.dyeArmor(output, dyeItems);
+ output = DyedItemColor.applyDyes(output, dyeItems);
displays.add(new DefaultCustomShapelessDisplay(recipe,
inputs, List.of(EntryIngredients.of(output))));
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/BookCloningRecipeFiller.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/BookCloningRecipeFiller.java
index cab460f70..4a58cf71f 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/BookCloningRecipeFiller.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/BookCloningRecipeFiller.java
@@ -28,18 +28,15 @@ import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay;
-import net.minecraft.nbt.IntTag;
-import net.minecraft.nbt.StringTag;
+import net.minecraft.core.component.DataComponents;
+import net.minecraft.server.network.Filterable;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
-import net.minecraft.world.item.WrittenBookItem;
+import net.minecraft.world.item.component.WrittenBookContent;
import net.minecraft.world.item.crafting.BookCloningRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
public class BookCloningRecipeFiller implements CraftingRecipeFiller<BookCloningRecipe> {
private static final String[] TITLES = new String[]{
@@ -78,7 +75,7 @@ public class BookCloningRecipeFiller implements CraftingRecipeFiller<BookCloning
inputs[k + 1].add(EntryStacks.of(bookAndQuill));
}
ItemStack cloned = writtenBook.copy();
- cloned.addTagElement(WrittenBookItem.TAG_GENERATION, IntTag.valueOf(1));
+ cloned.update(DataComponents.WRITTEN_BOOK_CONTENT, WrittenBookContent.EMPTY, WrittenBookContent::tryCraftCopy);
cloned.setCount(i);
output.add(EntryStacks.of(cloned));
}
@@ -92,9 +89,8 @@ public class BookCloningRecipeFiller implements CraftingRecipeFiller<BookCloning
private ItemStack generateBook() {
ItemStack stack = new ItemStack(Items.WRITTEN_BOOK);
- stack.addTagElement(WrittenBookItem.TAG_AUTHOR, StringTag.valueOf(AUTHORS[new Random().nextInt(AUTHORS.length)]));
- stack.addTagElement(WrittenBookItem.TAG_TITLE, StringTag.valueOf(TITLES[new Random().nextInt(TITLES.length)]));
- stack.addTagElement(WrittenBookItem.TAG_GENERATION, IntTag.valueOf(0));
+ stack.set(DataComponents.WRITTEN_BOOK_CONTENT, new WrittenBookContent(new Filterable<>(TITLES[new Random().nextInt(TITLES.length)], Optional.empty()),
+ AUTHORS[new Random().nextInt(AUTHORS.length)], 0, List.of(), true));
return stack;
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java
index 3a9f04b0f..4511c5408 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java
@@ -30,10 +30,11 @@ import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay;
-import net.minecraft.nbt.CompoundTag;
+import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
+import net.minecraft.world.item.component.Fireworks;
import net.minecraft.world.item.crafting.FireworkRocketRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
@@ -54,8 +55,7 @@ public class FireworkRocketRecipeFiller implements CraftingRecipeFiller<Firework
EntryStack<ItemStack>[] outputs = new EntryStack[3];
for (int i = 0; i < 3; i++) {
outputs[i] = EntryStacks.of(new ItemStack(Items.FIREWORK_ROCKET, 3));
- CompoundTag tag = outputs[i].getValue().getOrCreateTagElement("Fireworks");
- tag.putByte("Flight", (byte) (i + 1));
+ outputs[i].getValue().set(DataComponents.FIREWORKS, new Fireworks(i + 1, List.of()));
}
displays.add(new DefaultCustomShapelessDisplay(recipe,
List.of(inputs),
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ShieldDecorationRecipeFiller.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ShieldDecorationRecipeFiller.java
index 54272d078..2a74d4f66 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ShieldDecorationRecipeFiller.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/ShieldDecorationRecipeFiller.java
@@ -23,23 +23,25 @@
package me.shedaniel.rei.plugin.client.categories.crafting.filler;
-import com.google.common.base.MoreObjects;
import com.mojang.datafixers.util.Pair;
import me.shedaniel.rei.api.common.display.Display;
+import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay;
import net.minecraft.core.Holder;
+import net.minecraft.core.Registry;
+import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
-import net.minecraft.nbt.CompoundTag;
+import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.*;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.ShieldDecorationRecipe;
import net.minecraft.world.level.block.entity.BannerPattern;
-import net.minecraft.world.level.block.entity.BlockEntityType;
+import net.minecraft.world.level.block.entity.BannerPatternLayers;
import java.util.*;
@@ -55,16 +57,16 @@ public class ShieldDecorationRecipeFiller implements CraftingRecipeFiller<Shield
out.add(Pair.of(color, new ItemStack(bannerOptional.get())));
for (int i = 0; i < 2; i++) {
- BannerPattern.Builder patternBuilder = new BannerPattern.Builder();
- Holder<BannerPattern>[] allPatterns = BuiltInRegistries.BANNER_PATTERN.holders().toArray(Holder[]::new);
+ List<BannerPatternLayers.Layer> layers = new ArrayList<>();
+ Optional<Registry<BannerPattern>> registry = BasicDisplay.registryAccess().registry(Registries.BANNER_PATTERN);
+ if (registry.isEmpty()) return Collections.emptyList();
+ Holder<BannerPattern>[] allPatterns = registry.get().holders().toArray(Holder[]::new);
for (int j = 0; j < 2; j++) {
Holder<BannerPattern> pattern = allPatterns[random.nextInt(allPatterns.length - 1) + 1];
- patternBuilder.addPattern(pattern, colors[random.nextInt(colors.length)]);
+ layers.add(new BannerPatternLayers.Layer(pattern, colors[random.nextInt(colors.length)]));
}
ItemStack banner = new ItemStack(bannerOptional.get());
- CompoundTag newTag = new CompoundTag();
- newTag.put("Patterns", patternBuilder.toListTag());
- banner.addTagElement("BlockEntityTag", newTag);
+ banner.set(DataComponents.BANNER_PATTERNS, new BannerPatternLayers(layers));
out.add(Pair.of(color, banner));
}
}
@@ -98,9 +100,8 @@ public class ShieldDecorationRecipeFiller implements CraftingRecipeFiller<Shield
private static EntryStack<ItemStack> createOutput(DyeColor color, ItemStack banner) {
ItemStack output = new ItemStack(Items.SHIELD);
- CompoundTag beTag = MoreObjects.firstNonNull(BlockItem.getBlockEntityData(banner), new CompoundTag());
- beTag.putInt("Base", color.getId());
- BlockItem.setBlockEntityData(output, BlockEntityType.BANNER, beTag);
+ output.set(DataComponents.BANNER_PATTERNS, banner.get(DataComponents.BANNER_PATTERNS));
+ output.set(DataComponents.BASE_COLOR, ((BannerItem) banner.getItem()).getColor());
return EntryStacks.of(output);
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/TippedArrowRecipeFiller.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/TippedArrowRecipeFiller.java
index f544ae1e8..6a119ec23 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/TippedArrowRecipeFiller.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/TippedArrowRecipeFiller.java
@@ -23,36 +23,33 @@
package me.shedaniel.rei.plugin.client.categories.crafting.filler;
-import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
-import it.unimi.dsi.fastutil.objects.ReferenceSet;
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomDisplay;
+import net.minecraft.core.component.DataComponents;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
-import net.minecraft.world.item.alchemy.Potion;
-import net.minecraft.world.item.alchemy.PotionUtils;
+import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.TippedArrowRecipe;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import java.util.*;
public class TippedArrowRecipeFiller implements CraftingRecipeFiller<TippedArrowRecipe> {
@Override
public Collection<Display> apply(RecipeHolder<TippedArrowRecipe> recipe) {
EntryIngredient arrowStack = EntryIngredient.of(EntryStacks.of(Items.ARROW));
- ReferenceSet<Potion> registeredPotions = new ReferenceOpenHashSet<>();
+ Set<ResourceLocation> registeredPotions = new HashSet<>();
List<Display> displays = new ArrayList<>();
EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getValueType() == ItemStack.class && entry.<ItemStack>castValue().getItem() == Items.LINGERING_POTION).forEach(entry -> {
ItemStack itemStack = (ItemStack) entry.getValue();
- Potion potion = PotionUtils.getPotion(itemStack);
- if (registeredPotions.add(potion)) {
+ PotionContents potion = itemStack.get(DataComponents.POTION_CONTENTS);
+ if (potion.potion().isPresent() && potion.potion().get().unwrapKey().isPresent() && registeredPotions.add(potion.potion().get().unwrapKey().get().location())) {
List<EntryIngredient> input = new ArrayList<>();
for (int i = 0; i < 4; i++)
input.add(arrowStack);
@@ -60,8 +57,7 @@ public class TippedArrowRecipeFiller implements CraftingRecipeFiller<TippedArrow
for (int i = 0; i < 4; i++)
input.add(arrowStack);
ItemStack outputStack = new ItemStack(Items.TIPPED_ARROW, 8);
- PotionUtils.setPotion(outputStack, potion);
- PotionUtils.setCustomEffects(outputStack, PotionUtils.getCustomEffects(itemStack));
+ outputStack.set(DataComponents.POTION_CONTENTS, potion);
displays.add(new DefaultCustomDisplay(recipe, input, List.of(EntryIngredients.of(outputStack))));
}
});
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
index 71259b466..0cb016597 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
@@ -27,13 +27,9 @@ import dev.architectury.event.CompoundEventResult;
import dev.architectury.hooks.fluid.FluidBucketHooks;
import dev.architectury.hooks.fluid.FluidStackHooks;
import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry;
-import me.shedaniel.rei.api.common.entry.comparison.EntryComparator;
import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
import me.shedaniel.rei.api.common.fluid.FluidSupportProvider;
import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
-import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry;
-import me.shedaniel.rei.api.common.transfer.info.simple.RecipeBookGridMenuInfo;
-import me.shedaniel.rei.api.common.transfer.info.simple.SimpleMenuInfoProvider;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.displays.*;
import me.shedaniel.rei.plugin.common.displays.beacon.DefaultBeaconBaseDisplay;
@@ -46,14 +42,16 @@ import me.shedaniel.rei.plugin.common.displays.cooking.DefaultSmeltingDisplay;
import me.shedaniel.rei.plugin.common.displays.cooking.DefaultSmokingDisplay;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay;
import me.shedaniel.rei.plugin.common.displays.tag.TagNodes;
-import net.minecraft.nbt.CompoundTag;
-import net.minecraft.nbt.ListTag;
-import net.minecraft.nbt.Tag;
-import net.minecraft.world.inventory.InventoryMenu;
-import net.minecraft.world.item.*;
+import net.minecraft.core.component.DataComponents;
+import net.minecraft.world.item.BucketItem;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.Items;
+import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.level.material.Fluid;
import org.jetbrains.annotations.ApiStatus;
+import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Stream;
@@ -65,23 +63,20 @@ public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin {
@Override
public void registerItemComparators(ItemComparatorRegistry registry) {
- EntryComparator<Tag> nbtHasher = EntryComparator.nbt();
- Function<ItemStack, ListTag> enchantmentTag = stack -> {
- CompoundTag tag = stack.getTag();
- if (tag == null) return null;
- if (!tag.contains(ItemStack.TAG_ENCH, Tag.TAG_LIST)) {
- if (tag.contains(EnchantedBookItem.TAG_STORED_ENCHANTMENTS, Tag.TAG_LIST)) {
- return tag.getList(EnchantedBookItem.TAG_STORED_ENCHANTMENTS, Tag.TAG_COMPOUND);
+ Function<ItemStack, ItemEnchantments> enchantmentTag = stack -> {
+ if (!stack.has(DataComponents.ENCHANTMENTS)) {
+ if (stack.has(DataComponents.STORED_ENCHANTMENTS)) {
+ return stack.get(DataComponents.STORED_ENCHANTMENTS);
}
return null;
}
- return tag.getList(ItemStack.TAG_ENCH, Tag.TAG_COMPOUND);
+ return stack.get(DataComponents.ENCHANTMENTS);
};
- registry.register((context, stack) -> nbtHasher.hash(context, enchantmentTag.apply(stack)), Items.ENCHANTED_BOOK);
- registry.registerNbt(Items.POTION);
- registry.registerNbt(Items.SPLASH_POTION);
- registry.registerNbt(Items.LINGERING_POTION);
- registry.registerNbt(Items.TIPPED_ARROW);
+ registry.register((context, stack) -> Objects.hashCode(enchantmentTag.apply(stack)), Items.ENCHANTED_BOOK);
+ registry.registerComponents(Items.POTION);
+ registry.registerComponents(Items.SPLASH_POTION);
+ registry.registerComponents(Items.LINGERING_POTION);
+ registry.registerComponents(Items.TIPPED_ARROW);
registry.register((context, stack) -> 0, Items.FIREWORK_ROCKET, Items.FILLED_MAP);
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java
index 7b88ed0b5..e5cd3efab 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java
@@ -27,6 +27,7 @@ import com.google.common.collect.Lists;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.display.DisplaySerializer;
+import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.plugin.common.BuiltinPlugin;
@@ -104,10 +105,10 @@ public class DefaultInformationDisplay implements Display {
@Override
public CompoundTag save(CompoundTag tag, DefaultInformationDisplay display) {
tag.put("stacks", display.getEntryStacks().saveIngredient());
- tag.putString("name", Component.Serializer.toJson(display.getName()));
+ tag.putString("name", Component.Serializer.toJson(display.getName(), BasicDisplay.registryAccess()));
ListTag descriptions = new ListTag();
for (Component text : display.getTexts()) {
- descriptions.add(StringTag.valueOf(Component.Serializer.toJson(text)));
+ descriptions.add(StringTag.valueOf(Component.Serializer.toJson(text, BasicDisplay.registryAccess())));
}
tag.put("descriptions", descriptions);
return tag;
@@ -116,10 +117,10 @@ public class DefaultInformationDisplay implements Display {
@Override
public DefaultInformationDisplay read(CompoundTag tag) {
EntryIngredient stacks = EntryIngredient.read(tag.getList("stacks", Tag.TAG_COMPOUND));
- Component name = Component.Serializer.fromJson(tag.getString("name"));
+ Component name = Component.Serializer.fromJson(tag.getString("name"), BasicDisplay.registryAccess());
List<Component> descriptions = new ArrayList<>();
for (Tag descriptionTag : tag.getList("descriptions", Tag.TAG_STRING)) {
- descriptions.add(Component.Serializer.fromJson(descriptionTag.getAsString()));
+ descriptions.add(Component.Serializer.fromJson(descriptionTag.getAsString(), BasicDisplay.registryAccess()));
}
return new DefaultInformationDisplay(stacks, name).lines(descriptions);
}
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java
index 4d2c0a07c..a4242768f 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java
@@ -31,6 +31,7 @@ import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.BuiltinPlugin;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
+import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.armortrim.*;
@@ -59,20 +60,6 @@ public class DefaultSmithingDisplay extends BasicDisplay {
);
}
- @Deprecated(forRemoval = true)
- public static DefaultSmithingDisplay ofTrimming(RecipeHolder<SmithingTrimRecipe> recipe) {
- return new DefaultSmithingDisplay(
- recipe.value(),
- recipe.id(),
- List.of(
- EntryIngredients.ofIngredient(recipe.value().template),
- EntryIngredients.ofIngredient(recipe.value().base),
- EntryIngredients.ofIngredient(recipe.value().addition)
- )
- );
- }
-
- @ApiStatus.Experimental
public static List<DefaultSmithingDisplay> fromTrimming(RecipeHolder<SmithingTrimRecipe> recipe) {
RegistryAccess registryAccess = BasicDisplay.registryAccess();
List<DefaultSmithingDisplay> displays = new ArrayList<>();
@@ -89,14 +76,12 @@ public class DefaultSmithingDisplay extends BasicDisplay {
ArmorTrim armorTrim = new ArmorTrim(trimMaterial, trimPattern);
EntryIngredient.Builder baseItems = EntryIngredient.builder(), outputItems = EntryIngredient.builder();
for (ItemStack item : recipe.value().base.getItems()) {
- Optional<ArmorTrim> trim = ArmorTrim.getTrim(registryAccess, item, true);
- if (trim.isEmpty() || !trim.get().hasPatternAndMaterial(trimPattern, trimMaterial)) {
- ItemStack newItem = item.copy();
- newItem.setCount(1);
- if (ArmorTrim.setTrim(registryAccess, newItem, armorTrim)) {
- baseItems.add(EntryStacks.of(item.copy()));
- outputItems.add(EntryStacks.of(newItem));
- }
+ ArmorTrim trim = item.get(DataComponents.TRIM);
+ if (trim == null || !trim.hasPatternAndMaterial(trimPattern, trimMaterial)) {
+ ItemStack newItem = item.copyWithCount(1);
+ newItem.set(DataComponents.TRIM, armorTrim);
+ baseItems.add(EntryStacks.of(item.copy()));
+ outputItems.add(EntryStacks.of(newItem));
}
}
displays.add(new DefaultSmithingDisplay(List.of(
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java
index 9e4fafadd..488beb78e 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java
@@ -32,6 +32,7 @@ import dev.architectury.utils.EnvExecutor;
import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
+import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
@@ -40,6 +41,7 @@ import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;</