diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-10-22 22:39:04 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-10-22 22:39:04 +0800 |
| commit | 83b7f0488de9cc91951f4d9b2017f6ca1c0fa17e (patch) | |
| tree | db95f347f2e784c4adf17e7ce0acd9a1fe239f08 | |
| parent | 438d2387f330ffe8b328c4990498efa175b88a68 (diff) | |
| download | RoughlyEnoughItems-83b7f0488de9cc91951f4d9b2017f6ca1c0fa17e.tar.gz RoughlyEnoughItems-83b7f0488de9cc91951f4d9b2017f6ca1c0fa17e.tar.bz2 RoughlyEnoughItems-83b7f0488de9cc91951f4d9b2017f6ca1c0fa17e.zip | |
Support 22w42a
20 files changed, 582 insertions, 127 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java index f673a3356..d700051ad 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java @@ -28,6 +28,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; +import me.shedaniel.rei.impl.VersionAdapter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.renderer.MultiBufferSource; @@ -191,7 +192,7 @@ public class SpriteRenderer { throw new RuntimeException("Invalid Sprite!"); } - next(sprite.getName()); + next(VersionAdapter.INSTANCE.spriteName(sprite)); } public void next(ResourceLocation texture) { @@ -212,8 +213,8 @@ public class SpriteRenderer { this.normal = this.matrices.last().normal(); } - float sX = sprite.getWidth(); - float sY = sprite.getHeight(); + float sX = VersionAdapter.INSTANCE.spriteWidth(sprite); + float sY = VersionAdapter.INSTANCE.spriteHeight(sprite); RenderSystem.setShaderTexture(0, texture); diff --git a/api/src/main/java/me/shedaniel/rei/impl/VersionAdapter.java b/api/src/main/java/me/shedaniel/rei/impl/VersionAdapter.java new file mode 100644 index 000000000..12a91f0df --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/VersionAdapter.java @@ -0,0 +1,86 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.impl; + +import me.shedaniel.rei.api.common.entry.EntryStack; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +import java.util.Comparator; +import java.util.List; +import java.util.Optional; + +public interface VersionAdapter { + VersionAdapter INSTANCE = load(); + + private static VersionAdapter load() { + try { + Class.forName("me.shedaniel.rei.impl.init.versions.Version1_19_3AdapterCheck"); + return (VersionAdapter) Class.forName("me.shedaniel.rei.impl.init.versions.Version1_19_3Adapter").getDeclaredConstructor().newInstance(); + } catch (Throwable throwable) { + } + try { + Class.forName("me.shedaniel.rei.impl.init.versions.Version1_19_1AdapterCheck"); + return (VersionAdapter) Class.forName("me.shedaniel.rei.impl.init.versions.Version1_19_1Adapter").getDeclaredConstructor().newInstance(); + } catch (Throwable throwable) { + } + try { + return (VersionAdapter) Class.forName("me.shedaniel.rei.impl.init.versions.Version1_19Adapter").getDeclaredConstructor().newInstance(); + } catch (Throwable throwable) { + throw new RuntimeException(throwable); + } + } + + @Environment(EnvType.CLIENT) + List<ItemStack> appendStacksForItem(Item item, Comparator<ItemStack> comparator); + + @Environment(EnvType.CLIENT) + ResourceLocation spriteAtlasLocation(TextureAtlasSprite sprite); + + @Environment(EnvType.CLIENT) + ResourceLocation spriteName(TextureAtlasSprite sprite); + + @Environment(EnvType.CLIENT) + int spriteWidth(TextureAtlasSprite sprite); + + @Environment(EnvType.CLIENT) + int spriteHeight(TextureAtlasSprite sprite); + + <T> Optional<Holder<T>> getHolder(Registry<T> registry, ResourceKey<T> key); + + <T> Optional<Holder<T>> getHolder(Registry<T> registry, int id); + + @Environment(EnvType.CLIENT) + void sendCommand(String command); + + @Environment(EnvType.CLIENT) + Comparator<? super EntryStack<?>> getEntryGroupComparator(); +} diff --git a/build.gradle b/build.gradle index 3fefac531..4da517541 100755 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,15 @@ subprojects { } dependencies { - minecraft("com.mojang:minecraft:${rootProject.minecraft_version}") + if (project.path in gradle.ext.versions_targeted_list) { + gradle.ext.versions_targeted.split(",").each { + if (":version_support:${it.split(":")[1]}" == project.path) { + minecraft("com.mojang:minecraft:${it.split(":")[0]}") + } + } + } else { + minecraft("com.mojang:minecraft:${rootProject.minecraft_version}") + } mappings(loom.layered { officialMojangMappings() parchment("org.parchmentmc.data:parchment-1.17.1:2021.10.10@zip") @@ -57,6 +65,24 @@ subprojects { depProjects.each { sourceSet project(it).sourceSets.main } + gradle.ext.versions_targeted.split(",").each { splitTarget -> + if (splitTarget.split(":")[2] != "true" && project.path == ":forge") { + return + } + if (splitTarget.split(":")[0] == gradle.rootProject.minecraft_version) { + sourceSet project(":version_support:${splitTarget.split(":")[1]}").sourceSets.main + afterEvaluate { + project.dependencies { + common(project.dependencies.project(path: ":version_support:${splitTarget.split(":")[1]}", configuration: "namedElements")) { transitive false } + } + } + } + afterEvaluate { + project.dependencies { + shadowCommon(project.dependencies.project(path: ":version_support:${splitTarget.split(":")[1]}", configuration: "transformProduction${project.path == ":forge" ? "Forge" : "Fabric"}")) { transitive false } + } + } + } } } } @@ -76,6 +102,7 @@ allprojects { maven { url "https://maven.shedaniel.me" } maven { url "https://maven.parchmentmc.org" } maven { url "https://maven.terraformersmc.com/releases" } + mavenLocal() } license { @@ -99,6 +126,32 @@ allprojects { } subprojects { + if (project.path in gradle.ext.versions_targeted_list) { + loom { + accessWidenerPath = gradle.rootProject.project("fabric").file("src/main/resources/roughlyenoughitems.accessWidener") + } + + architectury { + def forge = forgeEnabled.toBoolean() + if (forge) { + gradle.ext.versions_targeted.split(",").each { + if (":version_support:${it.split(":")[1]}" == project.path) { + forge = it.split(":")[2].toBoolean() + } + } + } + common(forge ? ["forge", "fabric"] : ["fabric"]) + } + + dependencies { + modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}") + compileClasspath(project(path: ":api", configuration: "namedElements")) + compileClasspath(project(path: ":runtime", configuration: "namedElements")) + } + } +} + +subprojects { group = rootProject.group version = rootProject.version archivesBaseName = rootProject.name diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java index 1024fb190..a4dccf718 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java @@ -38,6 +38,7 @@ import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.common.util.CollectionUtils; +import me.shedaniel.rei.impl.VersionAdapter; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -147,7 +148,7 @@ public class GameModeFavoriteEntry extends FavoriteEntry { if (mode == null) { mode = GameType.byId(Minecraft.getInstance().gameMode.getPlayerMode().getId() + 1 % 4); } - CommandSender.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getGamemodeCommand().replaceAll("\\{gamemode}", mode.name().toLowerCase(Locale.ROOT)), "/")); + VersionAdapter.INSTANCE.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getGamemodeCommand().replaceAll("\\{gamemode}", mode.name().toLowerCase(Locale.ROOT)), "/")); Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); return true; } @@ -275,7 +276,7 @@ public class GameModeFavoriteEntry extends FavoriteEntry { public boolean mouseClicked(double mouseX, double mouseY, int button) { boolean disabled = this.minecraft.gameMode.getPlayerMode() == gameMode; if (!disabled && rendering && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 12) { - CommandSender.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getGamemodeCommand().replaceAll("\\{gamemode}", gameMode.name().toLowerCase(Locale.ROOT)), "/")); + VersionAdapter.INSTANCE.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getGamemodeCommand().replaceAll("\\{gamemode}", gameMode.name().toLowerCase(Locale.ROOT)), "/")); minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); closeMenu(); return true; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/TimeFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/TimeFavoriteEntry.java index 39bbc96a9..66245d37d 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/TimeFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/TimeFavoriteEntry.java @@ -39,6 +39,7 @@ import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.common.util.CollectionUtils; +import me.shedaniel.rei.impl.VersionAdapter; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.multiplayer.ClientLevel; @@ -181,7 +182,7 @@ public class TimeFavoriteEntry extends FavoriteEntry { if (time == null) { time = nextTime(); } - CommandSender.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getTimeCommand().replaceAll("\\{time}", time.getPart().toLowerCase(Locale.ROOT)), "/")); + VersionAdapter.INSTANCE.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getTimeCommand().replaceAll("\\{time}", time.getPart().toLowerCase(Locale.ROOT)), "/")); Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); return true; } @@ -303,7 +304,7 @@ public class TimeFavoriteEntry extends FavoriteEntry { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (rendering && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 12) { - CommandSender.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getTimeCommand().replaceAll("\\{time}", time.getPart().toLowerCase(Locale.ROOT)), "/")); + VersionAdapter.INSTANCE.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getTimeCommand().replaceAll("\\{time}", time.getPart().toLowerCase(Locale.ROOT)), "/")); minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); closeMenu(); return true; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java index c59abec80..f1f18d345 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java @@ -39,6 +39,7 @@ import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.common.util.CollectionUtils; +import me.shedaniel.rei.impl.VersionAdapter; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.multiplayer.ClientLevel; @@ -154,7 +155,7 @@ public class WeatherFavoriteEntry extends FavoriteEntry { public boolean doAction(int button) { if (button == 0) { if (weather != null) { - CommandSender.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT)), "/")); + VersionAdapter.INSTANCE.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT)), "/")); Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); } return true; @@ -312,7 +313,7 @@ public class WeatherFavoriteEntry extends FavoriteEntry { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (rendering && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 12) { - CommandSender.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT)), "/")); + VersionAdapter.INSTANCE.sendCommand(StringUtils.removeStart(ConfigObject.getInstance().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT)), "/")); minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); closeMenu(); return true; 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 51113aea0..da9fd0bea 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.impl.VersionAdapter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -207,7 +208,7 @@ public class TagNodes { TagNode<T> self = TagNode.ofReference(tagKey); List<Holder<T>> holders = new ArrayList<>(); for (int element : tagData.otherElements()) { - Optional<Holder<T>> holder = registry.getHolder(element); + Optional<Holder<T>> holder = VersionAdapter.INSTANCE.getHolder(registry, element); if (holder.isPresent()) { holders.add(holder.get()); } diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CommandSenderImpl.java b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CommandSenderImpl.java deleted file mode 100644 index 84212209e..000000000 --- a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CommandSenderImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.impl.client.fabric; - -import dev.architectury.platform.Platform; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -public class CommandSenderImpl { - public static void sendCommand(String command) { - LocalPlayer player = Minecraft.getInstance().player; - if (player == null) return; - String methodName = "method_44099"; - if (Platform.isDevelopmentEnvironment()) { - // 1.19.1 with boolean return - methodName = FabricLoader.getInstance().getMappingResolver().mapMethodName("intermediary", "net.minecraft.class_746", "method_44099", "(Ljava/lang/String;)Z"); - if (methodName.equals("method_44099")) { - // 1.19 with void return - methodName = FabricLoader.getInstance().getMappingResolver().mapMethodName("intermediary", "net.minecraft.class_746", "method_44099", "(Ljava/lang/String;)V"); - } - } - try { - Method declaredMethod = LocalPlayer.class.getDeclaredMethod(methodName, String.class); - if (declaredMethod != null) declaredMethod.setAccessible(true); - declaredMethod.invoke(player, command); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } -} diff --git a/fabric/src/main/resources/error_notifier.json b/fabric/src/main/resources/error_notifier.json index eb85f6a7c..f6ba1b432 100644 --- a/fabric/src/main/resources/error_notifier.json +++ b/fabric/src/main/resources/error_notifier.json @@ -12,7 +12,7 @@ "type": "depends", "modId": "architectury", "modName": "Architectury API", - "versions": ">=5.0.0 <7.0.0", + "versions": ">=5.0.0 <8.0.0", "url": "https://www.curseforge.com/minecraft/mc-mods/architectury-api/files/all" }, { diff --git a/gradle.properties b/gradle.properties index bc90c0201..133a8f7f3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,10 +5,10 @@ supported_version=1.19-1.19.2 minecraft_version=1.19 forgeEnabled=true forge_version=41.0.94 -fabricloader_version=0.14.6 +fabricloader_version=0.14.10 cloth_config_version=7.0.73 modmenu_version=4.0.0 -fabric_api=0.55.2+1.19 -architectury_version=5.9.31 +fabric_api=0.58.0+1.19 +architectury_version=5.12.45 api_exculde= #api_include=me.shedaniel.cloth:cloth-events,me.shedaniel.cloth:config-2,me.sargunvohra.mcmods:autoconfig1u,org.jetbrains:annotations,net.fabricmc.fabric-api:fabric diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 8acb6c09e..43204cec1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -47,6 +47,7 @@ import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.api.common.util.FormattingUtils; import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.VersionAdapter; import me.shedaniel.rei.impl.client.gui.screen.CompositeDisplayViewingScreen; import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; import me.shedaniel.rei.impl.client.view.ViewsImpl; @@ -70,7 +71,6 @@ import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.InvocationTargetException; import java.time.LocalDateTime; import java.util.*; import java.util.function.Supplier; @@ -226,13 +226,7 @@ public class ClientHelperImpl implements ClientHelper { madeUpCommand = og.replaceAll("\\{player_name}", Minecraft.getInstance().player.getScoreboardName()).replaceAll("\\{item_name}", identifier.getPath()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", "").replaceAll("\\{count}", String.valueOf(cheatedStack.getCount())); Minecraft.getInstance().player.displayClientMessage(Component.translatable("text.rei.too_long_nbt"), false); } - try { - Class.forName("me.shedaniel.rei.impl.client.%s.CommandSenderImpl".formatted(Platform.isForge() ? "forge" : "fabric")) - .getDeclaredMethod("sendCommand", String.class) - .invoke(null, StringUtils.removeStart(madeUpCommand, "/")); - } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) { - throw new RuntimeException(e); - } + VersionAdapter.INSTANCE.sendCommand(StringUtils.removeStart(madeUpCommand, "/")); return true; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListSearchManager.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListSearchManager.java index a03865208..8272fbfc2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListSearchManager.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListSearchManager.java @@ -33,15 +33,13 @@ import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.view.Views; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.impl.VersionAdapter; import me.shedaniel.rei.impl.client.search.AsyncSearchManager; import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.common.entry.type.collapsed.CollapsedStack; import me.shedaniel.rei.impl.common.entry.type.collapsed.CollapsibleEntryRegistryImpl; import net.minecraft.client.Minecraft; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; import org.apache.logging.log4j.Level; import org.jetbrains.annotations.Nullable; @@ -50,14 +48,7 @@ import java.util.function.Consumer; public class EntryListSearchManager { private static final Comparator<? super EntryStack<?>> ENTRY_NAME_COMPARER = Comparator.comparing(stack -> stack.asFormatStrippedText().getString()); - private static final Comparator<? super EntryStack<?>> ENTRY_GROUP_COMPARER = Comparator.comparingInt(stack -> { - if (stack.getType() == VanillaEntryTypes.ITEM) { - CreativeModeTab group = ((ItemStack) stack.getValue()).getItem().getItemCategory(); - if (group != null) - return group.getId(); - } - return Integer.MAX_VALUE; - }); + private static final Comparator<? super EntryStack<?>> ENTRY_GROUP_COMPARER = VersionAdapter.INSTANCE.getEntryGroupComparator(); public static final EntryListSearchManager INSTANCE = new EntryListSearchManager(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java index 293f3bc3e..ab01910f1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java @@ -33,17 +33,13 @@ import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; -import me.shedaniel.rei.api.common.entry.type.EntryDefinition; -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.common.InternalLogger; +import me.shedaniel.rei.impl.VersionAdapter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; @@ -135,27 +131,7 @@ public class EntryRegistryImpl implements EntryRegistry { @Override public List<ItemStack> appendStacksForItem(Item item) { - NonNullList<ItemStack> list = NonNullList.create(); - LongSet set = new LongOpenHashSet(); - EntryDefinition<ItemStack> itemDefinition = VanillaEntryTypes.ITEM.getDefinition(); - for (CreativeModeTab tab : CreativeModeTab.TABS) { - if (tab != CreativeModeTab.TAB_HOTBAR && tab != CreativeModeTab.TAB_INVENTORY) { - NonNullList<ItemStack> tabList = NonNullList.create(); - item.fillItemCategory(tab, tabList); - for (ItemStack stack : tabList) { - if (set.add(itemDefinition.hash(null, stack, ComparisonContext.EXACT))) { - list.add(stack); - } - } - } - } - if (list.isEmpty()) { - return Collections.singletonList(item.getDefaultInstance()); - } - if (list.size() > 1) { - list.sort(STACK_COMPARATOR); - } - return list; + return VersionAdapter.INSTANCE.appendStacksForItem(item, STACK_COMPARATOR); } @ApiStatus.Internal 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 4798ac656..928ee7a74 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 @@ -45,6 +45,7 @@ import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry; import me.shedaniel.rei.api.common.entry.type.EntryDefinition; import me.shedaniel.rei.api.common.entry.type.EntryType; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.impl.VersionAdapter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; @@ -256,7 +257,7 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS .alpha(0xff) .normal(matrices.last().normal(), 0, 0, 0) .position(matrices.last().pose(), bounds.x, bounds.getMaxY() - bounds.height * Mth.clamp(entry.get(EntryStack.Settings.FLUID_RENDER_RATIO), 0, 1), bounds.getMaxX(), bounds.getMaxY(), entry.getZ()) - .next(s.atlas().location()); + .next(VersionAdapter.INSTANCE.spriteAtlasLoca |
