@@ -4,18 +4,25 @@ import com.algorithmlx.dimore.LOGGER
44import com.algorithmlx.dimore.ModId
55import com.algorithmlx.dimore.block.DimensionalOreBlock
66import com.algorithmlx.dimore.block.DimensionalRedstoneOre
7+ import com.algorithmlx.dimore.init.post.PostBlock
8+ import com.algorithmlx.dimore.init.config.DimensionalOresConfig
79import com.algorithmlx.dimore.item.NamedBlockItem
810import com.algorithmlx.dimore.util.OreDimensionType
911import com.algorithmlx.dimore.util.OreDimensionTypes
1012import com.algorithmlx.dimore.util.OreType
1113import com.algorithmlx.dimore.util.OreTypes
1214import com.algorithmlx.dimore.util.ResLoc
15+ import kotlinx.serialization.ExperimentalSerializationApi
16+ import kotlinx.serialization.json.Json
17+ import kotlinx.serialization.json.decodeFromStream
1318import net.minecraft.world.level.block.state.BlockBehaviour
1419import net.minecraft.core.registries.Registries
1520import net.minecraft.resources.ResourceKey
1621import net.minecraft.world.item.Item
1722import net.minecraft.world.level.block.Block
1823import net.minecraft.world.level.block.Blocks
24+ import net.minecraft.world.level.block.RedStoneOreBlock
25+ import net.minecraft.world.level.storage.loot.LootTable
1926// ? if neoforge {
2027/* import com.algorithmlx.dimore.worldgen.DimOreModifier
2128import net.minecraft.core.Holder
@@ -27,23 +34,18 @@ import java.util.function.Supplier
2734*/ // ?}
2835// ? if fabric {
2936import com.algorithmlx.dimore.init.config.CommentedJSONManager
30- import com.algorithmlx.dimore.init.post.PostBlock
3137import com.algorithmlx.dimore.util.DimensionOreConfig
3238import com.algorithmlx.dimore.util.OreGeneratorFactory
33- import kotlinx.serialization.ExperimentalSerializationApi
34- import kotlinx.serialization.json.Json
35- import kotlinx.serialization.json.decodeFromStream
3639import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback
3740import net.minecraft.core.Registry
3841import net.minecraft.core.registries.BuiltInRegistries
39- import net.minecraft.world.level.block.RedStoneOreBlock
4042import net.minecraft.world.level.levelgen.feature.ConfiguredFeature
4143import net.minecraft.world.level.levelgen.placement.PlacedFeature
42- import java.io.File
43-
4444// ?}
45+ import java.io.File
4546
4647object Registry {
48+ private val postBlocks = mutableMapOf<String , PostBlock >()
4749 // ? if neoforge {
4850 /* private val blockRegistry = DeferredRegister.createBlocks(ModId)
4951 private val itemRegistry = DeferredRegister.createItems(ModId)
@@ -100,6 +102,8 @@ object Registry {
100102 val id = " custom.${it.name.removeSuffix(" .json" )} "
101103 val config: PostBlock = json.decodeFromStream(it.inputStream())
102104
105+ postBlocks[id] = config
106+
103107 if (! config.isRedstone) this .registerBlock(
104108 id, ::Block ,
105109 config.properties.asBlockBehaviourProperties(), true
@@ -110,9 +114,10 @@ object Registry {
110114 }
111115 }
112116
117+ fun getPostBlocks (): Map <String , PostBlock > = mapOf (* postBlocks.entries.map { it.toPair() }.toTypedArray())
118+
113119 private fun registerOres () {
114120 // Nether Ores
115-
116121 OreTypes .netherOres.forEach {
117122 val id = " nether_${it.name.lowercase()} _ore"
118123 if (it == OreTypes .REDSTONE ) {
@@ -124,7 +129,6 @@ object Registry {
124129 }
125130
126131 // Overworld ores
127-
128132 OreTypes .overworldOres.forEach {
129133 val id = " stone_${it.name.lowercase()} _ore"
130134 val deepSlateId = " deepslate_${it.name.lowercase()} _ore"
@@ -145,6 +149,11 @@ object Registry {
145149 }
146150 }
147151
152+ @JvmStatic
153+ fun spawnCustomLoot (): MutableMap <ResourceKey <LootTable >, LootTable> {
154+ return mutableMapOf ()
155+ }
156+
148157 private fun registerOre (id : String , oreType : OreType , oreDimensionType : OreDimensionType ) = registerBlock(
149158 id,
150159 { p -> DimensionalOreBlock (oreType, oreDimensionType, p) },
@@ -202,13 +211,11 @@ object Registry {
202211 OreTypes .netherOres.forEach { type ->
203212 val id = " nether_${type.name.lowercase()} _ore"
204213 val config = OreTypes .configByTypeNether[type] ? : return @forEach
205- // ? if >1.21.1 {
214+
206215 val block = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , id))
207- .orElseThrow()
216+ // $ if >1.21.1 '.orElseThrow().value()' else ''
217+ .orElseThrow().value()
208218 .value()
209- // ?} else {
210- /* val block = BuiltInRegistries.BLOCK.get(ResLoc.fromNamespaceAndPath(ModId, id))
211- */ // ?}
212219
213220 createFeature(cfReg, pfReg, id, block, OreDimensionTypes .NETHER , config)
214221 }
@@ -220,18 +227,12 @@ object Registry {
220227 val deepslateId = " deepslate_${type.name.lowercase()} _ore"
221228 val config = OreTypes .configByTypeOverworld[type] ? : return @forEach
222229
223- // ? if >1.21.1 {
224230 val stoneBlock = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , stoneId))
225- .orElseThrow()
226- .value()
227- val deepslateBlock =
228- BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , deepslateId))
229- .orElseThrow()
230- .value()
231- // ?} else {
232- /* val stoneBlock = BuiltInRegistries.BLOCK.get(ResLoc.fromNamespaceAndPath(ModId, stoneId))
231+ // $ if >1.21.1 '.orElseThrow().value()' else ''
232+ .orElseThrow().value()
233233 val deepslateBlock = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , deepslateId))
234- */ // ?}
234+ // $ if >1.21.1 '.orElseThrow().value()' else ''
235+ .orElseThrow().value()
235236
236237 createFeature(cfReg, pfReg, stoneId, stoneBlock, OreDimensionTypes .OVERWORLD , config)
237238 createFeature(cfReg, pfReg, deepslateId, deepslateBlock, OreDimensionTypes .OVERWORLD_DEEPSLATE , config)
@@ -242,17 +243,28 @@ object Registry {
242243 OreTypes .endOres.forEach { type ->
243244 val id = " end_${type.name.lowercase()} _ore"
244245 val config = OreTypes .configByTypeEnd[type] ? : return @forEach
245- // ? if >1.21.1 {
246246 val block = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , id))
247- .orElseThrow()
248- .value()
249- // ?} else {
250- /* val block = BuiltInRegistries.BLOCK.get(ResLoc.fromNamespaceAndPath(ModId, id))
251- */ // ?}
247+ // $ if >1.21.1 '.orElseThrow().value()' else ''
248+ .orElseThrow().value()
252249
253250 createFeature(cfReg, pfReg, id, block, OreDimensionTypes .END , config)
254251 }
255252 }
253+
254+ this .getPostBlocks().forEach { (id, block) ->
255+ val settings = block.generationSettings
256+ val generationConfig = settings.config
257+ val convertedConfig = DimensionalOresConfig .OreGenerationSettings (
258+ true , generationConfig.size, generationConfig.count,
259+ generationConfig.minHeight, generationConfig.maxHeight
260+ )
261+
262+ val mcBlock = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , id))
263+ // $ if >1.21.1 '.orElseThrow().value()' else ''
264+ .orElseThrow().value()
265+
266+ createFeature(cfReg, pfReg, id, mcBlock, settings.asDimensionType(), convertedConfig)
267+ }
256268 }
257269
258270 private fun createFeature (
0 commit comments