From 6285c7632f0aa45a445a2796296664f2d18235af Mon Sep 17 00:00:00 2001 From: Amarok <91077200+AmarokIce@users.noreply.github.com> Date: Tue, 29 Nov 2022 21:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=8D=20Fix=20group=20data=20and=20creat?= =?UTF-8?q?e=20the=20DataGenerator.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ovo/ovotest/info.json | 3 +- .../kotlin/club/someoneice/ovo/IDataGem.kt | 3 + .../club/someoneice/ovo/core/CoreRunner.kt | 25 +- .../club/someoneice/ovo/core/DataClearer.kt | 4 +- .../club/someoneice/ovo/core/DataList.kt | 2 + .../club/someoneice/ovo/core/DataProcessor.kt | 16 +- .../kotlin/club/someoneice/ovo/core/Info.kt | 1 + .../club/someoneice/ovo/data/BlockData.kt | 4 +- .../kotlin/club/someoneice/ovo/data/Group.kt | 4 +- .../club/someoneice/ovo/data/ItemData.kt | 4 +- .../club/someoneice/ovo/data/ItemFoods.kt | 4 +- .../club/someoneice/ovo/data/ItemGift.kt | 3 +- .../club/someoneice/ovo/data/ItemKnife.kt | 4 +- .../club/someoneice/ovo/data/ItemTool.kt | 4 +- .../club/someoneice/ovo/data/Recipes.kt | 10 + .../ovo/json/data/CoreDataOutput.kt | 12 + .../club/someoneice/ovo/json/data/JsonData.kt | 7 + .../ovo/json/data/helper/BlockJsonHelper.kt | 54 +++++ .../ovo/json/data/helper/ItemJsonHelper.kt | 57 +++++ .../ovo/json/data/helper/RecipeJsonHelper.kt | 217 ++++++++++++++++++ .../club/someoneice/ovo/json/reader/Group.kt | 3 +- .../someoneice/ovo/json/reader/Recipes.kt | 34 +++ .../club/someoneice/ovo/util/BlockBase.kt | 5 +- .../club/someoneice/ovo/util/ItemBase.kt | 7 +- .../club/someoneice/ovo/util/ItemFoodsBase.kt | 3 + .../club/someoneice/ovo/util/ItemGifts.kt | 3 + .../club/someoneice/ovo/util/ItemWeapons.kt | 3 + .../kotlin/club/someoneice/ovo/util/Util.kt | 8 +- .../club/someoneice/ovo/util/tool/ItemAxes.kt | 3 + .../club/someoneice/ovo/util/tool/ItemHoes.kt | 3 + .../someoneice/ovo/util/tool/ItemPickaxe.kt | 3 + .../someoneice/ovo/util/tool/ItemShovels.kt | 3 + 32 files changed, 492 insertions(+), 24 deletions(-) create mode 100644 src/main/kotlin/club/someoneice/ovo/IDataGem.kt create mode 100644 src/main/kotlin/club/someoneice/ovo/data/Recipes.kt create mode 100644 src/main/kotlin/club/someoneice/ovo/json/data/CoreDataOutput.kt create mode 100644 src/main/kotlin/club/someoneice/ovo/json/data/JsonData.kt create mode 100644 src/main/kotlin/club/someoneice/ovo/json/data/helper/BlockJsonHelper.kt create mode 100644 src/main/kotlin/club/someoneice/ovo/json/data/helper/ItemJsonHelper.kt create mode 100644 src/main/kotlin/club/someoneice/ovo/json/data/helper/RecipeJsonHelper.kt create mode 100644 src/main/kotlin/club/someoneice/ovo/json/reader/Recipes.kt diff --git a/ovo/ovotest/info.json b/ovo/ovotest/info.json index 46c9415..0eb865f 100644 --- a/ovo/ovotest/info.json +++ b/ovo/ovotest/info.json @@ -1,3 +1,4 @@ { - "modid": "ovotest" + "modid": "ovotest", + "data": "true" } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/IDataGem.kt b/src/main/kotlin/club/someoneice/ovo/IDataGem.kt new file mode 100644 index 0000000..2c3ef54 --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/IDataGem.kt @@ -0,0 +1,3 @@ +package club.someoneice.ovo + +interface IDataGem \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt b/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt index 5f90a6c..6be3d8f 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt @@ -28,6 +28,7 @@ class CoreRunner { private val tool = ItemTools() private val swords = ItemSwords() private val block = ItemBlocks() + private val recipes = Recipes() private val JsonProcessor = JsonProcessor(group, item, block, food, gift, swords, tool) @@ -38,11 +39,12 @@ class CoreRunner { Sandman.nullSandman() } else { readerPackage() - init() } } catch (_: FileNotFoundException) { throw FileNotFoundException("package.json is not find!") Sandman.nullSandman() + } finally { + init() } } @@ -66,12 +68,9 @@ class CoreRunner { private fun getFile(baseFile: String) { if (File("${baseFile}\\Group.json").isFile) { - OVOMain.Logger.info("Such File: ${baseFile}\\Group.json") - // group.getToolType(JsonProcessor, File("${baseFile}\\Group.json")) group.init(File("${baseFile}\\Group.json")) } - if (File("${baseFile}\\Item.json").isFile) { item.getToolType(JsonProcessor, File("${baseFile}\\Item.json")) } else if (File("${baseFile}\\Item").isDirectory) { @@ -125,6 +124,17 @@ class CoreRunner { block.getToolType(JsonProcessor, i) } } + + if (!Info.dataMode) return + + if (File("${baseFile}\\Recipes.json").isFile) { + recipes.init(File("${baseFile}\\Recipes.json")) + } else if (File("${baseFile}\\Recipes").isDirectory) { + val fileList: Array = File("${baseFile}\\Recipes").listFiles() as Array + for (i in fileList) { + recipes.init(i) + } + } } private fun readerPackage() { @@ -158,7 +168,12 @@ class CoreRunner { buffreader.close() val output: String = text.toString() - val infoList: HashMap = gson.fromJson(output, (object: TypeToken> () {} .type) ) + val infoList: Map = gson.fromJson(output, (object: TypeToken> () {} .type) ) + if (infoList.containsKey("data") && infoList["data"] == "true") { + OVOMain.Logger.info("Now will output Data!") + Info.dataMode = true + } + if (infoList.containsKey("modid")) { OVOMain.Logger.info("Find modid ${infoList["modid"]}") return infoList["modid"] diff --git a/src/main/kotlin/club/someoneice/ovo/core/DataClearer.kt b/src/main/kotlin/club/someoneice/ovo/core/DataClearer.kt index 032cd87..5a9b918 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/DataClearer.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/DataClearer.kt @@ -8,8 +8,8 @@ class DataClearer { DataList.dataItemFood.clear() DataList.dataItemTool.clear() DataList.dataItemWeapons.clear() + DataList.dataItemGift.clear() - // DataList.dataItemGift.clear() - + DataList.dataRecipe.clear() } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/core/DataList.kt b/src/main/kotlin/club/someoneice/ovo/core/DataList.kt index 8b910e3..494e3cd 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/DataList.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/DataList.kt @@ -16,4 +16,6 @@ object DataList { var dataBlock = ArrayList() var dataGroup = ArrayList() + + var dataRecipe = ArrayList() } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/core/DataProcessor.kt b/src/main/kotlin/club/someoneice/ovo/core/DataProcessor.kt index 646a257..a8e895c 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/DataProcessor.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/DataProcessor.kt @@ -2,6 +2,8 @@ package club.someoneice.ovo.core import club.someoneice.ovo.OVOMain import club.someoneice.ovo.data.Group +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.RecipeJsonHelper import club.someoneice.ovo.util.* import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder import net.minecraft.block.AbstractBlock @@ -21,6 +23,10 @@ class DataProcessor(private val mod_id: String?) { toolGroupProcessing() toolItemProcessing() toolBlockProcessing() + if (Info.dataMode) { + recipeDataProcessor() + // TODO - Lang... + } } private fun toolInfoProcessing() { @@ -42,7 +48,9 @@ class DataProcessor(private val mod_id: String?) { } private fun toolCreateGroupHelper(group: Group): ItemGroup { - return FabricItemGroupBuilder.build(Identifier(Info.modid, group.name)) { ItemStack(Util.findItemByText(group.icon) ?: Items.APPLE) } + return FabricItemGroupBuilder.build(Identifier(Info.modid, group.name)) { + ItemStack(Util.findItemByText(group.icon) ?: Items.APPLE) + } } private fun toolItemProcessing() { @@ -89,4 +97,10 @@ class DataProcessor(private val mod_id: String?) { } } } + + public fun recipeDataProcessor() { + for (recipe in DataList.dataRecipe) { + CoreDataOutput(RecipeJsonHelper(), recipe) + } + } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/core/Info.kt b/src/main/kotlin/club/someoneice/ovo/core/Info.kt index 8d7e832..0175f56 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/Info.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/Info.kt @@ -2,4 +2,5 @@ package club.someoneice.ovo.core object Info { var modid: String = "" + var dataMode: Boolean = false } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/data/BlockData.kt b/src/main/kotlin/club/someoneice/ovo/data/BlockData.kt index 7c0a212..4240d3a 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/BlockData.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/BlockData.kt @@ -1,8 +1,10 @@ package club.someoneice.ovo.data +import club.someoneice.ovo.IDataGem + data class BlockData( val name: String, val hard: Float, val drop_item: String, val group: String - ) \ No newline at end of file + ): IDataGem \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/data/Group.kt b/src/main/kotlin/club/someoneice/ovo/data/Group.kt index 59c1e38..5b93725 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/Group.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/Group.kt @@ -1,6 +1,8 @@ package club.someoneice.ovo.data +import club.someoneice.ovo.IDataGem + data class Group( val name: String, val icon: String -) +): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemData.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemData.kt index 494bfd0..3668c77 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemData.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemData.kt @@ -1,7 +1,9 @@ package club.someoneice.ovo.data +import club.someoneice.ovo.IDataGem + data class ItemData( val name: String, val max_size: Int, val group: String -) +): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemFoods.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemFoods.kt index d224266..bbec53a 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemFoods.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemFoods.kt @@ -1,6 +1,6 @@ package club.someoneice.ovo.data -import net.minecraft.item.Item +import club.someoneice.ovo.IDataGem data class ItemFoods( val name: String, @@ -13,4 +13,4 @@ data class ItemFoods( val isDrink: Boolean, val return_item: String, val group: String -) +): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemGift.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemGift.kt index c34fdd6..344f1e3 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemGift.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemGift.kt @@ -1,5 +1,6 @@ package club.someoneice.ovo.data +import club.someoneice.ovo.IDataGem import club.someoneice.ovo.data.helper.ItemGiftHelper import java.util.* @@ -8,4 +9,4 @@ data class ItemGift( val max_size: Int, val items: ArrayList, val group: String -) +): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemKnife.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemKnife.kt index 8fef409..4f25208 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemKnife.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemKnife.kt @@ -1,8 +1,10 @@ package club.someoneice.ovo.data +import club.someoneice.ovo.IDataGem + data class ItemKnife( val name: String, val attackDamage: Int, val tool_meta: String, val group: String -) +): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemTool.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemTool.kt index fb70b24..14cabd3 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemTool.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemTool.kt @@ -1,5 +1,7 @@ package club.someoneice.ovo.data +import club.someoneice.ovo.IDataGem + data class ItemTool( val name: String, @@ -7,4 +9,4 @@ data class ItemTool( val toolkit: String, val tool_meta: String, val group: String -) +): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/Recipes.kt b/src/main/kotlin/club/someoneice/ovo/data/Recipes.kt new file mode 100644 index 0000000..33460de --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/data/Recipes.kt @@ -0,0 +1,10 @@ +package club.someoneice.ovo.data + +import club.someoneice.ovo.IDataGem + +data class Recipes( + val type: String, + val count: Int, + val output: String, + val input: List +): IDataGem \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/data/CoreDataOutput.kt b/src/main/kotlin/club/someoneice/ovo/json/data/CoreDataOutput.kt new file mode 100644 index 0000000..d26f9c7 --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/json/data/CoreDataOutput.kt @@ -0,0 +1,12 @@ +package club.someoneice.ovo.json.data + +import club.someoneice.ovo.IDataGem +import club.someoneice.ovo.core.Info + +class CoreDataOutput(data: JsonData, dataSet: IDataGem) { + val modid = Info.modid + + init { + if (Info.dataMode) data.startIn(modid, dataSet) + } +} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/data/JsonData.kt b/src/main/kotlin/club/someoneice/ovo/json/data/JsonData.kt new file mode 100644 index 0000000..c697602 --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/json/data/JsonData.kt @@ -0,0 +1,7 @@ +package club.someoneice.ovo.json.data + +import club.someoneice.ovo.IDataGem + +abstract class JsonData { + abstract fun startIn(modid: String, dataSet: IDataGem) +} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/data/helper/BlockJsonHelper.kt b/src/main/kotlin/club/someoneice/ovo/json/data/helper/BlockJsonHelper.kt new file mode 100644 index 0000000..5532939 --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/json/data/helper/BlockJsonHelper.kt @@ -0,0 +1,54 @@ +package club.someoneice.ovo.json.data.helper + +import club.someoneice.ovo.IDataGem +import club.someoneice.ovo.data.BlockData +import club.someoneice.ovo.json.data.JsonData +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import java.io.BufferedWriter +import java.io.File +import java.io.FileWriter +import java.io.Writer +import java.nio.file.Files +import java.nio.file.Paths + +class BlockJsonHelper: JsonData() { + + override fun startIn(modid: String, dataSet: IDataGem) { + val basePath = "${System.getProperty("user.dir")}\\ovo\\resources\\assets\\$modid" + if (!File(basePath).exists()) File(basePath).mkdir() + if (!File("${basePath}\\blockstates").exists()) File("${basePath}\\blockstates").mkdir() + if (!File("${basePath}\\models\\block").exists()) File("${basePath}\\models\\block").mkdir() + if (!File("${basePath}\\textures\\block").exists()) File("${basePath}\\textures\\block").mkdir() + + if (dataSet is BlockData) { + File("${basePath}\\blockstates\\${dataSet.name}.json").createNewFile() + File("${basePath}\\models\\block\\${dataSet.name}.json").createNewFile() + + val gson = GsonBuilder().setPrettyPrinting().create() + + // State + val StateMap = HashMap() + val StateModelMap = HashMap() + val ModelMap = HashMap() + ModelMap["model"] = "${modid}:block/${dataSet.name}" + StateModelMap[""] = ModelMap + StateMap["variants"] = StateModelMap + + val writerState: BufferedWriter = Files.newBufferedWriter(Paths.get("${basePath}\\blockstates\\${dataSet.name}.json")) + writerState.append(gson.toJson(StateMap)) + writerState.close() + + // Model + val BaseMap = HashMap() + val TexturesMap = HashMap() + BaseMap["parent"] = "minecraft:block/cube_all" + TexturesMap["all"] = "${modid}:block/${dataSet.name}" + BaseMap["textures"] = TexturesMap + + val writerModel: BufferedWriter = Files.newBufferedWriter(Paths.get("${basePath}\\models\\block\\${dataSet.name}.json")) + writerModel.append(gson.toJson(BaseMap)) + writerModel.close() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/data/helper/ItemJsonHelper.kt b/src/main/kotlin/club/someoneice/ovo/json/data/helper/ItemJsonHelper.kt new file mode 100644 index 0000000..9a94b79 --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/json/data/helper/ItemJsonHelper.kt @@ -0,0 +1,57 @@ +package club.someoneice.ovo.json.data.helper + +import club.someoneice.ovo.IDataGem +import club.someoneice.ovo.data.* +import club.someoneice.ovo.json.data.JsonData +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import java.io.BufferedWriter +import java.io.File +import java.io.FileWriter +import java.nio.file.Files +import java.nio.file.Paths + +class ItemJsonHelper: JsonData() { + override fun startIn(modid: String, dataSet: IDataGem) { + if (dataSet is ItemData) { + dataProcessor(modid, dataSet.name) + } + + if (dataSet is ItemKnife) { + dataProcessor(modid, dataSet.name) + } + + if (dataSet is ItemFoods) { + dataProcessor(modid, dataSet.name) + } + + if (dataSet is ItemTool) { + dataProcessor(modid, dataSet.name) + } + + if (dataSet is ItemGift) { + dataProcessor(modid, dataSet.name) + } + } + + private fun dataProcessor(modid: String, name: String) { + val basePath = "${System.getProperty("user.dir")}\\ovo\\resources\\assets\\$modid" + + if (!File(basePath).exists()) File(basePath).mkdir() + if (!File("${basePath}\\models\\item").exists()) File("${basePath}\\models\\item").mkdir() + if (!File("${basePath}\\textures\\item").exists()) File("${basePath}\\textures\\item").mkdirs() + + File("${basePath}\\models\\item\\${name}.json").createNewFile() + + val BaseMap = HashMap() + val TexturesMap = HashMap() + BaseMap["parent"] = "item/generated" + TexturesMap["layer0"] = "${modid}:item/${name}" + BaseMap["textures"] = TexturesMap + + val gson = GsonBuilder().setPrettyPrinting().create() + val writer: BufferedWriter = Files.newBufferedWriter(Paths.get("${basePath}\\models\\item\\${name}.json")) + writer.append(gson.toJson(BaseMap)) + writer.close() + } +} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/data/helper/RecipeJsonHelper.kt b/src/main/kotlin/club/someoneice/ovo/json/data/helper/RecipeJsonHelper.kt new file mode 100644 index 0000000..aa35b4b --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/json/data/helper/RecipeJsonHelper.kt @@ -0,0 +1,217 @@ +package club.someoneice.ovo.json.data.helper + +import club.someoneice.ovo.IDataGem +import club.someoneice.ovo.data.Recipes +import club.someoneice.ovo.json.data.JsonData +import club.someoneice.ovo.util.Util +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import java.io.BufferedWriter +import java.io.File +import java.io.FileWriter +import java.nio.file.Files +import java.nio.file.Paths + +class RecipeJsonHelper: JsonData() { + var modid: String? = null + var dataSet: Recipes? = null + val gson: Gson = GsonBuilder().setPrettyPrinting().create() + val basePath = "${System.getProperty("user.dir")}\\ovo\\resources\\data\\$modid" + + override fun startIn(modid: String, dataSet: IDataGem) { + if (!File(basePath).exists()) File(basePath).mkdir() + if (!File("${basePath}\\recipes").exists()) File("${basePath}\\recipes").mkdir() + + if (dataSet is Recipes) { + this.modid = modid + this.dataSet = dataSet + + when (dataSet.type) { + "crafting_shapeless" -> craftingShapeless() + "crafting_shaped" -> craftingShaped() + "smelting" -> smeltingRecipe() + "smoking" -> smokingRecipe() + "blast" -> blastRecipe() + "campfire" -> campfire() + + // TODO + "pot" -> pot() + "cut" -> cut() + } + } + } + + private fun craftingShapeless() { + val dataSet = this.dataSet!! + val path = File("${basePath}\\recipes\\shapeless") + if (!path.exists()) path.mkdir() + + File("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}").createNewFile() + + val BaseMap = HashMap() + val RecipeList = ArrayList() + val ResultMap = HashMap() + + for (i in dataSet.input) { + val ItemMap = HashMap() + ItemMap["item"] = i + RecipeList.add(ItemMap) + } + + ResultMap["item"] = dataSet.output + ResultMap["count"] = dataSet.count + + BaseMap["type"] = "minecraft:crafting_shapeless" + BaseMap["ingredients"] = RecipeList + BaseMap["result"] = ResultMap + + val writerModel: BufferedWriter = Files.newBufferedWriter(Paths.get("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}")) + writerModel.append(gson.toJson(BaseMap)) + writerModel.close() + } + + private fun craftingShaped() { + val dataSet = this.dataSet!! + var startRecipes = false + var recipesCounter = 0 + val path = File("${basePath}\\recipes\\shaped") + if (!path.exists()) path.mkdir() + + File("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}").createNewFile() + + val BaseMap = HashMap() + val RecipeList = ArrayList() + val KeyMap = HashMap() + val ResultMap = HashMap() + + RecipeList.add(dataSet.input[0]) + + for (i in 1 .. dataSet.input.size) { + if ((i == 1 && dataSet.input[0].length == dataSet.input[i].length && dataSet.input[i + 1].length <= 3) || i < 3 ) { + RecipeList.add(dataSet.input[i]) + } else if (!startRecipes){ + startRecipes = true + continue + } + + if (startRecipes && i != recipesCounter) { + val ItemMap = HashMap() + ItemMap["item"] = dataSet.input[i + 1] + KeyMap[dataSet.input[i]] = ItemMap + recipesCounter = i + 1 + } + } + + ResultMap["item"] = dataSet.output + ResultMap["count"] = dataSet.count + + BaseMap["type"] = "minecraft:crafting_shaped" + BaseMap["ingredients"] = RecipeList + BaseMap["key"] = KeyMap + BaseMap["result"] = ResultMap + + val writerModel: BufferedWriter = Files.newBufferedWriter(Paths.get("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}")) + writerModel.append(gson.toJson(BaseMap)) + writerModel.close() + } + + private fun smeltingRecipe() { + val dataSet = this.dataSet!! + val path = File("${basePath}\\recipes\\smelting") + if (!path.exists()) path.mkdir() + + File("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}").createNewFile() + + val BaseMap = HashMap() + val KeyMap = HashMap() + + KeyMap["item"] = dataSet.input[0] + + BaseMap["type"] = "minecraft:smelting" + BaseMap["ingredient"] = KeyMap + BaseMap["result"] = dataSet.output + BaseMap["experience"] = 0.5 + BaseMap["cookingtime"] = 200 + + val writerModel: BufferedWriter = Files.newBufferedWriter(Paths.get("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}")) + writerModel.append(gson.toJson(BaseMap)) + writerModel.close() + } + + private fun smokingRecipe() { + val dataSet = this.dataSet!! + val path = File("${basePath}\\recipes\\smoking") + if (!path.exists()) path.mkdir() + + File("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}").createNewFile() + + val BaseMap = HashMap() + val KeyMap = HashMap() + + KeyMap["item"] = dataSet.input[0] + + BaseMap["type"] = "minecraft:smoking" + BaseMap["ingredient"] = KeyMap + BaseMap["result"] = dataSet.output + BaseMap["experience"] = 0.5 + BaseMap["cookingtime"] = 100 + + val writerModel: BufferedWriter = Files.newBufferedWriter(Paths.get("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}")) + writerModel.append(gson.toJson(BaseMap)) + writerModel.close() + } + + private fun blastRecipe() { + val dataSet = this.dataSet!! + val path = File("${basePath}\\recipes\\blasting") + if (!path.exists()) path.mkdir() + + File("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}").createNewFile() + + val BaseMap = HashMap() + val KeyMap = HashMap() + + KeyMap["item"] = dataSet.input[0] + + BaseMap["type"] = "minecraft:blasting" + BaseMap["ingredient"] = KeyMap + BaseMap["result"] = dataSet.output + BaseMap["experience"] = 0.5 + BaseMap["cookingtime"] = 100 + + val writerModel: BufferedWriter = Files.newBufferedWriter(Paths.get("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}")) + writerModel.append(gson.toJson(BaseMap)) + writerModel.close() + } + + private fun campfire() { + val dataSet = this.dataSet!! + val path = File("${basePath}\\recipes\\campfire") + if (!path.exists()) path.mkdir() + + File("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}").createNewFile() + + val BaseMap = HashMap() + val KeyMap = HashMap() + + KeyMap["item"] = dataSet.input[0] + + BaseMap["type"] = "minecraft:campfire_cooking" + BaseMap["ingredient"] = KeyMap + BaseMap["result"] = dataSet.output + BaseMap["experience"] = 0.5 + BaseMap["cookingtime"] = 400 + + val writerModel: BufferedWriter = Files.newBufferedWriter(Paths.get("${path}\\${ Util.getItemNameByRegistryName(dataSet.output)}")) + writerModel.append(gson.toJson(BaseMap)) + writerModel.close() + } + + private fun pot() { + + } + + private fun cut() { + + } +} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/Group.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/Group.kt index 5225753..57484a2 100644 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/Group.kt +++ b/src/main/kotlin/club/someoneice/ovo/json/reader/Group.kt @@ -9,7 +9,6 @@ import com.google.gson.reflect.TypeToken import java.io.BufferedReader import java.io.File import java.io.FileReader -import java.util.* class Group: JsonTypeHelper() { override fun getToolType(typeGetter: JsonTypeGetter, filePath: File) { @@ -17,7 +16,7 @@ class Group: JsonTypeHelper() { } fun init(filePath: File) { - val type = object: TypeToken>() {}.type + val type = object: TypeToken>() {}.type val gson = Gson() val text = StringBuffer() diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/Recipes.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/Recipes.kt new file mode 100644 index 0000000..5a61ac8 --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/json/reader/Recipes.kt @@ -0,0 +1,34 @@ +package club.someoneice.ovo.json.reader + +import club.someoneice.ovo.core.DataList +import club.someoneice.ovo.json.Sandman +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import java.io.BufferedReader +import java.io.File +import java.io.FileReader + +class Recipes { + fun init(filePath: File) { + val type = object: TypeToken>() {}.type + + val gson = Gson() + val text = StringBuffer() + val buffreader = BufferedReader(FileReader(filePath)) + + try { + while (true) { + val str = buffreader.readLine() + if (str == null) break else text.append(str.toString()) + } + + buffreader.close() + val output: String = text.toString() + val list: List = gson.fromJson(output, type) + for (i in list) DataList.dataRecipe.add(i) + + } catch (_: Exception) { + Sandman.nullSandman() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/BlockBase.kt b/src/main/kotlin/club/someoneice/ovo/util/BlockBase.kt index f4179e8..60754fe 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/BlockBase.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/BlockBase.kt @@ -1,10 +1,11 @@ package club.someoneice.ovo.util -import club.someoneice.ovo.OVOMain import club.someoneice.ovo.core.DataList import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.BlockData import club.someoneice.ovo.json.Sandman +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.BlockJsonHelper import club.someoneice.ovo.util.Util.findItemByText import net.minecraft.block.Block import net.minecraft.block.BlockState @@ -20,6 +21,8 @@ class BlockBase(settings: Settings, private val blockSet: BlockData): Block(sett init { Registry.register(Registry.BLOCK, Identifier(Info.modid, blockSet.name), this) Registry.register(Registry.ITEM, Identifier(Info.modid, blockSet.name), BlockItem(this, Item.Settings().group(DataList.getGroup[blockSet.group]))) + + CoreDataOutput(BlockJsonHelper(), blockSet) } override fun getDroppedStacks(state: BlockState, builder: LootContext.Builder): MutableList { diff --git a/src/main/kotlin/club/someoneice/ovo/util/ItemBase.kt b/src/main/kotlin/club/someoneice/ovo/util/ItemBase.kt index 8ee7d54..70054b1 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemBase.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemBase.kt @@ -3,6 +3,9 @@ package club.someoneice.ovo.util import club.someoneice.ovo.OVOMain import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.ItemData +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.BlockJsonHelper +import club.someoneice.ovo.json.data.helper.ItemJsonHelper import net.minecraft.item.Item import net.minecraft.util.Identifier import net.minecraft.util.registry.Registry @@ -10,6 +13,8 @@ import net.minecraft.util.registry.Registry class ItemBase(settings: Settings, itemSet: ItemData): Item(settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, itemSet.name), this) - OVOMain.Logger.info("Item ${itemSet.name} is register success!") + + CoreDataOutput(ItemJsonHelper(), itemSet) + OVOMain.Logger.debug("Item ${itemSet.name} is register success!") } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/ItemFoodsBase.kt b/src/main/kotlin/club/someoneice/ovo/util/ItemFoodsBase.kt index ebc63d1..fa1a3d7 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemFoodsBase.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemFoodsBase.kt @@ -3,6 +3,8 @@ package club.someoneice.ovo.util import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.ItemFoods import club.someoneice.ovo.json.Sandman +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.ItemJsonHelper import club.someoneice.ovo.util.Util.findItemByText import net.minecraft.entity.LivingEntity import net.minecraft.item.Item @@ -15,6 +17,7 @@ import net.minecraft.world.World class ItemFoodsBase(settings: Settings, private val foodSet: ItemFoods): Item(settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, foodSet.name), this) + CoreDataOutput(ItemJsonHelper(), foodSet) } override fun getUseAction(stack: ItemStack?): UseAction { diff --git a/src/main/kotlin/club/someoneice/ovo/util/ItemGifts.kt b/src/main/kotlin/club/someoneice/ovo/util/ItemGifts.kt index 585684a..456c789 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemGifts.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemGifts.kt @@ -2,6 +2,8 @@ package club.someoneice.ovo.util import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.ItemGift +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.ItemJsonHelper import club.someoneice.ovo.util.Util.findItemByText import net.minecraft.entity.LivingEntity import net.minecraft.entity.player.PlayerEntity @@ -14,6 +16,7 @@ import net.minecraft.world.World class ItemGifts(settings: Settings, private val itemSet: ItemGift): Item(settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, itemSet.name), this) + CoreDataOutput(ItemJsonHelper(), itemSet) } override fun finishUsing(stack: ItemStack, world: World, user: LivingEntity): ItemStack { diff --git a/src/main/kotlin/club/someoneice/ovo/util/ItemWeapons.kt b/src/main/kotlin/club/someoneice/ovo/util/ItemWeapons.kt index 60eabc2..6960716 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemWeapons.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemWeapons.kt @@ -2,6 +2,8 @@ package club.someoneice.ovo.util import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.ItemKnife +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.ItemJsonHelper import net.minecraft.item.* import net.minecraft.util.Identifier import net.minecraft.util.registry.Registry @@ -9,5 +11,6 @@ import net.minecraft.util.registry.Registry class ItemWeapons(settings: Settings, toolSet: ItemKnife, toolMate: ToolMaterials?): SwordItem(toolMate, toolSet.attackDamage, -2.4F, settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, toolSet.name), this) + CoreDataOutput(ItemJsonHelper(), toolSet) } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/Util.kt b/src/main/kotlin/club/someoneice/ovo/util/Util.kt index 83e0caa..b922df3 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/Util.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/Util.kt @@ -1,8 +1,6 @@ package club.someoneice.ovo.util -import club.someoneice.ovo.json.Sandman import net.minecraft.item.Item -import net.minecraft.item.Items import net.minecraft.util.Identifier import net.minecraft.util.registry.Registry @@ -11,7 +9,7 @@ object Util { if (Item == "null") return null return try { - val modid: String = Item.substring(1, Item.indexOf(":") - 1) + val modid: String = Item.substring(0, Item.indexOf(":")) val name: String = Item.substring(Item.indexOf(":") + 1) Registry.ITEM.get(Identifier(modid, name)) @@ -20,4 +18,8 @@ object Util { } } + fun getItemNameByRegistryName(ItemName: String): String { + return ItemName.substring(ItemName.indexOf(":") + 1) + } + } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemAxes.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemAxes.kt index 37e59b5..c07e1b2 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemAxes.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemAxes.kt @@ -2,6 +2,8 @@ package club.someoneice.ovo.util.tool import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.ItemTool +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.ItemJsonHelper import net.minecraft.item.AxeItem import net.minecraft.item.ToolMaterials import net.minecraft.util.Identifier @@ -10,5 +12,6 @@ import net.minecraft.util.registry.Registry class ItemAxes(settings: Settings, toolMate: ToolMaterials, toolSet: ItemTool): AxeItem(toolMate, toolSet.attackDamage.toFloat(), -3.2f, settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, toolSet.name), this) + CoreDataOutput(ItemJsonHelper(), toolSet) } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemHoes.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemHoes.kt index ca04f53..0a51a15 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemHoes.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemHoes.kt @@ -2,6 +2,8 @@ package club.someoneice.ovo.util.tool import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.ItemTool +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.ItemJsonHelper import net.minecraft.item.HoeItem import net.minecraft.item.ToolMaterials import net.minecraft.util.Identifier @@ -10,5 +12,6 @@ import net.minecraft.util.registry.Registry class ItemHoes(settings: Settings, toolMate: ToolMaterials, toolSet: ItemTool): HoeItem(toolMate, toolSet.attackDamage, -3.0f, settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, toolSet.name), this) + CoreDataOutput(ItemJsonHelper(), toolSet) } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemPickaxe.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemPickaxe.kt index 2a4944d..9c906de 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemPickaxe.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemPickaxe.kt @@ -2,6 +2,8 @@ package club.someoneice.ovo.util.tool import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.ItemTool +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.ItemJsonHelper import net.minecraft.item.PickaxeItem import net.minecraft.item.ToolMaterials import net.minecraft.util.Identifier @@ -10,5 +12,6 @@ import net.minecraft.util.registry.Registry class ItemPickaxe(settings: Settings, toolMate: ToolMaterials, toolSet: ItemTool): PickaxeItem(toolMate, toolSet.attackDamage,-2.8f,settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, toolSet.name), this) + CoreDataOutput(ItemJsonHelper(), toolSet) } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemShovels.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemShovels.kt index 07bf972..515337d 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemShovels.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemShovels.kt @@ -2,6 +2,8 @@ package club.someoneice.ovo.util.tool import club.someoneice.ovo.core.Info import club.someoneice.ovo.data.ItemTool +import club.someoneice.ovo.json.data.CoreDataOutput +import club.someoneice.ovo.json.data.helper.ItemJsonHelper import net.minecraft.item.ShovelItem import net.minecraft.item.ToolMaterials import net.minecraft.util.Identifier @@ -10,5 +12,6 @@ import net.minecraft.util.registry.Registry class ItemShovels(settings: Settings, toolMate: ToolMaterials, toolSet: ItemTool): ShovelItem(toolMate, toolSet.attackDamage.toFloat(), -3.0f, settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, toolSet.name), this) + CoreDataOutput(ItemJsonHelper(), toolSet) } } \ No newline at end of file