diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTables.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTables.kt index baf8b310e..ce73cd29e 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTables.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTables.kt @@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArraySet import net.minecraft.data.DataGenerator import net.minecraft.data.loot.LootTableProvider import net.minecraft.resources.ResourceLocation +import net.minecraft.world.level.ItemLike import net.minecraft.world.level.block.Block import net.minecraft.world.level.storage.loot.LootPool import net.minecraft.world.level.storage.loot.LootTable @@ -14,6 +15,8 @@ import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity +import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import java.util.function.BiConsumer import java.util.function.Consumer import java.util.function.Supplier @@ -28,7 +31,32 @@ fun singleLootPool(f: (LootPool.Builder) -> Unit): LootTable.Builder { } data class NbtCopy(val source: String, val destination: String, val strategy: CopyNbtFunction.MergeStrategy = CopyNbtFunction.MergeStrategy.REPLACE) -data class TileNbtCopy(val source: String, val strategy: CopyNbtFunction.MergeStrategy = CopyNbtFunction.MergeStrategy.REPLACE) + +fun TileNbtCopy(source: String, strategy: CopyNbtFunction.MergeStrategy = CopyNbtFunction.MergeStrategy.REPLACE): NbtCopy { + return NbtCopy(source, "BlockEntityTag.$source", strategy) +} + +private val basicTags = arrayOf( + TileNbtCopy(MatteryBlockEntity.REDSTONE_SIGNAL_KEY), + TileNbtCopy(MatteryBlockEntity.REDSTONE_SETTING_KEY), +) + +private val poweredTags = arrayOf( + *basicTags, + TileNbtCopy(MatteryBlockEntity.ENERGY_KEY), + TileNbtCopy(MatteryBlockEntity.BATTERY_KEY), +) + +private val workerTags = arrayOf( + *poweredTags, + TileNbtCopy(MatteryWorkerBlockEntity.JOB_KEY), + TileNbtCopy(MatteryWorkerBlockEntity.WORK_TICKS_KEY), +) + +private val poweredMatterWorker = arrayOf( + *workerTags, + TileNbtCopy(MatteryBlockEntity.MATTER_STORAGE_KEY), +) class LootTables(generator: DataGenerator) : LootTableProvider(generator) { private val providers = ArrayList() @@ -57,6 +85,18 @@ class LootTables(generator: DataGenerator) : LootTableProvider(generator) { } } + fun dropsOther(block: Block, other: ItemLike) { + if (!seenStuff.add(block)) { + throw IllegalStateException("Already seen $block") + } + + block { + it.accept(block.lootTable, singleLootPool { + it.add(LootItem.lootTableItem(other)) + }) + } + } + fun dropsSelf(vararg blocks: Block) { blocks.forEach(this::dropsSelf) } @@ -90,7 +130,72 @@ class LootTables(generator: DataGenerator) : LootTableProvider(generator) { } } - fun tile(block: Block, vararg tags: TileNbtCopy) { - tile(block, *tags.map { NbtCopy(it.source, "BlockEntityTag.${it.source}", it.strategy) }.toTypedArray()) + fun basicTile(block: Block, vararg tags: NbtCopy) { + tile(block) { + for ((source, destination, strategy) in tags) { + it.copy(source, destination, strategy) + } + + for ((source, destination, strategy) in basicTags) { + it.copy(source, destination, strategy) + } + } + } + + fun poweredTile(block: Block, vararg tags: NbtCopy) { + tile(block) { + for ((source, destination, strategy) in tags) { + it.copy(source, destination, strategy) + } + + for ((source, destination, strategy) in poweredTags) { + it.copy(source, destination, strategy) + } + } + } + + fun workerTile(block: Block, vararg tags: NbtCopy) { + tile(block) { + for ((source, destination, strategy) in tags) { + it.copy(source, destination, strategy) + } + + for ((source, destination, strategy) in workerTags) { + it.copy(source, destination, strategy) + } + } + } + + fun matterWorkerTile(block: Block, vararg tags: NbtCopy) { + tile(block) { + for ((source, destination, strategy) in tags) { + it.copy(source, destination, strategy) + } + + for ((source, destination, strategy) in poweredMatterWorker) { + it.copy(source, destination, strategy) + } + } + } + + fun tile(block: Block, vararg tags: String) { + tile(block, *tags.map { NbtCopy(it, "BlockEntityTag.$it", CopyNbtFunction.MergeStrategy.REPLACE) }.toTypedArray()) + } + + // fix overload resolution by adding extra required argument + fun basicTile(block: Block, f: String, vararg tags: String) { + basicTile(block, *tags.map { TileNbtCopy(it) }.toMutableList().also { it.add(TileNbtCopy(f)) }.toTypedArray()) + } + + fun poweredTile(block: Block, f: String, vararg tags: String) { + poweredTile(block, *tags.map { TileNbtCopy(it) }.toMutableList().also { it.add(TileNbtCopy(f)) }.toTypedArray()) + } + + fun workerTile(block: Block, f: String, vararg tags: String) { + workerTile(block, *tags.map { TileNbtCopy(it) }.toMutableList().also { it.add(TileNbtCopy(f)) }.toTypedArray()) + } + + fun matterWorkerTile(block: Block, f: String, vararg tags: String) { + matterWorkerTile(block, *tags.map { TileNbtCopy(it) }.toMutableList().also { it.add(TileNbtCopy(f)) }.toTypedArray()) } } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt index 127c78a18..980a3a558 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt @@ -1,15 +1,22 @@ package ru.dbotthepony.mc.otm.datagen.loot +import ru.dbotthepony.mc.otm.block.MatteryBlock +import ru.dbotthepony.mc.otm.block.entity.ChemicalGeneratorBlockEntity +import ru.dbotthepony.mc.otm.block.entity.EnergyCounterBlockEntity +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.INVENTORY_KEY +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.ENERGY_KEY +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.BATTERY_KEY +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.MATTER_STORAGE_KEY +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.REDSTONE_SETTING_KEY +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.REDSTONE_SIGNAL_KEY +import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity +import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity +import ru.dbotthepony.mc.otm.block.entity.storage.AbstractStorageImportExport.Companion.FILTER_KEY +import ru.dbotthepony.mc.otm.block.entity.storage.StoragePowerSupplierBlockEntity import ru.dbotthepony.mc.otm.registry.MBlocks import ru.dbotthepony.mc.otm.registry.MRegistry -private val workerTags = arrayOf( - TileNbtCopy("work_ticks"), - TileNbtCopy("current_job"), - TileNbtCopy("battery_container"), - TileNbtCopy("energy"), -) - fun addLootTables(lootTables: LootTables) { lootTables.dropsSelf(MBlocks.CRATE_LIST) @@ -28,26 +35,40 @@ fun addLootTables(lootTables: LootTables) { lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_BLOCK) lootTables.dropsSelf(MBlocks.MATTER_CABLE) lootTables.dropsSelf(MBlocks.GRAVITATION_STABILIZER) + lootTables.dropsOther(MBlocks.GRAVITATION_STABILIZER_LENS, MBlocks.GRAVITATION_STABILIZER) - lootTables.tile(MBlocks.ENERGY_COUNTER, TileNbtCopy("passed"), TileNbtCopy("history"), TileNbtCopy("history_tick")) - lootTables.tile(MBlocks.CHEMICAL_GENERATOR, TileNbtCopy("energy"), TileNbtCopy("container"), TileNbtCopy("working_ticks"), TileNbtCopy("working_ticks_total")) + lootTables.tile(MBlocks.ENERGY_COUNTER, + EnergyCounterBlockEntity.IO_LIMIT_KEY, EnergyCounterBlockEntity.PASSED_ENERGY_KEY, + EnergyCounterBlockEntity.POWER_HISTORY_KEY, EnergyCounterBlockEntity.POWER_HISTORY_POINTER_KEY) - lootTables.tile(MBlocks.ANDROID_STATION, TileNbtCopy("energy"), TileNbtCopy("battery_container")) - lootTables.tile(MBlocks.BATTERY_BANK, TileNbtCopy("container")) - lootTables.tile(MBlocks.DRIVE_VIEWER, TileNbtCopy("energy"), TileNbtCopy("container"), TileNbtCopy("battery_container")) + lootTables.tile(MBlocks.CHEMICAL_GENERATOR, + ChemicalGeneratorBlockEntity.WORK_TICKS_KEY, + ChemicalGeneratorBlockEntity.WORK_TICKS_TOTAL_KEY, + ENERGY_KEY, + REDSTONE_SIGNAL_KEY, + REDSTONE_SETTING_KEY, + ) - lootTables.tile(MBlocks.STORAGE_BUS, TileNbtCopy("energy"), TileNbtCopy("battery_container")) - lootTables.tile(MBlocks.STORAGE_IMPORTER, TileNbtCopy("energy"), TileNbtCopy("battery_container")) - lootTables.tile(MBlocks.STORAGE_POWER_SUPPLIER, TileNbtCopy("energy"), TileNbtCopy("battery_container"), TileNbtCopy("power_supplied")) + lootTables.dropsSelf(MBlocks.STORAGE_CABLE) + lootTables.poweredTile(MBlocks.ANDROID_STATION) + lootTables.basicTile(MBlocks.BATTERY_BANK) + lootTables.poweredTile(MBlocks.DRIVE_VIEWER) - lootTables.tile(MBlocks.MATTER_DECOMPOSER, TileNbtCopy("container"), TileNbtCopy("matter"), *workerTags) - lootTables.tile(MBlocks.MATTER_REPLICATOR, TileNbtCopy("container"), TileNbtCopy("matter"), *workerTags) - lootTables.tile(MBlocks.MATTER_RECYCLER, TileNbtCopy("container"), TileNbtCopy("matter"), *workerTags) - lootTables.tile(MBlocks.MATTER_SCANNER, TileNbtCopy("container"), *workerTags) - lootTables.tile(MBlocks.PLATE_PRESS, TileNbtCopy("container"), *workerTags) + lootTables.poweredTile(MBlocks.STORAGE_BUS, TileNbtCopy(FILTER_KEY)) + lootTables.poweredTile(MBlocks.STORAGE_IMPORTER, TileNbtCopy(FILTER_KEY)) + lootTables.poweredTile(MBlocks.STORAGE_EXPORTER, TileNbtCopy(FILTER_KEY)) + lootTables.poweredTile(MBlocks.STORAGE_POWER_SUPPLIER, TileNbtCopy(StoragePowerSupplierBlockEntity.POWER_PASSED_KEY)) + lootTables.poweredTile(MBlocks.DRIVE_RACK) - lootTables.tile(MBlocks.MATTER_PANEL, TileNbtCopy("tasks")) - lootTables.tile(MBlocks.PATTERN_STORAGE, TileNbtCopy("patterns")) - lootTables.tile(MBlocks.MATTER_CAPACITOR_BANK, TileNbtCopy("container")) - lootTables.tile(MBlocks.MATTER_BOTTLER, TileNbtCopy("energy"), TileNbtCopy("battery_container"), TileNbtCopy("work_slots"), TileNbtCopy("work_flow"), TileNbtCopy("matter")) + lootTables.matterWorkerTile(MBlocks.MATTER_DECOMPOSER) + lootTables.matterWorkerTile(MBlocks.MATTER_REPLICATOR) + lootTables.matterWorkerTile(MBlocks.MATTER_RECYCLER) + lootTables.workerTile(MBlocks.MATTER_SCANNER) + lootTables.workerTile(MBlocks.PLATE_PRESS) + + lootTables.basicTile(MBlocks.MATTER_PANEL, TileNbtCopy("tasks")) + lootTables.basicTile(MBlocks.PATTERN_STORAGE) + lootTables.basicTile(MBlocks.MATTER_CAPACITOR_BANK) + lootTables.poweredTile(MBlocks.MATTER_BOTTLER, + TileNbtCopy(MATTER_STORAGE_KEY), TileNbtCopy(MatterBottlerBlockEntity.IS_BOTTLING_KEY)) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/CargoCrateBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/CargoCrateBlock.kt index 9e4df360a..476a82294 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/CargoCrateBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/CargoCrateBlock.kt @@ -32,25 +32,6 @@ class CargoCrateBlock(val color: DyeColor?) : RotatableMatteryBlock( return super.getStateForPlacement(context)?.setValue(IS_OPEN, false) } - override fun onRemove( - old_block_state: BlockState, - level: Level, - block_pos: BlockPos, - new_block_state: BlockState, - p_51542_: Boolean - ) { - if (!old_block_state.`is`(new_block_state.block)) { - val blockentity = level.getBlockEntity(block_pos) - - if (blockentity is CargoCrateBlockEntity) { - Containers.dropContents(level, block_pos, blockentity.container); - level.updateNeighbourForOutputSignal(block_pos, this); - } - - super.onRemove(old_block_state, level, block_pos, new_block_state, p_51542_) - } - } - override fun hasAnalogOutputSignal(p_60457_: BlockState): Boolean { return true } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt index aad27f026..5900bee1b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt @@ -2,6 +2,8 @@ package ru.dbotthepony.mc.otm.block import net.minecraft.core.BlockPos import net.minecraft.core.Direction +import net.minecraft.world.Container +import net.minecraft.world.Containers import net.minecraft.world.InteractionHand import net.minecraft.world.InteractionResult import net.minecraft.world.MenuProvider @@ -20,6 +22,10 @@ import net.minecraft.world.level.material.MaterialColor import net.minecraft.world.phys.BlockHitResult import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity +interface IDroppableContainer { + val droppableContainer: Container +} + abstract class MatteryBlock @JvmOverloads constructor( properties: Properties = DEFAULT_PROPERTIES ) : Block(properties) { @@ -82,8 +88,27 @@ abstract class MatteryBlock @JvmOverloads constructor( } } + @Suppress("OVERRIDE_DEPRECATION") + override fun onRemove( + oldBlockState: BlockState, + level: Level, + blockPos: BlockPos, + newBlockState: BlockState, + movedByPiston: Boolean + ) { + if (!oldBlockState.`is`(newBlockState.block)) { + val blockentity = level.getBlockEntity(blockPos) + + if (blockentity is IDroppableContainer) { + Containers.dropContents(level, blockPos, blockentity.droppableContainer) + level.updateNeighbourForOutputSignal(blockPos, this) + } + } + + super.onRemove(oldBlockState, level, blockPos, newBlockState, movedByPiston) + } + companion object { - @JvmField val DEFAULT_PROPERTIES: Properties = Properties.of(Material.STONE, MaterialColor.METAL).requiresCorrectToolForDrops().strength(1.5f, 25.0f) } } @@ -120,7 +145,6 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope open val hasFreeRotation get() = false companion object { - @JvmField val FACING: EnumProperty = EnumProperty.create( "facing", Direction::class.java, @@ -130,7 +154,6 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope Direction.EAST ) - @JvmField val FACING_FULL: EnumProperty = EnumProperty.create("facing", Direction::class.java) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt index ceb42db6b..8c4cac0ae 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/BatteryBankBlockEntity.kt @@ -6,6 +6,7 @@ import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerLevel +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -20,9 +21,11 @@ import net.minecraftforge.energy.IEnergyStorage import org.apache.logging.log4j.LogManager import ru.dbotthepony.mc.otm.* import ru.dbotthepony.mc.otm.block.BatteryBankBlock +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.capability.* import ru.dbotthepony.mc.otm.container.MatteryContainer +import ru.dbotthepony.mc.otm.container.MatteryContainerFilter import ru.dbotthepony.mc.otm.core.* import ru.dbotthepony.mc.otm.menu.BatteryBankMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities @@ -30,7 +33,7 @@ import javax.annotation.ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryBlockEntity(MBlockEntities.BATTERY_BANK, p_155229_, p_155230_) { +class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryBlockEntity(MBlockEntities.BATTERY_BANK, p_155229_, p_155230_), IDroppableContainer { // 6 на 2 val container: MatteryContainer = object : MatteryContainer(this::setChanged, CAPACITY) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { @@ -51,9 +54,18 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte } } + override val droppableContainer: Container + get() = container private val itemHandler = container.handler( - { slot: Int, stack: ItemStack -> stack.getCapability(ForgeCapabilities.ENERGY).isPresent }, - { slot: Int, amount: Int, stack: ItemStack? -> true } + object : MatteryContainerFilter { + override fun canInsert(slot: Int, stack: ItemStack): Boolean { + return stack.getCapability(ForgeCapabilities.ENERGY).isPresent + } + + override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean { + return true + } + } ) private data class BatteryBankDistribution(val distribution: Array, val maxThroughput: ImpreciseFraction) @@ -200,11 +212,11 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["container"] = container.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() } override fun load(nbt: CompoundTag) { - container.deserializeNBT(nbt["container"]) + container.deserializeNBT(nbt[INVENTORY_KEY]) super.load(nbt) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/CargoCrateBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/CargoCrateBlockEntity.kt index 42810e5cb..2e5f503e1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/CargoCrateBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/CargoCrateBlockEntity.kt @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -14,6 +15,7 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.block.CargoCrateBlock +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.menu.CargoCrateMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities @@ -23,11 +25,14 @@ import ru.dbotthepony.mc.otm.core.set class CargoCrateBlockEntity( p_155229_: BlockPos, p_155230_: BlockState -) : MatteryBlockEntity(MBlockEntities.CARGO_CRATE, p_155229_, p_155230_) { +) : MatteryBlockEntity(MBlockEntities.CARGO_CRATE, p_155229_, p_155230_), IDroppableContainer { val container = MatteryContainer(this::setChanged, CAPACITY) private var interactingPlayers = 0 val handler = container.handler() + override val droppableContainer: Container + get() = container + fun onPlayerOpen() { if (interactingPlayers++ == 0) { level?.setBlock(blockPos, blockState.setValue(CargoCrateBlock.IS_OPEN, true), Block.UPDATE_CLIENTS) @@ -59,12 +64,12 @@ class CargoCrateBlockEntity( public override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["slots"] = container.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - container.deserializeNBT(nbt["slots"]) + container.deserializeNBT(nbt[INVENTORY_KEY]) } override val defaultDisplayName: Component diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt index 7cc7b630e..4f5c9b15d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/ChemicalGeneratorBlockEntity.kt @@ -5,6 +5,7 @@ import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.IntTag import net.minecraft.network.chat.Component +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -18,15 +19,17 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional import net.minecraftforge.energy.IEnergyStorage import ru.dbotthepony.mc.otm.* +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.capability.* import ru.dbotthepony.mc.otm.container.MatteryContainer +import ru.dbotthepony.mc.otm.container.MatteryContainerFilter import ru.dbotthepony.mc.otm.core.* import ru.dbotthepony.mc.otm.menu.ChemicalGeneratorMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities import java.lang.ref.WeakReference -class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBlockEntity(MBlockEntities.CHEMICAL_GENERATOR, pos, state) { +class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBlockEntity(MBlockEntities.CHEMICAL_GENERATOR, pos, state), IDroppableContainer { override val defaultDisplayName: Component get() = MACHINE_NAME @@ -35,10 +38,13 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl } private var valid = true - - @JvmField + val container = MatteryContainer(this::setChangedLight, 3) + override val droppableContainer: Container + get() = container val energy = GeneratorEnergyStorage(this::setChangedLight, MAX_ENERGY, THROUGHPUT) + private val consumers = ArrayList>() + override fun setChangedLight() { super.setChangedLight() check = true @@ -76,31 +82,21 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["energy"] = energy.serializeNBT() - nbt["container"] = container.serializeNBT() - nbt["working_ticks"] = workingTicks - nbt["working_ticks_total"] = workingTicksTotal + nbt[ENERGY_KEY] = energy.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() + nbt[WORK_TICKS_KEY] = workTicks + nbt[WORK_TICKS_TOTAL_KEY] = workTicksTotal } override fun load(nbt: CompoundTag) { super.load(nbt) - nbt.ifHas("energy", CompoundTag::class.java, energy::deserializeNBT) - container.deserializeNBT(nbt["container"]) - - nbt.ifHas("working_ticks") { - if (it is IntTag) - workingTicks = it.asInt - } - - nbt.ifHas("working_ticks_total") { - if (it is IntTag) - workingTicksTotal = it.asInt - } + nbt.map(ENERGY_KEY, energy::deserializeNBT) + container.deserializeNBT(nbt[INVENTORY_KEY]) + workTicks = nbt.getInt(WORK_TICKS_KEY) + workTicksTotal = nbt.getInt(WORK_TICKS_TOTAL_KEY) } - private val consumers = ArrayList>() - fun checkSurroundings() { if (!valid) return @@ -131,21 +127,23 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl } } - val container = MatteryContainer(this::setChangedLight, 3) + val itemHandler = container.handler(object : MatteryContainerFilter { + override fun canInsert(slot: Int, stack: ItemStack): Boolean { + if (slot == SLOT_INPUT) + return ForgeHooks.getBurnTime(stack, null) > 0 - val itemHandler = container.handler(fun (slot, stack): Boolean { - if (slot == SLOT_INPUT) - return ForgeHooks.getBurnTime(stack, null) > 0 + if (slot == SLOT_RESIDUE) + return false - if (slot == SLOT_RESIDUE) - return false + return stack.getCapability(ForgeCapabilities.ENERGY).isPresent + } - return stack.getCapability(ForgeCapabilities.ENERGY).isPresent - }, fun (slot, _, stack): Boolean { - if (slot == SLOT_RESIDUE) return true + override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean { + if (slot == SLOT_RESIDUE) return true - return slot == SLOT_BATTERY && + return slot == SLOT_BATTERY && (!stack.getCapability(ForgeCapabilities.ENERGY).isPresent || stack.getCapability(ForgeCapabilities.ENERGY).resolve().get().receiveEnergy(Int.MAX_VALUE, true) <= 0) + } }) override fun setBlockState(p_155251_: BlockState) { @@ -155,10 +153,10 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl tickOnceServer(this::checkSurroundings) } - var workingTicks = 0 + var workTicks = 0 private set - var workingTicksTotal = 0 + var workTicksTotal = 0 private set private var check = true @@ -173,12 +171,12 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl } fun tick() { - if (workingTicks > 0 && !isBlockedByRedstone) { - workingTicks-- + if (workTicks > 0) { + workTicks-- energy.receiveEnergyInner(GENERATION_SPEED, false) - if (workingTicks == 0) { - workingTicksTotal = 0 + if (workTicks == 0) { + workTicksTotal = 0 check = true } @@ -189,15 +187,15 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl level?.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS) } - if (workingTicks == 0 && !isBlockedByRedstone && check) { + if (workTicks == 0 && !isBlockedByRedstone && check) { if (!container[SLOT_INPUT].isEmpty) { val ticks = ForgeHooks.getBurnTime(container[SLOT_INPUT], null) val residue = container[SLOT_INPUT].item.getCraftingRemainingItem(container[SLOT_INPUT].copy().also { it.count = 1 }) val canPutResidue = residue.isEmpty || container[SLOT_RESIDUE].isEmpty || ItemStack.isSameItemSameTags(container[SLOT_RESIDUE], residue) && container[SLOT_RESIDUE].count < container[2].maxStackSize if (canPutResidue && ticks >= 4 && (energy.batteryLevel < ImpreciseFraction.ONE || GENERATION_SPEED * (ticks / 4) + energy.batteryLevel <= energy.maxBatteryLevel)) { - workingTicksTotal = ticks / 4 - workingTicks = ticks / 4 + workTicksTotal = ticks / 4 + workTicks = ticks / 4 container[SLOT_INPUT].shrink(1) if (!residue.isEmpty) { @@ -239,5 +237,8 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl const val SLOT_INPUT = 0 const val SLOT_BATTERY = 1 const val SLOT_RESIDUE = 2 + + const val WORK_TICKS_KEY = "workTicks" + const val WORK_TICKS_TOTAL_KEY = "workTicksTotal" } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyCounterBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyCounterBlockEntity.kt index ccf4efca9..063de299e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyCounterBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/EnergyCounterBlockEntity.kt @@ -3,7 +3,6 @@ package ru.dbotthepony.mc.otm.block.entity import net.minecraft.client.Minecraft import net.minecraft.core.BlockPos import net.minecraft.core.Direction -import net.minecraft.nbt.ByteArrayTag import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.IntTag import net.minecraft.nbt.ListTag @@ -128,38 +127,32 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["passed"] = passed.serializeNBT() + nbt[PASSED_ENERGY_KEY] = passed.serializeNBT() val list = ListTag() - nbt["history"] = list - nbt["history_tick"] = historyTick + nbt[POWER_HISTORY_KEY] = list + nbt[POWER_HISTORY_POINTER_KEY] = historyTick for (num in history) list.add(num.serializeNBT()) - ioLimit?.let { nbt["io_limit"] = it.serializeNBT() } + ioLimit?.let { nbt[IO_LIMIT_KEY] = it.serializeNBT() } } override fun load(nbt: CompoundTag) { super.load(nbt) - nbt.ifHas(("passed")) { - passed = ImpreciseFraction.deserializeNBT(it) - } + passed = nbt.getImpreciseFraction(PASSED_ENERGY_KEY) + ioLimit = nbt.map(IO_LIMIT_KEY, ImpreciseFraction.Companion::deserializeNBT) - nbt.ifHas(("io_limit")) { - ioLimit = ImpreciseFraction.deserializeNBT(it) - } - - nbt.ifHas(("history_tick"), IntTag::class.java) { + nbt.ifHas(POWER_HISTORY_POINTER_KEY, IntTag::class.java) { historyTick = it.asInt } - nbt.ifHas("history", ListTag::class.java) { - for (i in it.indices) { - val bytes = it[i] as? ByteArrayTag - history[i] = if (bytes != null) ImpreciseFraction.deserializeNBT(bytes) else ImpreciseFraction.ZERO - } + Arrays.fill(history, ImpreciseFraction.ZERO) + + for ((i, bytes) in nbt.getByteArrayList(POWER_HISTORY_KEY).withIndex()) { + history[i] = ImpreciseFraction.deserializeNBT(bytes) } } @@ -468,5 +461,9 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat companion object { private val MACHINE_NAME = TranslatableComponent("block.overdrive_that_matters.energy_counter") + const val PASSED_ENERGY_KEY = "passedEnergy" + const val IO_LIMIT_KEY = "IOLimit" + const val POWER_HISTORY_KEY = "passHistory" + const val POWER_HISTORY_POINTER_KEY = "passHistoryPointer" } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt index 6f6f20736..c3c933dfc 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt @@ -18,7 +18,6 @@ import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.StringTag -import net.minecraft.nbt.ByteTag import net.minecraft.network.chat.Component import net.minecraft.world.level.Level import net.minecraftforge.common.capabilities.Capability @@ -126,7 +125,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc return customDisplayName ?: defaultDisplayName } - protected open fun redstoneStatusUpdated(new_blocked: Boolean, old_blocked: Boolean) {} + protected open fun redstoneStatusUpdated(newBlocked: Boolean, oldBlocked: Boolean) {} override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) @@ -135,8 +134,8 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc if (customDisplayName != null) nbt.putString("Name", Component.Serializer.toJson(customDisplayName)) - nbt["redstone"] = redstoneSetting.ordinal.toByte() - nbt["redstone_signal"] = redstoneSignal.toByte() + nbt[REDSTONE_SETTING_KEY] = redstoneSetting.ordinal.toByte() + nbt[REDSTONE_SIGNAL_KEY] = redstoneSignal.toByte() } override fun load(nbt: CompoundTag) { @@ -146,13 +145,8 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc customDisplayName = Component.Serializer.fromJson(it.asString) } - nbt.ifHas("redstone", ByteTag::class.java) { - redstoneSetting = RedstoneSetting.get(it.asInt) - } - - nbt.ifHas("redstone_signal", ByteTag::class.java) { - redstoneSignal = it.asInt - } + redstoneSetting = RedstoneSetting[nbt.getByte(REDSTONE_SETTING_KEY).toInt()] + redstoneSignal = nbt.getByte(REDSTONE_SIGNAL_KEY).toInt() } // Just to mark chunk unsaved @@ -164,4 +158,13 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc SectionPos.blockToSectionCoord(blockPos.z))?.isUnsaved = true } } + + companion object { + const val REDSTONE_SETTING_KEY = "redstoneSetting" + const val REDSTONE_SIGNAL_KEY = "redstoneSignal" + const val INVENTORY_KEY = "container" + const val MATTER_STORAGE_KEY = "matterStorage" + const val ENERGY_KEY = "energyStorage" + const val BATTERY_KEY = "batteryInventory" + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryPoweredBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryPoweredBlockEntity.kt index ae82e2dd0..61c0d9f82 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryPoweredBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryPoweredBlockEntity.kt @@ -79,13 +79,13 @@ abstract class MatteryPoweredBlockEntity(p_155228_: BlockEntityType<*>, p_155229 public override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["energy"] = energy.serializeNBT() - nbt["battery_container"] = batteryContainer.serializeNBT() + nbt[ENERGY_KEY] = energy.serializeNBT() + nbt[BATTERY_KEY] = batteryContainer.serializeNBT() } override fun load(nbt: CompoundTag) { - nbt.ifHas("energy", CompoundTag::class.java, energy::deserializeNBT) - batteryContainer.deserializeNBT(nbt["battery_container"]) + nbt.ifHas(ENERGY_KEY, CompoundTag::class.java, energy::deserializeNBT) + batteryContainer.deserializeNBT(nbt[BATTERY_KEY]) super.load(nbt) } } \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryWorkerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryWorkerBlockEntity.kt index 4ddaf9721..ea3315bd1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryWorkerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryWorkerBlockEntity.kt @@ -23,14 +23,19 @@ abstract class MatteryWorkerBlockEntity( ) { constructor( tag: CompoundTag - ) : this(tag.getDouble("ticks"), tag.getImpreciseFraction("power")) + ) : this(tag.getDouble(TICKS_KEY), tag.getImpreciseFraction(POWER_KEY)) open fun serializeNBT(): CompoundTag { return CompoundTag().also { - it["ticks"] = ticks - it["power"] = powerUsage + it[TICKS_KEY] = ticks + it[POWER_KEY] = powerUsage } } + + companion object { + const val TICKS_KEY = "ticks" + const val POWER_KEY = "power" + } } @Suppress("LeakingThis") @@ -53,9 +58,13 @@ abstract class MatteryWorkerBlockEntity( override fun serializeNBT(): CompoundTag { return super.serializeNBT().also { - it["item"] = itemStack.serializeNBT() + it[ITEM_KEY] = itemStack.serializeNBT() } } + + companion object { + const val ITEM_KEY = "item" + } } enum class IdleReason { @@ -108,15 +117,15 @@ abstract class MatteryWorkerBlockEntity( override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["work_ticks"] = workTicks - currentJob?.let { nbt["job"] = it.serializeNBT() } + nbt[WORK_TICKS_KEY] = workTicks + currentJob?.let { nbt[JOB_KEY] = it.serializeNBT() } } override fun load(nbt: CompoundTag) { super.load(nbt) - workTicks = nbt.getDouble("work_ticks") - currentJob = nbt.map("job", jobDeserializer::invoke) + workTicks = nbt.getDouble(WORK_TICKS_KEY) + currentJob = nbt.map(JOB_KEY, jobDeserializer::invoke) if (currentJob == null) workTicks = 0.0 @@ -179,9 +188,9 @@ abstract class MatteryWorkerBlockEntity( private var workingTicksAnim = 0 private var errorTicksAnim = 0 - override fun redstoneStatusUpdated(new_blocked: Boolean, old_blocked: Boolean) { - super.redstoneStatusUpdated(new_blocked, old_blocked) - isIdling = new_blocked + override fun redstoneStatusUpdated(newBlocked: Boolean, oldBlocked: Boolean) { + super.redstoneStatusUpdated(newBlocked, oldBlocked) + isIdling = newBlocked } protected fun workerLoop() { @@ -339,4 +348,9 @@ abstract class MatteryWorkerBlockEntity( batteryChargeLoop() workerLoop() } -} \ No newline at end of file + + companion object { + const val WORK_TICKS_KEY = "workTicks" + const val JOB_KEY = "job" + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PlatePressBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PlatePressBlockEntity.kt index 85a24a20b..bd2771aae 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PlatePressBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PlatePressBlockEntity.kt @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -12,6 +13,7 @@ import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage import ru.dbotthepony.mc.otm.container.MatteryContainer @@ -21,15 +23,18 @@ import ru.dbotthepony.mc.otm.menu.PlatePressMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MRecipes import ru.dbotthepony.mc.otm.container.set +import ru.dbotthepony.mc.otm.core.map import ru.dbotthepony.mc.otm.core.set class PlatePressBlockEntity( p_155229_: BlockPos, p_155230_: BlockState -) : MatteryWorkerBlockEntity(MBlockEntities.PLATE_PRESS, p_155229_, p_155230_, ::ItemJob) { +) : MatteryWorkerBlockEntity(MBlockEntities.PLATE_PRESS, p_155229_, p_155230_, ::ItemJob), IDroppableContainer { val container = MatteryContainer(this::setChangedLight, 2) override val energy = WorkerEnergyStorage(this::setChangedLight) + override val droppableContainer: Container + get() = container val itemHandler = container.handler(object : MatteryContainerFilter { override fun canInsert(slot: Int, stack: ItemStack): Boolean { return slot != SLOT_OUTPUT @@ -59,12 +64,12 @@ class PlatePressBlockEntity( override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["container"] = container.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - container.deserializeNBT(nbt["container"]) + nbt.map(INVENTORY_KEY, container::deserializeNBT) } override val defaultDisplayName: Component diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/RedstoneSetting.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/RedstoneSetting.kt index 4c353f217..43a75fdf8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/RedstoneSetting.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/RedstoneSetting.kt @@ -15,7 +15,6 @@ enum class RedstoneSetting(val label: Component, val description: Component) { companion object { private val values = values() - @JvmStatic operator fun get(index: Int): RedstoneSetting { if (index !in 0 .. 2) return LOW diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt index 54c36c604..7531cbff5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt @@ -5,6 +5,7 @@ import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerLevel +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -13,8 +14,10 @@ import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.capabilities.Capability +import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional import net.minecraftforge.items.CapabilityItemHandler +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState @@ -24,31 +27,29 @@ import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler import ru.dbotthepony.mc.otm.capability.matter.MatterDirection import ru.dbotthepony.mc.otm.capability.matter.MatterHandlerImpl import ru.dbotthepony.mc.otm.container.MatteryContainer +import ru.dbotthepony.mc.otm.container.MatteryContainerFilter import ru.dbotthepony.mc.otm.graph.Graph6Node import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph import ru.dbotthepony.mc.otm.menu.MatterBottlerMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities -import ru.dbotthepony.mc.otm.container.set import ru.dbotthepony.mc.otm.core.* class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : - MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, p_155229_, p_155230_), IMatterGraphNode { + MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, p_155229_, p_155230_), IMatterGraphNode, IDroppableContainer { override val matterNode = Graph6Node(this) private val resolverNode = LazyOptional.of { this } override val energy = WorkerEnergyStorage(this) - // true - bottling - // false - unbottling - var workFlow: Boolean = true + var isBottling: Boolean = true set(value) { field = value this.setChangedLight() } fun switchWorkFlow() { - workFlow = !workFlow + isBottling = !isBottling updateBlockState() } @@ -56,7 +57,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : val level = level as? ServerLevel ?: return var state = blockState - val initial = if (workFlow) 0 else 3 + val initial = if (isBottling) 0 else 3 for (i in initial .. initial + 2) { val desired = !container.getItem(i).isEmpty && container.getItem(i).getCapability(MatteryCapability.MATTER).isPresent @@ -76,7 +77,6 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : // false - spit into output slot //private var work_behavior = true - @JvmField val container: MatteryContainer = object : MatteryContainer(this::setChangedLight, 6) { override fun getMaxStackSize(slot: Int): Int { return 1 @@ -88,25 +88,32 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } } - val itemHandler = container.handler({ slot: Int, stack: ItemStack -> - if (this.workFlow) { - return@handler slot < 3 && stack.getCapability(MatteryCapability.MATTER).isPresent + override val droppableContainer: Container + get() = container + + val itemHandler = container.handler(object : MatteryContainerFilter { + override fun canInsert(slot: Int, stack: ItemStack): Boolean { + if (isBottling) { + return slot < 3 && stack.getCapability(MatteryCapability.MATTER).isPresent + } + + return slot >= 3 && stack.getCapability(MatteryCapability.MATTER).isPresent } - slot >= 3 && stack.getCapability(MatteryCapability.MATTER).isPresent - }, { slot: Int, amount: Int, stack: ItemStack? -> - if (this.workFlow) { - return@handler slot >= 3 + + override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean { + if (isBottling) { + return slot >= 3 + } + + return slot < 3 } - slot < 3 }) - @JvmField - val matter: MatterHandlerImpl = - object : MatterHandlerImpl(this::setChangedLight, MatterDirection.BIDIRECTIONAL, CAPACITY) { - override val direction: MatterDirection get() { - return if (this@MatterBottlerBlockEntity.workFlow) MatterDirection.RECEIVE else MatterDirection.EXTRACT - } + val matter: MatterHandlerImpl = object : MatterHandlerImpl(this::setChangedLight, MatterDirection.BIDIRECTIONAL, CAPACITY) { + override val direction: MatterDirection get() { + return if (this@MatterBottlerBlockEntity.isBottling) MatterDirection.RECEIVE else MatterDirection.EXTRACT } + } private var initialCapacity: ImpreciseFraction? = null private var lastWorkStack: ItemStack? = null @@ -140,15 +147,15 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : override fun getCapability(cap: Capability, side: Direction?): LazyOptional { if (valid) { - if (cap === MatteryCapability.MATTER) { + if (cap == MatteryCapability.MATTER) { return matter.get().cast() } - if (cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (cap == ForgeCapabilities.ITEM_HANDLER) { return itemHandler.get().cast() } - if (cap === MatteryCapability.MATTER_NODE) { + if (cap == MatteryCapability.MATTER_NODE) { return resolverNode.cast() } } @@ -165,16 +172,16 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["work_slots"] = container.serializeNBT() - nbt["work_flow"] = this.workFlow - nbt["matter"] = matter.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() + nbt[IS_BOTTLING_KEY] = isBottling + nbt[MATTER_STORAGE_KEY] = matter.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - container.deserializeNBT(nbt["work_slots"]) - workFlow = nbt.getBoolean("work_flow") - nbt.ifHas("matter", CompoundTag::class.java, matter::deserializeNBT) + isBottling = nbt.getBoolean(IS_BOTTLING_KEY) + nbt.map(MATTER_STORAGE_KEY, matter::deserializeNBT) + nbt.map(INVENTORY_KEY, container::deserializeNBT) } fun getWorkProgress(): Float { @@ -182,7 +189,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : val initialCapacity = initialCapacity ?: return 0f val cap = lastWorkStack.getCapability(MatteryCapability.MATTER).orNull() ?: return 0f - if (this.workFlow) { + if (this.isBottling) { if (cap.maxStoredMatter - initialCapacity <= ImpreciseFraction.ZERO) { return 0f } @@ -219,9 +226,9 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : var work_stack: ItemStack? = null var capability: IMatterHandler? = null - val align = if (workFlow) 0 else 3 + val align = if (isBottling) 0 else 3 var work_slot = -1 - val unexpectedDirection = if (workFlow) MatterDirection.EXTRACT else MatterDirection.RECEIVE + val unexpectedDirection = if (isBottling) MatterDirection.EXTRACT else MatterDirection.RECEIVE for (i in align until align + 3) { val itemStack = container.getItem(i) @@ -230,7 +237,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : val cap = itemStack.getCapability(MatteryCapability.MATTER).orNull() ?: continue if (cap.direction !== unexpectedDirection) { - if (this.workFlow && cap.missingMatter > ImpreciseFraction.ZERO || !this.workFlow && cap.storedMatter > ImpreciseFraction.ZERO) { + if (this.isBottling && cap.missingMatter > ImpreciseFraction.ZERO || !this.isBottling && cap.storedMatter > ImpreciseFraction.ZERO) { work_stack = itemStack capability = cap work_slot = i @@ -255,7 +262,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : level?.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS) } - if (workFlow) { + if (isBottling) { if (matter.storedMatter < MATTER_EXCHANGE_RATE && graph != null) { val extracted = graph.extractMatter( matter.missingMatter.coerceAtMost(MATTER_EXCHANGE_RATE * EXTRACTION_TICKS).coerceAtMost(capability.missingMatter - matter.storedMatter), true @@ -319,7 +326,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : level!!.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS) } - if (!workFlow && !matter.storedMatter.isZero && graph != null) { + if (!isBottling && !matter.storedMatter.isZero && graph != null) { val diff = matter.extractMatterInner(matter.storedMatter, true) val diff2 = graph.receiveMatter(diff, true) matter.extractMatterInner(diff2, false) @@ -333,5 +340,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : private val ENERGY_CONSUMPTION = ImpreciseFraction(20) private val EXTRACTION_TICKS = ImpreciseFraction(200) private val CAPACITY = ImpreciseFraction(4) + + const val IS_BOTTLING_KEY = "isBottling" } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt index 55f026f69..13c271fab 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt @@ -6,6 +6,7 @@ import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerLevel +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -17,6 +18,7 @@ import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.util.LazyOptional import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.block.BatteryBankBlock +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler @@ -29,13 +31,12 @@ import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph import ru.dbotthepony.mc.otm.menu.MatterCapacitorBankMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.container.set +import ru.dbotthepony.mc.otm.core.map import ru.dbotthepony.mc.otm.core.set import javax.annotation.ParametersAreNonnullByDefault -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : - MatteryBlockEntity(MBlockEntities.MATTER_CAPACITOR_BANK, p_155229_, p_155230_), IMatterGraphNode, IMatterHandler { + MatteryBlockEntity(MBlockEntities.MATTER_CAPACITOR_BANK, p_155229_, p_155230_), IMatterGraphNode, IMatterHandler, IDroppableContainer { override val matterNode = Graph6Node(this) private val resolverNode = LazyOptional.of { this } @@ -69,7 +70,8 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) } override fun receiveMatterInner(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction { - @Suppress("NAME_SHADOWING") var howMuch = howMuch + @Suppress("NAME_SHADOWING") + var howMuch = howMuch var summ = ImpreciseFraction.ZERO for (stack in container) { @@ -94,7 +96,8 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) } override fun extractMatterInner(howMuch: ImpreciseFraction, simulate: Boolean): ImpreciseFraction { - @Suppress("NAME_SHADOWING") var howMuch = howMuch + @Suppress("NAME_SHADOWING") + var howMuch = howMuch var summ = ImpreciseFraction.ZERO for (stack in container) { @@ -119,7 +122,6 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) private var resolver = LazyOptional.of { this } - @JvmField val container = object : MatteryContainer(this::setChangedLight, 6 * 2) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { super.setChanged(slot, new, old) @@ -142,21 +144,19 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) } } - companion object { - private val MACHINE_NAME = TranslatableComponent("block.overdrive_that_matters.matter_capacitor_bank") - } - + override val droppableContainer: Container + get() = container override val defaultDisplayName: Component get() = MACHINE_NAME override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["container"] = container.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() } override fun load(nbt: CompoundTag) { - container.deserializeNBT(nbt["container"]) super.load(nbt) + nbt.map(INVENTORY_KEY, container::deserializeNBT) } override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu { @@ -201,4 +201,8 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) override fun getMatterHandler(): IMatterHandler { return this } -} \ No newline at end of file + + companion object { + private val MACHINE_NAME = TranslatableComponent("block.overdrive_that_matters.matter_capacitor_bank") + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt index 94990d288..f276d7a55 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt @@ -5,6 +5,7 @@ import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerLevel +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -15,6 +16,7 @@ import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional import net.minecraftforge.items.IItemHandler +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage @@ -90,15 +92,15 @@ fun moveMatterAsDustIntoContainer(_matterValue: ImpreciseFraction, container: Ma } class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) - : MatteryWorkerBlockEntity(MBlockEntities.MATTER_DECOMPOSER, pos, state, ::DecomposerJob), IMatterGraphNode { + : MatteryWorkerBlockEntity(MBlockEntities.MATTER_DECOMPOSER, pos, state, ::DecomposerJob), IMatterGraphNode, IDroppableContainer { class DecomposerJob : Job { val toDust: Boolean var matterValue: ImpreciseFraction constructor(tag: CompoundTag) : super(tag) { - toDust = tag.getBoolean("to_dust") - matterValue = tag.getImpreciseFraction("value") + toDust = tag.getBoolean(TO_DUST_KEY) + matterValue = tag.getImpreciseFraction(MATTER_VALUE_KEY) } constructor(toDust: Boolean, matterValue: ImpreciseFraction, ticks: Double) : super(ticks, BASE_CONSUMPTION) { @@ -108,22 +110,22 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) override fun serializeNBT(): CompoundTag { return super.serializeNBT().also { - it["to_dust"] = toDust - it["value"] = matterValue + it[TO_DUST_KEY] = toDust + it[MATTER_VALUE_KEY] = matterValue } } + + companion object { + const val TO_DUST_KEY = "toDust" + const val MATTER_VALUE_KEY = "matterValue" + } } override val energy = WorkerEnergyStorage(this, ENERGY_STORAGE, MAX_IO) private var valid = true override val matterNode = Graph6Node(this) - @JvmField - val matter = MatterHandlerImpl( - this::setChangedLight, - MatterDirection.EXTRACT, - CAPACITY - ) + val matter = MatterHandlerImpl(this::setChangedLight, MatterDirection.EXTRACT, CAPACITY) private var resolverMatter = LazyOptional.of { matter } private var resolverNode = LazyOptional.of { this } @@ -131,6 +133,9 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) // вход, выход val container = MatteryContainer(this::setChangedLight, 3) + override val droppableContainer: Container + get() = container + private val itemHandler = LazyOptional.of { container.handler(object : MatteryContainerFilter { override fun canInsert(slot: Int, stack: ItemStack): Boolean { @@ -152,18 +157,14 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["container"] = container.serializeNBT() - nbt["matter"] = matter.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() + nbt[MATTER_STORAGE_KEY] = matter.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - - nbt.ifHas("matter", CompoundTag::class.java) { - matter.deserializeNBT(it) - } - - container.deserializeNBT(nbt["container"]) + nbt.map(INVENTORY_KEY, container::deserializeNBT) + nbt.map(MATTER_STORAGE_KEY, matter::deserializeNBT) } override fun reviveCaps() { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterPanelBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterPanelBlockEntity.kt index 6cd1340d2..26494ce9d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterPanelBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterPanelBlockEntity.kt @@ -209,4 +209,4 @@ class MatterPanelBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : companion object { private val MACHINE_NAME = TranslatableComponent("block.overdrive_that_matters.matter_panel") } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt index 286254d3a..4235177c1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt @@ -5,6 +5,7 @@ import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerLevel +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -14,6 +15,7 @@ import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.capability.MatteryCapability @@ -35,7 +37,7 @@ import ru.dbotthepony.mc.otm.container.set import ru.dbotthepony.mc.otm.core.set class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) - : MatteryWorkerBlockEntity(MBlockEntities.MATTER_RECYCLER, blockPos, blockState, ::Job), IMatterGraphNode { + : MatteryWorkerBlockEntity(MBlockEntities.MATTER_RECYCLER, blockPos, blockState, ::Job), IMatterGraphNode, IDroppableContainer { val matter = MatterHandlerImpl( this::matterLevelUpdated, @@ -44,6 +46,9 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) ) val container = MatteryContainer(this::itemContainerUpdated, 1) + + override val droppableContainer: Container + get() = container override val matterNode = Graph6Node(this) private var resolverNode = LazyOptional.of { this } private var valid = true @@ -91,14 +96,14 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["matter"] = matter.serializeNBT() - nbt["container"] = container.serializeNBT() + nbt[MATTER_STORAGE_KEY] = matter.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - nbt.map("matter", matter::deserializeNBT) - container.deserializeNBT(nbt["container"]) + nbt.map(MATTER_STORAGE_KEY, matter::deserializeNBT) + nbt.map(INVENTORY_KEY, container::deserializeNBT) } override fun getCapability(cap: Capability, side: Direction?): LazyOptional { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt index 125d88ee8..e8a4c89a5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt @@ -5,6 +5,7 @@ import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerLevel +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -14,6 +15,7 @@ import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage @@ -37,7 +39,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } catch(err: NoSuchElementException) { null } - }), IMatterGraphNode { + }), IMatterGraphNode, IDroppableContainer { class ReplicatorJob : ItemJob { val matterPerTick: ImpreciseFraction @@ -47,11 +49,11 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : val asDust: Boolean constructor(tag: CompoundTag) : super(tag) { - matterPerTick = tag.getImpreciseFraction("matterPerTick") - matterValue = tag.getImpreciseFraction("matterValue") - pattern = tag.map("pattern", PatternState::deserializeNBT) - asDust = tag.getBoolean("asDust") - task = tag.map("task", ReplicationTask::deserializeNBT) ?: throw NoSuchElementException("Unable to deserialize matter task") + matterPerTick = tag.getImpreciseFraction(MATTER_PER_TICK_KEY) + matterValue = tag.getImpreciseFraction(MATTER_VALUE_KEY) + pattern = tag.map(PATTERN_KEY, PatternState::deserializeNBT) + asDust = tag.getBoolean(AS_DUST_KEY) + task = tag.map(TASK_KEY, ReplicationTask::deserializeNBT) ?: throw NoSuchElementException("Unable to deserialize matter task") } constructor( @@ -72,16 +74,24 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : override fun serializeNBT(): CompoundTag { return super.serializeNBT().also { - it["matterPerTick"] = this.matterPerTick - it["task"] = this.task.serializeNBT() - it["matterValue"] = this.matterValue + it[MATTER_PER_TICK_KEY] = this.matterPerTick + it[TASK_KEY] = this.task.serializeNBT() + it[MATTER_VALUE_KEY] = this.matterValue if (this.pattern != null) - it["pattern"] = this.pattern.serializeNBT() + it[PATTERN_KEY] = this.pattern.serializeNBT() - it["asDust"] = this.asDust + it[AS_DUST_KEY] = this.asDust } } + + companion object { + const val MATTER_PER_TICK_KEY = "matterPerTick" + const val MATTER_VALUE_KEY = "matterValue" + const val PATTERN_KEY = "pattern" + const val AS_DUST_KEY = "asDust" + const val TASK_KEY = "task" + } } override val energy = WorkerEnergyStorage(this::powerLevelUpdated, STORAGE, MAX_IO) @@ -100,6 +110,9 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : override val defaultDisplayName: Component get() = MACHINE_NAME + override val droppableContainer: Container + get() = container + override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu { return MatterReplicatorMenu(containerID, inventory, this) } @@ -232,14 +245,14 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["container"] = container.serializeNBT() - nbt["matter"] = matter.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() + nbt[MATTER_STORAGE_KEY] = matter.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - container.deserializeNBT(nbt["container"]) - nbt.map("matter", matter::deserializeNBT) + nbt.map(INVENTORY_KEY, container::deserializeNBT) + nbt.map(MATTER_STORAGE_KEY, matter::deserializeNBT) } private var valid = true diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt index a604d99c4..85074774f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt @@ -5,6 +5,7 @@ import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerLevel +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -14,6 +15,7 @@ import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.capability.MatteryCapability @@ -23,6 +25,7 @@ import ru.dbotthepony.mc.otm.capability.matter.PatternState import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.MatteryContainerFilter import ru.dbotthepony.mc.otm.core.ImpreciseFraction +import ru.dbotthepony.mc.otm.core.map import ru.dbotthepony.mc.otm.graph.Graph6Node import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph @@ -32,7 +35,7 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities import java.util.* class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : - MatteryWorkerBlockEntity(MBlockEntities.MATTER_SCANNER, p_155229_, p_155230_, ::ItemJob), IMatterGraphNode { + MatteryWorkerBlockEntity(MBlockEntities.MATTER_SCANNER, p_155229_, p_155230_, ::ItemJob), IMatterGraphNode, IDroppableContainer { val container = MatteryContainer(this::itemContainerUpdated, 1) override val energy = WorkerEnergyStorage(this::powerLevelUpdated, STORAGE, MAX_IO) @@ -47,6 +50,9 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } }) + override val droppableContainer: Container + get() = container + // IMatterGraphNode override fun onPatternAdded(state: IPatternState) { if (idleReason == IdleReason.OBSERVING) { @@ -109,12 +115,12 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt.put("container", container.serializeNBT()) + nbt.put(INVENTORY_KEY, container.serializeNBT()) } override fun load(nbt: CompoundTag) { - container.deserializeNBT(nbt["container"]) super.load(nbt) + nbt.map(INVENTORY_KEY, container::deserializeNBT) } override fun onJobFinish(job: ItemJob): Status { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PatternStorageBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/PatternStorageBlockEntity.kt similarity index 90% rename from src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PatternStorageBlockEntity.kt rename to src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/PatternStorageBlockEntity.kt index 11e675fa4..07a081342 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/PatternStorageBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/PatternStorageBlockEntity.kt @@ -1,4 +1,4 @@ -package ru.dbotthepony.mc.otm.block.entity +package ru.dbotthepony.mc.otm.block.entity.matter import com.google.common.collect.Streams import javax.annotation.ParametersAreNonnullByDefault @@ -18,17 +18,20 @@ import net.minecraft.MethodsReturnNonnullByDefault import net.minecraft.core.Direction import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerLevel +import net.minecraft.world.Container import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.capabilities.ForgeCapabilities +import ru.dbotthepony.mc.otm.block.IDroppableContainer +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.capability.matter.* import ru.dbotthepony.mc.otm.core.iterator import ru.dbotthepony.mc.otm.graph.Graph6Node import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph -import ru.dbotthepony.mc.otm.core.ifHas +import ru.dbotthepony.mc.otm.core.map import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.core.set import java.util.ArrayList @@ -37,7 +40,7 @@ import java.util.stream.Stream @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : - MatteryBlockEntity(MBlockEntities.PATTERN_STORAGE, p_155229_, p_155230_), IMatterGraphNode, IPatternStorage { + MatteryBlockEntity(MBlockEntities.PATTERN_STORAGE, p_155229_, p_155230_), IMatterGraphNode, IPatternStorage, IDroppableContainer { override val matterNode = Graph6Node(this) private val resolverPatterns = LazyOptional.of { this } @@ -89,21 +92,21 @@ class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } private val resolverItem = - this.patternContainer.handler { slot: Int, stack: ItemStack -> stack.getCapability(MatteryCapability.PATTERN).isPresent } + patternContainer.handler { slot: Int, stack: ItemStack -> stack.getCapability(MatteryCapability.PATTERN).isPresent } override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["patterns"] = this.patternContainer.serializeNBT() + nbt[INVENTORY_KEY] = patternContainer.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - - nbt.ifHas("patterns") { - this.patternContainer.deserializeNBT(it) - } + nbt.map(INVENTORY_KEY, patternContainer::deserializeNBT) } + override val droppableContainer: Container + get() = patternContainer + override fun setLevel(p_155231_: Level) { super.setLevel(p_155231_) @@ -209,4 +212,4 @@ class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : companion object { private val MACHINE_NAME = TranslatableComponent("block.overdrive_that_matters.pattern_storage") } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveRackBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveRackBlockEntity.kt index eafe1d9d7..5c387641f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveRackBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveRackBlockEntity.kt @@ -20,9 +20,8 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.core.ImpreciseFraction -import ru.dbotthepony.mc.otm.core.ifHas import ru.dbotthepony.mc.otm.menu.DriveRackMenu -import ru.dbotthepony.mc.otm.container.set +import ru.dbotthepony.mc.otm.core.map import ru.dbotthepony.mc.otm.core.set import ru.dbotthepony.mc.otm.graph.storage.StorageNetworkGraph import ru.dbotthepony.mc.otm.registry.MBlockEntities @@ -32,8 +31,7 @@ class DriveRackBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.DRIVE_RACK, p_155229_, p_155230_) { override val energy = WorkerEnergyStorage(this, STORAGE) - @JvmField - val drives: MatteryContainer = object : MatteryContainer(this::setChanged, 4) { + val container: MatteryContainer = object : MatteryContainer(this::setChanged, 4) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { super.setChanged(slot, new, old) @@ -55,15 +53,12 @@ class DriveRackBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : override fun load(nbt: CompoundTag) { super.load(nbt) - - nbt.ifHas("drives", CompoundTag::class.java) { - drives.deserializeNBT(it) - } + nbt.map(INVENTORY_KEY, container::deserializeNBT) } override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["drives"] = drives.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() } override fun setLevel(p_155231_: Level) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveViewerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveViewerBlockEntity.kt index 015fac0e0..07514187d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveViewerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveViewerBlockEntity.kt @@ -4,6 +4,7 @@ import net.minecraft.MethodsReturnNonnullByDefault import net.minecraft.core.BlockPos import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component +import net.minecraft.world.Container import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -11,6 +12,7 @@ import net.minecraft.world.item.ItemStack import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.state.BlockState import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.storage.DriveViewerBlock @@ -21,12 +23,11 @@ import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.menu.DriveViewerMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.container.set +import ru.dbotthepony.mc.otm.core.map import ru.dbotthepony.mc.otm.core.set import javax.annotation.ParametersAreNonnullByDefault -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -class DriveViewerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.DRIVE_VIEWER, p_155229_, p_155230_) { +class DriveViewerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.DRIVE_VIEWER, p_155229_, p_155230_), IDroppableContainer { override fun setChanged() { super.setChanged() @@ -47,7 +48,6 @@ class DriveViewerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte override val energy = WorkerEnergyStorage(this) - @JvmField val container: MatteryContainer = object : MatteryContainer(this::setChanged, 1) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { super.setChanged(slot, new, old) @@ -70,6 +70,8 @@ class DriveViewerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte } } + override val droppableContainer: Container + get() = container override val defaultDisplayName: Component get() = MACHINE_NAME @@ -79,13 +81,12 @@ class DriveViewerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["container"] = container.serializeNBT() + nbt[INVENTORY_KEY] = container.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - - container.deserializeNBT(nbt["container"]) + nbt.map(INVENTORY_KEY, container::deserializeNBT) } fun tick() { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt index 44f88858b..8ec1acecd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt @@ -40,6 +40,7 @@ import ru.dbotthepony.mc.otm.menu.ItemMonitorMenu import ru.dbotthepony.mc.otm.network.MatteryPacket import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.container.set +import ru.dbotthepony.mc.otm.core.getEnum import ru.dbotthepony.mc.otm.core.set import ru.dbotthepony.mc.otm.storage.* import java.math.BigInteger @@ -48,7 +49,7 @@ import java.util.function.Supplier import kotlin.collections.HashMap class ItemMonitorPlayerSettings : INBTSerializable, MatteryPacket { - enum class RefillSource(val component: Component) { + enum class IngredientPriority(val component: Component) { // Refill everything from system SYSTEM(TranslatableComponent("otm.gui.item_monitor.refill_source.system")), @@ -83,38 +84,38 @@ class ItemMonitorPlayerSettings : INBTSerializable, MatteryPacket { FULL(TranslatableComponent("otm.gui.item_monitor.amount.full")) } - var refillSource = RefillSource.SYSTEM + var ingredientPriority = IngredientPriority.SYSTEM var resultTarget = ResultTarget.MIXED var craftingAmount = Amount.STACK override fun serializeNBT(): CompoundTag { return CompoundTag().also { - it["ingredientPriority"] = refillSource.name - it["resultTarget"] = resultTarget.name - it["craftingAmount"] = craftingAmount.name + it[INGREDIENT_PRIORITY_KEY] = ingredientPriority.name + it[RESULT_TARGET_KEY] = resultTarget.name + it[QUICK_CRAFT_AMOUNT_KEY] = craftingAmount.name } } override fun deserializeNBT(nbt: CompoundTag) { - nbt.ifHas("ingredientPriority", StringTag::class.java) { refillSource = RefillSource.valueOf(it.asString) } - nbt.ifHas("resultTarget", StringTag::class.java) { resultTarget = ResultTarget.valueOf(it.asString) } - nbt.ifHas("craftingAmount", StringTag::class.java) { craftingAmount = Amount.valueOf(it.asString) } + ingredientPriority = nbt.getEnum(INGREDIENT_PRIORITY_KEY) + resultTarget = nbt.getEnum(RESULT_TARGET_KEY) + craftingAmount = nbt.getEnum(QUICK_CRAFT_AMOUNT_KEY) } fun read(buff: FriendlyByteBuf) { - refillSource = buff.readEnum(RefillSource::class.java) + ingredientPriority = buff.readEnum(IngredientPriority::class.java) resultTarget = buff.readEnum(ResultTarget::class.java) craftingAmount = buff.readEnum(Amount::class.java) } fun read(other: ItemMonitorPlayerSettings) { - refillSource = other.refillSource + ingredientPriority = other.ingredientPriority resultTarget = other.resultTarget craftingAmount = other.craftingAmount } override fun write(buff: FriendlyByteBuf) { - buff.writeEnum(refillSource) + buff.writeEnum(ingredientPriority) buff.writeEnum(resultTarget) buff.writeEnum(craftingAmount) } @@ -149,6 +150,9 @@ class ItemMonitorPlayerSettings : INBTSerializable, MatteryPacket { } private val LOGGER = LogManager.getLogger() + const val INGREDIENT_PRIORITY_KEY = "ingredientPriority" + const val RESULT_TARGET_KEY = "resultTarget" + const val QUICK_CRAFT_AMOUNT_KEY = "quickCraftAmount" } } @@ -336,22 +340,22 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : var newItem = craftingGrid[slot] if (newItem.isEmpty) { - when (settings.refillSource) { - ItemMonitorPlayerSettings.RefillSource.SYSTEM -> { + when (settings.ingredientPriority) { + ItemMonitorPlayerSettings.IngredientPriority.SYSTEM -> { if (poweredView != null && takeOne(craftingGridTuples[slot], poweredView!!)) { newItem = oldItem craftingGrid[slot] = newItem } } - ItemMonitorPlayerSettings.RefillSource.INVENTORY -> { + ItemMonitorPlayerSettings.IngredientPriority.INVENTORY -> { if (takeOne(craftingPlayer.inventory, oldItem)) { newItem = oldItem craftingGrid[slot] = newItem } } - ItemMonitorPlayerSettings.RefillSource.SYSTEM_FIRST -> { + ItemMonitorPlayerSettings.IngredientPriority.SYSTEM_FIRST -> { if (poweredView != null && takeOne(craftingGridTuples[slot], poweredView!!)) { newItem = oldItem craftingGrid[slot] = newItem @@ -363,7 +367,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } } - ItemMonitorPlayerSettings.RefillSource.INVENTORY_FIRST -> { + ItemMonitorPlayerSettings.IngredientPriority.INVENTORY_FIRST -> { if (takeOne(craftingPlayer.inventory, oldItem)) { newItem = oldItem craftingGrid[slot] = newItem @@ -373,7 +377,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } } - ItemMonitorPlayerSettings.RefillSource.DO_NOT -> { /* no op */ } + ItemMonitorPlayerSettings.IngredientPriority.DO_NOT -> { /* no op */ } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageBusBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageBusBlockEntity.kt index 1ba36b88d..3b862a104 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageBusBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageBusBlockEntity.kt @@ -15,13 +15,14 @@ import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.capabilities.Capability +import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional -import net.minecraftforge.items.CapabilityItemHandler import net.minecraftforge.items.IItemHandler import ru.dbotthepony.mc.otm.* import ru.dbotthepony.mc.otm.block.CableBlock import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity +import ru.dbotthepony.mc.otm.block.entity.storage.AbstractStorageImportExport.Companion.FILTER_KEY import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.WorkerEnergyStorage import ru.dbotthepony.mc.otm.container.ItemFilter @@ -137,14 +138,12 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - - nbt["filter"] = filter.serializeNBT() + nbt[FILTER_KEY] = filter.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - - nbt.ifHas("filter", CompoundTag::class.java, filter::deserializeNBT) + nbt.map(FILTER_KEY, filter::deserializeNBT) } fun checkSurroundings() { @@ -152,7 +151,7 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter return val front = blockPos + blockState.getValue(RotatableMatteryBlock.FACING_FULL) - val storage = level?.getBlockEntity(front)?.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, -blockState.getValue(RotatableMatteryBlock.FACING_FULL))?.let { if (it.isPresent) it else null } + val storage = level?.getBlockEntity(front)?.getCapability(ForgeCapabilities.ITEM_HANDLER, -blockState.getValue(RotatableMatteryBlock.FACING_FULL))?.let { if (it.isPresent) it else null } if (neighbour != storage) { neighbour = storage diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt index a2a63c5ff..bc1838690 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt @@ -14,6 +14,7 @@ import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.capabilities.Capability +import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.util.LazyOptional import net.minecraftforge.items.CapabilityItemHandler import net.minecraftforge.items.IItemHandler @@ -112,8 +113,21 @@ abstract class AbstractStorageImportExport( ) { tickOnceServer(this::checkSurroundings) } } + abstract val filter: ItemFilter + + override fun saveAdditional(nbt: CompoundTag) { + super.saveAdditional(nbt) + nbt[FILTER_KEY] = filter.serializeNBT() + } + + override fun load(nbt: CompoundTag) { + super.load(nbt) + nbt.map(FILTER_KEY, filter::deserializeNBT) + } + companion object { val MAX_POWER = ImpreciseFraction(10_000) + const val FILTER_KEY = "filter" } } @@ -123,7 +137,7 @@ class StorageImporterBlockEntity(blockPos: BlockPos, blockState: BlockState) override val defaultDisplayName: Component get() = MACHINE_NAME - val filter = ItemFilter(MAX_FILTERS) { _, _, _ -> + override val filter = ItemFilter(MAX_FILTERS) { _, _, _ -> setChangedLight() } @@ -137,19 +151,7 @@ class StorageImporterBlockEntity(blockPos: BlockPos, blockState: BlockState) private val enoughEnergy get() = energy.batteryLevel >= ITEM_STORAGE.energyPerOperation override val targetCapability: Capability - get() = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY - - override fun saveAdditional(nbt: CompoundTag) { - super.saveAdditional(nbt) - - nbt["filter"] = filter.serializeNBT() - } - - override fun load(nbt: CompoundTag) { - super.load(nbt) - - nbt.ifHas("filter", CompoundTag::class.java, filter::deserializeNBT) - } + get() = ForgeCapabilities.ITEM_HANDLER private var valid = true private var resolverItemHandler = LazyOptional.of { this } @@ -167,7 +169,7 @@ class StorageImporterBlockEntity(blockPos: BlockPos, blockState: BlockState) } override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - if (valid && cap === CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && side == blockState.getValue(RotatableMatteryBlock.FACING_FULL)) { + if (valid && cap == ForgeCapabilities.ITEM_HANDLER && side == blockState.getValue(RotatableMatteryBlock.FACING_FULL)) { return resolverItemHandler.cast() } @@ -295,7 +297,7 @@ class StorageExporterBlockEntity(blockPos: BlockPos, blockState: BlockState) : relevantTuples.remove(id) } - val filter = ItemFilter(MAX_FILTERS) { _, _, _ -> + override val filter = ItemFilter(MAX_FILTERS) { _, _, _ -> relevantTuples.clear() val component = cell.storageGraph?.getVirtualComponent(ITEM_STORAGE) ?: return@ItemFilter @@ -314,7 +316,7 @@ class StorageExporterBlockEntity(blockPos: BlockPos, blockState: BlockState) : private val enoughEnergy get() = energy.batteryLevel >= ITEM_STORAGE.energyPerOperation override val targetCapability: Capability - get() = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY + get() = ForgeCapabilities.ITEM_HANDLER private val exportStacks: Stream> get() { @@ -322,18 +324,6 @@ class StorageExporterBlockEntity(blockPos: BlockPos, blockState: BlockState) : return relevantTuples.stream().map { it to view[it] } } - override fun saveAdditional(nbt: CompoundTag) { - super.saveAdditional(nbt) - - nbt["filter"] = filter.serializeNBT() - } - - override fun load(nbt: CompoundTag) { - super.load(nbt) - - nbt.ifHas("filter", CompoundTag::class.java, filter::deserializeNBT) - } - fun tick() { batteryChargeLoop() cell.tickEnergyDemanding() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StoragePowerSupplierBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StoragePowerSupplierBlockEntity.kt index 499b66901..659ae0184 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StoragePowerSupplierBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StoragePowerSupplierBlockEntity.kt @@ -24,7 +24,7 @@ import ru.dbotthepony.mc.otm.graph.storage.StorageNetworkGraph import ru.dbotthepony.mc.otm.menu.StoragePowerSupplierMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MNames -import ru.dbotthepony.mc.otm.container.set +import ru.dbotthepony.mc.otm.core.getImpreciseFraction import ru.dbotthepony.mc.otm.core.set class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.STORAGE_POWER_SUPPLIER, blockPos, blockState) { @@ -37,7 +37,7 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState val cell = BasicStorageGraphNode() - var powerSupplied = ImpreciseFraction.ZERO + var powerPassed = ImpreciseFraction.ZERO private set override fun setLevel(p_155231_: Level) { @@ -103,13 +103,13 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState return } else if (demand < available) { for (demanding in graph.powerDemandingNodes) { - powerSupplied += energy.transferInner(demanding, available, false) + powerPassed += energy.transferInner(demanding, available, false) } } else { val forEach = available / i for (demanding in graph.powerDemandingNodes) { - powerSupplied += energy.transferInner(demanding, forEach, false) + powerPassed += energy.transferInner(demanding, forEach, false) } } } @@ -118,17 +118,18 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState override fun saveAdditional(nbt: CompoundTag) { super.saveAdditional(nbt) - nbt["power_supplied"] = powerSupplied.serializeNBT() + nbt[POWER_PASSED_KEY] = powerPassed.serializeNBT() } override fun load(nbt: CompoundTag) { super.load(nbt) - nbt["power_supplied"]?.let { powerSupplied = ImpreciseFraction.deserializeNBT(it) } + powerPassed = nbt.getImpreciseFraction(POWER_PASSED_KEY) } companion object { private val MACHINE_NAME = TranslatableComponent("block.${OverdriveThatMatters.MOD_ID}.${MNames.STORAGE_POWER_SUPPLIER}") private val MAX_POWER = ImpreciseFraction(100_000) private val MAX_IO = ImpreciseFraction(320) + const val POWER_PASSED_KEY = "powerPassed" } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterBottlerBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterBottlerBlock.kt index e6542499d..d81a21840 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterBottlerBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterBottlerBlock.kt @@ -1,30 +1,26 @@ package ru.dbotthepony.mc.otm.block.matter -import net.minecraft.MethodsReturnNonnullByDefault -import javax.annotation.ParametersAreNonnullByDefault -import net.minecraft.world.level.block.EntityBlock import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block -import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.EntityBlock import net.minecraft.world.level.block.entity.BlockEntity -import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity -import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.entity.BlockEntityTicker +import net.minecraft.world.level.block.entity.BlockEntityType +import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateDefinition import net.minecraft.world.level.block.state.properties.BooleanProperty import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault class MatterBottlerBlock : RotatableMatteryBlock(), EntityBlock { override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? { return MatterBottlerBlockEntity(blockPos, blockState) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/PatternStorageBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/PatternStorageBlock.kt index 7df2879e5..5bdcb39ea 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/PatternStorageBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/PatternStorageBlock.kt @@ -2,8 +2,10 @@ package ru.dbotthepony.mc.otm.block.matter import net.minecraft.core.BlockPos import net.minecraft.core.Direction +import net.minecraft.world.Containers import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.level.BlockGetter +import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.EntityBlock import net.minecraft.world.level.block.entity.BlockEntity @@ -13,7 +15,7 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock -import ru.dbotthepony.mc.otm.block.entity.PatternStorageBlockEntity +import ru.dbotthepony.mc.otm.block.entity.matter.PatternStorageBlockEntity import ru.dbotthepony.mc.otm.shapes.BlockShapes class PatternStorageBlock : RotatableMatteryBlock(), EntityBlock { @@ -35,6 +37,25 @@ class PatternStorageBlock : RotatableMatteryBlock(), EntityBlock { return state } + override fun onRemove( + oldBlockState: BlockState, + level: Level, + blockPos: BlockPos, + newBlockState: BlockState, + movedByPiston: Boolean + ) { + if (!oldBlockState.`is`(newBlockState.block)) { + val blockentity = level.getBlockEntity(blockPos) + + if (blockentity is PatternStorageBlockEntity) { + Containers.dropContents(level, blockPos, blockentity.patternContainer) + level.updateNeighbourForOutputSignal(blockPos, this) + } + } + + super.onRemove(oldBlockState, level, blockPos, newBlockState, movedByPiston) + } + override fun getShape( p_60555_: BlockState, p_60556_: BlockGetter, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ItemMonitorScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ItemMonitorScreen.kt index be83c64fb..f862e8c45 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ItemMonitorScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/ItemMonitorScreen.kt @@ -126,17 +126,17 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp val arrowLine = EditablePanel(this, arrowAndButtons, y = 38f, height = 8f, width = arrowAndButtons.width) val refillPriority = SmallEnumSquareButtonPanel(this, arrowLine, - enum = ItemMonitorPlayerSettings.RefillSource::class.java, - prop = menu.settings::refillSource, - defaultValue = ItemMonitorPlayerSettings.RefillSource.SYSTEM, + enum = ItemMonitorPlayerSettings.IngredientPriority::class.java, + prop = menu.settings::ingredientPriority, + defaultValue = ItemMonitorPlayerSettings.IngredientPriority.SYSTEM, onChange = { menu.sendSettingsToServer() }) refillPriority.mainTooltip = TranslatableComponent("otm.gui.item_monitor.refill_source.desc") - refillPriority.add(ItemMonitorPlayerSettings.RefillSource.SYSTEM, ItemMonitorPlayerSettings.RefillSource.SYSTEM.component, Widgets8.WHITE_ARROW_DOWN, UVWindingOrder.FLIP) - refillPriority.add(ItemMonitorPlayerSettings.RefillSource.INVENTORY, ItemMonitorPlayerSettings.RefillSource.INVENTORY.component, Widgets8.WHITE_ARROW_DOWN) - refillPriority.add(ItemMonitorPlayerSettings.RefillSource.INVENTORY_FIRST, ItemMonitorPlayerSettings.RefillSource.INVENTORY_FIRST.component, Widgets8.ARROW_SIDEWAYS, UVWindingOrder.FLIP) - refillPriority.add(ItemMonitorPlayerSettings.RefillSource.SYSTEM_FIRST, ItemMonitorPlayerSettings.RefillSource.SYSTEM_FIRST.component, Widgets8.ARROW_SIDEWAYS) - refillPriority.add(ItemMonitorPlayerSettings.RefillSource.DO_NOT, ItemMonitorPlayerSettings.RefillSource.DO_NOT.component, Widgets8.MINUS) + refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.SYSTEM, ItemMonitorPlayerSettings.IngredientPriority.SYSTEM.component, Widgets8.WHITE_ARROW_DOWN, UVWindingOrder.FLIP) + refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.INVENTORY, ItemMonitorPlayerSettings.IngredientPriority.INVENTORY.component, Widgets8.WHITE_ARROW_DOWN) + refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.INVENTORY_FIRST, ItemMonitorPlayerSettings.IngredientPriority.INVENTORY_FIRST.component, Widgets8.ARROW_SIDEWAYS, UVWindingOrder.FLIP) + refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.SYSTEM_FIRST, ItemMonitorPlayerSettings.IngredientPriority.SYSTEM_FIRST.component, Widgets8.ARROW_SIDEWAYS) + refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.DO_NOT, ItemMonitorPlayerSettings.IngredientPriority.DO_NOT.component, Widgets8.MINUS) refillPriority.dock = Dock.LEFT diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/CompoundTagExt.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/CompoundTagExt.kt index 7a9575472..2571fc42e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/CompoundTagExt.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/CompoundTagExt.kt @@ -41,8 +41,8 @@ fun CompoundTag.contains(vararg keys: String): Boolean { return true } -inline fun CompoundTag.map(s: String, consumer: (T) -> R): R? { - val tag = get(s) +inline fun CompoundTag.map(key: String, consumer: (T) -> R): R? { + val tag = get(key) if (tag is T) { return consumer(tag) @@ -51,6 +51,16 @@ inline fun CompoundTag.map(s: String, consumer: (T) -> R): return null } +inline fun > CompoundTag.getEnum(key: String): R { + val tag = get(key) + + if (tag is StringTag) { + return R::class.java.enumConstants.first { it.name == tag.asString } + } + + return R::class.java.enumConstants[0] +} + fun CompoundTag.getItemStack(key: String): ItemStack = map(key, ItemStack::of) ?: ItemStack.EMPTY inline fun CompoundTag.ifHas(s: String, consumer: (Tag) -> Unit) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ChemicalGeneratorMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ChemicalGeneratorMenu.kt index 7f0433b01..11dbdd27a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ChemicalGeneratorMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/ChemicalGeneratorMenu.kt @@ -33,7 +33,7 @@ class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, t } } - val progress = ProgressGaugeWidget(this) { 1f - tile!!.workingTicks.toFloat() / tile.workingTicksTotal } + val progress = ProgressGaugeWidget(this) { 1f - tile!!.workTicks.toFloat() / tile.workTicksTotal } val energy = LevelGaugeWidget(this, tile?.energy) var burnTime by mSynchronizer.int() @@ -50,6 +50,6 @@ class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, t override fun broadcastChanges() { super.broadcastChanges() progress.updateServer() - burnTime = (tile as ChemicalGeneratorBlockEntity).workingTicks + burnTime = (tile as ChemicalGeneratorBlockEntity).workTicks } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/DriveRackMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/DriveRackMenu.kt index c65d34795..7b31075c2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/DriveRackMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/DriveRackMenu.kt @@ -2,7 +2,6 @@ package ru.dbotthepony.mc.otm.menu import net.minecraft.world.SimpleContainer import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.inventory.Slot import ru.dbotthepony.mc.otm.core.ImmutableList import ru.dbotthepony.mc.otm.block.entity.storage.DriveRackBlockEntity import ru.dbotthepony.mc.otm.registry.MMenus @@ -15,7 +14,7 @@ class DriveRackMenu @JvmOverloads constructor( override val storageSlots: List init { - val container = tile?.drives ?: SimpleContainer(4) + val container = tile?.container ?: SimpleContainer(4) storageSlots = ImmutableList(4) { val slot = DriveSlot(container, it) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatterBottlerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatterBottlerMenu.kt index 242a84bb4..afca430f3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatterBottlerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatterBottlerMenu.kt @@ -2,7 +2,6 @@ package ru.dbotthepony.mc.otm.menu import net.minecraft.world.SimpleContainer import net.minecraft.world.entity.player.Inventory -import net.minecraft.world.inventory.Slot import net.minecraft.world.item.ItemStack import ru.dbotthepony.mc.otm.core.ImmutableList import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity @@ -37,7 +36,7 @@ class MatterBottlerMenu @JvmOverloads constructor( } else { progressWidget = ProgressGaugeWidget(this) { tile.getWorkProgress() } matterWidget = LevelGaugeWidget(this, tile.matter) - workFlow = BooleanPlayerInputWidget(this, tile::workFlow) + workFlow = BooleanPlayerInputWidget(this, tile::isBottling) } storageSlots = ImmutableList(6) { index -> @@ -60,6 +59,6 @@ class MatterBottlerMenu @JvmOverloads constructor( override fun broadcastChanges() { super.broadcastChanges() - workFlow.value = (tile as MatterBottlerBlockEntity).workFlow + workFlow.value = (tile as MatterBottlerBlockEntity).isBottling } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/PatternStorageMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/PatternStorageMenu.kt index 07498acdd..d78250a82 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/PatternStorageMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/PatternStorageMenu.kt @@ -3,7 +3,7 @@ package ru.dbotthepony.mc.otm.menu import net.minecraft.world.SimpleContainer import net.minecraft.world.entity.player.Inventory import ru.dbotthepony.mc.otm.core.ImmutableList -import ru.dbotthepony.mc.otm.block.entity.PatternStorageBlockEntity +import ru.dbotthepony.mc.otm.block.entity.matter.PatternStorageBlockEntity import ru.dbotthepony.mc.otm.core.ImpreciseFraction import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StoragePowerSupplierMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StoragePowerSupplierMenu.kt index 8a9d8971c..0e7483177 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StoragePowerSupplierMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StoragePowerSupplierMenu.kt @@ -19,7 +19,7 @@ class StoragePowerSupplierMenu @JvmOverloads constructor( override fun broadcastChanges() { if (tile is StoragePowerSupplierBlockEntity) { - totalTransferred = tile.powerSupplied + totalTransferred = tile.powerPassed activeNodes = tile.cell.storageGraph?.powerDemandingNodes?.size ?: 0 } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockEntities.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockEntities.kt index f3f4f181a..e9ae3b22c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockEntities.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockEntities.kt @@ -4,7 +4,6 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderers import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraftforge.eventbus.api.IEventBus import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.ForgeRegistries import ru.dbotthepony.mc.otm.OverdriveThatMatters