Skip to content

Commit

Permalink
Revert "0.4 component fix (LotsOfPixelsStudios#53)" (LotsOfPixelsStud…
Browse files Browse the repository at this point in the history
…ios#54)

This reverts commit 5b61a35.
  • Loading branch information
12rcu authored Mar 19, 2024
1 parent 5b61a35 commit 2fbf28b
Show file tree
Hide file tree
Showing 751 changed files with 23,106 additions and 28,457 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ dependencies {
//test
testImplementation(kotlin("test"))
implementation(group = "org.skyscreamer", name = "jsonassert", version = "1.5.1")

testImplementation("org.jsoup:jsoup:1.17.2")
}

java {
Expand Down
27 changes: 3 additions & 24 deletions src/main/kotlin/com/lop/devtools/monstera/Config.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@file:Suppress("MemberVisibilityCanBePrivate", "unused")

package com.lop.devtools.monstera

import com.lop.devtools.monstera.addon.dev.ResourceLoader
import com.lop.devtools.monstera.addon.entity.resource.copyDefaultTextureTo
import com.lop.devtools.monstera.addon.entity.resource.generateDefaultGeo
import com.lop.devtools.monstera.files.File
import com.lop.devtools.monstera.files.getVersionAsString
import com.lop.devtools.monstera.files.lang.LangFileBuilder
import java.io.File
import java.nio.file.Path
Expand Down Expand Up @@ -49,11 +46,10 @@ class Config(
"com.mojang"
),
var paths: AddonPaths = AddonPaths(behPath, resPath),
var targetMcVersion: ArrayList<Int> = arrayListOf(1, 20, 70),
var formatVersions: FormatVersions = FormatVersions(getVersionAsString(targetMcVersion)),
var targetMcVersion: ArrayList<Int> = arrayListOf(1, 19, 40),
var langFileBuilder: AddonLangFileBuilders = AddonLangFileBuilders(behPath, resPath),
var scriptEntryFile: File = File(),
var scriptingVersion: String = "1.8.0"
var scriptingVersion: String = "1.6.0"
) {
init {
behPath.toFile().deleteRecursively()
Expand Down Expand Up @@ -95,7 +91,7 @@ class Config(
var lootTableEntity: Path = behBase.resolve("loot_tables").resolve("entities"),
var lootTableBlock: Path = behBase.resolve("loot_tables").resolve("blocks"),
var behSpawnRules: Path = behBase.resolve("spawn_rules"),
var behTrading: Path = behBase.resolve("trading").resolve("economy_trades"),
var behTrading: Path = behBase.resolve("trading"),
var behRecipe: Path = behBase.resolve("recipes"),
var behTexts: Path = behBase.resolve("texts"),
var behScripts: Path = behBase.resolve("scripts"),
Expand Down Expand Up @@ -133,22 +129,5 @@ class Config(
"textures/default"
}
}

class FormatVersions(
targetMcVersion: String,
var behEntity: String = targetMcVersion,
var resEntity: String = "1.10.0",
var resItem: String = "1.10.0",
var behItem: String = targetMcVersion,
var behAnimation: String = "1.8.0",
var behBlock: String = targetMcVersion,
var behRecipe: String = "1.17.41",
var behSpawnRules: String = "1.8.0",
var behAnimController: String = "1.10.0",
var resAnimController: String = "1.10.0",
var resAttachable: String = "1.10.0",
var resSoundDefs: String = "1.14.0",
var resRendercontroller: String = "1.10.0"
)
}

228 changes: 22 additions & 206 deletions src/main/kotlin/com/lop/devtools/monstera/addon/Addon.kt
Original file line number Diff line number Diff line change
@@ -1,70 +1,36 @@
@file:Suppress("MemberVisibilityCanBePrivate", "unused")

package com.lop.devtools.monstera.addon

import com.lop.devtools.monstera.Config
import com.lop.devtools.monstera.MonsteraLoggerContext
import com.lop.devtools.monstera.addon.api.InvokeBeforeEnd
import com.lop.devtools.monstera.addon.api.MonsteraUnsafeField
import com.lop.devtools.monstera.addon.api.PackageInvoke
import com.lop.devtools.monstera.addon.block.Block
import com.lop.devtools.monstera.addon.dev.buildToMcFolder
import com.lop.devtools.monstera.addon.dev.validateTextures
import com.lop.devtools.monstera.addon.entity.Entity
import com.lop.devtools.monstera.addon.item.Item
import com.lop.devtools.monstera.addon.mcfunction.McFunction
import com.lop.devtools.monstera.addon.mcfunction.buildMcFunctions
import com.lop.devtools.monstera.addon.sound.SoundUtil
import com.lop.devtools.monstera.files.File
import com.lop.devtools.monstera.files.getVersionAsString
import com.lop.devtools.monstera.files.manifest.generateManifest
import com.lop.devtools.monstera.files.res.ItemTextureIndex
import com.lop.devtools.monstera.files.res.TextureIndex
import com.lop.devtools.monstera.files.res.blocks.BlockDefs
import com.lop.devtools.monstera.files.res.blocks.TerrainTextures
import com.lop.devtools.monstera.files.res.materials.Materials
import com.lop.devtools.monstera.files.res.particleGetTexturePath
import org.slf4j.LoggerFactory
import java.io.File
import java.lang.Integer.max
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*

open class Addon(val config: Config) {
interface Addon {
@DslMarker
annotation class AddonTopLevel

companion object {
var active: Addon? = null
}

val unsafe = Unsafe()
private val logger = LoggerFactory.getLogger("Addon")

inner class Unsafe {
val sounds = SoundUtil(this@Addon)
val mcFunctions = mutableListOf<McFunction>()
}

val onEndListener: ArrayList<InvokeBeforeEnd> = arrayListOf()
val onPackage: ArrayList<PackageInvoke> = arrayListOf()
val config: Config

@MonsteraUnsafeField
val entities: MutableMap<String, Entity> = mutableMapOf()
val onEndListener: MutableList<InvokeBeforeEnd>
val onPackage: MutableList<PackageInvoke>

@MonsteraUnsafeField
val items: MutableMap<String, Item> = mutableMapOf()
var buildFunctions: Boolean
var buildTextureList: Boolean
var buildItemTextureIndex: Boolean
var buildToMcFolder: Boolean
var manifestMinEnginVersion: ArrayList<Int>

@MonsteraUnsafeField
val blocks: MutableMap<String, Block> = mutableMapOf()

var buildFunctions: Boolean = true
var buildTextureList: Boolean = true
var buildItemTextureIndex: Boolean = true
var buildToMcFolder: Boolean = true
var manifestMinEnginVersion: ArrayList<Int> = config.targetMcVersion

var includeInfoMcFunction: Boolean = true
var includeInfoMcFunction: Boolean

/**
* Define an abstract entity
Expand All @@ -77,12 +43,7 @@ open class Addon(val config: Config) {
* ```
*/
@AddonTopLevel
fun entity(name: String, displayName: String = name, entity: Entity.() -> Unit): Entity {
MonsteraLoggerContext.setEntity(name)
entities[name] = (entities[name] ?: Entity(this, name, displayName)).apply(entity)
MonsteraLoggerContext.clear()
return entities[name]!!
}
fun entity(name: String, displayName: String = name, entity: Entity.() -> Unit): Entity

/**
* Define sounds
Expand Down Expand Up @@ -138,9 +99,7 @@ open class Addon(val config: Config) {
* ```
*/
@AddonTopLevel
fun sounds(sounds: SoundUtil.() -> Unit): SoundUtil {
return unsafe.sounds.apply(sounds)
}
fun sounds(sounds: SoundUtil.() -> Unit): SoundUtil

/**
* ```
Expand All @@ -155,12 +114,7 @@ open class Addon(val config: Config) {
* ```
*/
@AddonTopLevel
fun item(name: String, displayName: String = name, item: Item.() -> Unit): Item {
MonsteraLoggerContext.setItem(name)
items[name] = (items[name] ?: Item(name, displayName, this)).apply(item)
MonsteraLoggerContext.clear()
return items[name]!!
}
fun item(name: String, displayName: String = name, item: Item.() -> Unit): Item

/**
* ```
Expand All @@ -172,44 +126,8 @@ open class Addon(val config: Config) {
* ```
*/
@AddonTopLevel
fun mcFunction(name: String, data: McFunction.() -> Unit): String {
val func = McFunction(name).apply(data)
unsafe.mcFunctions.add(func)
return func.name
}

fun loadParticle(value: File) {
if (value.isDirectory) {
var texturePath = ""
var texture = File()
value.walk().forEach {
if (it.name.contains("particle.json")) {
//copy the particle json into the res pack
val target = config.paths.resParticles.resolve(it.name).toFile()
it.copyTo(target, true)
//set the texture path that is given in the json
texturePath = particleGetTexturePath(it).getOrElse { e ->
logger.warn("Invalid Particle at ${it.name}, see: ${e.stackTrace}")
return@forEach
}
} else if (it.name.contains(".png")) {
//set the texture, don't copy yet as there may be no path yet
texture = it
}
}
val target = config.paths.resTextures.toFile()
texture.copyTo(File(target, "$texturePath.png"), true)
} else if (value.isFile) {
//just copy, no need for a texture
var fileName = value.name
if (!fileName.contains(".json"))
fileName += ".json"
val target = config.paths.resParticles.resolve(fileName)
value.copyTo(target.toFile(), true)
} else {
logger.warn("Could not find particle file ${value.path}")
}
}
fun mcFunction(name: String, data: McFunction.() -> Unit): String
fun loadParticle(value: File)

/**
* add a block
Expand All @@ -227,114 +145,12 @@ open class Addon(val config: Config) {
* ```
*/
@AddonTopLevel
fun block(name: String, displayName: String, data: Block.() -> Unit): Block {
MonsteraLoggerContext.setBlock(name)
blocks[name] = (blocks[name] ?: Block(this, name, displayName)).apply(data)
MonsteraLoggerContext.clear()
return blocks[name]!!
}

fun scripts(directory: File) {
val scriptingDir = config.paths.behScripts.toFile()
fun block(name: String, displayName: String = name, data: Block.() -> Unit): Block

if (directory.isDirectory) {
directory
.walk()
.maxDepth(1)
.filter { directory.name != it.name }
.forEach {
it.copyRecursively(File(scriptingDir, it.name), true)
}
} else {
logger.warn("${directory.path}' does not exist or is not a directory (scripting)")
}
}
fun scripts(directory: File)

fun build() {
//entities
entities.forEach { (name, body) ->
MonsteraLoggerContext.setEntity(name)
body.build()
MonsteraLoggerContext.clear()
}
//items
items.forEach { (name, body) ->
MonsteraLoggerContext.setItem(name)
body.build()
MonsteraLoggerContext.clear()
}
//blocks
blocks.forEach { (name, body) ->
MonsteraLoggerContext.setBlock(name)
body.build()
MonsteraLoggerContext.clear()
}
BlockDefs.instance(this).unsafe.build(config.resPath)
TerrainTextures.instance(this).unsafe.buildFile(this)
Materials.instance(this).apply {
version("1.0.0")
}.unsafe.build(this)
onEndListener.forEach {
it.invoke(this)
}
if (includeInfoMcFunction) {
buildInformation(this)
}
generateManifest(
config.version,
config,
minEnginVersion = manifestMinEnginVersion,
scriptEntryFile = config.scriptEntryFile
)

if (unsafe.mcFunctions.isNotEmpty())
buildMcFunctions(config.paths.behMcFunction, unsafe.mcFunctions)
if (buildTextureList)
TextureIndex.instance(this).build(this)
if (buildItemTextureIndex)
ItemTextureIndex.instance(this).build(this)

unsafe.sounds.unsafe.build()

config.langFileBuilder.addonRes.sort().build()
config.langFileBuilder.addonBeh.sort().build()

validateTextures(this)
if (buildToMcFolder)
buildToMcFolder(config)

onPackage.forEach {
it.invoke(this)
}
}
}

fun buildInformation(addon: Addon) {
val time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))

val characterLength = max(
max(
addon.config.monsteraVersion.length + 21,
(System.getenv("CI_COMMIT_REF_NAME") ?: "local").length + 17
), time.length + 14
)
val format = StringBuilder()

for (i in 0 until characterLength) {
format.append("#")
}

addon.mcFunction(name = "build_information") {
entries = arrayListOf(
"say §b$format",
"say §b#§a Monstera version: ${addon.config.monsteraVersion}",
"say §b#§a build version: ${
(System.getenv("CI_COMMIT_REF_NAME") ?: System.getenv("GITHUB_REF") ?: getVersionAsString(
addon.config.version
))
}",
"say §b#§a build time: $time",
"say §b$format",
)
}
/**
* internal function to build the addon
*/
fun build()
}
Loading

0 comments on commit 2fbf28b

Please sign in to comment.