Skip to content

Commit

Permalink
move generated datapack dimensions manually for now
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Mar 7, 2022
1 parent 3601a7b commit 92d59b6
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 46 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package possible_triangle.skygrid.data.generation

import kotlinx.serialization.ExperimentalSerializationApi
import net.minecraft.data.DataGenerator
import net.minecraft.data.DataProvider
import net.minecraftforge.common.data.ExistingFileHelper
import net.minecraftforge.eventbus.api.SubscribeEvent
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent
import nl.adaptivity.xmlutil.ExperimentalXmlUtilApi
import possible_triangle.skygrid.data.generation.dimensions.*

@ExperimentalXmlUtilApi
@ExperimentalSerializationApi
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
object DataGenerators {

@SubscribeEvent
fun register(event: GatherDataEvent) {
event.includeDev()

fun DataGenerator.addProvider(factory: (DataGenerator) -> DataProvider) {
addProvider(factory(this))
}

fun DataGenerator.addProvider(
factory: (DataGenerator) -> DimensionConfigGenerator,
datapack: String?,
) {
factory(this).also {
it.datapack = datapack
addProvider(it)
}
}

fun DataGenerator.addProvider(factory: (DataGenerator, ExistingFileHelper) -> DataProvider) {
addProvider(factory(this, event.existingFileHelper))
}

if (event.includeServer()) {
event.generator.addProvider(::SkygridTags)
event.generator.addProvider(::Presets)
event.generator.addProvider(::Overworld)
event.generator.addProvider(::Nether)
event.generator.addProvider(::End)

event.generator.addProvider(::Cave, "custom-examples")
event.generator.addProvider(::Aqua, "custom-examples")
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import possible_triangle.skygrid.data.generation.builder.IBlocksBuilder
import possible_triangle.skygrid.data.xml.DimensionConfig
import possible_triangle.skygrid.data.xml.Preset
import possible_triangle.skygrid.data.xml.impl.BlockList
import kotlin.io.path.absolutePathString
import kotlin.io.path.createDirectories
import kotlin.io.path.exists
import kotlin.io.path.writeText
Expand All @@ -28,7 +29,7 @@ abstract class DimensionConfigGenerator(private val name: String, private val ge
private val configs = hashMapOf<ResourceLocation, DimensionConfig>()
private val presets = hashMapOf<ResourceLocation, Preset>()

open val datapack: String? = null
var datapack: String? = null

fun dimension(key: ResourceKey<LevelStem>, builder: DimensionConfigBuilder.() -> Unit) =
dimension(key.location(), builder)
Expand Down Expand Up @@ -61,17 +62,18 @@ abstract class DimensionConfigGenerator(private val name: String, private val ge
final override fun run(cache: HashCache) {
generate()

val directory = datapack?.let {
generator.outputFolder.resolve("datapacks/$it")
} ?: generator.outputFolder
val directory = if (datapack == null)
generator.outputFolder
else
generator.outputFolder.resolve("datapacks/${datapack}")

fun write(type: String, key: ResourceLocation, content: String) {
val file = directory.resolve("data/" + key.namespace + "/skygrid/$type/" + key.path + ".xml")

val sha = DataProvider.SHA1.hashUnencodedChars(content).toString()
if (cache.getHash(file) != sha || !file.exists()) {
if (!file.parent.exists()) file.parent.createDirectories()
SkygridMod.LOGGER.info("Writing $type/$key")
SkygridMod.LOGGER.info("Writing $type/$key to ${file.absolutePathString()}")
file.writeText(content)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import possible_triangle.skygrid.data.generation.DimensionConfigGenerator
@ExperimentalSerializationApi
class Aqua(generator: DataGenerator) : DimensionConfigGenerator("aqua", generator) {

override val datapack = "custom-examples"

override fun generate() {

dimension(ResourceLocation(SkygridMod.MOD_ID, "aqua")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import possible_triangle.skygrid.data.xml.Distance
@ExperimentalSerializationApi
class Cave(generator: DataGenerator) : DimensionConfigGenerator("cave", generator) {

override val datapack = "custom-examples"

override fun generate() {

dimension(ResourceLocation(SkygridMod.MOD_ID, "cave")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<dimension>
<blocks>
<reference id="ocean"/>
</blocks>
<gap id="water"/>
</dimension>
18 changes: 18 additions & 0 deletions datapacks/custom-examples/data/skygrid/skygrid/dimensions/cave.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<dimension>
<blocks>
<reference id="ores" weight="0.1"/>
<reference id="dripstone" weight="0.1"/>
<reference id="moss" weight="0.05"/>
<block id="obsidian" weight="0.1"/>
<list weight="0.05" name="fluids">
<block id="lava"/>
<block id="water"/>
</list>
<tag id="base_stone_overworld">
<side on="up" probability="0.1">
<block id="glow_shroom" mod="quark"/>
</side>
</tag>
</blocks>
<distance x="3" y="3" z="3"/>
</dimension>

0 comments on commit 92d59b6

Please sign in to comment.