@@ -4,8 +4,12 @@ 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.block.NamedExperienceBlock
8+ import com.algorithmlx.dimore.block.NamedRedstoneBlock
79import com.algorithmlx.dimore.init.post.PostBlock
8- import com.algorithmlx.dimore.init.config.DimensionalOresConfig
10+ import com.algorithmlx.dimore.init.config.CommentedJSONManager
11+ import com.algorithmlx.dimore.init.post.loot.ItemEntry
12+ import com.algorithmlx.dimore.init.post.loot.SimpleLootTable
913import com.algorithmlx.dimore.item.NamedBlockItem
1014import com.algorithmlx.dimore.util.OreDimensionType
1115import com.algorithmlx.dimore.util.OreDimensionTypes
@@ -15,14 +19,19 @@ import com.algorithmlx.dimore.util.ResLoc
1519import kotlinx.serialization.ExperimentalSerializationApi
1620import kotlinx.serialization.json.decodeFromStream
1721import net.minecraft.world.level.block.state.BlockBehaviour
22+ // $ if >1.21.1 'import net.minecraft.core.HolderLookup' else 'import net.minecraft.core.HolderGetter'
1823import net.minecraft.core.HolderLookup
19- import net.minecraft.core.registries.Registries
24+ import net.minecraft.core.registries.BuiltInRegistries
25+ import net.minecraft.network.chat.Component
2026import net.minecraft.resources.ResourceKey
2127import net.minecraft.world.item.Item
2228import net.minecraft.world.level.block.Block
2329import net.minecraft.world.level.block.Blocks
24- import net.minecraft.world.level.block.RedStoneOreBlock
2530import net.minecraft.world.level.storage.loot.LootTable
31+ import net.minecraft.world.level.storage.loot.LootPool
32+ import net.minecraft.world.level.storage.loot.entries.AlternativesEntry
33+ import net.minecraft.world.level.storage.loot.entries.LootItem
34+ import net.minecraft.world.level.storage.loot.providers.number.ConstantValue
2635// ? if neoforge {
2736/* import com.algorithmlx.dimore.worldgen.DimOreModifier
2837import net.minecraft.core.Holder
@@ -31,22 +40,15 @@ import net.neoforged.neoforge.registries.DeferredBlock
3140import net.neoforged.neoforge.registries.DeferredRegister
3241import net.neoforged.neoforge.registries.NeoForgeRegistries
3342import java.util.function.Supplier
34- */ // ?}
35- // ? if fabric {
36- import com.algorithmlx.dimore.init.config.CommentedJSONManager
37- import com.algorithmlx.dimore.init.post.loot.ItemEntry
38- import com.algorithmlx.dimore.init.post.loot.SimpleLootTable
43+ */ // ?} elif fabric {
44+ import com.algorithmlx.dimore.init.config.DimensionalOresConfig
3945import com.algorithmlx.dimore.util.DimensionOreConfig
4046import com.algorithmlx.dimore.util.OreGeneratorFactory
4147import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback
4248import net.minecraft.core.Registry
43- import net.minecraft.core.registries.BuiltInRegistries
49+ import net.minecraft.core.registries.Registries
4450import net.minecraft.world.level.levelgen.feature.ConfiguredFeature
4551import net.minecraft.world.level.levelgen.placement.PlacedFeature
46- import net.minecraft.world.level.storage.loot.LootPool
47- import net.minecraft.world.level.storage.loot.entries.AlternativesEntry
48- import net.minecraft.world.level.storage.loot.entries.LootItem
49- import net.minecraft.world.level.storage.loot.providers.number.ConstantValue
5052// ?}
5153import java.io.File
5254
@@ -60,22 +62,23 @@ object Registry {
6062 private val itemRegistry = DeferredRegister.createItems(ModId)
6163 private val biomeModifierSerializers = DeferredRegister.create(NeoForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, ModId)
6264 val blockHolders = mutableMapOf<String, Holder<Block>>()
65+ */ // ?}
6366
64- fun init(bus: IEventBus) {
65- blockRegistry.register(bus)
67+ // $ if forgeLike 'fun init(bus: IEventBus) {' else 'fun init() {'
68+ fun init () {
69+ // ? if forgeLike {
70+ /* blockRegistry.register(bus)
6671 itemRegistry.register(bus)
6772 biomeModifierSerializers.register(bus)
68-
73+ */ // ?}
74+
6975 registerOres()
70- initOresFromJSON()
71-
72- biomeModifierSerializers.register("dimore_modifier", Supplier { DimOreModifier.codec }) }
73- */ // ?} else {
74- fun init () {
75- registerOres()
76- initOresFromJSON()
77- registerLootTables()
76+ if (CommentedJSONManager .config.enableCustomBlocks) initOresFromJSON()
77+ if (CommentedJSONManager .config.enableLootTables) registerLootTables()
7878
79+ // ? if forgeLike {
80+ /* biomeModifierSerializers.register("dimore_modifier", Supplier { DimOreModifier.codec })
81+ */ // ?} else {
7982 DynamicRegistrySetupCallback .EVENT .register { regMgr ->
8083 val confReg = regMgr.getOptional(Registries .CONFIGURED_FEATURE )
8184 val placedReg = regMgr.getOptional(Registries .PLACED_FEATURE )
@@ -84,8 +87,8 @@ object Registry {
8487
8588 registerFeatures(confReg.get(), placedReg.get())
8689 }
90+ // ?}
8791 }
88- // ?}
8992
9093 private fun initOresFromJSON () {
9194 val configFiles = File (" config/$ModId /custom/" )
@@ -106,10 +109,21 @@ object Registry {
106109 postBlocks[id] = config
107110
108111 if (! config.isRedstone) this .registerBlock(
109- id, ::Block ,
112+ id, { properties ->
113+ NamedExperienceBlock (
114+ config.experienceDrop.asMC(),
115+ properties,
116+ if (config.displayName.isNotEmpty()) Component .translatable(config.displayName) else null
117+ )
118+ },
110119 config.properties.asBlockBehaviourProperties(), true
111120 ) else this .registerBlock(
112- id, ::RedStoneOreBlock ,
121+ id, { properties ->
122+ NamedRedstoneBlock (
123+ properties,
124+ if (config.displayName.isNotEmpty()) Component .translatable(config.displayName) else null
125+ )
126+ },
113127 config.properties.asBlockBehaviourProperties(), true
114128 )
115129 }
@@ -151,6 +165,7 @@ object Registry {
151165 }
152166
153167 @JvmStatic
168+ // $ if >1.21.1 'fun getLoot(requestedId: ResourceKey<LootTable>, lookup: HolderLookup.Provider): LootTable? {' else 'fun getLoot(requestedId: ResourceKey<LootTable>, lookup: HolderGetter.Provider): LootTable? {'
154169 fun getLoot (requestedId : ResourceKey <LootTable >, lookup : HolderLookup .Provider ): LootTable ? {
155170 val resourceId =
156171 // $ if >1.21.1 'requestedId.identifier()' else 'requestedId.location()'
@@ -160,7 +175,9 @@ object Registry {
160175
161176 val lootItemsConditioned = table.entries.filter { it.requires.isNotEmpty() }.map {
162177 val itemId = if (it is ItemEntry ) it.id else " ${resourceId.namespace} :${resourceId.path.split(' /' ).last()} "
163- val item = BuiltInRegistries .ITEM .getValue(ResLoc .parse(itemId))
178+ val item = BuiltInRegistries .ITEM
179+ // $ if >1.21.1 '.getValue(ResLoc.parse(itemId))' else '.get(ResLoc.parse(itemId))'
180+ .getValue(ResLoc .parse(itemId))
164181 var lootItem = LootItem .lootTableItem(item)
165182
166183 it.requires.map { req -> req.asMC(lookup) }.forEach { req ->
@@ -176,7 +193,9 @@ object Registry {
176193
177194 val lootItemsNoCondition = table.entries.filter { it.requires.isEmpty() }.map {
178195 val itemId = if (it is ItemEntry ) it.id else " ${resourceId.namespace} :${resourceId.path.split(' /' ).last()} "
179- val item = BuiltInRegistries .ITEM .getValue(ResLoc .parse(itemId))
196+ val item = BuiltInRegistries .ITEM
197+ // $ if >1.21.1 '.getValue(ResLoc.parse(itemId))' else '.get(ResLoc.parse(itemId))'
198+ .getValue(ResLoc .parse(itemId))
180199 var lootItem = LootItem .lootTableItem(item)
181200
182201 it.functions.map { func -> func.asMC(lookup) }.forEach { func ->
@@ -237,33 +256,32 @@ object Registry {
237256 shouldRegisterItem: Boolean
238257 ): DeferredBlock<B> {
239258 //? if >1.21.1 {
240- val blockKey = { it: ResLoc -> ResourceKey.create(Registries.BLOCK, it) }
259+ /* val blockKey = { it: ResLoc -> ResourceKey.create(Registries.BLOCK, it) }
241260 val bl = blockRegistry.register(id) { rk ->
242261 block(properties.setId(blockKey(rk)))
243262 }
244- //?} else
245- // val bl = blockRegistry.register(id, Supplier { block(properties) })
263+ */ //?} else
264+ val bl = blockRegistry.register(id, Supplier { block(properties) })
246265
247266 if (shouldRegisterItem) {
248267 //? if >1.21.1 {
249- itemRegistry.register(id) { rk ->
268+ /* itemRegistry.register(id) { rk ->
250269 NamedBlockItem(
251270 bl.get(),
252271 Item.Properties()
253272 .setId(ResourceKey.create(Registries.ITEM, rk))
254273 .useBlockDescriptionPrefix()
255274 )
256275 }
257- //?} else
258- // itemRegistry.register(id, Supplier { NamedBlockItem(bl.get(), Item.Properties()) })
276+ */ //?} else
277+ itemRegistry.register(id, Supplier { NamedBlockItem(bl.get(), Item.Properties()) })
259278 }
260279
261280 blockHolders[id] = bl
262281
263282 return bl
264283 }
265284 */ // ?} else {
266-
267285 private fun registerFeatures (
268286 cfReg : Registry <ConfiguredFeature <* , * >>,
269287 pfReg : Registry <PlacedFeature >
@@ -274,9 +292,8 @@ object Registry {
274292 val config = OreTypes .configByTypeNether[type] ? : return @forEach
275293
276294 val block = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , id))
277- // $ if >1.21.1 '.orElseThrow().value()' else ''
295+ // $ if >1.21.1 '.orElseThrow().value()' else '//.orElseThrow().value() '
278296 .orElseThrow().value()
279-
280297 createFeature(cfReg, pfReg, id, block, OreDimensionTypes .NETHER , config)
281298 }
282299 }
@@ -288,12 +305,11 @@ object Registry {
288305 val config = OreTypes .configByTypeOverworld[type] ? : return @forEach
289306
290307 val stoneBlock = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , stoneId))
291- // $ if >1.21.1 '.orElseThrow().value()' else ''
308+ // $ if >1.21.1 '.orElseThrow().value()' else '//.orElseThrow().value() '
292309 .orElseThrow().value()
293310 val deepslateBlock = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , deepslateId))
294- // $ if >1.21.1 '.orElseThrow().value()' else ''
311+ // $ if >1.21.1 '.orElseThrow().value()' else '//.orElseThrow().value() '
295312 .orElseThrow().value()
296-
297313 createFeature(cfReg, pfReg, stoneId, stoneBlock, OreDimensionTypes .OVERWORLD , config)
298314 createFeature(cfReg, pfReg, deepslateId, deepslateBlock, OreDimensionTypes .OVERWORLD_DEEPSLATE , config)
299315 }
@@ -304,9 +320,8 @@ object Registry {
304320 val id = " end_${type.name.lowercase()} _ore"
305321 val config = OreTypes .configByTypeEnd[type] ? : return @forEach
306322 val block = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , id))
307- // $ if >1.21.1 '.orElseThrow().value()' else ''
323+ // $ if >1.21.1 '.orElseThrow().value()' else '//.orElseThrow().value() '
308324 .orElseThrow().value()
309-
310325 createFeature(cfReg, pfReg, id, block, OreDimensionTypes .END , config)
311326 }
312327 }
@@ -320,7 +335,7 @@ object Registry {
320335 )
321336
322337 val mcBlock = BuiltInRegistries .BLOCK .get(ResLoc .fromNamespaceAndPath(ModId , id))
323- // $ if >1.21.1 '.orElseThrow().value()' else ''
338+ // $ if >1.21.1 '.orElseThrow().value()' else '//.orElseThrow().value() '
324339 .orElseThrow().value()
325340
326341 createFeature(cfReg, pfReg, id, mcBlock, settings.asDimensionType(), convertedConfig)
@@ -342,9 +357,8 @@ object Registry {
342357
343358 val cfKey = ResourceKey .create(Registries .CONFIGURED_FEATURE , location)
344359 val entry =
345- // $ if >1.21.1 'cfReg.get(cfKey)' else 'cfReg.getHolder(cfKey)'
346- cfReg.get(cfKey)
347- .orElseThrow()
360+ // $ if >1.21.1 'cfReg.get(cfKey).orElseThrow()' else 'cfReg.getHolder(cfKey).orElseThrow()'
361+ cfReg.get(cfKey).orElseThrow()
348362
349363 val placed = OreGeneratorFactory .createPlaced(entry, settings.count, settings.minHeight, settings.maxHeight)
350364 Registry .register(pfReg, location, placed)
@@ -354,7 +368,7 @@ object Registry {
354368 val blockKey = ResourceKey .create(Registries .BLOCK , ResLoc .fromNamespaceAndPath(ModId , id))
355369 val b = factory(
356370 properties
357- // $ if >1.21.1 '.setId(blockKey)' else ''
371+ // $ if >1.21.1 '.setId(blockKey)' else '//.setId(blockKey) '
358372 .setId(blockKey)
359373 )
360374
0 commit comments