diff --git a/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt b/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt index 4ac2db7..ac91ff1 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt @@ -1,187 +1,78 @@ package club.someoneice.ovo.core import club.someoneice.ovo.OVOMain +import club.someoneice.ovo.core.`object`.DataList +import club.someoneice.ovo.data.* +import club.someoneice.ovo.json.JsonReaderBean import club.someoneice.ovo.json.Sandman -import club.someoneice.ovo.json.helper.JsonProcessor -import club.someoneice.ovo.json.reader.Group -import club.someoneice.ovo.json.reader.Item -import club.someoneice.ovo.json.reader.* -import com.google.common.reflect.TypeToken import com.google.gson.Gson -import java.io.BufferedReader import java.io.File import java.io.FileNotFoundException -import java.io.FileReader import java.util.* -import kotlin.collections.List class CoreRunner { - private val gson: Gson = Gson() private val basePath: String = "${System.getProperty("user.dir")}\\ovo" private val packageInfoFilePath: File = File("$basePath\\ovo_package.json") private var packagePathList = ArrayList() - private val group = Group() - private val item = Item() - private val food = ItemFoods() - private val gift = ItemGifts() - 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) + private val group = JsonReaderBean() + private val item = JsonReaderBean() + private val food = JsonReaderBean() + private val gift = JsonReaderBean() + private val tool = JsonReaderBean() + private val swords = JsonReaderBean() + private val block = JsonReaderBean() init { try { - if (!packageInfoFilePath.isFile) { - OVOMain.Logger.info("ovo_package.json is not find!") - Sandman.nullSandman() - } else { - readerPackage() + if (packageInfoFilePath.isFile) { + JsonReaderBean().init(packageInfoFilePath, packagePathList) init() - } + } else OVOMain.Logger.info("ovo_package.json is not find!") } catch (_: FileNotFoundException) { - throw FileNotFoundException("package.json is not find!") Sandman.nullSandman() } } private fun init() { - if (packagePathList.size < 1) return - for (i in packagePathList){ - if (!File("${basePath}\\${i}").isDirectory || !File("${basePath}\\${i}\\info.json").isFile) { - continue - } else { - OVOMain.Logger.info("Such package: ${basePath}\\${i}") - val modid: String? = readInfo(File("${basePath}\\${i}\\info.json")) - getFile("${basePath}\\${i}") - - DataProcessor(modid) - - // Finish read this package, and now clear the DataList. - DataClearer() - } - } - } - - private fun getFile(baseFile: String) { - if (File("${baseFile}\\Group.json").isFile) { - group.init(File("${baseFile}\\Group.json")) - } + for (i in packagePathList) { + if (File("${basePath}\\${i}").isDirectory || !File("${basePath}\\${i}\\info.json").isFile) { + OVOMain.Logger.info("Such pockage: ${basePath}\\${i}") + val modid: String? = + (JsonReaderBean>().readWithOriginal(File("${basePath}\\${i}\\info.json")) as HashMap)["modid"] - if (File("${baseFile}\\Item.json").isFile) { - item.getToolType(JsonProcessor, File("${baseFile}\\Item.json")) - } else if (File("${baseFile}\\Item").isDirectory) { - val fileList: Array = File("${baseFile}\\Item").listFiles() as Array - for (i in fileList) { - item.getToolType(JsonProcessor, i) - } - } + // Scanning the OVOPackage! And add all we want! + scanning("${basePath}\\${i}") - if (File("${baseFile}\\ItemFood.json").isFile) { - food.getToolType(JsonProcessor, File("${baseFile}\\ItemFood.json")) - } else if (File("${baseFile}\\ItemFood").isDirectory) { - val fileList: Array = File("${baseFile}\\ItemFood").listFiles() as Array - for (i in fileList) { - food.getToolType(JsonProcessor, i) - } - } - - if (File("${baseFile}\\ItemGift.json").isFile) { - gift.getToolType(JsonProcessor, File("${baseFile}\\ItemGift.json")) - } else if (File("${baseFile}\\ItemGift").isDirectory) { - val fileList: Array = File("${baseFile}\\ItemGift").listFiles() as Array - for (i in fileList) { - gift.getToolType(JsonProcessor, i) - } - } - - if (File("${baseFile}\\ItemTool.json").isFile) { - tool.getToolType(JsonProcessor, File("${baseFile}\\ItemTool.json")) - } else if (File("${baseFile}\\ItemTool").isDirectory) { - val fileList: Array = File("${baseFile}\\ItemTool").listFiles() as Array - for (i in fileList) { - tool.getToolType(JsonProcessor, i) - } - } - - if (File("${baseFile}\\ItemWeapons.json").isFile) { - swords.getToolType(JsonProcessor, File("${baseFile}\\ItemWeapons.json")) - } else if (File("${baseFile}\\ItemWeapons").isDirectory) { - val fileList: Array = File("${baseFile}\\ItemWeapons").listFiles() as Array - for (i in fileList) { - swords.getToolType(JsonProcessor, i) - } - } - - if (File("${baseFile}\\Block.json").isFile) { - block.getToolType(JsonProcessor, File("${baseFile}\\Block.json")) - } else if (File("${baseFile}\\Block").isDirectory) { - val fileList: Array = File("${baseFile}\\Block").listFiles() as Array - for (i in fileList) { - 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) + DataProcessor(modid) + DataList.init() } } } - private fun readerPackage() { - val text = StringBuffer() - val buffreader = BufferedReader(FileReader(packageInfoFilePath)) - - try { - while (true) { - val str = buffreader.readLine() - if (str == null) break else text.append(str.toString()) + @OptIn(ExperimentalStdlibApi::class) + private fun scanning(baseFile: String) { + val initPath = File(baseFile) + if (!initPath.exists() || !initPath.isDirectory) return + for (file in initPath.listFiles()!!) { + val name: String = if (file.isDirectory) file.name else file.nameWithoutExtension + when (name.lowercase()) { + "Item".lowercase() -> handle(file, item, DataList.dataItem) + "ItemFood".lowercase() -> handle(file, food, DataList.dataItemFood) + "ItemGift".lowercase() -> handle(file, gift, DataList.dataItemGift) + "ItemTool".lowercase() -> handle(file, tool, DataList.dataItemTool) + "ItemWeapons".lowercase() -> handle(file, swords, DataList.dataItemWeapons) + "Block".lowercase() -> handle(file, block, DataList.dataBlock) + "Group".lowercase() -> { + if (file.isDirectory) continue + group.init(file, DataList.dataGroup) + } } - - buffreader.close() - val output: String = text.toString() - packagePathList = gson.fromJson(output, (object: TypeToken> () {} .type) ) - - } catch (_: Exception) { - Sandman.nullSandman() } } - private fun readInfo(infoPath: File): String? { - val text = StringBuffer() - val buffreader = BufferedReader(FileReader(infoPath)) - - try { - while (true) { - val str = buffreader.readLine() - if (str == null) break else text.append(str.toString()) - } - - buffreader.close() - val output: String = text.toString() - 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"] - } - - } catch (_: Exception) { - Sandman.nullSandman() - } - - return Sandman.missingNo() as String? + private fun handle(file: File, json: JsonReaderBean, list: ArrayList) { + if (file.isDirectory) for(f in file.listFiles()!!) json.init(f, list) + else json.init(file, list) } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/core/DataClearer.kt b/src/main/kotlin/club/someoneice/ovo/core/DataClearer.kt deleted file mode 100644 index 5a9b918..0000000 --- a/src/main/kotlin/club/someoneice/ovo/core/DataClearer.kt +++ /dev/null @@ -1,15 +0,0 @@ -package club.someoneice.ovo.core - -class DataClearer { - init { - DataList.dataItem.clear() - DataList.dataBlock.clear() - DataList.dataGroup.clear() - DataList.dataItemFood.clear() - DataList.dataItemTool.clear() - DataList.dataItemWeapons.clear() - DataList.dataItemGift.clear() - - DataList.dataRecipe.clear() - } -} \ 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 a8e895c..5d8ebd6 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/DataProcessor.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/DataProcessor.kt @@ -1,6 +1,8 @@ package club.someoneice.ovo.core import club.someoneice.ovo.OVOMain +import club.someoneice.ovo.core.`object`.DataList +import club.someoneice.ovo.core.`object`.Info import club.someoneice.ovo.data.Group import club.someoneice.ovo.json.data.CoreDataOutput import club.someoneice.ovo.json.data.helper.RecipeJsonHelper @@ -8,12 +10,7 @@ import club.someoneice.ovo.util.* import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder import net.minecraft.block.AbstractBlock import net.minecraft.block.Material -import net.minecraft.item.FoodComponent -import net.minecraft.item.Item -import net.minecraft.item.ItemGroup -import net.minecraft.item.ItemStack -import net.minecraft.item.Items -import net.minecraft.item.ToolMaterials +import net.minecraft.item.* import net.minecraft.util.Identifier @@ -23,10 +20,6 @@ class DataProcessor(private val mod_id: String?) { toolGroupProcessing() toolItemProcessing() toolBlockProcessing() - if (Info.dataMode) { - recipeDataProcessor() - // TODO - Lang... - } } private fun toolInfoProcessing() { @@ -86,6 +79,7 @@ class DataProcessor(private val mod_id: String?) { else -> ToolMaterials.WOOD } + ItemWeapons(Item.Settings().group(DataList.getGroup[weapons.group]).maxCount(1), weapons, mate) } } @@ -98,7 +92,7 @@ class DataProcessor(private val mod_id: String?) { } } - public fun recipeDataProcessor() { + private fun recipeDataProcessor() { for (recipe in DataList.dataRecipe) { CoreDataOutput(RecipeJsonHelper(), recipe) } diff --git a/src/main/kotlin/club/someoneice/ovo/core/DataList.kt b/src/main/kotlin/club/someoneice/ovo/core/object/DataList.kt similarity index 52% rename from src/main/kotlin/club/someoneice/ovo/core/DataList.kt rename to src/main/kotlin/club/someoneice/ovo/core/object/DataList.kt index 494e3cd..c3131b0 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/DataList.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/object/DataList.kt @@ -1,21 +1,32 @@ -package club.someoneice.ovo.core +package club.someoneice.ovo.core.`object` import club.someoneice.ovo.data.* import net.minecraft.item.ItemGroup -import java.util.* object DataList { var getGroup: HashMap = HashMap() var dataItem = ArrayList() var dataItemGift = ArrayList() - var dataItemFood = ArrayList() + var dataItemFood = ArrayList() var dataItemTool = ArrayList() - var dataItemWeapons = ArrayList() + var dataItemWeapons = ArrayList() var dataBlock = ArrayList() var dataGroup = ArrayList() var dataRecipe = ArrayList() + + fun init() { + dataItem.clear() + dataBlock.clear() + dataGroup.clear() + dataItemFood.clear() + dataItemTool.clear() + dataItemWeapons.clear() + dataItemGift.clear() + + dataRecipe.clear() + } } \ 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/object/Info.kt similarity index 64% rename from src/main/kotlin/club/someoneice/ovo/core/Info.kt rename to src/main/kotlin/club/someoneice/ovo/core/object/Info.kt index 0175f56..b69f536 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/Info.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/object/Info.kt @@ -1,4 +1,4 @@ -package club.someoneice.ovo.core +package club.someoneice.ovo.core.`object` object Info { var modid: String = "" diff --git a/src/main/kotlin/club/someoneice/ovo/data/BlockData.kt b/src/main/kotlin/club/someoneice/ovo/data/BlockData.kt index 4240d3a..9585c86 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/BlockData.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/BlockData.kt @@ -4,7 +4,7 @@ import club.someoneice.ovo.IDataGem data class BlockData( val name: String, - val hard: Float, - val drop_item: String, - val group: String + val hard: Float = 0.1F, + val drop_item: String = "null", + val group: String = "null" ): IDataGem \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemData.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemData.kt index 3668c77..052bb19 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemData.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemData.kt @@ -4,6 +4,6 @@ import club.someoneice.ovo.IDataGem data class ItemData( val name: String, - val max_size: Int, - val group: String + val max_size: Int = 64, + val group: String = "null" ): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemFood.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemFood.kt new file mode 100644 index 0000000..1587f03 --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemFood.kt @@ -0,0 +1,16 @@ +package club.someoneice.ovo.data + +import club.someoneice.ovo.IDataGem + +data class ItemFood( + val name: String, + val max_size: Int = 64, + val hunger: Int, + val saturation: Float, + val wolf: Boolean = false, + val always_eat: Boolean = false, + val fast_food: Boolean = false, + val isDrink: Boolean = false, + val return_item: String = "null", + val group: String = "null" +): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemFoods.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemFoods.kt deleted file mode 100644 index bbec53a..0000000 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemFoods.kt +++ /dev/null @@ -1,16 +0,0 @@ -package club.someoneice.ovo.data - -import club.someoneice.ovo.IDataGem - -data class ItemFoods( - val name: String, - val max_size: Int, - val hunger: Int, - val saturation: Float, - val wolf: Boolean, - val always_eat: Boolean, - val fast_food: Boolean, - 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 344f1e3..095bdc3 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemGift.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemGift.kt @@ -2,11 +2,10 @@ package club.someoneice.ovo.data import club.someoneice.ovo.IDataGem import club.someoneice.ovo.data.helper.ItemGiftHelper -import java.util.* data class ItemGift( val name: String, - val max_size: Int, + val max_size: Int = 64, val items: ArrayList, - val group: String + val group: String = "null" ): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemKnife.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemKnife.kt deleted file mode 100644 index 4f25208..0000000 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemKnife.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 14cabd3..1c15044 100644 --- a/src/main/kotlin/club/someoneice/ovo/data/ItemTool.kt +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemTool.kt @@ -7,6 +7,6 @@ data class ItemTool( val name: String, val attackDamage: Int, val toolkit: String, - val tool_meta: String, - val group: String + val tool_meta: String = "wood", + val group: String = "null" ): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/data/ItemWeapon.kt b/src/main/kotlin/club/someoneice/ovo/data/ItemWeapon.kt new file mode 100644 index 0000000..5a4bd9a --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/data/ItemWeapon.kt @@ -0,0 +1,10 @@ +package club.someoneice.ovo.data + +import club.someoneice.ovo.IDataGem + +data class ItemWeapon( + val name: String, + val attackDamage: Int = 0, + val tool_meta: String = "wood", + val group: String = "null" +): IDataGem diff --git a/src/main/kotlin/club/someoneice/ovo/json/JsonReaderBean.kt b/src/main/kotlin/club/someoneice/ovo/json/JsonReaderBean.kt new file mode 100644 index 0000000..e313bb3 --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/json/JsonReaderBean.kt @@ -0,0 +1,45 @@ +package club.someoneice.ovo.json + +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import java.io.File +import java.nio.file.Files + +class JsonReaderBean { + val gson = Gson() + + /** + * @param file Input the original json file, if input other file, it will not work. + * + * @return Input the originalList, the object for return will put into the originalList. + * */ + fun init(file: File, originalList: ArrayList) { + val type = object: TypeToken>() {}.type + val reader = Files.newInputStream(file.toPath()) + + try { + val byte = ByteArray(file.length().toInt()) + reader.read(byte) + reader.close() + + originalList.addAll(gson.fromJson(String(byte), type) as List) + } catch (_: Exception) { + Sandman.nullSandman() + } + } + + fun readWithOriginal(file: File): T? { + val type = object: TypeToken() {}.type + val reader = Files.newInputStream(file.toPath()) + + return try { + val byte = ByteArray(file.length().toInt()) + reader.read(byte) + reader.close() + gson.fromJson(String(byte), type) as T + + } catch (_: Exception) { + null + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/Sandman.kt b/src/main/kotlin/club/someoneice/ovo/json/Sandman.kt index 6da9f8d..a020928 100644 --- a/src/main/kotlin/club/someoneice/ovo/json/Sandman.kt +++ b/src/main/kotlin/club/someoneice/ovo/json/Sandman.kt @@ -1,19 +1,8 @@ package club.someoneice.ovo.json -import net.minecraft.block.Blocks -import net.minecraft.item.ItemStack - object Sandman { - fun sandman(): ItemStack { - return ItemStack(Blocks.AIR) - } - + // Just to decorate and deter false positives. fun nullSandman() { // Do nothing. } - - // Return a null and it will as any things. - fun missingNo(): Any? { - return null - } } \ 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 index d26f9c7..3072874 100644 --- a/src/main/kotlin/club/someoneice/ovo/json/data/CoreDataOutput.kt +++ b/src/main/kotlin/club/someoneice/ovo/json/data/CoreDataOutput.kt @@ -1,7 +1,7 @@ package club.someoneice.ovo.json.data import club.someoneice.ovo.IDataGem -import club.someoneice.ovo.core.Info +import club.someoneice.ovo.core.`object`.Info class CoreDataOutput(data: JsonData, dataSet: IDataGem) { val modid = Info.modid 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 index 5532939..8c6e5a8 100644 --- a/src/main/kotlin/club/someoneice/ovo/json/data/helper/BlockJsonHelper.kt +++ b/src/main/kotlin/club/someoneice/ovo/json/data/helper/BlockJsonHelper.kt @@ -3,12 +3,9 @@ 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 @@ -16,10 +13,10 @@ 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 (!File(basePath).exists()) File(basePath).mkdirs() + if (!File("${basePath}\\blockstates").exists()) File("${basePath}\\blockstates").mkdirs() + if (!File("${basePath}\\models\\block").exists()) File("${basePath}\\models\\block").mkdirs() + if (!File("${basePath}\\textures\\block").exists()) File("${basePath}\\textures\\block").mkdirs() if (dataSet is BlockData) { File("${basePath}\\blockstates\\${dataSet.name}.json").createNewFile() 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 index 9a94b79..0935b3e 100644 --- a/src/main/kotlin/club/someoneice/ovo/json/data/helper/ItemJsonHelper.kt +++ b/src/main/kotlin/club/someoneice/ovo/json/data/helper/ItemJsonHelper.kt @@ -3,11 +3,9 @@ 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 @@ -17,11 +15,11 @@ class ItemJsonHelper: JsonData() { dataProcessor(modid, dataSet.name) } - if (dataSet is ItemKnife) { + if (dataSet is ItemWeapon) { dataProcessor(modid, dataSet.name) } - if (dataSet is ItemFoods) { + if (dataSet is ItemFood) { dataProcessor(modid, dataSet.name) } @@ -37,8 +35,8 @@ class ItemJsonHelper: JsonData() { 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).exists()) File(basePath).mkdirs() + if (!File("${basePath}\\models\\item").exists()) File("${basePath}\\models\\item").mkdirs() if (!File("${basePath}\\textures\\item").exists()) File("${basePath}\\textures\\item").mkdirs() File("${basePath}\\models\\item\\${name}.json").createNewFile() 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 index aa35b4b..ad2e436 100644 --- a/src/main/kotlin/club/someoneice/ovo/json/data/helper/RecipeJsonHelper.kt +++ b/src/main/kotlin/club/someoneice/ovo/json/data/helper/RecipeJsonHelper.kt @@ -8,7 +8,6 @@ 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 @@ -19,8 +18,8 @@ class RecipeJsonHelper: JsonData() { 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 (!File(basePath).exists()) File(basePath).mkdirs() + if (!File("${basePath}\\recipes").exists()) File("${basePath}\\recipes").mkdirs() if (dataSet is Recipes) { this.modid = modid diff --git a/src/main/kotlin/club/someoneice/ovo/json/helper/JsonProcessor.kt b/src/main/kotlin/club/someoneice/ovo/json/helper/JsonProcessor.kt deleted file mode 100644 index 3490895..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/helper/JsonProcessor.kt +++ /dev/null @@ -1,31 +0,0 @@ -package club.someoneice.ovo.json.helper - -import club.someoneice.ovo.OVOMain -import club.someoneice.ovo.json.reader.* -import club.someoneice.ovo.json.Sandman -import java.io.File - -class JsonProcessor( - private val group : Group, - private val item : Item, - private val block : ItemBlocks, - private val foods : ItemFoods, - private val gift : ItemGifts, - private val swords : ItemSwords, - private val tools : ItemTools, -): JsonTypeGetter() { - override fun getType(typeGetter: String, filePath: File) { - OVOMain.Logger.info("Get type: $typeGetter") - when(typeGetter) { - "group" -> group.init(filePath) - "item" -> item.init(filePath) - "item_food" -> foods.init(filePath) - "item_gift" -> gift.init(filePath) - "item_tools" -> tools.init(filePath) - "item_swords" -> swords.init(filePath) - "block" -> block.init(filePath) - - else -> Sandman.missingNo() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/helper/JsonTypeGetter.kt b/src/main/kotlin/club/someoneice/ovo/json/helper/JsonTypeGetter.kt deleted file mode 100644 index e09b12c..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/helper/JsonTypeGetter.kt +++ /dev/null @@ -1,7 +0,0 @@ -package club.someoneice.ovo.json.helper - -import java.io.File - -abstract class JsonTypeGetter { - abstract fun getType(typeGetter: String, filePath: File) -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/helper/JsonTypeHelper.kt b/src/main/kotlin/club/someoneice/ovo/json/helper/JsonTypeHelper.kt deleted file mode 100644 index 3e84223..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/helper/JsonTypeHelper.kt +++ /dev/null @@ -1,7 +0,0 @@ -package club.someoneice.ovo.json.helper - -import java.io.File - -abstract class JsonTypeHelper { - abstract fun getToolType(typeGetter: JsonTypeGetter, filePath: File) -} \ 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 deleted file mode 100644 index 57484a2..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/Group.kt +++ /dev/null @@ -1,45 +0,0 @@ -package club.someoneice.ovo.json.reader - -import club.someoneice.ovo.OVOMain -import club.someoneice.ovo.core.DataList -import club.someoneice.ovo.json.helper.JsonTypeGetter -import club.someoneice.ovo.json.helper.JsonTypeHelper -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import java.io.BufferedReader -import java.io.File -import java.io.FileReader - -class Group: JsonTypeHelper() { - override fun getToolType(typeGetter: JsonTypeGetter, filePath: File) { - typeGetter.getType("group", filePath) - } - - 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() - - OVOMain.Logger.info(output) - OVOMain.Logger.info("START READ GROUP !") - - - val list: List = gson.fromJson(output, type) - for (i in list) DataList.dataGroup.add(i) - - - } catch (_: Exception) { - OVOMain.Logger.error("Cannot read a Group data!") - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/Item.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/Item.kt deleted file mode 100644 index 50e5075..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/Item.kt +++ /dev/null @@ -1,41 +0,0 @@ -package club.someoneice.ovo.json.reader - -import club.someoneice.ovo.core.DataList -import club.someoneice.ovo.data.ItemData -import club.someoneice.ovo.json.Sandman -import club.someoneice.ovo.json.helper.JsonTypeGetter -import club.someoneice.ovo.json.helper.JsonTypeHelper -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import java.io.BufferedReader -import java.io.File -import java.io.FileReader - -class Item: JsonTypeHelper() { - override fun getToolType(typeGetter: JsonTypeGetter, filePath: File) { - typeGetter.getType("item", filePath) - } - - 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.dataItem.add(i) - - } catch (_: Exception) { - Sandman.nullSandman() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemBlocks.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/ItemBlocks.kt deleted file mode 100644 index bbb4903..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemBlocks.kt +++ /dev/null @@ -1,41 +0,0 @@ -package club.someoneice.ovo.json.reader - -import club.someoneice.ovo.core.DataList -import club.someoneice.ovo.data.BlockData -import club.someoneice.ovo.json.Sandman -import club.someoneice.ovo.json.helper.JsonTypeGetter -import club.someoneice.ovo.json.helper.JsonTypeHelper -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import java.io.BufferedReader -import java.io.File -import java.io.FileReader - -class ItemBlocks: JsonTypeHelper() { - override fun getToolType(typeGetter: JsonTypeGetter, filePath: File) { - typeGetter.getType("block", filePath) - } - - 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.dataBlock.add(i) - - } catch (_: Exception) { - Sandman.nullSandman() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemFoods.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/ItemFoods.kt deleted file mode 100644 index 6f17e3b..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemFoods.kt +++ /dev/null @@ -1,41 +0,0 @@ -package club.someoneice.ovo.json.reader - -import club.someoneice.ovo.core.DataList -import club.someoneice.ovo.json.Sandman -import club.someoneice.ovo.json.helper.JsonTypeGetter -import club.someoneice.ovo.json.helper.JsonTypeHelper -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import java.io.BufferedReader -import java.io.File -import java.io.FileReader - -class ItemFoods: JsonTypeHelper() { - override fun getToolType(typeGetter: JsonTypeGetter, filePath: File) { - typeGetter.getType("item_food", filePath) - } - - 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.dataItemFood.add(i) - - - } catch (_: Exception) { - Sandman.nullSandman() - } - } -} diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemGifts.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/ItemGifts.kt deleted file mode 100644 index 586f71a..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemGifts.kt +++ /dev/null @@ -1,41 +0,0 @@ -package club.someoneice.ovo.json.reader - -import club.someoneice.ovo.core.DataList -import club.someoneice.ovo.data.ItemGift -import club.someoneice.ovo.json.Sandman -import club.someoneice.ovo.json.helper.JsonTypeGetter -import club.someoneice.ovo.json.helper.JsonTypeHelper -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import java.io.BufferedReader -import java.io.File -import java.io.FileReader - -class ItemGifts: JsonTypeHelper() { - override fun getToolType(typeGetter: JsonTypeGetter, filePath: File) { - typeGetter.getType("item_gift", filePath) - } - - 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.dataItemGift.add(i) - - } catch (_: Exception) { - Sandman.nullSandman() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemSwords.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/ItemSwords.kt deleted file mode 100644 index db9376f..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemSwords.kt +++ /dev/null @@ -1,41 +0,0 @@ -package club.someoneice.ovo.json.reader - -import club.someoneice.ovo.core.DataList -import club.someoneice.ovo.data.ItemKnife -import club.someoneice.ovo.json.Sandman -import club.someoneice.ovo.json.helper.JsonTypeGetter -import club.someoneice.ovo.json.helper.JsonTypeHelper -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import java.io.BufferedReader -import java.io.File -import java.io.FileReader - -class ItemSwords: JsonTypeHelper() { - override fun getToolType(typeGetter: JsonTypeGetter, filePath: File) { - typeGetter.getType("item_swords", filePath) - } - - 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.dataItemWeapons.add(i) - - } catch (_: Exception) { - Sandman.nullSandman() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemTools.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/ItemTools.kt deleted file mode 100644 index 3fa0702..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/ItemTools.kt +++ /dev/null @@ -1,41 +0,0 @@ -package club.someoneice.ovo.json.reader - -import club.someoneice.ovo.core.DataList -import club.someoneice.ovo.data.ItemTool -import club.someoneice.ovo.json.Sandman -import club.someoneice.ovo.json.helper.JsonTypeGetter -import club.someoneice.ovo.json.helper.JsonTypeHelper -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import java.io.BufferedReader -import java.io.File -import java.io.FileReader - -class ItemTools: JsonTypeHelper() { - override fun getToolType(typeGetter: JsonTypeGetter, filePath: File) { - typeGetter.getType("item_tools", filePath) - } - - 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.dataItemTool.add(i) - - } catch (_: Exception) { - Sandman.nullSandman() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/json/reader/Recipes.kt b/src/main/kotlin/club/someoneice/ovo/json/reader/Recipes.kt deleted file mode 100644 index 5a61ac8..0000000 --- a/src/main/kotlin/club/someoneice/ovo/json/reader/Recipes.kt +++ /dev/null @@ -1,34 +0,0 @@ -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 60754fe..333842f 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/BlockBase.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/BlockBase.kt @@ -1,34 +1,21 @@ package club.someoneice.ovo.util -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 -import net.minecraft.item.BlockItem -import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.loot.context.LootContext -import net.minecraft.util.Identifier -import net.minecraft.util.registry.Registry -import java.util.* class BlockBase(settings: Settings, private val blockSet: BlockData): Block(settings) { 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) + this.register(blockSet.name, blockSet.group) } override fun getDroppedStacks(state: BlockState, builder: LootContext.Builder): MutableList { val itemlist = ArrayList() when(blockSet.drop_item) { - "null" -> itemlist.add(Sandman.sandman()) + "null" -> return itemlist "this" -> itemlist.add(ItemStack(this)) else -> itemlist.add(ItemStack(findItemByText(blockSet.drop_item))) } diff --git a/src/main/kotlin/club/someoneice/ovo/util/ItemBase.kt b/src/main/kotlin/club/someoneice/ovo/util/ItemBase.kt index 70054b1..05cc899 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemBase.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemBase.kt @@ -1,20 +1,10 @@ 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 class ItemBase(settings: Settings, itemSet: ItemData): Item(settings) { init { - Registry.register(Registry.ITEM, Identifier(Info.modid, itemSet.name), this) - - CoreDataOutput(ItemJsonHelper(), itemSet) - OVOMain.Logger.debug("Item ${itemSet.name} is register success!") + this.register(itemSet.name) } } \ 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 fa1a3d7..54a84b0 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemFoodsBase.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemFoodsBase.kt @@ -1,8 +1,7 @@ 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.core.`object`.Info +import club.someoneice.ovo.data.ItemFood import club.someoneice.ovo.json.data.CoreDataOutput import club.someoneice.ovo.json.data.helper.ItemJsonHelper import club.someoneice.ovo.util.Util.findItemByText @@ -14,7 +13,7 @@ import net.minecraft.util.UseAction import net.minecraft.util.registry.Registry import net.minecraft.world.World -class ItemFoodsBase(settings: Settings, private val foodSet: ItemFoods): Item(settings) { +class ItemFoodsBase(settings: Settings, private val foodSet: ItemFood): Item(settings) { init { Registry.register(Registry.ITEM, Identifier(Info.modid, foodSet.name), this) CoreDataOutput(ItemJsonHelper(), foodSet) @@ -25,6 +24,7 @@ class ItemFoodsBase(settings: Settings, private val foodSet: ItemFoods): Item(se } override fun finishUsing(stack: ItemStack?, world: World?, user: LivingEntity?): ItemStack { - return ItemStack(findItemByText(foodSet.return_item) ?: Sandman.sandman().item) + val item = findItemByText(foodSet.return_item) ?: return ItemStack.EMPTY + return item.defaultStack } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/ItemGifts.kt b/src/main/kotlin/club/someoneice/ovo/util/ItemGifts.kt index 456c789..613471f 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemGifts.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemGifts.kt @@ -1,22 +1,16 @@ 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 import net.minecraft.item.Item import net.minecraft.item.ItemStack -import net.minecraft.util.Identifier -import net.minecraft.util.registry.Registry 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) + this.register(itemSet.name) } override fun finishUsing(stack: ItemStack, world: World, user: LivingEntity): ItemStack { diff --git a/src/main/kotlin/club/someoneice/ovo/util/ItemTools.kt b/src/main/kotlin/club/someoneice/ovo/util/ItemTools.kt index ac5f463..ed56f40 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemTools.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemTools.kt @@ -1,23 +1,39 @@ package club.someoneice.ovo.util +import club.someoneice.ovo.core.`object`.DataList import club.someoneice.ovo.data.ItemTool import club.someoneice.ovo.json.Sandman -import club.someoneice.ovo.util.tool.* +import club.someoneice.ovo.util.tool.ItemAxes +import club.someoneice.ovo.util.tool.ItemHoes +import club.someoneice.ovo.util.tool.ItemPickaxes +import club.someoneice.ovo.util.tool.ItemShovels +import net.minecraft.item.Item +import net.minecraft.item.ToolMaterials class ItemTools(toolSet: ItemTool) { init { - val axe = ToolAxe() - val pickaxe = ToolPickaxe() - val hoe = ToolHoe() - val shovel = ToolShovel() - val helper: ToolTypeGetter = Helper(axe, hoe, pickaxe, shovel, toolSet) - when(toolSet.toolkit) { - "axe" -> axe.getToolType(helper) - "hoe" -> hoe.getToolType(helper) - "pickaxe" -> pickaxe.getToolType(helper) - "shovel" -> shovel.getToolType(helper) + val settings: Item.Settings = Item.Settings() + settings.group(DataList.getGroup[toolSet.group]) + settings.maxCount(1) - else -> Sandman.nullSandman() + val mate: ToolMaterials = when (toolSet.tool_meta) { + "wood" -> ToolMaterials.WOOD + "stone" -> ToolMaterials.STONE + "iron" -> ToolMaterials.WOOD + "gold" -> ToolMaterials.GOLD + "diamond" -> ToolMaterials.DIAMOND + + else -> ToolMaterials.WOOD } + + when (toolSet.toolkit) { + "axe" -> ItemAxes(settings, mate, toolSet) + "pickaxe" -> ItemPickaxes(settings, mate, toolSet) + "hoe" -> ItemHoes(settings, mate, toolSet) + "shovel" -> ItemShovels(settings, mate, toolSet) + + else -> Sandman.nullSandman() + } + } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/ItemWeapons.kt b/src/main/kotlin/club/someoneice/ovo/util/ItemWeapons.kt index 6960716..e42659f 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/ItemWeapons.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/ItemWeapons.kt @@ -1,16 +1,14 @@ package club.someoneice.ovo.util -import club.someoneice.ovo.core.Info -import club.someoneice.ovo.data.ItemKnife +import club.someoneice.ovo.data.ItemWeapon 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 +import net.minecraft.item.SwordItem +import net.minecraft.item.ToolMaterials -class ItemWeapons(settings: Settings, toolSet: ItemKnife, toolMate: ToolMaterials?): SwordItem(toolMate, toolSet.attackDamage, -2.4F, settings) { +class ItemWeapons(settings: Settings, toolSet: ItemWeapon, toolMate: ToolMaterials?): SwordItem(toolMate, toolSet.attackDamage, -2.4F, settings) { init { - Registry.register(Registry.ITEM, Identifier(Info.modid, toolSet.name), this) + this.register(toolSet.name) 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 b922df3..b8230f6 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/Util.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/Util.kt @@ -1,6 +1,11 @@ package club.someoneice.ovo.util +import club.someoneice.ovo.core.`object`.DataList +import club.someoneice.ovo.core.`object`.Info +import net.minecraft.block.Block +import net.minecraft.item.BlockItem import net.minecraft.item.Item +import net.minecraft.item.ItemStack import net.minecraft.util.Identifier import net.minecraft.util.registry.Registry @@ -21,5 +26,20 @@ object Util { fun getItemNameByRegistryName(ItemName: String): String { return ItemName.substring(ItemName.indexOf(":") + 1) } +} +fun Block.register(name: String, group: String) { + Registry.register(Registry.BLOCK, Identifier(Info.modid, name), this) + Registry.register(Registry.ITEM, Identifier(Info.modid, name), BlockItem(this, Item.Settings().group( + DataList.getGroup[group])) + ) +} + +fun Item.register(name: String) { + Registry.register(Registry.ITEM, Identifier(Info.modid, name), this) +} + +fun ItemStack.setSize(size: Int): ItemStack { + this.count = size + return this } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/Helper.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/Helper.kt deleted file mode 100644 index b3b22f0..0000000 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/Helper.kt +++ /dev/null @@ -1,51 +0,0 @@ -package club.someoneice.ovo.util.tool - -import club.someoneice.ovo.core.DataList -import club.someoneice.ovo.data.ItemTool -import club.someoneice.ovo.json.Sandman -import net.minecraft.item.Item -import net.minecraft.item.Item.Settings -import net.minecraft.item.ToolMaterials - -class Helper(private val axe: ToolAxe, private val hoe: ToolHoe, private val pickaxe: ToolPickaxe, private val shovel: ToolShovel, private val toolSet: ItemTool): ToolTypeGetter() { - override fun getType(typeChooser: String) { - val settings: Item.Settings = Item.Settings() - settings.group(DataList.getGroup[toolSet.group]) - settings.maxCount(1) - - val mate: ToolMaterials = when (toolSet.tool_meta) { - "wood" -> ToolMaterials.WOOD - "stone" -> ToolMaterials.STONE - "iron" -> ToolMaterials.WOOD - "gold" -> ToolMaterials.GOLD - "diamond" -> ToolMaterials.DIAMOND - - else -> ToolMaterials.WOOD - } - - when (typeChooser) { - "axe" -> makeAxe (settings, toolSet, mate) - "pickaxe" -> makePickaxe (settings, toolSet, mate) - "hoe" -> makeHoe (settings, toolSet, mate) - "shovel" -> makeShovel (settings, toolSet, mate) - - else -> Sandman.nullSandman() - } - } - - private fun makeAxe(settings: Settings, toolSet: ItemTool, toolMate: ToolMaterials) { - axe.toolInit(settings, toolSet, toolMate) - } - - private fun makePickaxe(settings: Settings, toolSet: ItemTool, toolMate: ToolMaterials) { - pickaxe.toolInit(settings, toolSet, toolMate) - } - - private fun makeHoe(settings: Settings, toolSet: ItemTool, toolMate: ToolMaterials) { - hoe.toolInit(settings, toolSet, toolMate) - } - - private fun makeShovel(settings: Settings, toolSet: ItemTool, toolMate: ToolMaterials) { - shovel.toolInit(settings, toolSet, toolMate) - } -} \ 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 c07e1b2..790ef00 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemAxes.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemAxes.kt @@ -1,17 +1,12 @@ 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 club.someoneice.ovo.util.register import net.minecraft.item.AxeItem import net.minecraft.item.ToolMaterials -import net.minecraft.util.Identifier -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) + this.register(toolSet.name) } } \ 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 0a51a15..be754ed 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemHoes.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemHoes.kt @@ -1,17 +1,12 @@ 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 club.someoneice.ovo.util.register import net.minecraft.item.HoeItem import net.minecraft.item.ToolMaterials -import net.minecraft.util.Identifier -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) + this.register(toolSet.name) } } \ 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 deleted file mode 100644 index 9c906de..0000000 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemPickaxe.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 -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/ItemPickaxes.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemPickaxes.kt new file mode 100644 index 0000000..02f3eae --- /dev/null +++ b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemPickaxes.kt @@ -0,0 +1,12 @@ +package club.someoneice.ovo.util.tool + +import club.someoneice.ovo.data.ItemTool +import club.someoneice.ovo.util.register +import net.minecraft.item.PickaxeItem +import net.minecraft.item.ToolMaterials + +class ItemPickaxes(settings: Settings, toolMate: ToolMaterials, toolSet: ItemTool): PickaxeItem(toolMate, toolSet.attackDamage,-2.8f,settings) { + init { + this.register(toolSet.name) + } +} \ 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 515337d..1ef3b07 100644 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ItemShovels.kt +++ b/src/main/kotlin/club/someoneice/ovo/util/tool/ItemShovels.kt @@ -1,17 +1,12 @@ 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 club.someoneice.ovo.util.register import net.minecraft.item.ShovelItem import net.minecraft.item.ToolMaterials -import net.minecraft.util.Identifier -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) + this.register(toolSet.name) } } \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolAxe.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ToolAxe.kt deleted file mode 100644 index d27055e..0000000 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolAxe.kt +++ /dev/null @@ -1,15 +0,0 @@ -package club.someoneice.ovo.util.tool - -import club.someoneice.ovo.data.ItemTool -import net.minecraft.item.Item.Settings -import net.minecraft.item.ToolMaterials - -class ToolAxe: ToolTypeMain() { - override fun getToolType(typeGetter: ToolTypeGetter) { - typeGetter.getType("axe") - } - - fun toolInit(settings: Settings, toolSet: ItemTool, toolMate: ToolMaterials) { - ItemAxes(settings, toolMate, toolSet) - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolHoe.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ToolHoe.kt deleted file mode 100644 index b083e8d..0000000 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolHoe.kt +++ /dev/null @@ -1,15 +0,0 @@ -package club.someoneice.ovo.util.tool - -import club.someoneice.ovo.data.ItemTool -import net.minecraft.item.Item -import net.minecraft.item.ToolMaterials - -class ToolHoe(): ToolTypeMain() { - override fun getToolType(typeGetter: ToolTypeGetter) { - typeGetter.getType("hoe") - } - - fun toolInit(settings: Item.Settings, toolSet: ItemTool, toolMate: ToolMaterials) { - ItemHoes(settings, toolMate, toolSet) - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolPickaxe.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ToolPickaxe.kt deleted file mode 100644 index ddacd12..0000000 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolPickaxe.kt +++ /dev/null @@ -1,15 +0,0 @@ -package club.someoneice.ovo.util.tool - -import club.someoneice.ovo.data.ItemTool -import net.minecraft.item.Item -import net.minecraft.item.ToolMaterials - -class ToolPickaxe: ToolTypeMain() { - override fun getToolType(typeGetter: ToolTypeGetter) { - typeGetter.getType("pickaxe") - } - - fun toolInit(settings: Item.Settings, toolSet: ItemTool, toolMate: ToolMaterials) { - ItemPickaxe(settings, toolMate, toolSet) - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolShovel.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ToolShovel.kt deleted file mode 100644 index 30becd1..0000000 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolShovel.kt +++ /dev/null @@ -1,15 +0,0 @@ -package club.someoneice.ovo.util.tool - -import club.someoneice.ovo.data.ItemTool -import net.minecraft.item.Item -import net.minecraft.item.ToolMaterials - -class ToolShovel: ToolTypeMain() { - override fun getToolType(typeGetter: ToolTypeGetter) { - typeGetter.getType("shovel") - } - - fun toolInit(settings: Item.Settings, toolSet: ItemTool, toolMate: ToolMaterials) { - ItemShovels(settings, toolMate, toolSet) - } -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolTypeGetter.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ToolTypeGetter.kt deleted file mode 100644 index 0f64ffd..0000000 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolTypeGetter.kt +++ /dev/null @@ -1,5 +0,0 @@ -package club.someoneice.ovo.util.tool - -abstract class ToolTypeGetter { - abstract fun getType(typeChooser: String) -} \ No newline at end of file diff --git a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolTypeMain.kt b/src/main/kotlin/club/someoneice/ovo/util/tool/ToolTypeMain.kt deleted file mode 100644 index 5dba0fa..0000000 --- a/src/main/kotlin/club/someoneice/ovo/util/tool/ToolTypeMain.kt +++ /dev/null @@ -1,5 +0,0 @@ -package club.someoneice.ovo.util.tool - -abstract class ToolTypeMain { - abstract fun getToolType(typeGetter: ToolTypeGetter) -} \ No newline at end of file