Maintain inner list of decorative blocks to register

This commit is contained in:
DBotThePony 2024-01-04 00:00:06 +07:00
parent f36019b4ef
commit 1e8aecb5d7
Signed by: DBot
GPG Key ID: DCC23B5715498507
6 changed files with 52 additions and 55 deletions

View File

@ -348,19 +348,6 @@ object MBlocks {
) } ) }
init { init {
MRegistry.INDUSTRIAL_GLASS.registerBlocks(registry) MRegistry.registerBlocks(registry)
MRegistry.INDUSTRIAL_GLASS_PANE.registerBlocks(registry)
MRegistry.UNREFINED_FLOOR_TILES.registerBlocks(registry)
MRegistry.FLOOR_TILES.registerBlocks(registry)
MRegistry.FLOOR_TILES_STAIRS.registerBlocks(registry)
MRegistry.FLOOR_TILES_SLAB.registerBlocks(registry)
MRegistry.VENT.registerBlocks(registry)
MRegistry.VENT_ALTERNATIVE.registerBlocks(registry)
MRegistry.DECORATIVE_CRATE.registerBlocks(registry)
MRegistry.TRITANIUM_STRIPED_BLOCK.registerBlocks(registry)
MRegistry.TRITANIUM_STRIPED_STAIRS.registerBlocks(registry)
MRegistry.TRITANIUM_STRIPED_SLAB.registerBlocks(registry)
MRegistry.TRITANIUM_STRIPED_WALL.registerBlocks(registry)
MRegistry.COMPUTER_TERMINAL.registerBlocks(registry)
} }
} }

View File

@ -672,19 +672,6 @@ object MItems {
val CHEST_UPGRADER: Item by registry.register(MNames.CHEST_UPGRADER) { ChestUpgraderItem() } val CHEST_UPGRADER: Item by registry.register(MNames.CHEST_UPGRADER) { ChestUpgraderItem() }
init { init {
MRegistry.INDUSTRIAL_GLASS.registerItems(registry) MRegistry.registerItems(registry)
MRegistry.INDUSTRIAL_GLASS_PANE.registerItems(registry)
MRegistry.UNREFINED_FLOOR_TILES.registerItems(registry)
MRegistry.FLOOR_TILES.registerItems(registry)
MRegistry.FLOOR_TILES_STAIRS.registerItems(registry)
MRegistry.FLOOR_TILES_SLAB.registerItems(registry)
MRegistry.VENT.registerItems(registry)
MRegistry.VENT_ALTERNATIVE.registerItems(registry)
MRegistry.DECORATIVE_CRATE.registerItems(registry)
MRegistry.TRITANIUM_STRIPED_BLOCK.registerItems(registry)
MRegistry.TRITANIUM_STRIPED_STAIRS.registerItems(registry)
MRegistry.TRITANIUM_STRIPED_SLAB.registerItems(registry)
MRegistry.TRITANIUM_STRIPED_WALL.registerItems(registry)
MRegistry.COMPUTER_TERMINAL.registerItems(registry)
} }
} }

View File

@ -14,6 +14,7 @@ import net.minecraft.world.entity.ai.village.poi.PoiType
import net.minecraft.world.entity.ai.village.poi.PoiTypes import net.minecraft.world.entity.ai.village.poi.PoiTypes
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.DyeableArmorItem import net.minecraft.world.item.DyeableArmorItem
import net.minecraft.world.item.Item
import net.minecraft.world.item.Items import net.minecraft.world.item.Items
import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.block.* import net.minecraft.world.level.block.*
@ -29,6 +30,7 @@ import net.minecraftforge.eventbus.api.IEventBus
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
import net.minecraftforge.fml.loading.FMLEnvironment import net.minecraftforge.fml.loading.FMLEnvironment
import net.minecraftforge.registries.DeferredRegister
import net.minecraftforge.registries.NewRegistryEvent import net.minecraftforge.registries.NewRegistryEvent
import net.minecraftforge.registries.RegisterEvent import net.minecraftforge.registries.RegisterEvent
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
@ -54,6 +56,7 @@ import ru.dbotthepony.mc.otm.matter.AbstractRegistryAction
import ru.dbotthepony.mc.otm.matter.IMatterFunction import ru.dbotthepony.mc.otm.matter.IMatterFunction
import ru.dbotthepony.mc.otm.registry.objects.ColoredDecorativeBlock import ru.dbotthepony.mc.otm.registry.objects.ColoredDecorativeBlock
import ru.dbotthepony.mc.otm.registry.objects.DecorativeBlock import ru.dbotthepony.mc.otm.registry.objects.DecorativeBlock
import ru.dbotthepony.mc.otm.registry.objects.IBlockItemRegistryAcceptor
import ru.dbotthepony.mc.otm.registry.objects.StripedColoredDecorativeBlock import ru.dbotthepony.mc.otm.registry.objects.StripedColoredDecorativeBlock
import ru.dbotthepony.mc.otm.shapes.BlockShapes import ru.dbotthepony.mc.otm.shapes.BlockShapes
import ru.dbotthepony.mc.otm.storage.StorageStack import ru.dbotthepony.mc.otm.storage.StorageStack
@ -80,7 +83,7 @@ import ru.dbotthepony.mc.otm.triggers.ShockwaveDamageMobTrigger
import ru.dbotthepony.mc.otm.triggers.ShockwaveTrigger import ru.dbotthepony.mc.otm.triggers.ShockwaveTrigger
import ru.dbotthepony.mc.otm.triggers.TakeItemOutOfReplicatorTrigger import ru.dbotthepony.mc.otm.triggers.TakeItemOutOfReplicatorTrigger
object MRegistry { object MRegistry : IBlockItemRegistryAcceptor {
private val features = RegistryDelegate<AndroidFeatureType<*>>("android_features") private val features = RegistryDelegate<AndroidFeatureType<*>>("android_features")
val ANDROID_FEATURES by features val ANDROID_FEATURES by features
val ANDROID_FEATURES_LOCATION get() = features.location val ANDROID_FEATURES_LOCATION get() = features.location
@ -109,7 +112,17 @@ object MRegistry {
features.build(event) features.build(event)
} }
val CARGO_CRATES = DecorativeBlock(MNames.CARGO_CRATE, ::CargoCrateBlock) private val decorativeBlocks = ArrayList<IBlockItemRegistryAcceptor>()
override fun registerItems(registry: DeferredRegister<Item>) {
decorativeBlocks.forEach { it.registerItems(registry) }
}
override fun registerBlocks(registry: DeferredRegister<Block>) {
decorativeBlocks.forEach { it.registerBlocks(registry) }
}
val CARGO_CRATES = DecorativeBlock(MNames.CARGO_CRATE, ::CargoCrateBlock).also { decorativeBlocks.add(it) }
val DECORATIVE_CRATE = DecorativeBlock.simple(MNames.DECORATIVE_CRATE) { val DECORATIVE_CRATE = DecorativeBlock.simple(MNames.DECORATIVE_CRATE) {
BlockBehaviour.Properties.of() BlockBehaviour.Properties.of()
@ -118,7 +131,7 @@ object MRegistry {
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.explosionResistance(10f) .explosionResistance(10f)
.destroyTime(1f) .destroyTime(1f)
} }.also { decorativeBlocks.add(it) }
val TRITANIUM_BLOCK = DecorativeBlock.simple(MNames.TRITANIUM_BLOCK) { val TRITANIUM_BLOCK = DecorativeBlock.simple(MNames.TRITANIUM_BLOCK) {
BlockBehaviour.Properties.of() BlockBehaviour.Properties.of()
@ -127,7 +140,7 @@ object MRegistry {
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.explosionResistance(80f) .explosionResistance(80f)
.destroyTime(2.5f) .destroyTime(2.5f)
} }.also { decorativeBlocks.add(it) }
val COMPUTER_TERMINAL = DecorativeBlock.rotatable("computer_terminal", BlockShapes.COMPUTER_TERMINAL, BlockRotationFreedom.HORIZONTAL) { val COMPUTER_TERMINAL = DecorativeBlock.rotatable("computer_terminal", BlockShapes.COMPUTER_TERMINAL, BlockRotationFreedom.HORIZONTAL) {
BlockBehaviour.Properties.of() BlockBehaviour.Properties.of()
@ -135,24 +148,24 @@ object MRegistry {
.sound(SoundType.METAL) .sound(SoundType.METAL)
.explosionResistance(15f) .explosionResistance(15f)
.destroyTime(1.5f) .destroyTime(1.5f)
} }.also { decorativeBlocks.add(it) }
val TRITANIUM_STAIRS = DecorativeBlock(MNames.TRITANIUM_STAIRS) { val TRITANIUM_STAIRS = DecorativeBlock(MNames.TRITANIUM_STAIRS) {
StairBlock( StairBlock(
{ TRITANIUM_BLOCK.allBlocks[it]!!.defaultBlockState() }, { TRITANIUM_BLOCK.allBlocks[it]!!.defaultBlockState() },
BlockBehaviour.Properties.copy(TRITANIUM_BLOCK.allBlocks[it]!!) BlockBehaviour.Properties.copy(TRITANIUM_BLOCK.allBlocks[it]!!)
) )
} }.also { decorativeBlocks.add(it) }
val TRITANIUM_SLAB = DecorativeBlock(MNames.TRITANIUM_SLAB) { val TRITANIUM_SLAB = DecorativeBlock(MNames.TRITANIUM_SLAB) {
SlabBlock(BlockBehaviour.Properties.copy(TRITANIUM_BLOCK.allBlocks[it]!!)) SlabBlock(BlockBehaviour.Properties.copy(TRITANIUM_BLOCK.allBlocks[it]!!))
} }.also { decorativeBlocks.add(it) }
val TRITANIUM_WALL = DecorativeBlock(MNames.TRITANIUM_WALL) { val TRITANIUM_WALL = DecorativeBlock(MNames.TRITANIUM_WALL) {
WallBlock(BlockBehaviour.Properties.copy(TRITANIUM_BLOCK.allBlocks[it]!!)) WallBlock(BlockBehaviour.Properties.copy(TRITANIUM_BLOCK.allBlocks[it]!!))
} }.also { decorativeBlocks.add(it) }
val TRITANIUM_PRESSURE_PLATE = DecorativeBlock(MNames.TRITANIUM_PRESSURE_PLATE, ::TritaniumPressurePlate) val TRITANIUM_PRESSURE_PLATE = DecorativeBlock(MNames.TRITANIUM_PRESSURE_PLATE, ::TritaniumPressurePlate).also { decorativeBlocks.add(it) }
val VENT = DecorativeBlock.simple(MNames.VENT) { val VENT = DecorativeBlock.simple(MNames.VENT) {
BlockBehaviour.Properties.of() BlockBehaviour.Properties.of()
@ -161,7 +174,7 @@ object MRegistry {
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.explosionResistance(20f) .explosionResistance(20f)
.destroyTime(1.5f) .destroyTime(1.5f)
} }.also { decorativeBlocks.add(it) }
val VENT_ALTERNATIVE = DecorativeBlock.simple(MNames.VENT_ALTERNATIVE) { val VENT_ALTERNATIVE = DecorativeBlock.simple(MNames.VENT_ALTERNATIVE) {
BlockBehaviour.Properties.of() BlockBehaviour.Properties.of()
@ -170,7 +183,7 @@ object MRegistry {
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.explosionResistance(20f) .explosionResistance(20f)
.destroyTime(1.5f) .destroyTime(1.5f)
} }.also { decorativeBlocks.add(it) }
val FLOOR_TILES = ColoredDecorativeBlock.simple(MNames.FLOOR_TILES) { val FLOOR_TILES = ColoredDecorativeBlock.simple(MNames.FLOOR_TILES) {
BlockBehaviour.Properties.of() BlockBehaviour.Properties.of()
@ -178,25 +191,25 @@ object MRegistry {
.sound(SoundType.STONE) .sound(SoundType.STONE)
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.strength(1.5f, 6f) .strength(1.5f, 6f)
} }.also { decorativeBlocks.add(it) }
val FLOOR_TILES_STAIRS = ColoredDecorativeBlock(MNames.FLOOR_TILES_STAIRS) { val FLOOR_TILES_STAIRS = ColoredDecorativeBlock(MNames.FLOOR_TILES_STAIRS) {
StairBlock( StairBlock(
{ FLOOR_TILES.blocks[it]!!.defaultBlockState() }, { FLOOR_TILES.blocks[it]!!.defaultBlockState() },
BlockBehaviour.Properties.copy(FLOOR_TILES.blocks[it]!!) BlockBehaviour.Properties.copy(FLOOR_TILES.blocks[it]!!)
) )
} }.also { decorativeBlocks.add(it) }
val FLOOR_TILES_SLAB = ColoredDecorativeBlock(MNames.FLOOR_TILES_SLAB) { val FLOOR_TILES_SLAB = ColoredDecorativeBlock(MNames.FLOOR_TILES_SLAB) {
SlabBlock(BlockBehaviour.Properties.copy(FLOOR_TILES.blocks[it]!!)) SlabBlock(BlockBehaviour.Properties.copy(FLOOR_TILES.blocks[it]!!))
} }.also { decorativeBlocks.add(it) }
val UNREFINED_FLOOR_TILES = ColoredDecorativeBlock.simple(MNames.UNREFINED_FLOOR_TILES) { val UNREFINED_FLOOR_TILES = ColoredDecorativeBlock.simple(MNames.UNREFINED_FLOOR_TILES) {
BlockBehaviour.Properties.of() BlockBehaviour.Properties.of()
.mapColor(it.mapColor) .mapColor(it.mapColor)
.sound(SoundType.GRAVEL) .sound(SoundType.GRAVEL)
.strength(1f, 2f) .strength(1f, 2f)
} }.also { decorativeBlocks.add(it) }
val INDUSTRIAL_GLASS = DecorativeBlock(MNames.INDUSTRIAL_GLASS) { color -> val INDUSTRIAL_GLASS = DecorativeBlock(MNames.INDUSTRIAL_GLASS) { color ->
val properties = val properties =
@ -218,7 +231,7 @@ object MRegistry {
} }
return@DecorativeBlock GlassBlock(properties) return@DecorativeBlock GlassBlock(properties)
} }.also { decorativeBlocks.add(it) }
val INDUSTRIAL_GLASS_PANE = DecorativeBlock(MNames.INDUSTRIAL_GLASS_PANE) { color -> val INDUSTRIAL_GLASS_PANE = DecorativeBlock(MNames.INDUSTRIAL_GLASS_PANE) { color ->
val properties = val properties =
@ -235,7 +248,7 @@ object MRegistry {
} }
return@DecorativeBlock IronBarsBlock(properties) return@DecorativeBlock IronBarsBlock(properties)
} }.also { decorativeBlocks.add(it) }
val TRITANIUM_STRIPED_BLOCK = StripedColoredDecorativeBlock(MNames.TRITANIUM_STRIPED_BLOCK, { colorA, _ -> val TRITANIUM_STRIPED_BLOCK = StripedColoredDecorativeBlock(MNames.TRITANIUM_STRIPED_BLOCK, { colorA, _ ->
Block(BlockBehaviour.Properties.of() Block(BlockBehaviour.Properties.of()
@ -244,19 +257,19 @@ object MRegistry {
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.explosionResistance(80f) .explosionResistance(80f)
.strength(4f)) .strength(4f))
}) }).also { decorativeBlocks.add(it) }
val TRITANIUM_STRIPED_STAIRS = StripedColoredDecorativeBlock(MNames.TRITANIUM_STRIPED_STAIRS, { colorA, colorB -> val TRITANIUM_STRIPED_STAIRS = StripedColoredDecorativeBlock(MNames.TRITANIUM_STRIPED_STAIRS, { colorA, colorB ->
StairBlock({ TRITANIUM_STRIPED_BLOCK.getBlock(colorA, colorB).defaultBlockState() }, BlockBehaviour.Properties.copy(TRITANIUM_STRIPED_BLOCK.getBlock(colorA, colorB))) StairBlock({ TRITANIUM_STRIPED_BLOCK.getBlock(colorA, colorB).defaultBlockState() }, BlockBehaviour.Properties.copy(TRITANIUM_STRIPED_BLOCK.getBlock(colorA, colorB)))
}) }).also { decorativeBlocks.add(it) }
val TRITANIUM_STRIPED_SLAB = StripedColoredDecorativeBlock(MNames.TRITANIUM_STRIPED_SLAB, { colorA, colorB -> val TRITANIUM_STRIPED_SLAB = StripedColoredDecorativeBlock(MNames.TRITANIUM_STRIPED_SLAB, { colorA, colorB ->
SlabBlock(BlockBehaviour.Properties.copy(TRITANIUM_STRIPED_BLOCK.getBlock(colorA, colorB))) SlabBlock(BlockBehaviour.Properties.copy(TRITANIUM_STRIPED_BLOCK.getBlock(colorA, colorB)))
}) }).also { decorativeBlocks.add(it) }
val TRITANIUM_STRIPED_WALL = StripedColoredDecorativeBlock(MNames.TRITANIUM_STRIPED_WALL, { colorA, colorB -> val TRITANIUM_STRIPED_WALL = StripedColoredDecorativeBlock(MNames.TRITANIUM_STRIPED_WALL, { colorA, colorB ->
WallBlock(BlockBehaviour.Properties.copy(TRITANIUM_STRIPED_BLOCK.getBlock(colorA, colorB))) WallBlock(BlockBehaviour.Properties.copy(TRITANIUM_STRIPED_BLOCK.getBlock(colorA, colorB)))
}) }).also { decorativeBlocks.add(it) }
private fun registerEvent(event: RegisterEvent) { private fun registerEvent(event: RegisterEvent) {
// mojang moment // mojang moment

View File

@ -18,7 +18,7 @@ import java.util.EnumMap
open class ColoredDecorativeBlock( open class ColoredDecorativeBlock(
val baseName: String, val baseName: String,
private val provider: (DyeColor) -> Block, private val provider: (DyeColor) -> Block,
) { ) : IBlockItemRegistryAcceptor {
var registeredItems = false var registeredItems = false
private set private set
@ -60,7 +60,7 @@ open class ColoredDecorativeBlock(
SupplierMap(MRegistry.DYE_ORDER.map { it to itemMap[it]!! }) SupplierMap(MRegistry.DYE_ORDER.map { it to itemMap[it]!! })
} }
open fun registerBlocks(registry: DeferredRegister<Block>) { override fun registerBlocks(registry: DeferredRegister<Block>) {
check(blockMap.isEmpty()) { "( ͡° ͜ʖ ͡°) No. \\(• ε •)/ ( ͠° ل͜ ͡°) ( ͠° ͟ ͟ʖ ͡°) (ง ͠° ͟ل͜ ͡°)ง ( ͡°︺͡°) ('ω')" } check(blockMap.isEmpty()) { "( ͡° ͜ʖ ͡°) No. \\(• ε •)/ ( ͠° ل͜ ͡°) ( ͠° ͟ ͟ʖ ͡°) (ง ͠° ͟ل͜ ͡°)ง ( ͡°︺͡°) ('ω')" }
MRegistry.DYE_ORDER.forEach { MRegistry.DYE_ORDER.forEach {
@ -72,7 +72,7 @@ open class ColoredDecorativeBlock(
private val properties = Item.Properties().stacksTo(64) private val properties = Item.Properties().stacksTo(64)
open fun registerItems(registry: DeferredRegister<Item>) { override fun registerItems(registry: DeferredRegister<Item>) {
check(itemMap.isEmpty()) { "( ͡° ͜ʖ ͡°) No. \\(• ε •)/ ( ͠° ل͜ ͡°) ( ͠° ͟ ͟ʖ ͡°) (ง ͠° ͟ل͜ ͡°)ง ( ͡°︺͡°) ('ω')" } check(itemMap.isEmpty()) { "( ͡° ͜ʖ ͡°) No. \\(• ε •)/ ( ͠° ل͜ ͡°) ( ͠° ͟ ͟ʖ ͡°) (ง ͠° ͟ل͜ ͡°)ง ( ͡°︺͡°) ('ω')" }
check(registeredBlocks) { "wtffffff???????????" } check(registeredBlocks) { "wtffffff???????????" }

View File

@ -0,0 +1,10 @@
package ru.dbotthepony.mc.otm.registry.objects
import net.minecraft.world.item.Item
import net.minecraft.world.level.block.Block
import net.minecraftforge.registries.DeferredRegister
interface IBlockItemRegistryAcceptor {
fun registerItems(registry: DeferredRegister<Item>)
fun registerBlocks(registry: DeferredRegister<Block>)
}

View File

@ -20,7 +20,7 @@ class StripedColoredDecorativeBlock(
val itemFactory: ((colorA: DyeColor, colorB: DyeColor, block: Block) -> Item) = { _, _, block -> val itemFactory: ((colorA: DyeColor, colorB: DyeColor, block: Block) -> Item) = { _, _, block ->
BlockItem(block, Item.Properties().stacksTo(64)) BlockItem(block, Item.Properties().stacksTo(64))
} }
) { ) : IBlockItemRegistryAcceptor {
private val mapBlocks = EnumMap<DyeColor, EnumMap<DyeColor, RegistryObject<Block>>>(DyeColor::class.java) private val mapBlocks = EnumMap<DyeColor, EnumMap<DyeColor, RegistryObject<Block>>>(DyeColor::class.java)
private val mapItems = EnumMap<DyeColor, EnumMap<DyeColor, RegistryObject<Item>>>(DyeColor::class.java) private val mapItems = EnumMap<DyeColor, EnumMap<DyeColor, RegistryObject<Item>>>(DyeColor::class.java)
@ -82,7 +82,7 @@ class StripedColoredDecorativeBlock(
SupplierList(mapBlocks.flatMap { it.value.values }) SupplierList(mapBlocks.flatMap { it.value.values })
} }
fun registerItems(registry: DeferredRegister<Item>) { override fun registerItems(registry: DeferredRegister<Item>) {
for (base in DyeColor.entries) { for (base in DyeColor.entries) {
for (stripe in DyeColor.entries) { for (stripe in DyeColor.entries) {
if (base == stripe) { if (base == stripe) {
@ -97,7 +97,7 @@ class StripedColoredDecorativeBlock(
registeredItems = true registeredItems = true
} }
fun registerBlocks(registry: DeferredRegister<Block>) { override fun registerBlocks(registry: DeferredRegister<Block>) {
for (base in DyeColor.entries) { for (base in DyeColor.entries) {
for (stripe in DyeColor.entries) { for (stripe in DyeColor.entries) {
if (base == stripe) { if (base == stripe) {