From d6095aa4a0ccd8c4e2a0386f651dccc8b0134220 Mon Sep 17 00:00:00 2001 From: TexTrue <3140846162@qq.com> Date: Thu, 11 Jul 2024 00:01:16 +0800 Subject: [PATCH] sync with `sakura-ryoko/itemscroller` --- build.gradle | 59 ++++++++----------- gradle.properties | 19 ------ gradle/libs.versions.toml | 44 ++++++++++++++ .../itemscroller/gui/ItemScrollerIcons.java | 2 +- .../mixin/MixinCraftingScreenHandler.java | 4 +- .../itemscroller/util/InventoryUtils.java | 8 ++- .../masa/itemscroller/villager/TradeType.java | 2 +- .../assets/rocknroller/lang/en_us.json | 2 + .../assets/rocknroller/lang/zh_cn.json | 7 ++- 9 files changed, 83 insertions(+), 64 deletions(-) create mode 100644 gradle/libs.versions.toml diff --git a/build.gradle b/build.gradle index 7e76c7c..6412981 100644 --- a/build.gradle +++ b/build.gradle @@ -1,29 +1,31 @@ plugins { - id "dev.architectury.loom" version "1.6-SNAPSHOT" + alias(libs.plugins.architectury.loom) + alias(libs.plugins.modpublisher) id "maven-publish" - id "com.hypherionmc.modutils.modpublisher" version "2.+" } -base.archivesName = project.archives_base_name -version = "${project.mod_version}-mc${project.minecraft_version}" -group = project.maven_group +base.archivesName = libs.versions.archives.name +version = "${libs.versions.version.get()}-mc${libs.versions.minecraft.version.get()}" +group = libs.versions.maven.group repositories { - maven { url 'https://api.modrinth.com/maven' } + maven { url "https://www.jitpack.io" } maven { url "https://maven.neoforged.net/releases/" } + maven { url 'https://api.modrinth.com/maven' } } dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" + minecraft libs.minecraft mappings loom.layered { - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - mappings "dev.architectury:yarn-mappings-patch-${loom.platform.get().id()}:${project.yarn_patch}" + mappings variantOf(libs.yarn.mappings) { classifier("v2") } + mappings libs.yarn.mappings.patch } - neoForge "net.neoforged:neoforge:${project.neoforge_version}" + neoForge libs.neoforge - modImplementation "maven.modrinth:mafglib:${project.malilib_version}" + modImplementation libs.mafglib + modImplementation libs.neonetwork - implementation "com.google.code.findbugs:jsr305:3.0.2" + implementation libs.jsr305 } processResources { @@ -46,27 +48,12 @@ java { withSourcesJar() } -jar { - // add some additional metadata to the jar manifest - manifest { - attributes([ - "Specification-Title" : project.mod_id, - "Specification-Vendor" : project.mod_author, - "Specification-Version" : "1", - "Implementation-Title" : project.name, - "Implementation-Version" : version, - "Implementation-Vendor" : project.mod_author, - "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") - ]) - } -} - // configure the maven publication publishing { publications { mavenJava(MavenPublication) { - from components.java - } + from components.java + } } // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. @@ -84,17 +71,17 @@ publisher { curseforge System.getenv("CURSEFORGE_TOKEN") } - setCurseID("${project.curseforge_id}") - setModrinthID("${project.modrinth_id}") + setCurseID("${libs.versions.id.curseforge.get()}") + setModrinthID("${libs.versions.id.modrinth.get()}") setVersionType("alpha") setChangelog(file("CHANGELOG.md").getText("UTF-8")) setVersion("${project.version}") setDisplayName("${project.version}") - setGameVersions("1.20.5", "1.20.6") - setLoaders("neoforge") + setGameVersions(libs.versions.minecraft.range.get()) + setLoaders(loom.platform.get().id()) setCurseEnvironment("client") setArtifact(remapJar) addAdditionalFile(sourcesJar) - curseDepends { required("mafglib") } - modrinthDepends { required("mafglib") } -} + curseDepends.required("mafglib") + modrinthDepends.required("mafglib") +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index de7d55a..9e13dd0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,22 +2,3 @@ org.gradle.jvmargs=-Xmx1G loom.platform=neoforge - -# Base properties - # minecraft version - minecraft_version=1.20.6 - neoforge_version=20.6.119 - yarn_mappings=1.20.6+build.3 - yarn_patch=1.20.6+build.4 - -# Mod Properties - mod_version=0.1.3 - maven_group=org.thinkingstudio.rocknroller - archives_base_name=RocknRoller - mod_id=rocknroller - mod_author=ThinkingStudio - modrinth_id=hYq29QmW - curseforge_id=916852 - -# Dependencies - malilib_version=0.1.12-mc1.20.6 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..ed133bd --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,44 @@ +[versions] + +minecraft-range="1.21" + +# Base properties +minecraft_version="1.21" +yarn_mappings="1.21+build.2" +mappings_patch="1.21+build.4" +neoforge="21.0.78-beta" + +# Mod properties +version="0.1.3" +maven-group="org.thinkingstudio.rocknroller" +archives-name="RocknRoller" + +# Publish properties +id-modrinth="hYq29QmW" +id-curseforge="916852" + +# Mod dependencies +mafglib="0.1.14-mc1.21" +neonetwork="0.1.5+mc1.21" + +# Libraries +jsr305="3.0.2" + +# Gradle plugin +architectury-loom = "1.6-SNAPSHOT" +modpublisher = "2.1.+" + +[libraries] +minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft_version" } +yarn-mappings = { group = "net.fabricmc", name = "yarn", version.ref = "yarn_mappings"} +yarn-mappings-patch = { group = "dev.architectury", name = "yarn-mappings-patch-neoforge", version.ref = "mappings_patch"} + +neoforge = { group = "net.neoforged", name = "neoforge", version.ref = "neoforge" } +neonetwork = { group = "maven.modrinth", name = "neonetwork", version.ref = "neonetwork" } +mafglib = { group = "maven.modrinth", name = "mafglib", version.ref = "mafglib"} + +jsr305 = { group = "com.google.code.findbugs", name = "jsr305", version.ref = "jsr305"} + +[plugins] +architectury-loom = { id = "dev.architectury.loom", version.ref = "architectury-loom" } +modpublisher = { id = "com.hypherionmc.modutils.modpublisher", version.ref = "modpublisher" } \ No newline at end of file diff --git a/src/main/java/fi/dy/masa/itemscroller/gui/ItemScrollerIcons.java b/src/main/java/fi/dy/masa/itemscroller/gui/ItemScrollerIcons.java index 2abf639..0061599 100644 --- a/src/main/java/fi/dy/masa/itemscroller/gui/ItemScrollerIcons.java +++ b/src/main/java/fi/dy/masa/itemscroller/gui/ItemScrollerIcons.java @@ -13,7 +13,7 @@ public enum ItemScrollerIcons implements IGuiIcon STAR_5_YELLOW (112, 18, 5, 5), STAR_5_PURPLE (117, 18, 5, 5); - public static final Identifier TEXTURE = new Identifier(Reference.MOD_ID, "textures/gui/gui_widgets.png"); + public static final Identifier TEXTURE = Identifier.splitOn(Reference.MOD_ID + ":textures/gui/gui_widgets.png", ':'); private final int u; private final int v; diff --git a/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java b/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java index 07b2f81..7758524 100644 --- a/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java +++ b/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java @@ -9,6 +9,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.RecipeInputInventory; +import net.minecraft.recipe.CraftingRecipe; +import net.minecraft.recipe.RecipeEntry; import net.minecraft.screen.ScreenHandler; import net.minecraft.world.World; import fi.dy.masa.itemscroller.util.InventoryUtils; @@ -33,7 +35,7 @@ private static void onUpdateResult( PlayerEntity player, RecipeInputInventory craftingInventory, CraftingResultInventory resultInv, - CallbackInfo ci) + RecipeEntry recipeEntry, CallbackInfo ci) { InventoryUtils.onSlotChangedCraftingGrid(player, craftingInventory, resultInv); } diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 8d2ac07..5623e70 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -23,6 +23,7 @@ import net.minecraft.recipe.CraftingRecipe; import net.minecraft.recipe.RecipeEntry; import net.minecraft.recipe.RecipeType; +import net.minecraft.recipe.input.CraftingRecipeInput; import net.minecraft.registry.Registries; import net.minecraft.screen.MerchantScreenHandler; import net.minecraft.screen.ScreenHandler; @@ -107,10 +108,11 @@ public static void updateCraftingOutputSlot(PlayerEntity player, ItemStack stack = ItemStack.EMPTY; CraftingRecipe recipe = Configs.Generic.USE_RECIPE_CACHING.getBooleanValue() ? lastRecipe : null; RecipeEntry recipeEntry = null; + CraftingRecipeInput recipeInput = craftMatrix.createRecipeInput(); - if (recipe == null || recipe.matches(craftMatrix, world) == false) + if (recipe == null || recipe.matches(recipeInput, world) == false) { - Optional> optional = world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftMatrix, world); + Optional> optional = world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, recipeInput, world); recipe = optional.map(RecipeEntry::value).orElse(null); recipeEntry = optional.orElse(null); } @@ -122,7 +124,7 @@ public static void updateCraftingOutputSlot(PlayerEntity player, ((ClientPlayerEntity) player).getRecipeBook().contains(recipeEntry))) { inventoryCraftResult.setLastRecipe(recipeEntry); - stack = recipe.craft(craftMatrix, world.getRegistryManager()); + stack = recipe.craft(recipeInput, world.getRegistryManager()); } if (setEmptyStack || stack.isEmpty() == false) diff --git a/src/main/java/fi/dy/masa/itemscroller/villager/TradeType.java b/src/main/java/fi/dy/masa/itemscroller/villager/TradeType.java index f706f54..60f683f 100644 --- a/src/main/java/fi/dy/masa/itemscroller/villager/TradeType.java +++ b/src/main/java/fi/dy/masa/itemscroller/villager/TradeType.java @@ -65,7 +65,7 @@ public static Item getItemForName(String name) { try { - Identifier id = new Identifier(name); + Identifier id = Identifier.tryParse(name); return Registries.ITEM.get(id); } catch (Exception e) diff --git a/src/main/resources/assets/rocknroller/lang/en_us.json b/src/main/resources/assets/rocknroller/lang/en_us.json index 839ed36..be8259d 100644 --- a/src/main/resources/assets/rocknroller/lang/en_us.json +++ b/src/main/resources/assets/rocknroller/lang/en_us.json @@ -1,4 +1,6 @@ { + "fml.menu.mods.info.description.rocknroller": "ItemScroller unofficial (Neo)Forge port.\nMove items in inventory GUIs by scrolling the mouse wheel or dragging over slots.", + "itemscroller.gui.button.config_gui.generic": "Generic", "itemscroller.gui.button.config_gui.hotkeys": "Hotkeys", "itemscroller.gui.button.config_gui.toggles": "Toggles", diff --git a/src/main/resources/assets/rocknroller/lang/zh_cn.json b/src/main/resources/assets/rocknroller/lang/zh_cn.json index 6604148..87cfa60 100644 --- a/src/main/resources/assets/rocknroller/lang/zh_cn.json +++ b/src/main/resources/assets/rocknroller/lang/zh_cn.json @@ -1,6 +1,7 @@ { + "fml.menu.mods.info.description.rocknroller": "ItemScroller 非官方 (Neo)Forge 移植。\n通过滚动鼠标滚轮或在物品槽上拖动来移动库存图形用户界面中的物品。", - "itemscroller.gui.button.config_gui.generic": "通用", + "itemscroller.gui.button.config_gui.generic": "通用", "itemscroller.gui.button.config_gui.hotkeys": "快捷键", "itemscroller.gui.button.config_gui.toggles": "开关", @@ -8,8 +9,8 @@ "itemscroller.gui.label.trades": "交易", "itemscroller.gui.label.trade_uses": "交易使用: %d / %", - "itemscroller.message.toggled_mod_off": "Item Scroller功能调整为: §c关闭", - "itemscroller.message.toggled_mod_on": "tem Scroller功能调整为: §a开启", + "itemscroller.message.toggled_mod_off": "Item Scroller功能调整为: §c关闭", + "itemscroller.message.toggled_mod_on": "Item Scroller功能调整为: §a开启", "enableCraftingFeatures":"Crafting | 制作特性", "Enables scrolling items to and from crafting grids,\nwith a built-in 18 recipe memory.\nHold down the Recipe key to see the stored recipes and\nto change the selection. While holding the Recipe key,\nyou can either scroll or press a number key to change the selection.\nA recipe is stored to the currently selected \"recipe slot\"\n by clicking pick block over a configured crafting output slot.\nThe supported crafting grids must be added to the scrollableCraftingGrids list.":"开启内置共8页每页18种配方的存储,使得物品可以放置到合成表\n按住Recipe(配方)的快捷键查看配方列表,您可以滑动滚轮或使用数字键选择配方\n点击配方可以在工作台完成合成,在放置配方达到待命状态时(不取出合成产物)\n按下设定的storeRecipe(储存配方)快捷键就可以在选定的列表格内进行配方储存(自动覆写)。",