Colored machines test, update creative menu order

update SupplierList/Map impl to use Java's suppliers
general code layout improvements
This commit is contained in:
DBotThePony 2024-01-03 18:36:06 +07:00
parent 0ab411fd90
commit cb50ee2c68
Signed by: DBot
GPG Key ID: DCC23B5715498507
48 changed files with 378 additions and 193 deletions

113
machine_colorizer.js Normal file
View File

@ -0,0 +1,113 @@
// Использует Image Magick для автоматической перекраски текстур
const fs = require('fs')
const root_main = './src/main/resources/assets/overdrive_that_matters/textures/block/'
const child_process = require('child_process')
const args = process.argv.slice(2)
if (args.length != 1) {
console.error('Usage: <texture name>')
process.exit(2)
}
const colors = [
['white', [255, 255, 255]],
['orange', [245, 116, 16]],
['magenta', [186, 63, 175]],
['light_blue', [59, 180, 219]],
['yellow', [252, 199, 36]],
['lime', [111, 187, 24]],
['pink', [243, 139, 170]],
['gray', [62, 66, 70]],
['light_gray', [140, 140, 131]],
['cyan', [22, 134, 145]],
['purple', [116, 38, 169]],
['blue', [51, 53, 155]],
['brown', [114, 71, 40]],
['green', [84, 109, 28]],
['red', [156, 37, 34]],
['black', [31, 31, 35]],
]
process.stderr.setMaxListeners(40)
process.stdout.setMaxListeners(40)
async function size(path) {
const identify = child_process.spawn('magick', [
'identify',
path,
])
identify.stderr.pipe(process.stderr)
const chunks = []
identify.stdout.on('data', (a) => chunks.push(a))
await new Promise((resolve) => {
identify.on('close', () => resolve())
})
const chunk = chunks[0].toString('utf-8')
const size = chunk.match(/PNG ([0-9]+)x([0-9]+)/)
const width = parseInt(size[1])
const height = parseInt(size[2])
return [width, height]
}
(async function() {
const textureOverlay = args[0]
const textureColor = textureOverlay + '_mask'
if (!fs.existsSync(`${root_main}${textureOverlay}.png`)) {
process.stderr.write(`${textureOverlay}.png does not exist\n`)
process.exit(1)
}
if (!fs.existsSync(`${root_main}${textureColor}.png`)) {
process.stderr.write(`${textureColor}.png does not exist\n`)
process.exit(1)
}
try {
fs.mkdirSync(`${root_main}/${textureOverlay}`)
} catch(err) {
}
const [widthOverlay, heightOverlay] = await size(`${root_main}${textureOverlay}.png`)
const [width, height] = await size(`${root_main}${textureColor}.png`)
if (widthOverlay != width || heightOverlay != height) {
process.stderr.write(`${textureColor}.png has size of ${width}x${height}, overlay has size of ${widthOverlay}x${heightOverlay}!\n`)
process.exit(3)
}
for (const color of colors) {
const name = color[0]
const rgb = color[1]
const magick = child_process.spawn('magick', [
'convert',
`${root_main}${textureOverlay}.png`,
'(',
`${root_main}${textureColor}.png`,
'-size', `${width}x${height}`,
`xc:rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`,
'-channel', 'rgb',
'-compose', 'Multiply',
'-composite',
')',
'-compose', 'Over',
'-composite',
`${root_main}${textureOverlay}/${name}.png`])
magick.stdout.pipe(process.stdout)
magick.stderr.pipe(process.stderr)
}
})()

View File

@ -36,6 +36,7 @@ import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.datagen.advancements.addAdvancements import ru.dbotthepony.mc.otm.datagen.advancements.addAdvancements
import ru.dbotthepony.mc.otm.datagen.advancements.addAndroidAdvancements import ru.dbotthepony.mc.otm.datagen.advancements.addAndroidAdvancements
import ru.dbotthepony.mc.otm.datagen.advancements.addMachineAdvancements import ru.dbotthepony.mc.otm.datagen.advancements.addMachineAdvancements
import ru.dbotthepony.mc.otm.datagen.blocks.addBlockModels
import ru.dbotthepony.mc.otm.datagen.blocks.addBlockStates import ru.dbotthepony.mc.otm.datagen.blocks.addBlockStates
import ru.dbotthepony.mc.otm.datagen.blocks.addComplexBlockStates import ru.dbotthepony.mc.otm.datagen.blocks.addComplexBlockStates
import ru.dbotthepony.mc.otm.datagen.items.addItemModels import ru.dbotthepony.mc.otm.datagen.items.addItemModels
@ -43,7 +44,6 @@ import ru.dbotthepony.mc.otm.datagen.lang.AddRussianLanguage
import ru.dbotthepony.mc.otm.datagen.lang.MatteryLanguageProvider import ru.dbotthepony.mc.otm.datagen.lang.MatteryLanguageProvider
import ru.dbotthepony.mc.otm.datagen.loot.* import ru.dbotthepony.mc.otm.datagen.loot.*
import ru.dbotthepony.mc.otm.datagen.loot.LootModifiers import ru.dbotthepony.mc.otm.datagen.loot.LootModifiers
import ru.dbotthepony.mc.otm.datagen.models.addBlockModels
import ru.dbotthepony.mc.otm.datagen.recipes.* import ru.dbotthepony.mc.otm.datagen.recipes.*
import ru.dbotthepony.mc.otm.datagen.tags.TagsProvider import ru.dbotthepony.mc.otm.datagen.tags.TagsProvider
import ru.dbotthepony.mc.otm.datagen.tags.addTags import ru.dbotthepony.mc.otm.datagen.tags.addTags

View File

@ -16,15 +16,23 @@ import ru.dbotthepony.mc.otm.triggers.TakeItemOutOfReplicatorTrigger
import java.util.function.Consumer import java.util.function.Consumer
private data class CraftEntry( private data class CraftEntry(
val item: Item, val item: Collection<Item>,
val englishName: String, val englishName: String,
val englishSuffix: String? = null, val englishSuffix: String? = null,
val russianName: String? = null, val russianName: String? = null,
val russianSuffix: String? = null, val russianSuffix: String? = null,
) { ) {
constructor(
item: Item,
englishName: String,
englishSuffix: String? = null,
russianName: String? = null,
russianSuffix: String? = null,
) : this(listOf(item), englishName, englishSuffix, russianName, russianSuffix)
fun make(serializer: Consumer<AdvancementHolder>, parent: AdvancementHolder, translation: MatteryLanguageProvider.MultiBuilder): AdvancementHolder { fun make(serializer: Consumer<AdvancementHolder>, parent: AdvancementHolder, translation: MatteryLanguageProvider.MultiBuilder): AdvancementHolder {
val path = item.registryName!!.path val path = item.first().registryName!!.path
val translated = translation.add("$path.desc", "Craft a %s%s") { val translated = translation.add("$path.desc", "Craft a %s%s") {
russian("Создайте %s%s") russian("Создайте %s%s")
@ -37,15 +45,19 @@ private data class CraftEntry(
return AdvancementBuilder() return AdvancementBuilder()
.parent(parent) .parent(parent)
.display( .display(
itemStack = ItemStack(item), itemStack = ItemStack(item.first()),
title = translation.add(path, englishName) { title = translation.add(path, englishName) {
if (russianName != null) { if (russianName != null) {
russian(russianName) russian(russianName)
} }
}, },
description = TranslatableComponent(translated.contents.key, item.description, translatedSuffix), description = TranslatableComponent(translated.contents.key, item.first().description, translatedSuffix),
) )
.addCriterion("has_machine", criterion(item)) .also {
for ((i, item) in item.withIndex()) {
it.addCriterion(i.toString(), criterion(item))
}
}
.save(serializer, modLocation("machines/$path")) .save(serializer, modLocation("machines/$path"))
} }
} }
@ -171,7 +183,7 @@ fun addMachineAdvancements(serializer: Consumer<AdvancementHolder>, lang: Matter
charger.make(serializer, it, translation) charger.make(serializer, it, translation)
} }
CraftEntry(MItems.COBBLESTONE_GENERATOR, "Cobblestone: Infinity + 1", CraftEntry(MItems.COBBLESTONE_GENERATOR.values, "Cobblestone: Infinity + 1",
russianName = "Булыжник: бесконечность + 1", russianName = "Булыжник: бесконечность + 1",
russianSuffix = "Смотрите, чтоб он не просыпался во все сундуки", russianSuffix = "Смотрите, чтоб он не просыпался во все сундуки",
englishSuffix = "Watch for not to spill it over all your chests").make(serializer, press, translation) englishSuffix = "Watch for not to spill it over all your chests").make(serializer, press, translation)

View File

@ -1,6 +1,6 @@
package ru.dbotthepony.mc.otm.datagen.models package ru.dbotthepony.mc.otm.datagen.blocks
import net.minecraft.resources.ResourceLocation import ru.dbotthepony.mc.otm.datagen.models.MatteryBlockModelProvider
import ru.dbotthepony.mc.otm.registry.MBlocks import ru.dbotthepony.mc.otm.registry.MBlocks
fun addBlockModels(provider: MatteryBlockModelProvider) { fun addBlockModels(provider: MatteryBlockModelProvider) {
@ -9,5 +9,7 @@ fun addBlockModels(provider: MatteryBlockModelProvider) {
resourceCubeAll(MBlocks.TRITANIUM_RAW_BLOCK) resourceCubeAll(MBlocks.TRITANIUM_RAW_BLOCK)
resourceCubeAll(MBlocks.DEEPSLATE_TRITANIUM_ORE) resourceCubeAll(MBlocks.DEEPSLATE_TRITANIUM_ORE)
resourceCubeAll(MBlocks.TRITANIUM_INGOT_BLOCK) resourceCubeAll(MBlocks.TRITANIUM_INGOT_BLOCK)
coloredMachine(MBlocks.COBBLESTONE_GENERATOR, listOf("0", "particle"))
} }
} }

View File

@ -106,7 +106,7 @@ fun addBlockStates(provider: MatteryBlockStateProvider) {
provider.block(MBlocks.MATTER_RECYCLER) provider.block(MBlocks.MATTER_RECYCLER)
provider.block(MBlocks.MATTER_RECONSTRUCTOR) provider.block(MBlocks.MATTER_RECONSTRUCTOR)
provider.block(MBlocks.ENERGY_SERVO) provider.block(MBlocks.ENERGY_SERVO)
provider.block(MBlocks.COBBLESTONE_GENERATOR) provider.block(MBlocks.COBBLESTONE_GENERATOR.values)
provider.block(MBlocks.ESSENCE_STORAGE) provider.block(MBlocks.ESSENCE_STORAGE)
provider.exec { provider.exec {

View File

@ -183,7 +183,7 @@ fun addItemModels(provider: MatteryItemModelProvider) {
provider.block(MItems.TWIN_PLATE_PRESS, "twin_plate_press_idle") provider.block(MItems.TWIN_PLATE_PRESS, "twin_plate_press_idle")
provider.block(MItems.STORAGE_POWER_SUPPLIER, "storage_power_supplier") provider.block(MItems.STORAGE_POWER_SUPPLIER, "storage_power_supplier")
provider.block(MItems.MATTER_RECYCLER, "matter_recycler_working") provider.block(MItems.MATTER_RECYCLER, "matter_recycler_working")
provider.block(MItems.COBBLESTONE_GENERATOR, "cobblestone_generator") provider.allColoredBlock(MItems.COBBLESTONE_GENERATOR, "cobblestone_generator")
provider.block(MItems.STORAGE_BUS) provider.block(MItems.STORAGE_BUS)
provider.block(MItems.STORAGE_IMPORTER) provider.block(MItems.STORAGE_IMPORTER)

View File

@ -4,9 +4,9 @@ import net.minecraft.data.models.ItemModelGenerators
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
import net.minecraft.server.packs.PackType import net.minecraft.server.packs.PackType
import net.minecraft.world.item.ArmorItem import net.minecraft.world.item.ArmorItem
import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.Item import net.minecraft.world.item.Item
import net.minecraftforge.client.model.generators.ItemModelProvider import net.minecraftforge.client.model.generators.ItemModelProvider
import net.minecraftforge.client.model.generators.ModelBuilder
import net.minecraftforge.data.event.GatherDataEvent import net.minecraftforge.data.event.GatherDataEvent
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.core.registryName
@ -30,6 +30,27 @@ class MatteryItemModelProvider(event: GatherDataEvent) : ItemModelProvider(event
fun block(item: Item) = exec { withExistingParent(item.registryName!!.path, modLocation("block/${item.registryName!!.path}")) } fun block(item: Item) = exec { withExistingParent(item.registryName!!.path, modLocation("block/${item.registryName!!.path}")) }
fun block(item: Item, path: String) = exec { withExistingParent(item.registryName!!.path, modLocation("block/$path")) } fun block(item: Item, path: String) = exec { withExistingParent(item.registryName!!.path, modLocation("block/$path")) }
fun allColoredBlock(items: Map<DyeColor?, Item>, path: String) {
block(items[DyeColor.BLACK]!!, path + "_black")
block(items[DyeColor.BLUE]!!, path + "_blue")
block(items[DyeColor.BROWN]!!, path + "_brown")
block(items[DyeColor.CYAN]!!, path + "_cyan")
block(items[DyeColor.GRAY]!!, path + "_gray")
block(items[DyeColor.GREEN]!!, path + "_green")
block(items[DyeColor.LIGHT_BLUE]!!, path + "_light_blue")
block(items[DyeColor.LIGHT_GRAY]!!, path + "_light_gray")
block(items[DyeColor.LIME]!!, path + "_lime")
block(items[DyeColor.MAGENTA]!!, path + "_magenta")
block(items[DyeColor.ORANGE]!!, path + "_orange")
block(items[DyeColor.PINK]!!, path + "_pink")
block(items[DyeColor.PURPLE]!!, path + "_purple")
block(items[DyeColor.RED]!!, path + "_red")
block(items[DyeColor.WHITE]!!, path + "_white")
block(items[DyeColor.YELLOW]!!, path + "_yellow")
block(items[null]!!, path)
}
fun blocks(vararg items: Item) = items.forEach(this::block) fun blocks(vararg items: Item) = items.forEach(this::block)
fun blocks(items: Collection<Item>) = items.forEach(this::block) fun blocks(items: Collection<Item>) = items.forEach(this::block)

View File

@ -424,7 +424,7 @@ private fun blocks(provider: MatteryLanguageProvider) {
add(MBlocks.MATTER_BOTTLER, "Matter Bottler") add(MBlocks.MATTER_BOTTLER, "Matter Bottler")
add(MBlocks.DRIVE_VIEWER, "Drive Viewer") add(MBlocks.DRIVE_VIEWER, "Drive Viewer")
add(MBlocks.BLACK_HOLE, "Local Anomalous Spacetime Dilation Singular Point") add(MBlocks.BLACK_HOLE, "Local Anomalous Spacetime Dilation Singular Point")
add(MBlocks.COBBLESTONE_GENERATOR, "Cobblestone Generator") addBlock(MBlocks.COBBLESTONE_GENERATOR.values, "Cobblestone Generator")
add(MBlocks.INFINITE_WATER_SOURCE, "Infinite Water Source") add(MBlocks.INFINITE_WATER_SOURCE, "Infinite Water Source")
add(MBlocks.ESSENCE_STORAGE, "Essence Storage") add(MBlocks.ESSENCE_STORAGE, "Essence Storage")
add(MBlocks.ESSENCE_STORAGE, "desc", "Allows to store and retrieve experience levels") add(MBlocks.ESSENCE_STORAGE, "desc", "Allows to store and retrieve experience levels")

View File

@ -81,8 +81,10 @@ class MatteryLanguageProvider(private val gen: DataGenerator) {
fun add(key: String, value: String) = slave.add(key, value) fun add(key: String, value: String) = slave.add(key, value)
fun add(key: Block, value: String) = slave.add(key, value) fun add(key: Block, value: String) = slave.add(key, value)
fun addBlock(key: Collection<Block>, value: String) = key.forEach { add(it, value) }
fun add(key: Block, suffix: String, value: String) = slave.add("${key.descriptionId}.${suffix}", value) fun add(key: Block, suffix: String, value: String) = slave.add("${key.descriptionId}.${suffix}", value)
fun add(key: Item, value: String) = slave.add(key, value) fun add(key: Item, value: String) = slave.add(key, value)
fun addItem(key: Collection<Item>, value: String) = key.forEach { add(it, value) }
fun add(key: Item, suffix: String, value: String) = slave.add("${key.descriptionId}.${suffix}", value) fun add(key: Item, suffix: String, value: String) = slave.add("${key.descriptionId}.${suffix}", value)
fun add(key: ItemStack, value: String) = slave.add(key, value) fun add(key: ItemStack, value: String) = slave.add(key, value)
fun add(key: Enchantment, value: String) = slave.add(key, value) fun add(key: Enchantment, value: String) = slave.add(key, value)

View File

@ -426,7 +426,7 @@ private fun blocks(provider: MatteryLanguageProvider) {
add(MBlocks.MATTER_BOTTLER, "Бутилировщик материи") add(MBlocks.MATTER_BOTTLER, "Бутилировщик материи")
add(MBlocks.DRIVE_VIEWER, "Просмотрщик дисков конденсации") add(MBlocks.DRIVE_VIEWER, "Просмотрщик дисков конденсации")
add(MBlocks.BLACK_HOLE, "Локализированная сингулярная точка аномального искажения пространства-времени") add(MBlocks.BLACK_HOLE, "Локализированная сингулярная точка аномального искажения пространства-времени")
add(MBlocks.COBBLESTONE_GENERATOR, "Генератор булыжника") addBlock(MBlocks.COBBLESTONE_GENERATOR.values, "Генератор булыжника")
add(MBlocks.INFINITE_WATER_SOURCE, "Неиссякаемый источник воды") add(MBlocks.INFINITE_WATER_SOURCE, "Неиссякаемый источник воды")
add(MBlocks.ESSENCE_STORAGE, "Хранилище эссенции") add(MBlocks.ESSENCE_STORAGE, "Хранилище эссенции")
add(MBlocks.ESSENCE_STORAGE, "desc", "Позволяет хранить очки опыта") add(MBlocks.ESSENCE_STORAGE, "desc", "Позволяет хранить очки опыта")

View File

@ -141,4 +141,14 @@ class LootTables(generator: DataGenerator) : LootTableProvider(generator.packOut
}) })
} }
} }
fun tile(blocks: Collection<Block>, vararg filterTags: String) {
for (block in blocks) {
singleLootPool(LootContextParamSets.BLOCK, block.lootTable) {
add(LootItem.lootTableItem(block).also {
it.apply(CopyTileNbtFunction(filterTags.stream()))
})
}
}
}
} }

View File

@ -130,7 +130,7 @@ fun addLootTables(lootTables: LootTables) {
lootPool { item(Items.BLACK_DYE) { setCount(64) } } lootPool { item(Items.BLACK_DYE) { setCount(64) } }
} }
lootTables.tile(MBlocks.COBBLESTONE_GENERATOR) lootTables.tile(MBlocks.COBBLESTONE_GENERATOR.values)
lootTables.tile(MBlocks.ESSENCE_STORAGE) lootTables.tile(MBlocks.ESSENCE_STORAGE)
lootTables.tile(MBlocks.MATTER_RECONSTRUCTOR) lootTables.tile(MBlocks.MATTER_RECONSTRUCTOR)
lootTables.tile(MBlocks.FLUID_TANK) lootTables.tile(MBlocks.FLUID_TANK)

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.datagen.models package ru.dbotthepony.mc.otm.datagen.models
import net.minecraft.world.item.DyeColor
import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.Block
import net.minecraftforge.client.model.generators.BlockModelProvider import net.minecraftforge.client.model.generators.BlockModelProvider
import net.minecraftforge.data.event.GatherDataEvent import net.minecraftforge.data.event.GatherDataEvent
@ -96,4 +97,20 @@ class MatteryBlockModelProvider(event: GatherDataEvent) : BlockModelProvider(eve
} }
} }
} }
fun coloredMachine(blocks: Map<DyeColor?, Block>, textureKeys: Collection<String>) {
val base = blocks[null]!!.registryName!!
for ((color, block) in blocks.entries) {
if (color == null) continue
exec {
val model = withExistingParent(block.registryName!!.path, base)
for (key in textureKeys) {
model.texture(key, modLocation("block/${base.path}/${color.name.lowercase()}"))
}
}
}
}
} }

View File

@ -362,7 +362,7 @@ fun addCraftingTableRecipes(consumer: RecipeOutput) {
.build(consumer) .build(consumer)
// генератор коблы // генератор коблы
MatteryRecipe(MItems.COBBLESTONE_GENERATOR, category = machinesCategory) MatteryRecipe(MItems.COBBLESTONE_GENERATOR[null]!!, category = machinesCategory)
.row(MItemTags.HARDENED_GLASS_COLORLESS, MItems.TRITANIUM_PICKAXE, MItemTags.HARDENED_GLASS_COLORLESS) .row(MItemTags.HARDENED_GLASS_COLORLESS, MItems.TRITANIUM_PICKAXE, MItemTags.HARDENED_GLASS_COLORLESS)
.row(Items.LAVA_BUCKET, Items.HOPPER, Items.WATER_BUCKET) .row(Items.LAVA_BUCKET, Items.HOPPER, Items.WATER_BUCKET)
.rowB(Tags.Items.CHESTS) .rowB(Tags.Items.CHESTS)

View File

@ -271,6 +271,8 @@ fun addPainterRecipes(consumer: RecipeOutput) {
generate(consumer, MItems.TRITANIUM_DOOR[null]!!, MItems.TRITANIUM_DOOR) generate(consumer, MItems.TRITANIUM_DOOR[null]!!, MItems.TRITANIUM_DOOR)
generate(consumer, MItems.TRITANIUM_TRAPDOOR[null]!!, MItems.TRITANIUM_TRAPDOOR) generate(consumer, MItems.TRITANIUM_TRAPDOOR[null]!!, MItems.TRITANIUM_TRAPDOOR)
generate(consumer, MItems.COBBLESTONE_GENERATOR[null]!!, MItems.COBBLESTONE_GENERATOR)
generate(consumer, MRegistry.VENT.item, MRegistry.VENT.items) generate(consumer, MRegistry.VENT.item, MRegistry.VENT.items)
generate(consumer, MRegistry.VENT_ALTERNATIVE.item, MRegistry.VENT_ALTERNATIVE.items) generate(consumer, MRegistry.VENT_ALTERNATIVE.item, MRegistry.VENT_ALTERNATIVE.items)
generate(consumer, MItems.CARGO_CRATE_MINECARTS[null]!!, MItems.CARGO_CRATE_MINECARTS) generate(consumer, MItems.CARGO_CRATE_MINECARTS[null]!!, MItems.CARGO_CRATE_MINECARTS)

View File

@ -218,7 +218,7 @@ fun addTags(tagsProvider: TagsProvider) {
MBlocks.ENGINE, MBlocks.ENGINE,
MBlocks.HOLO_SIGN, MBlocks.HOLO_SIGN,
MBlocks.COBBLESTONE_GENERATOR, *MBlocks.COBBLESTONE_GENERATOR.values.toTypedArray(),
MBlocks.ESSENCE_STORAGE, MBlocks.ESSENCE_STORAGE,
MBlocks.MATTER_RECONSTRUCTOR, MBlocks.MATTER_RECONSTRUCTOR,
MBlocks.FLUID_TANK, MBlocks.FLUID_TANK,

View File

@ -47,6 +47,7 @@ abstract class RotatableMatteryBlock(properties: Properties = DEFAULT_PROPERTIES
} }
BlockRotationFreedom.FULL -> TODO("Can't rotate with four rotation freedom yet") BlockRotationFreedom.FULL -> TODO("Can't rotate with four rotation freedom yet")
BlockRotationFreedom.NONE -> defaultBlockState()
} }
} }

View File

@ -1,6 +1,7 @@
package ru.dbotthepony.mc.otm.block.tech package ru.dbotthepony.mc.otm.block.tech
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.world.item.DyeColor
import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.EntityBlock import net.minecraft.world.level.block.EntityBlock
@ -8,6 +9,8 @@ import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntityTicker import net.minecraft.world.level.block.entity.BlockEntityTicker
import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.entity.BlockEntityType
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.material.MapColor
import net.minecraft.world.level.material.PushReaction
import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
@ -16,7 +19,7 @@ import ru.dbotthepony.mc.otm.block.entity.tech.CobblerBlockEntity
import ru.dbotthepony.mc.otm.core.get import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.shapes.BlockShapes import ru.dbotthepony.mc.otm.shapes.BlockShapes
class CobblerBlock : RotatableMatteryBlock(DEFAULT_MACHINE_PROPERTIES), EntityBlock { class CobblerBlock(val color: DyeColor?) : RotatableMatteryBlock(Properties.of().mapColor(color?.mapColor ?: MapColor.METAL).pushReaction(PushReaction.BLOCK).requiresCorrectToolForDrops().destroyTime(1.5f).explosionResistance(25.0f)), EntityBlock {
override fun newBlockEntity(pPos: BlockPos, pState: BlockState): BlockEntity { override fun newBlockEntity(pPos: BlockPos, pState: BlockState): BlockEntity {
return CobblerBlockEntity(pPos, pState) return CobblerBlockEntity(pPos, pState)
} }

View File

@ -64,6 +64,28 @@ fun FriendlyByteBuf.writeBigInteger(value: BigInteger) {
fun FriendlyByteBuf.readBigInteger(byteLimit: Int = 128) = BigInteger(readByteArray(byteLimit)) fun FriendlyByteBuf.readBigInteger(byteLimit: Int = 128) = BigInteger(readByteArray(byteLimit))
fun <V> Map<*, V>.asLambdaSupplierArray(): Array<() -> V> {
val result = arrayOfNulls<() -> V>(size)
var i = 0
for (k in keys) {
result[i++] = { this[k] ?: throw ConcurrentModificationException("Key $k is no longer present in map $this") }
}
return result as Array<() -> V>
}
fun <V> Map<*, V>.asSupplierArray(): Array<Supplier<V>> {
val result = arrayOfNulls<Supplier<V>>(size)
var i = 0
for (k in keys) {
result[i++] = { this[k] ?: throw ConcurrentModificationException("Key $k is no longer present in map $this") }
}
return result as Array<Supplier<V>>
}
operator fun IItemHandler.get(index: Int): ItemStack = getStackInSlot(index) operator fun IItemHandler.get(index: Int): ItemStack = getStackInSlot(index)
operator fun JsonObject.set(s: String, value: JsonElement) = add(s, value) operator fun JsonObject.set(s: String, value: JsonElement) = add(s, value)

View File

@ -4,26 +4,22 @@ import java.util.function.Supplier
import java.util.stream.Stream import java.util.stream.Stream
class SupplierList<T> : AbstractList<T> { class SupplierList<T> : AbstractList<T> {
private val getters: Array<() -> T> private val getters: Array<Supplier<T>>
constructor(vararg getters: () -> T) : super() { constructor(getters: Collection<Supplier<T>>) : super() {
this.getters = Array(getters.size) { getters[it] }
}
constructor(getters: Collection<() -> T>) : super() {
val iterator = getters.iterator() val iterator = getters.iterator()
this.getters = Array(getters.size) { iterator.next() } this.getters = Array(getters.size) { iterator.next() }
} }
constructor(getters: Stream<() -> T>) : super() { constructor(getters: Stream<Supplier<T>>) : super() {
this.getters = getters.toArray(::arrayOfNulls) this.getters = getters.toArray(::arrayOfNulls)
} }
constructor(vararg getters: Supplier<T>) : super() { constructor(vararg getters: Supplier<T>) : super() {
this.getters = Array(getters.size) { getters[it]::get } this.getters = Array(getters.size) { getters[it] }
} }
constructor(size: Int, provider: (Int) -> () -> T) { constructor(size: Int, provider: (Int) -> Supplier<T>) {
this.getters = Array(size, provider) this.getters = Array(size, provider)
} }
@ -31,6 +27,6 @@ class SupplierList<T> : AbstractList<T> {
get() = getters.size get() = getters.size
override fun get(index: Int): T { override fun get(index: Int): T {
return getters[index].invoke() return getters[index].get()
} }
} }

View File

@ -1,20 +1,21 @@
package ru.dbotthepony.mc.otm.core.collect package ru.dbotthepony.mc.otm.core.collect
import com.google.common.collect.ImmutableSet import com.google.common.collect.ImmutableSet
import java.util.function.Supplier
import java.util.stream.Stream import java.util.stream.Stream
class SupplierMap<K, T> : AbstractMap<K, T> { class SupplierMap<K, T> : AbstractMap<K, T> {
override val entries: Set<Map.Entry<K, T>> override val entries: Set<Map.Entry<K, T>>
constructor(vararg mValues: Pair<K, () -> T>) : super() { constructor(vararg mValues: Pair<K, Supplier<T>>) : super() {
entries = ImmutableSet.copyOf(mValues.map { Entry(it.first, it.second) }) entries = ImmutableSet.copyOf(mValues.map { Entry(it.first, it.second) })
} }
constructor(mValues: Collection<Pair<K, () -> T>>) : super() { constructor(mValues: Collection<Pair<K, Supplier<T>>>) : super() {
entries = ImmutableSet.copyOf(mValues.map { Entry(it.first, it.second) }) entries = ImmutableSet.copyOf(mValues.map { Entry(it.first, it.second) })
} }
constructor(mValues: Stream<Pair<K, () -> T>>) : super() { constructor(mValues: Stream<Pair<K, Supplier<T>>>) : super() {
entries = mValues.map { Entry(it.first, it.second) }.collect(ImmutableSet.toImmutableSet()) entries = mValues.map { Entry(it.first, it.second) }.collect(ImmutableSet.toImmutableSet())
} }
@ -24,9 +25,9 @@ class SupplierMap<K, T> : AbstractMap<K, T> {
private inner class Entry( private inner class Entry(
override val key: K, override val key: K,
private val getter: () -> T private val getter: Supplier<T>
) : Map.Entry<K, T> { ) : Map.Entry<K, T> {
override val value: T override val value: T
get() = getter.invoke() get() = getter.get()
} }
} }

View File

@ -1,56 +1,25 @@
package ru.dbotthepony.mc.otm.registry package ru.dbotthepony.mc.otm.registry
import com.mojang.serialization.Lifecycle
import net.minecraft.core.Holder
import net.minecraft.core.Registry
import net.minecraft.core.WritableRegistry
import net.minecraft.resources.ResourceKey
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.DeferredRegister
import net.minecraftforge.registries.RegistryObject import net.minecraftforge.registries.RegistryObject
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.collect.SupplierMap import ru.dbotthepony.mc.otm.core.collect.SupplierMap
import java.util.function.Supplier
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
operator fun <T : Any> RegistryObject<T>.getValue(thisRef: Any, property: KProperty<*>): T { operator fun <T : Any> RegistryObject<T>.getValue(thisRef: Any, property: KProperty<*>): T {
return get() return get()
} }
private fun <T> DeferredRegister<T>.doColored(prefix: String, factory: (color: DyeColor, name: String) -> T): MutableCollection<Pair<DyeColor, () -> T>> { internal fun <T, R : T> DeferredRegister<T>.colored(prefix: String, factory: (color: DyeColor, name: String) -> R): Map<DyeColor, R> {
return mutableListOf( return SupplierMap(MRegistry.DYE_ORDER.map { it to register(prefix + "_" + it.name.lowercase()) { factory.invoke(it, prefix + "_" + it.name.lowercase()) } })
DyeColor.BLACK to register(prefix + "_black") { factory.invoke(DyeColor.BLACK, prefix + "_black") }::get,
DyeColor.BLUE to register(prefix + "_blue") { factory.invoke(DyeColor.BLUE, prefix + "_blue") }::get,
DyeColor.BROWN to register(prefix + "_brown") { factory.invoke(DyeColor.BROWN, prefix + "_brown") }::get,
DyeColor.CYAN to register(prefix + "_cyan") { factory.invoke(DyeColor.CYAN, prefix + "_cyan") }::get,
DyeColor.GRAY to register(prefix + "_gray") { factory.invoke(DyeColor.GRAY, prefix + "_gray") }::get,
DyeColor.GREEN to register(prefix + "_green") { factory.invoke(DyeColor.GREEN, prefix + "_green") }::get,
DyeColor.LIGHT_BLUE to register(prefix + "_light_blue") { factory.invoke(DyeColor.LIGHT_BLUE, prefix + "_light_blue") }::get,
DyeColor.LIGHT_GRAY to register(prefix + "_light_gray") { factory.invoke(DyeColor.LIGHT_GRAY, prefix + "_light_gray") }::get,
DyeColor.LIME to register(prefix + "_lime") { factory.invoke(DyeColor.LIME, prefix + "_lime") }::get,
DyeColor.MAGENTA to register(prefix + "_magenta") { factory.invoke(DyeColor.MAGENTA, prefix + "_magenta") }::get,
DyeColor.ORANGE to register(prefix + "_orange") { factory.invoke(DyeColor.ORANGE, prefix + "_orange") }::get,
DyeColor.PINK to register(prefix + "_pink") { factory.invoke(DyeColor.PINK, prefix + "_pink") }::get,
DyeColor.PURPLE to register(prefix + "_purple") { factory.invoke(DyeColor.PURPLE, prefix + "_purple") }::get,
DyeColor.RED to register(prefix + "_red") { factory.invoke(DyeColor.RED, prefix + "_red") }::get,
DyeColor.WHITE to register(prefix + "_white") { factory.invoke(DyeColor.WHITE, prefix + "_white") }::get,
DyeColor.YELLOW to register(prefix + "_yellow") { factory.invoke(DyeColor.YELLOW, prefix + "_yellow") }::get,
)
} }
internal fun <T> DeferredRegister<T>.colored(prefix: String, factory: (color: DyeColor, name: String) -> T): Map<DyeColor, T> { internal fun <T, R : T> DeferredRegister<T>.coloredWithBase(prefix: String, factory: (color: DyeColor?, name: String) -> R): Map<DyeColor?, R> {
return SupplierMap(doColored(prefix, factory)) val values = ArrayList<Pair<DyeColor?, Supplier<R>>>()
}
@Suppress("unchecked_cast") values.add(null to register(prefix) { factory.invoke(null, prefix) })
internal fun <T> DeferredRegister<T>.allColored(prefix: String, factory: (color: DyeColor?, name: String) -> T): Map<DyeColor?, T> { MRegistry.DYE_ORDER.forEach { values.add(it to register(prefix + "_" + it.name.lowercase()) { factory.invoke(it, prefix + "_" + it.name.lowercase()) }) }
return SupplierMap(doColored(prefix, factory).also { (it as MutableCollection<Pair<DyeColor?, () -> T>>).add((null as DyeColor?) to register(prefix) { factory.invoke(null, prefix) }::get) })
}
internal fun <T> Registry<T>.register(key: String, value: T): Holder<T> { return SupplierMap(values)
return this.register(ResourceLocation(OverdriveThatMatters.MOD_ID, key), value)
}
internal fun <T> Registry<T>.register(key: ResourceLocation, value: T): Holder<T> {
return (this as WritableRegistry<T>).register(ResourceKey.create(key(), key), value, Lifecycle.stable())
} }

View File

@ -12,20 +12,24 @@ object MBlockColors {
private const val DEFAULT_WATER_TINT: Int = 0x3F76E4 private const val DEFAULT_WATER_TINT: Int = 0x3F76E4
private fun registerBlockColors(event: RegisterColorHandlersEvent.Block) { private fun registerBlockColors(event: RegisterColorHandlersEvent.Block) {
event.register({ state: BlockState, light: BlockAndTintGetter?, pos: BlockPos?, index: Int -> for (it in MBlocks.COBBLESTONE_GENERATOR.values) {
if (index == 0) { event.register({ state: BlockState, light: BlockAndTintGetter?, pos: BlockPos?, index: Int ->
if (light == null || pos == null) if (index == 0) {
DEFAULT_WATER_TINT if (light == null || pos == null)
else DEFAULT_WATER_TINT
BiomeColors.getAverageWaterColor(light, pos) else
} else -1 BiomeColors.getAverageWaterColor(light, pos)
}, MBlocks.COBBLESTONE_GENERATOR) } else -1
}, it)
}
} }
private fun registerItemColors(event: RegisterColorHandlersEvent.Item) { private fun registerItemColors(event: RegisterColorHandlersEvent.Item) {
event.register({ stack: ItemStack, index: Int -> for (it in MBlocks.COBBLESTONE_GENERATOR.values) {
if (index == 0) DEFAULT_WATER_TINT else -1 event.register({ stack: ItemStack, index: Int ->
}, MBlocks.COBBLESTONE_GENERATOR) if (index == 0) DEFAULT_WATER_TINT else -1
}, it)
}
} }
internal fun register(bus: IEventBus) { internal fun register(bus: IEventBus) {

View File

@ -31,6 +31,7 @@ import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.tech.PlatePressBlockEntity import ru.dbotthepony.mc.otm.block.entity.tech.PlatePressBlockEntity
import ru.dbotthepony.mc.otm.client.render.blockentity.* import ru.dbotthepony.mc.otm.client.render.blockentity.*
import ru.dbotthepony.mc.otm.config.CablesConfig import ru.dbotthepony.mc.otm.config.CablesConfig
import ru.dbotthepony.mc.otm.core.asSupplierArray
import ru.dbotthepony.mc.otm.core.collect.SupplierMap import ru.dbotthepony.mc.otm.core.collect.SupplierMap
import ru.dbotthepony.mc.otm.core.getValue import ru.dbotthepony.mc.otm.core.getValue
import java.util.function.Supplier import java.util.function.Supplier
@ -56,7 +57,7 @@ object MBlockEntities {
val MATTER_BOTTLER by register(MNames.MATTER_BOTTLER, ::MatterBottlerBlockEntity, MBlocks::MATTER_BOTTLER) val MATTER_BOTTLER by register(MNames.MATTER_BOTTLER, ::MatterBottlerBlockEntity, MBlocks::MATTER_BOTTLER)
val DRIVE_VIEWER by register(MNames.DRIVE_VIEWER, ::DriveViewerBlockEntity, MBlocks::DRIVE_VIEWER) val DRIVE_VIEWER by register(MNames.DRIVE_VIEWER, ::DriveViewerBlockEntity, MBlocks::DRIVE_VIEWER)
val BLACK_HOLE by register(MNames.BLACK_HOLE, ::BlackHoleBlockEntity, MBlocks::BLACK_HOLE) val BLACK_HOLE by register(MNames.BLACK_HOLE, ::BlackHoleBlockEntity, MBlocks::BLACK_HOLE)
val CARGO_CRATE by registry.register(MNames.CARGO_CRATE) { BlockEntityType.Builder.of(::CargoCrateBlockEntity, *MRegistry.CARGO_CRATES.blocks.values.toTypedArray()).build(null) } val CARGO_CRATE by register(MNames.CARGO_CRATE, ::CargoCrateBlockEntity, *MRegistry.CARGO_CRATES.blocks.asSupplierArray())
val DRIVE_RACK by register(MNames.DRIVE_RACK, ::DriveRackBlockEntity, MBlocks::DRIVE_RACK) val DRIVE_RACK by register(MNames.DRIVE_RACK, ::DriveRackBlockEntity, MBlocks::DRIVE_RACK)
val ITEM_MONITOR by register(MNames.ITEM_MONITOR, ::ItemMonitorBlockEntity, MBlocks::ITEM_MONITOR) val ITEM_MONITOR by register(MNames.ITEM_MONITOR, ::ItemMonitorBlockEntity, MBlocks::ITEM_MONITOR)
val ENERGY_COUNTER by register(MNames.ENERGY_COUNTER, ::EnergyCounterBlockEntity, MBlocks::ENERGY_COUNTER) val ENERGY_COUNTER by register(MNames.ENERGY_COUNTER, ::EnergyCounterBlockEntity, MBlocks::ENERGY_COUNTER)
@ -66,7 +67,7 @@ object MBlockEntities {
val GRAVITATION_STABILIZER by register(MNames.GRAVITATION_STABILIZER, ::GravitationStabilizerBlockEntity, MBlocks::GRAVITATION_STABILIZER) val GRAVITATION_STABILIZER by register(MNames.GRAVITATION_STABILIZER, ::GravitationStabilizerBlockEntity, MBlocks::GRAVITATION_STABILIZER)
val MATTER_RECYCLER by register(MNames.MATTER_RECYCLER, ::MatterRecyclerBlockEntity, MBlocks::MATTER_RECYCLER) val MATTER_RECYCLER by register(MNames.MATTER_RECYCLER, ::MatterRecyclerBlockEntity, MBlocks::MATTER_RECYCLER)
val ENERGY_SERVO by register(MNames.ENERGY_SERVO, ::EnergyServoBlockEntity, MBlocks::ENERGY_SERVO) val ENERGY_SERVO by register(MNames.ENERGY_SERVO, ::EnergyServoBlockEntity, MBlocks::ENERGY_SERVO)
val COBBLESTONE_GENERATOR by register(MNames.COBBLESTONE_GENERATOR, ::CobblerBlockEntity, MBlocks::COBBLESTONE_GENERATOR) val COBBLESTONE_GENERATOR by register(MNames.COBBLESTONE_GENERATOR, ::CobblerBlockEntity, *MBlocks.COBBLESTONE_GENERATOR.asSupplierArray())
val ESSENCE_STORAGE by register(MNames.ESSENCE_STORAGE, ::EssenceStorageBlockEntity, MBlocks::ESSENCE_STORAGE) val ESSENCE_STORAGE by register(MNames.ESSENCE_STORAGE, ::EssenceStorageBlockEntity, MBlocks::ESSENCE_STORAGE)
val MATTER_RECONSTRUCTOR by register(MNames.MATTER_RECONSTRUCTOR, ::MatterReconstructorBlockEntity, MBlocks::MATTER_RECONSTRUCTOR) val MATTER_RECONSTRUCTOR by register(MNames.MATTER_RECONSTRUCTOR, ::MatterReconstructorBlockEntity, MBlocks::MATTER_RECONSTRUCTOR)
val FLUID_TANK by register(MNames.FLUID_TANK, ::FluidTankBlockEntity, MBlocks::FLUID_TANK) val FLUID_TANK by register(MNames.FLUID_TANK, ::FluidTankBlockEntity, MBlocks::FLUID_TANK)
@ -81,7 +82,7 @@ object MBlockEntities {
val ENERGY_CABLES: Map<CablesConfig.E, BlockEntityType<*>> = SupplierMap(CablesConfig.E.entries.map { conf -> val ENERGY_CABLES: Map<CablesConfig.E, BlockEntityType<*>> = SupplierMap(CablesConfig.E.entries.map { conf ->
var selfFeed: Supplier<BlockEntityType<*>> = Supplier { TODO() } var selfFeed: Supplier<BlockEntityType<*>> = Supplier { TODO() }
selfFeed = register("${conf.name.lowercase()}_energy_cable", { a, b -> SimpleEnergyCableBlockEntity(selfFeed.get(), a, b, conf) }) as Supplier<BlockEntityType<*>> selfFeed = register("${conf.name.lowercase()}_energy_cable", { a, b -> SimpleEnergyCableBlockEntity(selfFeed.get(), a, b, conf) }) as Supplier<BlockEntityType<*>>
conf to selfFeed::get conf to selfFeed
}) })
val POWERED_FURNACE: BlockEntityType<PoweredFurnaceBlockEntity> by registry.register(MNames.POWERED_FURNACE) { BlockEntityType.Builder.of({ a, b -> MBlocks.POWERED_FURNACE.newBlockEntity(a, b) }, MBlocks.POWERED_FURNACE).build(null) } val POWERED_FURNACE: BlockEntityType<PoweredFurnaceBlockEntity> by registry.register(MNames.POWERED_FURNACE) { BlockEntityType.Builder.of({ a, b -> MBlocks.POWERED_FURNACE.newBlockEntity(a, b) }, MBlocks.POWERED_FURNACE).build(null) }

View File

@ -84,6 +84,7 @@ import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.collect.SupplierList import ru.dbotthepony.mc.otm.core.collect.SupplierList
import ru.dbotthepony.mc.otm.core.collect.SupplierMap import ru.dbotthepony.mc.otm.core.collect.SupplierMap
import ru.dbotthepony.mc.otm.shapes.BlockShapes import ru.dbotthepony.mc.otm.shapes.BlockShapes
import java.util.function.Supplier
object MBlocks { object MBlocks {
private val registry = DeferredRegister.create(ForgeRegistries.BLOCKS, OverdriveThatMatters.MOD_ID) private val registry = DeferredRegister.create(ForgeRegistries.BLOCKS, OverdriveThatMatters.MOD_ID)
@ -112,7 +113,7 @@ object MBlocks {
val POWERED_SMOKER: PoweredFurnaceBlock by registry.register(MNames.POWERED_SMOKER) { PoweredFurnaceBlock(MBlockEntities::POWERED_SMOKER, RecipeType.SMOKING, MRecipes::MICROWAVE, MachinesConfig.POWERED_SMOKER, BlockShapes.POWERED_SMOKER_IDLE) } val POWERED_SMOKER: PoweredFurnaceBlock by registry.register(MNames.POWERED_SMOKER) { PoweredFurnaceBlock(MBlockEntities::POWERED_SMOKER, RecipeType.SMOKING, MRecipes::MICROWAVE, MachinesConfig.POWERED_SMOKER, BlockShapes.POWERED_SMOKER_IDLE) }
val MATTER_RECYCLER: Block by registry.register(MNames.MATTER_RECYCLER) { MatterRecyclerBlock() } val MATTER_RECYCLER: Block by registry.register(MNames.MATTER_RECYCLER) { MatterRecyclerBlock() }
val ENERGY_SERVO: Block by registry.register(MNames.ENERGY_SERVO) { EnergyServoBlock() } val ENERGY_SERVO: Block by registry.register(MNames.ENERGY_SERVO) { EnergyServoBlock() }
val COBBLESTONE_GENERATOR: Block by registry.register(MNames.COBBLESTONE_GENERATOR) { CobblerBlock() } val COBBLESTONE_GENERATOR = registry.coloredWithBase(MNames.COBBLESTONE_GENERATOR) { color, _ -> CobblerBlock(color) }
val INFINITE_WATER_SOURCE: Block by registry.register(MNames.INFINITE_WATER_SOURCE) { InfiniteWaterSourceBlock() } val INFINITE_WATER_SOURCE: Block by registry.register(MNames.INFINITE_WATER_SOURCE) { InfiniteWaterSourceBlock() }
val ESSENCE_STORAGE: EssenceStorageBlock by registry.register(MNames.ESSENCE_STORAGE) { EssenceStorageBlock() } val ESSENCE_STORAGE: EssenceStorageBlock by registry.register(MNames.ESSENCE_STORAGE) { EssenceStorageBlock() }
val MATTER_RECONSTRUCTOR: MatterReconstructorBlock by registry.register(MNames.MATTER_RECONSTRUCTOR) { MatterReconstructorBlock() } val MATTER_RECONSTRUCTOR: MatterReconstructorBlock by registry.register(MNames.MATTER_RECONSTRUCTOR) { MatterReconstructorBlock() }
@ -120,7 +121,7 @@ object MBlocks {
val MATTER_ENTANGLER: MatterEntanglerBlock by registry.register(MNames.MATTER_ENTANGLER) { MatterEntanglerBlock() } val MATTER_ENTANGLER: MatterEntanglerBlock by registry.register(MNames.MATTER_ENTANGLER) { MatterEntanglerBlock() }
val ENERGY_CABLES: Map<CablesConfig.E, EnergyCableBlock> = SupplierMap(CablesConfig.E.entries.map { conf -> val ENERGY_CABLES: Map<CablesConfig.E, EnergyCableBlock> = SupplierMap(CablesConfig.E.entries.map { conf ->
conf to registry.register("${conf.name.lowercase()}_energy_cable") { EnergyCableBlock { a, b -> MBlockEntities.ENERGY_CABLES[conf]!!.create(a, b)!! } }::get conf to registry.register("${conf.name.lowercase()}_energy_cable") { EnergyCableBlock { a, b -> MBlockEntities.ENERGY_CABLES[conf]!!.create(a, b)!! } }
}) })
val STORAGE_BUS: Block by registry.register(MNames.STORAGE_BUS) { StorageBusBlock() } val STORAGE_BUS: Block by registry.register(MNames.STORAGE_BUS) { StorageBusBlock() }
@ -216,7 +217,7 @@ object MBlocks {
val TRITANIUM_ANVIL: List<Block> val TRITANIUM_ANVIL: List<Block>
init { init {
val anvils = ArrayList<() -> Block>() val anvils = ArrayList<Supplier<Block>>()
for (i in 0 until TRITANIUM_ANVIL_VARIANTS) { for (i in 0 until TRITANIUM_ANVIL_VARIANTS) {
val props = BlockBehaviour.Properties.of() val props = BlockBehaviour.Properties.of()
@ -233,7 +234,7 @@ object MBlocks {
TRITANIUM_ANVIL = SupplierList(anvils) TRITANIUM_ANVIL = SupplierList(anvils)
} }
val TRITANIUM_DOOR = registry.allColored(MNames.TRITANIUM_DOOR) { color, _ -> val TRITANIUM_DOOR: Map<DyeColor?, DoorBlock> = registry.coloredWithBase(MNames.TRITANIUM_DOOR) { color, _ ->
object : DoorBlock( object : DoorBlock(
Properties.of() Properties.of()
.mapColor(color ?: DyeColor.LIGHT_BLUE) .mapColor(color ?: DyeColor.LIGHT_BLUE)
@ -270,7 +271,7 @@ object MBlocks {
} }
} }
val TRITANIUM_TRAPDOOR = registry.allColored(MNames.TRITANIUM_TRAPDOOR) { color, _ -> val TRITANIUM_TRAPDOOR: Map<DyeColor?, TrapDoorBlock> = registry.coloredWithBase(MNames.TRITANIUM_TRAPDOOR) { color, _ ->
object : TrapDoorBlock( object : TrapDoorBlock(
Properties.of() Properties.of()
.mapColor(color ?: DyeColor.LIGHT_BLUE) .mapColor(color ?: DyeColor.LIGHT_BLUE)

View File

@ -7,10 +7,8 @@ import net.minecraft.client.renderer.entity.MinecartRenderer
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.MobCategory import net.minecraft.world.entity.MobCategory
import net.minecraft.world.item.DyeColor
import net.minecraftforge.eventbus.api.IEventBus import net.minecraftforge.eventbus.api.IEventBus
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext
import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.DeferredRegister
import net.minecraftforge.registries.ForgeRegistries import net.minecraftforge.registries.ForgeRegistries
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
@ -25,7 +23,7 @@ object MEntityTypes {
EntityType.Builder.of<PlasmaProjectile>({ _, level -> PlasmaProjectile(level) }, MobCategory.MISC).sized(0.4f, 0.4f).build(MNames.PLASMA) EntityType.Builder.of<PlasmaProjectile>({ _, level -> PlasmaProjectile(level) }, MobCategory.MISC).sized(0.4f, 0.4f).build(MNames.PLASMA)
} }
val CARGO_CRATE_MINECARTS = registry.allColored(MNames.MINECART_CARGO_CRATE) { color, name -> val CARGO_CRATE_MINECARTS = registry.coloredWithBase(MNames.MINECART_CARGO_CRATE) { color, name ->
EntityType.Builder.of<MinecartCargoCrate>({ it, level -> MinecartCargoCrate(it, color, level)}, MobCategory.MISC).sized(0.98F, 0.7F).clientTrackingRange(8).build(name) EntityType.Builder.of<MinecartCargoCrate>({ it, level -> MinecartCargoCrate(it, color, level)}, MobCategory.MISC).sized(0.98F, 0.7F).clientTrackingRange(8).build(name)
} }

View File

@ -21,6 +21,9 @@ import ru.dbotthepony.mc.otm.config.CablesConfig
import ru.dbotthepony.mc.otm.config.ItemsConfig import ru.dbotthepony.mc.otm.config.ItemsConfig
import ru.dbotthepony.mc.otm.core.collect.SupplierList import ru.dbotthepony.mc.otm.core.collect.SupplierList
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.addAll
import ru.dbotthepony.mc.otm.core.asLambdaSupplierArray
import ru.dbotthepony.mc.otm.core.asSupplierArray
import ru.dbotthepony.mc.otm.core.collect.SupplierMap import ru.dbotthepony.mc.otm.core.collect.SupplierMap
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.item.* import ru.dbotthepony.mc.otm.item.*
@ -39,6 +42,7 @@ import ru.dbotthepony.mc.otm.item.armor.TritaniumArmorItem
import ru.dbotthepony.mc.otm.item.exopack.ExopackUpgradeItem import ru.dbotthepony.mc.otm.item.exopack.ExopackUpgradeItem
import ru.dbotthepony.mc.otm.item.exopack.ProceduralExopackSlotUpgradeItem import ru.dbotthepony.mc.otm.item.exopack.ProceduralExopackSlotUpgradeItem
import ru.dbotthepony.mc.otm.item.weapon.PlasmaRifleItem import ru.dbotthepony.mc.otm.item.weapon.PlasmaRifleItem
import java.util.function.Supplier
object MItems { object MItems {
private val DEFAULT_PROPERTIES = Item.Properties() private val DEFAULT_PROPERTIES = Item.Properties()
@ -49,7 +53,7 @@ object MItems {
} }
val ENERGY_CABLES: Map<CablesConfig.E, BlockItem> = SupplierMap(CablesConfig.E.entries.map { conf -> val ENERGY_CABLES: Map<CablesConfig.E, BlockItem> = SupplierMap(CablesConfig.E.entries.map { conf ->
conf to registry.register("${conf.name.lowercase()}_energy_cable") { BlockItem(MBlocks.ENERGY_CABLES[conf]!!, DEFAULT_PROPERTIES) }::get conf to registry.register("${conf.name.lowercase()}_energy_cable") { BlockItem(MBlocks.ENERGY_CABLES[conf]!!, DEFAULT_PROPERTIES) }
}) })
val ANDROID_STATION: BlockItem by registry.register(MNames.ANDROID_STATION) { BlockItem(MBlocks.ANDROID_STATION, DEFAULT_PROPERTIES) } val ANDROID_STATION: BlockItem by registry.register(MNames.ANDROID_STATION) { BlockItem(MBlocks.ANDROID_STATION, DEFAULT_PROPERTIES) }
@ -120,8 +124,8 @@ object MItems {
} }
} }
val COBBLESTONE_GENERATOR: BlockItem by registry.register(MNames.COBBLESTONE_GENERATOR) { val COBBLESTONE_GENERATOR: Map<DyeColor?, BlockItem> = registry.coloredWithBase(MNames.COBBLESTONE_GENERATOR) { color, name ->
object : BlockItem(MBlocks.COBBLESTONE_GENERATOR, DEFAULT_PROPERTIES) { object : BlockItem(MBlocks.COBBLESTONE_GENERATOR[color]!!, DEFAULT_PROPERTIES) {
override fun appendHoverText(p_40572_: ItemStack, p_40573_: Level?, p_40574_: MutableList<Component>, p_40575_: TooltipFlag) { override fun appendHoverText(p_40572_: ItemStack, p_40573_: Level?, p_40574_: MutableList<Component>, p_40575_: TooltipFlag) {
super.appendHoverText(p_40572_, p_40573_, p_40574_, p_40575_) super.appendHoverText(p_40572_, p_40573_, p_40574_, p_40575_)
p_40574_.add(TranslatableComponent("otm.needs_no_power").withStyle(ChatFormatting.GRAY)) p_40574_.add(TranslatableComponent("otm.needs_no_power").withStyle(ChatFormatting.GRAY))
@ -161,17 +165,49 @@ object MItems {
val PAINTER: BlockItem by registry.register(MNames.PAINTER) { BlockItem(MBlocks.PAINTER, DEFAULT_PROPERTIES) } val PAINTER: BlockItem by registry.register(MNames.PAINTER) { BlockItem(MBlocks.PAINTER, DEFAULT_PROPERTIES) }
val MATTER_ENTANGLER: BlockItem by registry.register(MNames.MATTER_ENTANGLER) { BlockItem(MBlocks.MATTER_ENTANGLER, DEFAULT_PROPERTIES) } val MATTER_ENTANGLER: BlockItem by registry.register(MNames.MATTER_ENTANGLER) { BlockItem(MBlocks.MATTER_ENTANGLER, DEFAULT_PROPERTIES) }
val MACHINES = SupplierList( val MACHINES: List<BlockItem>
::ANDROID_STATION, ::ANDROID_CHARGER, ::BATTERY_BANK, ::MATTER_DECOMPOSER, ::MATTER_CAPACITOR_BANK, ::MATTER_CABLE, ::PATTERN_STORAGE,
::MATTER_SCANNER, ::MATTER_PANEL, ::MATTER_REPLICATOR, ::MATTER_BOTTLER, ::MATTER_ENTANGLER, ::ENERGY_COUNTER, ::CHEMICAL_GENERATOR, init {
::MATTER_RECYCLER, ::PLATE_PRESS, ::TWIN_PLATE_PRESS, ::POWERED_FURNACE, ::POWERED_BLAST_FURNACE, val machines = ArrayList<Supplier<BlockItem>>()
::POWERED_SMOKER,
::STORAGE_BUS, ::STORAGE_IMPORTER, ::STORAGE_EXPORTER, ::DRIVE_VIEWER, machines.add(::PLATE_PRESS)
::DRIVE_RACK, ::ITEM_MONITOR, ::STORAGE_CABLE, ::STORAGE_POWER_SUPPLIER, machines.add(::TWIN_PLATE_PRESS)
::ENERGY_SERVO, ::PAINTER, machines.add(::POWERED_FURNACE)
::PHANTOM_ATTRACTOR, ::GRAVITATION_STABILIZER, ::COBBLESTONE_GENERATOR, ::INFINITE_WATER_SOURCE, machines.add(::POWERED_BLAST_FURNACE)
::ESSENCE_STORAGE, ::MATTER_RECONSTRUCTOR machines.add(::POWERED_SMOKER)
)
machines.add(::ANDROID_STATION)
machines.add(::ANDROID_CHARGER)
machines.add(::BATTERY_BANK)
machines.add(::ENERGY_COUNTER)
machines.add(::CHEMICAL_GENERATOR)
machines.add(::ENERGY_SERVO)
machines.add(::PAINTER)
machines.addAll(COBBLESTONE_GENERATOR.asSupplierArray().iterator())
machines.add(::MATTER_DECOMPOSER)
machines.add(::MATTER_CAPACITOR_BANK)
machines.add(::MATTER_CABLE)
machines.add(::PATTERN_STORAGE)
machines.add(::MATTER_SCANNER)
machines.add(::MATTER_PANEL)
machines.add(::MATTER_REPLICATOR)
machines.add(::MATTER_BOTTLER)
machines.add(::MATTER_ENTANGLER)
machines.add(::MATTER_RECYCLER)
machines.add(::STORAGE_BUS)
machines.add(::STORAGE_IMPORTER)
machines.add(::STORAGE_EXPORTER)
machines.add(::DRIVE_VIEWER)
machines.add(::DRIVE_RACK)
machines.add(::ITEM_MONITOR)
machines.add(::STORAGE_CABLE)
machines.add(::STORAGE_POWER_SUPPLIER)
MACHINES = SupplierList(machines)
}
val DEBUG_EXPLOSION_SMALL: Item by registry.register(MNames.DEBUG_EXPLOSION_SMALL) { BlockItem(MBlocks.DEBUG_EXPLOSION_SMALL, Item.Properties().stacksTo(64)) } val DEBUG_EXPLOSION_SMALL: Item by registry.register(MNames.DEBUG_EXPLOSION_SMALL) { BlockItem(MBlocks.DEBUG_EXPLOSION_SMALL, Item.Properties().stacksTo(64)) }
val DEBUG_SPHERE_POINTS: Item by registry.register(MNames.DEBUG_SPHERE_POINTS) { BlockItem(MBlocks.DEBUG_SPHERE_POINTS, Item.Properties().stacksTo(64)) } val DEBUG_SPHERE_POINTS: Item by registry.register(MNames.DEBUG_SPHERE_POINTS) { BlockItem(MBlocks.DEBUG_SPHERE_POINTS, Item.Properties().stacksTo(64)) }
@ -179,7 +215,7 @@ object MItems {
val TRITANIUM_ANVIL: List<BlockItem> val TRITANIUM_ANVIL: List<BlockItem>
init { init {
val props = ArrayList<() -> BlockItem>() val props = ArrayList<Supplier<BlockItem>>()
for (i in MBlocks.TRITANIUM_ANVIL.indices) { for (i in MBlocks.TRITANIUM_ANVIL.indices) {
props.add(registry.register(MNames.TRITANIUM_ANVIL + i) { BlockItem(MBlocks.TRITANIUM_ANVIL[i], DEFAULT_PROPERTIES) }::get) props.add(registry.register(MNames.TRITANIUM_ANVIL + i) { BlockItem(MBlocks.TRITANIUM_ANVIL[i], DEFAULT_PROPERTIES) }::get)
@ -475,8 +511,8 @@ object MItems {
val ENGINE: Item by registry.register(MNames.ENGINE) { BlockItem(MBlocks.ENGINE, DEFAULT_PROPERTIES) } val ENGINE: Item by registry.register(MNames.ENGINE) { BlockItem(MBlocks.ENGINE, DEFAULT_PROPERTIES) }
val HOLO_SIGN: Item by registry.register(MNames.HOLO_SIGN) { BlockItem(MBlocks.HOLO_SIGN, DEFAULT_PROPERTIES) } val HOLO_SIGN: Item by registry.register(MNames.HOLO_SIGN) { BlockItem(MBlocks.HOLO_SIGN, DEFAULT_PROPERTIES) }
val TRITANIUM_DOOR = registry.allColored(MNames.TRITANIUM_DOOR) { color, _ -> DoubleHighBlockItem(MBlocks.TRITANIUM_DOOR[color]!!, DEFAULT_PROPERTIES) } val TRITANIUM_DOOR = registry.coloredWithBase(MNames.TRITANIUM_DOOR) { color, _ -> DoubleHighBlockItem(MBlocks.TRITANIUM_DOOR[color]!!, DEFAULT_PROPERTIES) }
val TRITANIUM_TRAPDOOR = registry.allColored(MNames.TRITANIUM_TRAPDOOR) { color, _ -> BlockItem(MBlocks.TRITANIUM_TRAPDOOR[color]!!, DEFAULT_PROPERTIES) } val TRITANIUM_TRAPDOOR = registry.coloredWithBase(MNames.TRITANIUM_TRAPDOOR) { color, _ -> BlockItem(MBlocks.TRITANIUM_TRAPDOOR[color]!!, DEFAULT_PROPERTIES) }
init { init {
MRegistry.TRITANIUM_PRESSURE_PLATE.registerItems(registry) MRegistry.TRITANIUM_PRESSURE_PLATE.registerItems(registry)
@ -590,7 +626,7 @@ object MItems {
::REINFORCED_TRITANIUM_PLATE, ::REINFORCED_TRITANIUM_PLATE,
) )
val CARGO_CRATE_MINECARTS = registry.allColored(MNames.MINECART_CARGO_CRATE) { color, _ -> MinecartCargoCrateItem(color) } val CARGO_CRATE_MINECARTS = registry.coloredWithBase(MNames.MINECART_CARGO_CRATE) { color, _ -> MinecartCargoCrateItem(color) }
val EXOPACK_PROBE: Item by registry.register(MNames.EXOPACK_PROBE, ::ExopackProbeItem) val EXOPACK_PROBE: Item by registry.register(MNames.EXOPACK_PROBE, ::ExopackProbeItem)
@ -601,7 +637,7 @@ object MItems {
val ENDER_UPGRADE: ExopackUpgradeItem by registry.register("exopack_ender_upgrade") { ExopackUpgradeItem(MatteryPlayerCapability.UpgradeType.ENDER_ACCESS, "ender_access_upgrade", "ender_access_installed") } val ENDER_UPGRADE: ExopackUpgradeItem by registry.register("exopack_ender_upgrade") { ExopackUpgradeItem(MatteryPlayerCapability.UpgradeType.ENDER_ACCESS, "ender_access_upgrade", "ender_access_installed") }
val INVENTORY_UPGRADES = SupplierList(8) { val INVENTORY_UPGRADES = SupplierList(8) {
registry.register("exosuit_inventory_upgrade_$it") { ExopackSlotUpgradeItem(18, Rarity.COMMON) }::get registry.register("exosuit_inventory_upgrade_$it") { ExopackSlotUpgradeItem(18, Rarity.COMMON) }
} }
val INVENTORY_UPGRADE_PROCEDURAL: ProceduralExopackSlotUpgradeItem by registry.register("exosuit_inventory_upgrade_procedural") { ProceduralExopackSlotUpgradeItem() } val INVENTORY_UPGRADE_PROCEDURAL: ProceduralExopackSlotUpgradeItem by registry.register("exosuit_inventory_upgrade_procedural") { ProceduralExopackSlotUpgradeItem() }

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.registry package ru.dbotthepony.mc.otm.registry
import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableSet import com.google.common.collect.ImmutableSet
import com.google.common.collect.Streams import com.google.common.collect.Streams
import net.minecraft.advancements.CriteriaTriggers import net.minecraft.advancements.CriteriaTriggers
@ -11,6 +12,7 @@ import net.minecraft.resources.ResourceLocation
import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.ai.village.poi.PoiType 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.DyeableArmorItem import net.minecraft.world.item.DyeableArmorItem
import net.minecraft.world.item.Items import net.minecraft.world.item.Items
import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.BlockGetter
@ -81,6 +83,25 @@ object MRegistry {
val ANDROID_FEATURES_LOCATION get() = features.location val ANDROID_FEATURES_LOCATION get() = features.location
val ANDROID_FEATURES_KEY get() = features.key val ANDROID_FEATURES_KEY get() = features.key
val DYE_ORDER: ImmutableList<DyeColor> = ImmutableList.of(
DyeColor.BLACK,
DyeColor.BLUE,
DyeColor.BROWN,
DyeColor.CYAN,
DyeColor.GRAY,
DyeColor.GREEN,
DyeColor.LIGHT_BLUE,
DyeColor.LIGHT_GRAY,
DyeColor.LIME,
DyeColor.MAGENTA,
DyeColor.ORANGE,
DyeColor.PINK,
DyeColor.PURPLE,
DyeColor.RED,
DyeColor.WHITE,
DyeColor.YELLOW,
)
private fun register(event: NewRegistryEvent) { private fun register(event: NewRegistryEvent) {
features.build(event) features.build(event)
} }

View File

@ -8,12 +8,13 @@ import net.minecraft.world.level.block.state.BlockBehaviour
import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.DeferredRegister
import net.minecraftforge.registries.RegistryObject import net.minecraftforge.registries.RegistryObject
import ru.dbotthepony.mc.otm.core.collect.SupplierMap import ru.dbotthepony.mc.otm.core.collect.SupplierMap
import ru.dbotthepony.mc.otm.registry.MRegistry
import java.util.EnumMap import java.util.EnumMap
/** /**
* Colored only * Colored only
*/ */
@Suppress("PropertyName", "unused") @Suppress("unused")
open class ColoredDecorativeBlock( open class ColoredDecorativeBlock(
val baseName: String, val baseName: String,
private val provider: (DyeColor) -> Block, private val provider: (DyeColor) -> Block,
@ -28,41 +29,15 @@ open class ColoredDecorativeBlock(
protected val blockMap = EnumMap<DyeColor, RegistryObject<Block>>(DyeColor::class.java) protected val blockMap = EnumMap<DyeColor, RegistryObject<Block>>(DyeColor::class.java)
fun forEachItem(consumer: (String, DyeColor, Item) -> Unit) { fun forEachItem(consumer: (String, DyeColor, Item) -> Unit) {
consumer.invoke("black", DyeColor.BLACK, getItem(DyeColor.BLACK)) MRegistry.DYE_ORDER.forEach {
consumer.invoke("blue", DyeColor.BLUE, getItem(DyeColor.BLUE)) consumer.invoke(it.name.lowercase(), it, getItem(it))
consumer.invoke("brown", DyeColor.BROWN, getItem(DyeColor.BROWN)) }
consumer.invoke("cyan", DyeColor.CYAN, getItem(DyeColor.CYAN))
consumer.invoke("gray", DyeColor.GRAY, getItem(DyeColor.GRAY))
consumer.invoke("green", DyeColor.GREEN, getItem(DyeColor.GREEN))
consumer.invoke("light_blue", DyeColor.LIGHT_BLUE, getItem(DyeColor.LIGHT_BLUE))
consumer.invoke("light_gray", DyeColor.LIGHT_GRAY, getItem(DyeColor.LIGHT_GRAY))
consumer.invoke("lime", DyeColor.LIME, getItem(DyeColor.LIME))
consumer.invoke("magenta", DyeColor.MAGENTA, getItem(DyeColor.MAGENTA))
consumer.invoke("orange", DyeColor.ORANGE, getItem(DyeColor.ORANGE))
consumer.invoke("pink", DyeColor.PINK, getItem(DyeColor.PINK))
consumer.invoke("purple", DyeColor.PURPLE, getItem(DyeColor.PURPLE))
consumer.invoke("red", DyeColor.RED, getItem(DyeColor.RED))
consumer.invoke("white", DyeColor.WHITE, getItem(DyeColor.WHITE))
consumer.invoke("yellow", DyeColor.YELLOW, getItem(DyeColor.YELLOW))
} }
fun forEachBlock(consumer: (String, DyeColor, Block) -> Unit) { fun forEachBlock(consumer: (String, DyeColor, Block) -> Unit) {
consumer.invoke("black", DyeColor.BLACK, getBlock(DyeColor.BLACK)) MRegistry.DYE_ORDER.forEach {
consumer.invoke("blue", DyeColor.BLUE, getBlock(DyeColor.BLUE)) consumer.invoke(it.name.lowercase(), it, getBlock(it))
consumer.invoke("brown", DyeColor.BROWN, getBlock(DyeColor.BROWN)) }
consumer.invoke("cyan", DyeColor.CYAN, getBlock(DyeColor.CYAN))
consumer.invoke("gray", DyeColor.GRAY, getBlock(DyeColor.GRAY))
consumer.invoke("green", DyeColor.GREEN, getBlock(DyeColor.GREEN))
consumer.invoke("light_blue", DyeColor.LIGHT_BLUE, getBlock(DyeColor.LIGHT_BLUE))
consumer.invoke("light_gray", DyeColor.LIGHT_GRAY, getBlock(DyeColor.LIGHT_GRAY))
consumer.invoke("lime", DyeColor.LIME, getBlock(DyeColor.LIME))
consumer.invoke("magenta", DyeColor.MAGENTA, getBlock(DyeColor.MAGENTA))
consumer.invoke("orange", DyeColor.ORANGE, getBlock(DyeColor.ORANGE))
consumer.invoke("pink", DyeColor.PINK, getBlock(DyeColor.PINK))
consumer.invoke("purple", DyeColor.PURPLE, getBlock(DyeColor.PURPLE))
consumer.invoke("red", DyeColor.RED, getBlock(DyeColor.RED))
consumer.invoke("white", DyeColor.WHITE, getBlock(DyeColor.WHITE))
consumer.invoke("yellow", DyeColor.YELLOW, getBlock(DyeColor.YELLOW))
} }
fun getItem(dyeColor: DyeColor): Item { fun getItem(dyeColor: DyeColor): Item {
@ -77,33 +52,20 @@ open class ColoredDecorativeBlock(
val blocks: Map<DyeColor, Block> by lazy { val blocks: Map<DyeColor, Block> by lazy {
check(registeredBlocks) { "Didn't register blocks yet" } check(registeredBlocks) { "Didn't register blocks yet" }
SupplierMap(blockMap.map { it.key to it.value::get }) SupplierMap(MRegistry.DYE_ORDER.map { it to blockMap[it]!! })
} }
val items: Map<DyeColor, Item> by lazy { val items: Map<DyeColor, Item> by lazy {
check(registeredItems) { "Didn't register items yet" } check(registeredItems) { "Didn't register items yet" }
SupplierMap(itemMap.map { it.key to it.value::get }) SupplierMap(MRegistry.DYE_ORDER.map { it to itemMap[it]!! })
} }
open fun registerBlocks(registry: DeferredRegister<Block>) { open fun registerBlocks(registry: DeferredRegister<Block>) {
check(blockMap.isEmpty()) { "( ͡° ͜ʖ ͡°) No. \\(• ε •)/ ( ͠° ل͜ ͡°) ( ͠° ͟ ͟ʖ ͡°) (ง ͠° ͟ل͜ ͡°)ง ( ͡°︺͡°) ('ω')" } check(blockMap.isEmpty()) { "( ͡° ͜ʖ ͡°) No. \\(• ε •)/ ( ͠° ل͜ ͡°) ( ͠° ͟ ͟ʖ ͡°) (ง ͠° ͟ل͜ ͡°)ง ( ͡°︺͡°) ('ω')" }
blockMap[DyeColor.WHITE] = registry.register("${baseName}_white") { provider.invoke(DyeColor.WHITE) } MRegistry.DYE_ORDER.forEach {
blockMap[DyeColor.ORANGE] = registry.register("${baseName}_orange") { provider.invoke(DyeColor.ORANGE) } blockMap[it] = registry.register("${baseName}_${it.name.lowercase()}") { provider.invoke(it) }
blockMap[DyeColor.MAGENTA] = registry.register("${baseName}_magenta") { provider.invoke(DyeColor.MAGENTA) } }
blockMap[DyeColor.LIGHT_BLUE] = registry.register("${baseName}_light_blue") { provider.invoke(DyeColor.LIGHT_BLUE) }
blockMap[DyeColor.YELLOW] = registry.register("${baseName}_yellow") { provider.invoke(DyeColor.YELLOW) }
blockMap[DyeColor.LIME] = registry.register("${baseName}_lime") { provider.invoke(DyeColor.LIME) }
blockMap[DyeColor.PINK] = registry.register("${baseName}_pink") { provider.invoke(DyeColor.PINK) }
blockMap[DyeColor.GRAY] = registry.register("${baseName}_gray") { provider.invoke(DyeColor.GRAY) }
blockMap[DyeColor.LIGHT_GRAY] = registry.register("${baseName}_light_gray") { provider.invoke(DyeColor.LIGHT_GRAY) }
blockMap[DyeColor.CYAN] = registry.register("${baseName}_cyan") { provider.invoke(DyeColor.CYAN) }
blockMap[DyeColor.PURPLE] = registry.register("${baseName}_purple") { provider.invoke(DyeColor.PURPLE) }
blockMap[DyeColor.BLUE] = registry.register("${baseName}_blue") { provider.invoke(DyeColor.BLUE) }
blockMap[DyeColor.BROWN] = registry.register("${baseName}_brown") { provider.invoke(DyeColor.BROWN) }
blockMap[DyeColor.GREEN] = registry.register("${baseName}_green") { provider.invoke(DyeColor.GREEN) }
blockMap[DyeColor.RED] = registry.register("${baseName}_red") { provider.invoke(DyeColor.RED) }
blockMap[DyeColor.BLACK] = registry.register("${baseName}_black") { provider.invoke(DyeColor.BLACK) }
registeredBlocks = true registeredBlocks = true
} }
@ -114,22 +76,9 @@ open class ColoredDecorativeBlock(
check(itemMap.isEmpty()) { "( ͡° ͜ʖ ͡°) No. \\(• ε •)/ ( ͠° ل͜ ͡°) ( ͠° ͟ ͟ʖ ͡°) (ง ͠° ͟ل͜ ͡°)ง ( ͡°︺͡°) ('ω')" } check(itemMap.isEmpty()) { "( ͡° ͜ʖ ͡°) No. \\(• ε •)/ ( ͠° ل͜ ͡°) ( ͠° ͟ ͟ʖ ͡°) (ง ͠° ͟ل͜ ͡°)ง ( ͡°︺͡°) ('ω')" }
check(registeredBlocks) { "wtffffff???????????" } check(registeredBlocks) { "wtffffff???????????" }
itemMap[DyeColor.WHITE] = registry.register("${baseName}_white") { BlockItem(blockMap[DyeColor.WHITE]!!.get(), properties) } MRegistry.DYE_ORDER.forEach {
itemMap[DyeColor.ORANGE] = registry.register("${baseName}_orange") { BlockItem(blockMap[DyeColor.ORANGE]!!.get(), properties) } itemMap[it] = registry.register("${baseName}_${it.name.lowercase()}") { BlockItem(blockMap[DyeColor.WHITE]!!.get(), properties) }
itemMap[DyeColor.MAGENTA] = registry.register("${baseName}_magenta") { BlockItem(blockMap[DyeColor.MAGENTA]!!.get(), properties) } }
itemMap[DyeColor.LIGHT_BLUE] = registry.register("${baseName}_light_blue") { BlockItem(blockMap[DyeColor.LIGHT_BLUE]!!.get(), properties) }
itemMap[DyeColor.YELLOW] = registry.register("${baseName}_yellow") { BlockItem(blockMap[DyeColor.YELLOW]!!.get(), properties) }
itemMap[DyeColor.LIME] = registry.register("${baseName}_lime") { BlockItem(blockMap[DyeColor.LIME]!!.get(), properties) }
itemMap[DyeColor.PINK] = registry.register("${baseName}_pink") { BlockItem(blockMap[DyeColor.PINK]!!.get(), properties) }
itemMap[DyeColor.GRAY] = registry.register("${baseName}_gray") { BlockItem(blockMap[DyeColor.GRAY]!!.get(), properties) }
itemMap[DyeColor.LIGHT_GRAY] = registry.register("${baseName}_light_gray") { BlockItem(blockMap[DyeColor.LIGHT_GRAY]!!.get(), properties) }
itemMap[DyeColor.CYAN] = registry.register("${baseName}_cyan") { BlockItem(blockMap[DyeColor.CYAN]!!.get(), properties) }
itemMap[DyeColor.PURPLE] = registry.register("${baseName}_purple") { BlockItem(blockMap[DyeColor.PURPLE]!!.get(), properties) }
itemMap[DyeColor.BLUE] = registry.register("${baseName}_blue") { BlockItem(blockMap[DyeColor.BLUE]!!.get(), properties) }
itemMap[DyeColor.BROWN] = registry.register("${baseName}_brown") { BlockItem(blockMap[DyeColor.BROWN]!!.get(), properties) }
itemMap[DyeColor.GREEN] = registry.register("${baseName}_green") { BlockItem(blockMap[DyeColor.GREEN]!!.get(), properties) }
itemMap[DyeColor.RED] = registry.register("${baseName}_red") { BlockItem(blockMap[DyeColor.RED]!!.get(), properties) }
itemMap[DyeColor.BLACK] = registry.register("${baseName}_black") { BlockItem(blockMap[DyeColor.BLACK]!!.get(), properties) }
registeredItems = true registeredItems = true
} }

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.registry.objects package ru.dbotthepony.mc.otm.registry.objects
import com.google.common.collect.Streams
import net.minecraft.world.item.BlockItem import net.minecraft.world.item.BlockItem
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.Item import net.minecraft.world.item.Item
@ -9,6 +10,8 @@ import net.minecraftforge.registries.DeferredRegister
import net.minecraftforge.registries.RegistryObject import net.minecraftforge.registries.RegistryObject
import ru.dbotthepony.mc.otm.core.collect.SupplierMap import ru.dbotthepony.mc.otm.core.collect.SupplierMap
import ru.dbotthepony.mc.otm.core.util.WriteOnce import ru.dbotthepony.mc.otm.core.util.WriteOnce
import ru.dbotthepony.mc.otm.registry.MRegistry
import java.util.stream.Stream
/** /**
* Base + Colored * Base + Colored
@ -25,12 +28,12 @@ class DecorativeBlock(
val allBlocks: Map<DyeColor?, Block> by lazy { val allBlocks: Map<DyeColor?, Block> by lazy {
check(registeredBlocks) { "Didn't register items yet" } check(registeredBlocks) { "Didn't register items yet" }
SupplierMap(blockMap.map { it.key to it.value::get }.toMutableList().also { it.add(null to _block::get) }) SupplierMap(Streams.concat(MRegistry.DYE_ORDER.stream().map { it to blockMap[it]!! }, Stream.of(null to _block)))
} }
val allItems: Map<DyeColor?, Item> by lazy { val allItems: Map<DyeColor?, Item> by lazy {
check(registeredItems) { "Didn't register items yet" } check(registeredItems) { "Didn't register items yet" }
SupplierMap(itemMap.map { it.key to it.value::get }.toMutableList().also { it.add(null to _item::get) }) SupplierMap(Streams.concat(MRegistry.DYE_ORDER.stream().map { it to itemMap[it]!! }, Stream.of(null to _item)))
} }
override fun registerBlocks(registry: DeferredRegister<Block>) { override fun registerBlocks(registry: DeferredRegister<Block>) {

View File

@ -11,8 +11,9 @@ import net.minecraftforge.registries.RegistryObject
import ru.dbotthepony.mc.otm.core.collect.SupplierList import ru.dbotthepony.mc.otm.core.collect.SupplierList
import ru.dbotthepony.mc.otm.core.collect.SupplierMap import ru.dbotthepony.mc.otm.core.collect.SupplierMap
import java.util.EnumMap import java.util.EnumMap
import java.util.function.Supplier
@Suppress("PropertyName", "unused", "ReplaceGetOrSet", "ReplacePutWithAssignment") @Suppress("unused", "ReplaceGetOrSet", "ReplacePutWithAssignment")
class StripedColoredDecorativeBlock( class StripedColoredDecorativeBlock(
val basename: String, val basename: String,
val blockFactory: (colorA: DyeColor, colorB: DyeColor) -> Block, val blockFactory: (colorA: DyeColor, colorB: DyeColor) -> Block,
@ -54,7 +55,7 @@ class StripedColoredDecorativeBlock(
val builder = ImmutableMap.Builder<DyeColor, Map<DyeColor, Item>>() val builder = ImmutableMap.Builder<DyeColor, Map<DyeColor, Item>>()
for ((base, children) in mapItems) { for ((base, children) in mapItems) {
builder.put(base, SupplierMap(children.map { it.key to it.value::get })) builder.put(base, SupplierMap(children.map { it.key to it.value }))
} }
builder.build() builder.build()
@ -65,7 +66,7 @@ class StripedColoredDecorativeBlock(
val builder = ImmutableMap.Builder<DyeColor, Map<DyeColor, Block>>() val builder = ImmutableMap.Builder<DyeColor, Map<DyeColor, Block>>()
for ((base, children) in mapBlocks) { for ((base, children) in mapBlocks) {
builder.put(base, SupplierMap(children.map { it.key to it.value::get })) builder.put(base, SupplierMap(children.map { it.key to it.value }))
} }
builder.build() builder.build()
@ -73,17 +74,17 @@ class StripedColoredDecorativeBlock(
val flatItems: List<Item> by lazy { val flatItems: List<Item> by lazy {
check(registeredItems) { "Didn't register items yet" } check(registeredItems) { "Didn't register items yet" }
SupplierList(mapItems.flatMap { it.value.values }.map { it::get }) SupplierList(mapItems.flatMap { it.value.values })
} }
val flatBlocks: List<Block> by lazy { val flatBlocks: List<Block> by lazy {
check(registeredBlocks) { "Didn't register items yet" } check(registeredBlocks) { "Didn't register items yet" }
SupplierList(mapBlocks.flatMap { it.value.values }.map { it::get }) SupplierList(mapBlocks.flatMap { it.value.values })
} }
fun registerItems(registry: DeferredRegister<Item>) { fun registerItems(registry: DeferredRegister<Item>) {
for (base in DyeColor.values()) { for (base in DyeColor.entries) {
for (stripe in DyeColor.values()) { for (stripe in DyeColor.entries) {
if (base == stripe) { if (base == stripe) {
continue continue
} }
@ -97,8 +98,8 @@ class StripedColoredDecorativeBlock(
} }
fun registerBlocks(registry: DeferredRegister<Block>) { fun registerBlocks(registry: DeferredRegister<Block>) {
for (base in DyeColor.values()) { for (base in DyeColor.entries) {
for (stripe in DyeColor.values()) { for (stripe in DyeColor.entries) {
if (base == stripe) { if (base == stripe) {
continue continue
} }
@ -116,7 +117,7 @@ class StripedColoredDecorativeBlock(
throw IllegalStateException("Not yet registered blocks") throw IllegalStateException("Not yet registered blocks")
} }
val build = ImmutableList.Builder<() -> Pair<Block, Pair<DyeColor, DyeColor>>>() val build = ImmutableList.Builder<Supplier<Pair<Block, Pair<DyeColor, DyeColor>>>>()
for ((base, children) in mapBlocks) { for ((base, children) in mapBlocks) {
for ((stripe, registryObject) in children) { for ((stripe, registryObject) in children) {
@ -132,7 +133,7 @@ class StripedColoredDecorativeBlock(
throw IllegalStateException("Not yet registered items") throw IllegalStateException("Not yet registered items")
} }
val build = ImmutableList.Builder<() -> Pair<Item, Pair<DyeColor, DyeColor>>>() val build = ImmutableList.Builder<Supplier<Pair<Item, Pair<DyeColor, DyeColor>>>>()
for ((base, children) in mapItems) { for ((base, children) in mapItems) {
for ((stripe, registryObject) in children) { for ((stripe, registryObject) in children) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 787 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB