Skip to content

Commit

Permalink
📰 Clean the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarokIce committed Nov 27, 2023
1 parent 597429b commit 407029b
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 54 deletions.
15 changes: 7 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'maven-publish'

version = "0.1.0"
version = "0.1.3"
group = "club.someoneice.ovo"
archivesBaseName = "WithJson-1.7.10"

Expand All @@ -40,12 +40,9 @@ minecraft {
repositories {
mavenCentral()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/amarokice/withpineapplepsychic")
credentials {
username = "AmarokIce"
password = ProcessEnvironment.getenv("GITHUB_TOKEN")
}
name = "AmarokMaven"
url "http://maven.snowlyicewolf.club/"
allowInsecureProtocol = true
}

flatDir{
Expand All @@ -56,7 +53,9 @@ repositories {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"

// implementation 'club.someoneice.pineapplepsychic:pineapple-psychic:1.2.1'
implementation "club.someoneice.pineapplepsychic:pineapple-psychic:1.3.1"
implementation "club.someoneice.togocup.recipebook:PineappleRecipeBook:1.0"

implementation fileTree(dir: 'lib', includes: ['*.jar'])
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
19 changes: 10 additions & 9 deletions src/main/kotlin/club/someoneice/ovo/base/BlockBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import net.minecraft.world.World
class BlockBase(material: Material, private val blockSet: BlockData): Block(material) {
init {
this.setHardness(blockSet.hard.toFloat())
this.setHarvestLevel(blockSet.break_tool, blockSet.hard_level)

blockSet.break_tool?.let {
this.setHarvestLevel(it, blockSet.hard_level)
}
if (blockSet.is_glow) this.setLightLevel(15.0F)

if (DataList.getGroup.containsKey(blockSet.group)) {
Expand All @@ -28,13 +29,13 @@ class BlockBase(material: Material, private val blockSet: BlockData): Block(mate
}

override fun getDrops(world: World?, x: Int, y: Int, z: Int, metadata: Int, fortune: Int): ArrayList<ItemStack> {
val itemlist = Lists.newArrayList<ItemStack>()
when(blockSet.drop_item) {
"null" -> return itemlist
"this" -> itemlist.add(ItemStack(this))
else -> itemlist.add(ItemStack(findItemByText(blockSet.drop_item)))
}
return Lists.newArrayList<ItemStack>().also {
when(blockSet.drop_item) {
"null" -> Unit
"this" -> it.add(ItemStack(this))
else -> it.add(ItemStack(findItemByText(blockSet.drop_item)))

return itemlist
}
}
}
}
71 changes: 39 additions & 32 deletions src/main/kotlin/club/someoneice/ovo/core/JarRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,46 @@ class JarRunner {
}

for (key in mappings.keys) {
val mapping: ArrayList<JarUtil.UrlBuffered> = mappings[key]!!
if (mapping.isNotEmpty() && infoMappings.containsKey(key)) {
val type = object: TypeToken<HashMap<String, String>>() {}.type
val modid: String? =
(gson.fromJson(JarUtil.getInstance().readFileFromUrl(infoMappings[key]), type) as HashMap<String, String>).let { it["modid"] }
for (url in mappings[key]!!) {
if (url == infoMappings[key]) continue
val fileName = url.fileUrl.substring(url.fileUrl.lastIndexOf("/") + 1, url.fileUrl.lastIndexOf("."))
if (set.contains(fileName.lowercase())) fileName
else {
val path = url.fileUrl.replace("ovo/${key}/", "")
val filePath = path.substring(0, path.indexOf("/"))
if (set.contains(filePath.lowercase())) filePath
else null
}?.let {
val txt = JarUtil.getInstance().readFileFromUrl(url) ?: return@let
when (it.lowercase()) {
"Item".lowercase() -> CoreRunner.item.init (txt, DataList.dataItem)
"ItemFood".lowercase() -> CoreRunner.food.init (txt, DataList.dataItemFood)
"ItemGift".lowercase() -> CoreRunner.gift.init (txt, DataList.dataItemGift)
"ItemTool".lowercase() -> CoreRunner.tool.init (txt, DataList.dataItemTool)
"ItemWeapons".lowercase() -> CoreRunner.swords.init (txt, DataList.dataItemWeapons)
"Block".lowercase() -> CoreRunner.block.init (txt, DataList.dataBlock)
"Recipe".lowercase() -> CoreRunner.recipes.init (txt, DataList.dataRecipes)
"DeleteRecipe".lowercase() -> CoreRunner.delete_recipes.init (txt, DataList.dataDeleteRecipes)
"Biomes".lowercase() -> CoreRunner.biomes.init (txt, DataList.dataBiomes)
"Group".lowercase() -> CoreRunner.group.init (txt, DataList.dataGroup)
}
}
}
processor(mappings, infoMappings, key)
}
}

private fun processor(mappings: HashMap<String, ArrayList<JarUtil.UrlBuffered>>, infoMappings: HashMap<String, JarUtil.UrlBuffered>, key: String) {
val mapping: ArrayList<JarUtil.UrlBuffered> = mappings[key]!!
if (mapping.isNotEmpty() && infoMappings.containsKey(key)) {
val type = object: TypeToken<HashMap<String, String>>() {}.type
val modid: String? =
(gson.fromJson(JarUtil.getInstance().readFileFromUrl(infoMappings[key]), type) as HashMap<String, String>).let { it["modid"] }
for (url in mappings[key]!!)
processorUrl(url, infoMappings, key)

DataProcessor(modid).init()
DataList.init()
}
}

DataProcessor(modid).init()
DataList.init()
private fun processorUrl(url: JarUtil.UrlBuffered, infoMappings: HashMap<String, JarUtil.UrlBuffered>, key: String) {
if (url == infoMappings[key]) return
val fileName = url.fileUrl.substring(url.fileUrl.lastIndexOf("/") + 1, url.fileUrl.lastIndexOf("."))
if (set.contains(fileName.lowercase())) fileName
else {
val path = url.fileUrl.replace("ovo/${key}/", "")
val filePath = path.substring(0, path.indexOf("/"))
if (set.contains(filePath.lowercase())) filePath
else null
}?.let {
val txt = JarUtil.getInstance().readFileFromUrl(url) ?: return@let
when (it.lowercase()) {
"Item".lowercase() -> CoreRunner.item.init (txt, DataList.dataItem)
"ItemFood".lowercase() -> CoreRunner.food.init (txt, DataList.dataItemFood)
"ItemGift".lowercase() -> CoreRunner.gift.init (txt, DataList.dataItemGift)
"ItemTool".lowercase() -> CoreRunner.tool.init (txt, DataList.dataItemTool)
"ItemWeapons".lowercase() -> CoreRunner.swords.init (txt, DataList.dataItemWeapons)
"Block".lowercase() -> CoreRunner.block.init (txt, DataList.dataBlock)
"Recipe".lowercase() -> CoreRunner.recipes.init (txt, DataList.dataRecipes)
"DeleteRecipe".lowercase() -> CoreRunner.delete_recipes.init (txt, DataList.dataDeleteRecipes)
"Biomes".lowercase() -> CoreRunner.biomes.init (txt, DataList.dataBiomes)
"Group".lowercase() -> CoreRunner.group.init (txt, DataList.dataGroup)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/club/someoneice/ovo/core/OVOMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.apache.logging.log4j.Logger
class OVOMain {
companion object {
const val MODID: String = "ovo"
const val VERSION: String = "0.1.2"
const val VERSION: String = "0.1.3"
val ManaMetalModInstall: Boolean = Loader.isModLoaded("manametalmod")
val PineapplePsychicInstall: Boolean = Loader.isModLoaded("pineapple_psychic")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ object DataList {
val dataRecipes :ArrayList<Recipe> = Lists.newArrayList()
val dataDeleteRecipes :ArrayList<String> = Lists.newArrayList()

// Clean all the data list.
fun init() {
dataItem.clear()
dataBlock.clear()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/club/someoneice/ovo/data/BlockData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data class BlockData(
val texture_name: String = name,
val hard: Int = 1,
val hard_level: Int = 0,
val break_tool: String,
val break_tool: String?,
val is_glow: Boolean = false,
val drop_item: String = name,
val group: String = "null"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"modid": "ovo",
"name": "With Json",
"description": "A mod for minecraft, and now you can use json to make more Items!",
"version": "0.1.2",
"version": "0.1.3",
"mcversion": "${mcversion}",
"url": "",
"updateUrl": "",
Expand Down

0 comments on commit 407029b

Please sign in to comment.