aboutsummaryrefslogtreecommitdiff
path: root/default-plugin
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2024-03-02 03:09:05 +0900
committershedaniel <daniel@shedaniel.me>2024-03-02 03:09:05 +0900
commit52a6bf840ed665a2086ed37bbe0f99907d160350 (patch)
tree75687fc5f19a5d6880e396e0c316a70f88d6ea7f /default-plugin
parente4cf4d7a272dbf5da9a8ca868d003f011f5b0fc9 (diff)
downloadRoughlyEnoughItems-52a6bf840ed665a2086ed37bbe0f99907d160350.tar.gz
RoughlyEnoughItems-52a6bf840ed665a2086ed37bbe0f99907d160350.tar.bz2
RoughlyEnoughItems-52a6bf840ed665a2086ed37bbe0f99907d160350.zip
Update to 24w09a
Diffstat (limited to 'default-plugin')
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java49
-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
3 files changed, 49 insertions, 48 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 ea61c622f..f1c4267ac 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.level.GameType;
import net.minecraft.world.level.block.Block;
@@ -293,8 +296,8 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
ReferenceSet<Potion> registeredPotions = new ReferenceOpenHashSet<>();
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 potionContents = itemStack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
+ if (potionContents.potion().isPresent() && registeredPotions.add(potionContents.potion().get().value())) {
List<EntryIngredient> input = new ArrayList<>();
for (int i = 0; i < 4; i++)
input.add(arrowStack);
@@ -302,8 +305,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
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, potionContents);
EntryIngredient output = EntryIngredients.of(outputStack);
registry.add(new DefaultCustomDisplay(null, input, Collections.singletonList(output)));
}
@@ -337,31 +339,34 @@ 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();
+ Set<Holder<Potion>> potions = Collections.newSetFromMap(new LinkedTreeMap<>(Comparator.comparing(Holder::getRegisteredName), false));
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;
+ 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 (Holder<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);
+ 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);
}
}
@@ -375,7 +380,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin
}
protected void registerForgePotions(DisplayRegistry registry, BuiltinClientPlugin clientPlugin) {
-
+
}
@Override
@@ -438,8 +443,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() {
@@ -448,8 +453,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/common/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java
index e6a3e33ce..fc76dff56 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);
}
@Override
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);
}