diff options
| author | shedaniel <daniel@shedaniel.me> | 2024-10-26 16:55:52 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2024-10-26 16:55:57 +0800 |
| commit | ddb48e2032d1986709cad973067693eec3118504 (patch) | |
| tree | e7905130008c67767d2ad2a4d72f49ba4df7e6e3 /runtime/src/main/java/me/shedaniel/rei/plugin | |
| parent | eaf9236e3da2adafcea204778ecc0072e70d0aa5 (diff) | |
| download | RoughlyEnoughItems-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')
7 files changed, 107 insertions, 288 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java b/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java deleted file mode 100644 index 5f5a61cc1..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * 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.autocrafting; - -import dev.architectury.networking.NetworkManager; -import io.netty.buffer.Unpooled; -import it.unimi.dsi.fastutil.ints.IntArrayList; -import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet; -import it.unimi.dsi.fastutil.ints.IntList; -import it.unimi.dsi.fastutil.ints.IntSet; -import me.shedaniel.rei.RoughlyEnoughItemsNetwork; -import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.registry.transfer.TransferHandler; -import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.api.common.entry.InputIngredient; -import me.shedaniel.rei.api.common.transfer.RecipeFinder; -import me.shedaniel.rei.api.common.transfer.info.MenuInfo; -import me.shedaniel.rei.api.common.transfer.info.MenuInfoContext; -import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry; -import me.shedaniel.rei.api.common.transfer.info.MenuTransferException; -import me.shedaniel.rei.api.common.util.CollectionUtils; -import me.shedaniel.rei.api.common.util.EntryIngredients; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.ItemStack; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -@Environment(EnvType.CLIENT) -public class DefaultCategoryHandler implements TransferHandler { - @Override - public ApplicabilityResult checkApplicable(Context context) { - Display display = context.getDisplay(); - AbstractContainerScreen<?> containerScreen = context.getContainerScreen(); - if (containerScreen == null) return ApplicabilityResult.createNotApplicable(); - AbstractContainerMenu menu = context.getMenu(); - MenuInfoContext<AbstractContainerMenu, Player, Display> menuInfoContext = ofContext(menu, display); - MenuInfo<AbstractContainerMenu, Display> menuInfo = MenuInfoRegistry.getInstance().getClient(display, menuInfoContext, menu); - if (menuInfo == null) return ApplicabilityResult.createNotApplicable(); - return ApplicabilityResult.createApplicable(); - } - - @Override - public Result handle(Context context) { - Display display = context.getDisplay(); - AbstractContainerScreen<?> containerScreen = context.getContainerScreen(); - AbstractContainerMenu menu = context.getMenu(); - MenuInfoContext<AbstractContainerMenu, Player, Display> menuInfoContext = ofContext(menu, display); - MenuInfo<AbstractContainerMenu, Display> menuInfo = MenuInfoRegistry.getInstance().getClient(display, menuInfoContext, menu); - try { - menuInfo.validate(menuInfoContext); - } catch (MenuTransferException e) { - if (e.isApplicable()) { - return Result.createFailed(e.getError()); - } else { - return Result.createNotApplicable(); - } - } - List<InputIngredient<ItemStack>> input = menuInfo.getInputsIndexed(menuInfoContext, false); - List<InputIngredient<ItemStack>> missing = hasItemsIndexed(menuInfoContext, menu, menuInfo, display, input); - if (!missing.isEmpty()) { - IntList missingIndices = new IntArrayList(missing.size()); - for (InputIngredient<ItemStack> ingredient : missing) { - missingIndices.add(ingredient.getIndex()); - } - IntSet missingIndicesSet = new IntLinkedOpenHashSet(missingIndices); - List<List<ItemStack>> oldInputs = CollectionUtils.map(input, InputIngredient::get); - return Result.createFailed(Component.translatable("error.rei.not.enough.materials")) - .renderer((matrices, mouseX, mouseY, delta, widgets, bounds, d) -> { - menuInfo.renderMissingInput(menuInfoContext, oldInputs, missingIndices, matrices, mouseX, mouseY, delta, widgets, bounds); - menuInfo.renderMissingInput(menuInfoContext, input, missing, missingIndicesSet, matrices, mouseX, mouseY, delta, widgets, bounds); - }) - .tooltipMissing(CollectionUtils.map(missing, ingredient -> EntryIngredients.ofItemStacks(ingredient.get()))); - } - if (!ClientHelper.getInstance().canUseMovePackets()) { - return Result.createFailed(Component.translatable("error.rei.not.on.server")); - } - if (!context.isActuallyCrafting()) { - return Result.createSuccessful(); - } - - context.getMinecraft().setScreen(containerScreen); - if (containerScreen instanceof RecipeUpdateListener listener) { - listener.getRecipeBookComponent().ghostRecipe.clear(); - } - RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), context.getMinecraft().getConnection().registryAccess()); - buf.writeResourceLocation(display.getCategoryIdentifier().getIdentifier()); - buf.writeBoolean(context.isStackedCrafting()); - - buf.writeNbt(menuInfo.save(menuInfoContext, display)); - NetworkManager.sendToServer(RoughlyEnoughItemsNetwork.MOVE_ITEMS_PACKET, buf); - return Result.createSuccessful(); - } - - @Override - public double getPriority() { - return -10; - } - - private static MenuInfoContext<AbstractContainerMenu, Player, Display> ofContext(AbstractContainerMenu menu, Display display) { - return new MenuInfoContext<AbstractContainerMenu, Player, Display>() { - @Override - public AbstractContainerMenu getMenu() { - return menu; - } - - @Override - public Player getPlayerEntity() { - return Minecraft.getInstance().player; - } - - @Override - public CategoryIdentifier<Display> getCategoryIdentifier() { - return (CategoryIdentifier<Display>) display.getCategoryIdentifier(); - } - - @Override - public Display getDisplay() { - return display; - } - }; - } - - public IntList hasItems(MenuInfoContext<AbstractContainerMenu, Player, Display> menuInfoContext, AbstractContainerMenu menu, MenuInfo<AbstractContainerMenu, Display> info, Display display, List<List<ItemStack>> inputs) { - List<InputIngredient<ItemStack>> missing = hasItemsIndexed(menuInfoContext, menu, info, display, - CollectionUtils.mapIndexed(inputs, InputIngredient::of)); - IntList ids = new IntArrayList(missing.size()); - for (InputIngredient<ItemStack> ingredient : missing) { - ids.add(ingredient.getIndex()); - } - return ids; - } - - public List<InputIngredient<ItemStack>> hasItemsIndexed(MenuInfoContext<AbstractContainerMenu, Player, Display> menuInfoContext, AbstractContainerMenu menu, MenuInfo<AbstractContainerMenu, Display> info, Display display, List<InputIngredient<ItemStack>> inputs) { - // Create a clone of player's inventory, and count - RecipeFinder recipeFinder = new RecipeFinder(); - info.getRecipeFinderPopulator().populate(menuInfoContext, recipeFinder); - List<InputIngredient<ItemStack>> missing = new ArrayList<>(); - for (InputIngredient<ItemStack> possibleStacks : inputs) { - boolean done = possibleStacks.get().isEmpty(); - for (ItemStack possibleStack : possibleStacks.get()) { - if (!done) { - int invRequiredCount = possibleStack.getCount(); - int key = RecipeFinder.getItemId(possibleStack); - while (invRequiredCount > 0 && recipeFinder.contains(key)) { - invRequiredCount--; - recipeFinder.take(key, 1); - } - if (invRequiredCount <= 0) { - done = true; - break; - } - } - } - if (!done) { - missing.add(possibleStacks); - } - } - return missing; - } -} 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 93aac1fa6..ae94f80dc 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 @@ -25,6 +25,7 @@ package me.shedaniel.rei.plugin.client.entry; import com.google.common.base.Suppliers; import com.google.common.collect.Lists; +import com.mojang.serialization.Codec; import dev.architectury.fluid.FluidStack; import dev.architectury.hooks.fluid.FluidStackHooks; import dev.architectury.platform.Platform; @@ -60,10 +61,11 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.language.I18n; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.Tag; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; @@ -178,28 +180,18 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS } @Override - public boolean supportSaving() { - return true; - } - - @Override - public boolean supportReading() { - return true; - } - - @Override public boolean acceptsNull() { return false; } @Override - public CompoundTag save(EntryStack<FluidStack> entry, FluidStack value) { - return (CompoundTag) value.write(BasicDisplay.registryAccess(), new CompoundTag()); + public Codec<FluidStack> codec() { + return FluidStack.CODEC; } @Override - public FluidStack read(CompoundTag tag) { - return FluidStack.read(BasicDisplay.registryAccess(), tag).orElse(FluidStack.empty()); + public StreamCodec<RegistryFriendlyByteBuf, FluidStack> streamCodec() { + return FluidStack.STREAM_CODEC; } @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 2d5595ad6..6200ce8cd 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 @@ -27,6 +27,7 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.Lighting; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.serialization.Codec; import dev.architectury.hooks.item.ItemStackHooks; import dev.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; @@ -57,11 +58,13 @@ import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.Tag; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.inventory.tooltip.TooltipComponent; @@ -170,28 +173,18 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer } @Override - public boolean supportSaving() { - return true; - } - - @Override - public boolean supportReading() { - return true; - } - - @Override public boolean acceptsNull() { return false; } @Override - public CompoundTag save(EntryStack<ItemStack> entry, ItemStack value) { - return (CompoundTag) value.save(BasicDisplay.registryAccess()); + public Codec<ItemStack> codec() { + return ItemStack.CODEC; } @Override - public ItemStack read(CompoundTag tag) { - return ItemStack.parseOptional(BasicDisplay.registryAccess(), tag); + public StreamCodec<RegistryFriendlyByteBuf, ItemStack> streamCodec() { + return ItemStack.OPTIONAL_STREAM_CODEC; } private static final ReferenceSet<Item> SEARCH_BLACKLISTED = new ReferenceOpenHashSet<>(); @@ -283,11 +276,13 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer modelViewStack.mul(graphics.pose().last().pose()); modelViewStack.translate(bounds.x, bounds.y, 0); modelViewStack.scale(bounds.width / 16f, (bounds.getWidth() + bounds.getHeight()) / 2f / 16f, 1.0F); - RenderSystem.applyModelViewMatrix(); - renderOverlay(new GuiGraphics(Minecraft.getInstance(), graphics.bufferSource()), entry, bounds); + graphics.drawSpecial(source -> { + if (source instanceof MultiBufferSource.BufferSource multiBufferSource) { + renderOverlay(new GuiGraphics(Minecraft.getInstance(), multiBufferSource), entry, bounds); + } + }); modelViewStack.popMatrix(); endGL(entry, model); - RenderSystem.applyModelViewMatrix(); } @Override @@ -335,10 +330,12 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer modelViewStack.mul(graphics.pose().last().pose()); modelViewStack.translate(bounds.x, bounds.y, 0); modelViewStack.scale(bounds.width / 16f, (bounds.getWidth() + bounds.getHeight()) / 2f / 16f, 1.0F); - RenderSystem.applyModelViewMatrix(); - renderOverlay(new GuiGraphics(Minecraft.getInstance(), graphics.bufferSource()), entry, bounds); + graphics.drawSpecial(source -> { + if (source instanceof MultiBufferSource.BufferSource multiBufferSource) { + renderOverlay(new GuiGraphics(Minecraft.getInstance(), multiBufferSource), entry, bounds); + } + }); modelViewStack.popMatrix(); - RenderSystem.applyModelViewMatrix(); } public void renderOverlay(GuiGraphics graphics, EntryStack<ItemStack> entry, Rectangle bounds) { @@ -372,7 +369,7 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer for (int i = 1; i < components.size(); i++) { tooltip.add(components.get(i)); } - return tooltip; + return tooltip.withTooltipStyle(entry.getValue().get(DataComponents.TOOLTIP_STYLE)); } } } diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java index 4108837f9..fa300a5ba 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java @@ -34,12 +34,12 @@ import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.favorites.FavoriteEntryType; import me.shedaniel.rei.api.client.gui.Renderer; -import me.shedaniel.rei.api.client.gui.config.RecipeBorderType; import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponent; import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentProviderWidget; import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentVisitorWidget; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.*; +import me.shedaniel.rei.api.client.gui.widgets.utils.PanelTextures; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; @@ -47,12 +47,11 @@ import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.registry.screen.ExclusionZones; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; -import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry; import me.shedaniel.rei.api.client.search.method.InputMethodRegistry; import me.shedaniel.rei.api.client.util.ClientEntryStacks; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; +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.plugins.PluginManager; @@ -74,14 +73,16 @@ import me.shedaniel.rei.impl.common.InternalLogger; 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.HNEntryStackWrapper; -import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.RenderType; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; @@ -117,7 +118,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { @Override public void render(GuiGraphics graphics, Rectangle bounds, int mouseX, int mouseY, float delta) { - graphics.innerBlit(id, bounds.x, bounds.getMaxX(), bounds.y, bounds.getMaxY(), 0, 0, 1, 0, 1); + graphics.innerBlit(RenderType::guiTextured, id, bounds.x, bounds.getMaxX(), bounds.y, bounds.getMaxY(), 0, 0, 1, 0, 1); } @Override @@ -177,11 +178,6 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { } @Override - public void registerTransferHandlers(TransferHandlerRegistry registry) { - registry.register(new DefaultCategoryHandler()); - } - - @Override public void registerInputMethods(InputMethodRegistry registry) { registry.add(DefaultInputMethod.ID, DefaultInputMethod.INSTANCE); UniHanManager manager = new UniHanManager(Platform.getConfigFolder().resolve("roughlyenoughitems/unihan.zip")); @@ -203,13 +199,13 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { @Override public DataResult<EntryStackFavoriteEntry> read(CompoundTag object) { - EntryStack<?> stack; try { - stack = EntryStack.read(object.getCompound(key)); + return EntryStack.codec().parse(BasicDisplay.registryAccess().createSerializationContext(NbtOps.INSTANCE), object.getCompound(key)) + .map(EntryStackFavoriteEntry::new) + .setLifecycle(Lifecycle.stable()); } catch (Throwable throwable) { return DataResult.error(throwable::getMessage); } - return DataResult.success(new EntryStackFavoriteEntry(stack), Lifecycle.stable()); } @Override @@ -217,14 +213,14 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { if (args.length == 0) return DataResult.error(() -> "Cannot create EntryStackFavoriteEntry from empty args!"); if (!(args[0] instanceof EntryStack<?> stack)) return DataResult.error(() -> "Creation of EntryStackFavoriteEntry from args expected EntryStack as the first argument!"); - if (!stack.supportSaving()) + if (!stack.supportSerialization()) return DataResult.error(() -> "Creation of EntryStackFavoriteEntry from an unserializable stack!"); return DataResult.success(new EntryStackFavoriteEntry(stack), Lifecycle.stable()); } @Override public CompoundTag save(EntryStackFavoriteEntry entry, CompoundTag tag) { - tag.put(key, entry.stack.saveStack()); + tag.put(key, EntryStack.codec().encodeStart(BasicDisplay.registryAccess().createSerializationContext(NbtOps.INSTANCE), entry.stack).getOrThrow()); return tag; } } @@ -290,8 +286,8 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { public DataResult<DisplayFavoriteEntry> read(CompoundTag object) { try { if (object.contains("Data")) { - Display display = DisplaySerializerRegistry.getInstance().read(CategoryIdentifier.of(object.getString("CategoryID")), object.getCompound("Data")); - return DataResult.success(new DisplayFavoriteEntry(display, UUID.fromString(object.getString("UUID"))), Lifecycle.stable()); + DataResult<Display> result = Display.codec().parse(BasicDisplay.registryAccess().createSerializationContext(NbtOps.INSTANCE), object.getCompound("Data")); + return DataResult.success(new DisplayFavoriteEntry(result.getOrThrow(), UUID.fromString(object.getString("UUID"))), Lifecycle.stable()); } else { return DataResult.success(new DisplayFavoriteEntry(null, UUID.fromString(object.getString("UUID"))), Lifecycle.stable()); } @@ -310,13 +306,14 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { @Override public CompoundTag save(DisplayFavoriteEntry entry, CompoundTag tag) { - boolean hasSerializer = DisplaySerializerRegistry.getInstance().hasSerializer(entry.display.getCategoryIdentifier()); + boolean hasSerializer = entry.display.getSerializer() != null; tag.putString("CategoryID", entry.display.getCategoryIdentifier().toString()); tag.putString("UUID", entry.uuid.toString()); if (hasSerializer) { try { - tag.put("Data", DisplaySerializerRegistry.getInstance().save(entry.display, new CompoundTag())); + DataResult<Tag> displayTag = Display.codec().encodeStart(BasicDisplay.registryAccess().createSerializationContext(NbtOps.INSTANCE), entry.display); + tag.put("Data", displayTag.getOrThrow()); } catch (Exception e) { InternalLogger.getInstance().warn("Failed to save display favorite entry", e); } @@ -353,7 +350,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { @Override public Renderer getRenderer(boolean showcase) { Panel panel = Widgets.createRecipeBase(new Rectangle(0, 0, 18, 18)) - .yTextureOffset(RecipeBorderType.LIGHTER.getYOffset()); + .texture(PanelTextures.LIGHTER); Slot slot = Widgets.createSlot(new Rectangle()) .disableBackground() .disableHighlight() diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java index d38c7130d..4db2bf66b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java @@ -29,7 +29,7 @@ import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; -import me.shedaniel.rei.api.common.plugins.REIServerPlugin; +import me.shedaniel.rei.api.common.plugins.REICommonPlugin; import me.shedaniel.rei.api.common.transfer.info.stack.PlayerInventorySlotAccessor; import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessorRegistry; @@ -47,7 +47,7 @@ import java.util.Optional; import java.util.stream.Stream; @ApiStatus.Internal -public class DefaultRuntimePlugin implements REIServerPlugin { +public class DefaultRuntimePlugin implements REICommonPlugin { public static final ResourceLocation PLUGIN = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "default_runtime_plugin"); @Override 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().se |
