From 5ea0b649827d5119e0e0e0e8a771a9b2c1692f1c Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Tue, 4 Mar 2025 14:15:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83?= =?UTF-8?q?=D1=80=D0=B0=D1=82=D0=BE=D1=80=20=D0=B4=D0=BB=D1=8F=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5=D0=BA=20#341?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mc/otm/datagen/items/ItemModels.kt | 11 ++ .../mc/otm/datagen/lang/English.kt | 11 ++ .../mc/otm/datagen/lang/Russian.kt | 11 ++ .../mc/otm/block/entity/MatteryBlockEntity.kt | 15 +++ .../block/entity/MatteryDeviceBlockEntity.kt | 20 ++-- .../block/entity/MatteryWorkerBlockEntity.kt | 2 +- .../BlackHoleGeneratorBlockEntity.kt | 6 +- .../entity/decorative/HoloSignBlockEntity.kt | 14 +-- .../entity/decorative/PainterBlockEntity.kt | 2 +- .../entity/matter/MatterBottlerBlockEntity.kt | 4 +- .../entity/matter/MatterPanelBlockEntity.kt | 2 +- .../entity/storage/DriveRackBlockEntity.kt | 6 +- .../entity/storage/StorageBusBlockEntity.kt | 2 +- .../block/entity/storage/StorageInterfaces.kt | 2 +- .../entity/tech/EnergyCounterBlockEntity.kt | 2 +- .../mc/otm/item/ConfiguratorItem.kt | 111 ++++++++++++++++++ .../ru/dbotthepony/mc/otm/registry/MNames.kt | 1 + .../dbotthepony/mc/otm/registry/MRegistry.kt | 7 ++ .../mc/otm/registry/game/MCreativeTabs.kt | 1 + .../otm/registry/game/MDataComponentTypes.kt | 33 ++++++ .../mc/otm/registry/game/MItems.kt | 3 + .../ru/dbotthepony/mc/otm/server/Ext.kt | 9 ++ .../textures/item/configurator.png | Bin 0 -> 2677 bytes .../textures/item/configurator_ready.png | Bin 0 -> 2679 bytes 24 files changed, 244 insertions(+), 31 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/item/ConfiguratorItem.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/server/Ext.kt create mode 100644 src/main/resources/assets/overdrive_that_matters/textures/item/configurator.png create mode 100644 src/main/resources/assets/overdrive_that_matters/textures/item/configurator_ready.png diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/items/ItemModels.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/items/ItemModels.kt index f071a31a6..1c4bc7248 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/items/ItemModels.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/items/ItemModels.kt @@ -114,6 +114,17 @@ fun addItemModels(provider: MatteryItemModelProvider) { provider.handheld(MItems.CHEST_UPGRADER) + provider.exec { + val path = MItems.CONFIGURATOR.registryName!!.path + + val ready = provider.withExistingParent("${path}_ready", MatteryItemModelProvider.HANDHELD) + .texture("layer0", modLocation("item/${path}_ready")) + + provider.withExistingParent(path, MatteryItemModelProvider.HANDHELD) + .texture("layer0", modLocation("item/$path")) + .override().predicate(modLocation("has_configuration_saved"), 1f).model(ready).end() + } + provider.generated(MItems.BREAD_MONSTER_SPAWN_EGG, modLocation("item/egg/bread_monster")) provider.generated(MItems.LOADER_SPAWN_EGG, modLocation("item/egg/loader")) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt index 35455c300..77f5db3cb 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt @@ -924,6 +924,12 @@ private fun items(provider: MatteryLanguageProvider) { add(MItems.CHEST_UPGRADER, "desc", "Replaces placed chests and barrels with cargo crates while keeping storage contents") add(MItems.CHEST_UPGRADER, "desc2", "Hold desired crates in the opposite hand") + add(MItems.CONFIGURATOR, "Configurator") + add(MItems.CONFIGURATOR, "desc", "Copies configuration from one block to another") + add(MItems.CONFIGURATOR, "desc2", "Sneak-use on block to copy, use to paste") + add(MItems.CONFIGURATOR, "desc3", "Use on air while sneaking to clear saved configuration") + add(MItems.CONFIGURATOR, "desc_saved", "Saved configuration for: %s") + add(MItems.BREAD_MONSTER_SPAWN_EGG, "Bread Monster Spawn Egg") add(MEntityTypes.BREAD_MONSTER, "Bread Monster") @@ -981,6 +987,11 @@ private fun gui(provider: MatteryLanguageProvider) { gui("flow_direction_set", "Flow direction set to %s") gui("tick_timer_set", "Timer set to %s ticks") + gui("config_copied", "Copied configuration for %s") + gui("config_pasted", "Applied saved configuration") + gui("config_cleared", "Configuration cleared") + gui("config_missing", "No configuration to apply") + gui("black_hole_generator.help0", "Generates energy using angular momentum of Singularities") gui("black_hole_generator.help1", "The stronger gravity Singularity has, the more power is generated!") gui("black_hole_generator.help2", "Using Spacetime Normalizers will reduce gravitation strength of Singularity, which will reduce power output.") diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt index f0bb29256..48235c695 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt @@ -917,6 +917,12 @@ private fun items(provider: MatteryLanguageProvider) { add(MItems.CHEST_UPGRADER, "desc", "Заменяет установленные сундуки и бочки грузовыми ящиками с сохранением содержимого") add(MItems.CHEST_UPGRADER, "desc2", "Удерживайте необходимые ящики в противоположной руке") + add(MItems.CONFIGURATOR, "Конфигуратор") + add(MItems.CONFIGURATOR, "desc", "Копирует настройки между блоками") + add(MItems.CONFIGURATOR, "desc2", "Использование крадясь на блоке копирует настройки, простое использование применяет") + add(MItems.CONFIGURATOR, "desc3", "Используйте крадясь на воздухе для очистки") + add(MItems.CONFIGURATOR, "desc_saved", "Сохранены настройки для: %s") + add(MItems.BREAD_MONSTER_SPAWN_EGG, "Яйцо призыва хлебного монстра") add(MEntityTypes.BREAD_MONSTER, "Хлебный монстр") @@ -974,6 +980,11 @@ private fun gui(provider: MatteryLanguageProvider) { gui("flow_direction_set", "Направление потока установлено на %s") gui("tick_timer_set", "Таймер установлен на %s тиков") + gui("config_copied", "Скопированы настройки для %s") + gui("config_pasted", "Настройки применены") + gui("config_cleared", "Настройки очищены") + gui("config_missing", "Нет настроек для применения") + gui("black_hole_generator.help0", "Генерирует электричество используя угловое ускорение сингулярностей") gui("black_hole_generator.help1", "Чем сильнее гравитационное поле сингулярности, тем больше генерация!") gui("black_hole_generator.help2", "Использование стабилизаторов пространства-времени ослабляет гравитационное поле, снижая генерацию") 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 40941bf09..ab8ad4363 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 @@ -96,6 +96,11 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc */ protected val savetablesLevel = Savetables() + /** + * Savetables for things configured from user input + */ + protected val savetablesConfig = Savetables() + /** * "shortcut" for getting [BlockRotation] * @@ -269,6 +274,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc */ open fun saveShared(nbt: CompoundTag, registry: Provider) { savetables.serializeNBT(nbt, registry) + saveConfiguration(nbt, registry) } /** @@ -282,6 +288,15 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc super.loadAdditional(nbt, registry) savetables.deserializeNBT(registry, nbt) savetablesLevel.deserializeNBT(registry, nbt) + loadConfiguration(nbt, registry) + } + + fun saveConfiguration(nbt: CompoundTag, registry: Provider) { + savetablesConfig.serializeNBT(nbt, registry) + } + + fun loadConfiguration(nbt: CompoundTag, registry: Provider) { + savetablesConfig.deserializeNBT(registry, nbt) } @Suppress("OVERRIDE_DEPRECATION") diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryDeviceBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryDeviceBlockEntity.kt index 71085dd64..4580fcefe 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryDeviceBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryDeviceBlockEntity.kt @@ -56,7 +56,7 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo } init { - savetables.stateful(::redstoneControl, REDSTONE_CONTROL_KEY) + savetablesConfig.stateful(::redstoneControl, REDSTONE_CONTROL_KEY) } protected open val defaultDisplayName: Component @@ -146,9 +146,9 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo init { // https://tenor.com/view/simp-metal-gear-liquid-snake-running-gif-16717852 - savetables.enum(::flow, "fluid_${side}_flow", FlowDirection::valueOf) - savetables.bool(::automatePull, "fluid_${side}_pull") - savetables.bool(::automatePush, "fluid_${side}_push") + savetablesConfig.enum(::flow, "fluid_${side}_flow", FlowDirection::valueOf) + savetablesConfig.bool(::automatePull, "fluid_${side}_pull") + savetablesConfig.bool(::automatePush, "fluid_${side}_push") } var flow by syncher.enum(possibleModes, setter = { access, value -> @@ -375,9 +375,9 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo } init { - savetables.enum(::energyFlow, "energy_${side}_flow", FlowDirection::valueOf) - savetables.bool(::automatePull, "energy_${side}_pull") - savetables.bool(::automatePush, "energy_${side}_push") + savetablesConfig.enum(::energyFlow, "energy_${side}_flow", FlowDirection::valueOf) + savetablesConfig.bool(::automatePull, "energy_${side}_pull") + savetablesConfig.bool(::automatePush, "energy_${side}_push") dirtyListeners.addListener(Runnable { updateTickerState() @@ -626,9 +626,9 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo } init { - savetables.bool(::automatePull, "itemhandler_${side}_automatePull") - savetables.bool(::automatePush, "itemhandler_${side}_automatePush") - savetables.enum(::mode, "itemhandler_${side}_mode", ItemHandlerMode::valueOf) + savetablesConfig.bool(::automatePull, "itemhandler_${side}_automatePull") + savetablesConfig.bool(::automatePush, "itemhandler_${side}_automatePush") + savetablesConfig.enum(::mode, "itemhandler_${side}_mode", ItemHandlerMode::valueOf) waitForServerLevel { redstoneControl.addListener(::updateTickerState) 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 7b207ba54..4df7cc662 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 @@ -73,7 +73,7 @@ abstract class MatteryWorkerBlockEntity( var balanceInputs = false init { - savetables.bool(::balanceInputs) + savetablesConfig.bool(::balanceInputs) } protected open fun jobUpdated(new: JobType?, old: JobType?, id: Int) {} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleGeneratorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleGeneratorBlockEntity.kt index 2c3ab16f5..84c9bba76 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleGeneratorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleGeneratorBlockEntity.kt @@ -118,9 +118,9 @@ class BlackHoleGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) exposeSideless(MatteryCapability.BLOCK_ENERGY, energy) exposeSideless(Capabilities.EnergyStorage.BLOCK, energy) - savetables.enum(::mode, map = Mode::valueOf) - savetables.decimal(::injectionRate) - savetables.decimal(::targetMass) + savetablesConfig.enum(::mode, map = Mode::valueOf) + savetablesConfig.decimal(::injectionRate) + savetablesConfig.decimal(::targetMass) } private fun findBlackHoleRange(): Int { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt index e6125efa4..02062bea9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt @@ -64,16 +64,16 @@ class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryB var isLocked = false init { - savetables.string(::signText) + savetablesConfig.string(::signText) savetablesLevel.bool(::isLocked) - savetables.stateful(::redstoneControl) + savetablesConfig.stateful(::redstoneControl) - savetables.float(::textRed) - savetables.float(::textGreen) - savetables.float(::textBlue) - savetables.float(::textAlpha) + savetablesConfig.float(::textRed) + savetablesConfig.float(::textGreen) + savetablesConfig.float(::textBlue) + savetablesConfig.float(::textAlpha) - savetables.bool(::textAutoScale) + savetablesConfig.bool(::textAutoScale) } override fun createMenu(p_39954_: Int, p_39955_: Inventory, p_39956_: Player): AbstractContainerMenu { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/PainterBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/PainterBlockEntity.kt index 94311cead..59733f0ed 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/PainterBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/PainterBlockEntity.kt @@ -82,7 +82,7 @@ class PainterBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryDe init { addDroppableContainer(dyeInput) savetables.stateful(dyeInput, INVENTORY_KEY) - savetables.bool(::isBulk) + savetablesConfig.bool(::isBulk) exposeGlobally(Capabilities.FluidHandler.BLOCK, this) } 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 17aae98fe..dd474603b 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 @@ -112,8 +112,8 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) : exposeGlobally(MatteryCapability.MATTER_BLOCK, matter) exposeGlobally(MatteryCapability.MATTER_NODE, matterNode) - savetables.bool(::isBottling) - savetables.bool(::spitItemsWhenCantWork) + savetablesConfig.bool(::isBottling) + savetablesConfig.bool(::spitItemsWhenCantWork) savetables.stateful(::energy, ENERGY_KEY) savetables.stateful(::matter, MATTER_STORAGE_KEY) savetables.stateful(::bottling) 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 41490ae5b..8a5dc7ad7 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 @@ -84,7 +84,7 @@ class MatterPanelBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte exposeGlobally(MatteryCapability.MATTER_NODE, matterNode) exposeGlobally(MatteryCapability.REPLICATION_TASK, this) - savetables.bool(::isProvidingTasks) + savetablesConfig.bool(::isProvidingTasks) } override fun setLevel(level: Level) { 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 66b0ca54a..877a2d08a 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 @@ -63,9 +63,9 @@ class DriveRackBlockEntity(blockPos: BlockPos, blockState: BlockState) : Mattery savetables.stateful(::energy, ENERGY_KEY) savetables.stateful(::container, INVENTORY_KEY) exposeGlobally(MatteryCapability.STORAGE_NODE, cell) - savetables.int(::insertPriority) - savetables.int(::extractPriority) - savetables.enum(::mode, map = FlowDirection::valueOf) + savetablesConfig.int(::insertPriority) + savetablesConfig.int(::extractPriority) + savetablesConfig.enum(::mode, map = FlowDirection::valueOf) redstoneControl.addListener(Consumer { cell.isDetached = it 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 b5afdb850..9430419f0 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 @@ -131,7 +131,7 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter } init { - savetables.codec(::filter, ItemFilter.CODEC, FILTER_KEY, Supplier { ItemFilter(MAX_FILTERS) }) + savetablesConfig.codec(::filter, ItemFilter.CODEC, FILTER_KEY, Supplier { ItemFilter(MAX_FILTERS) }) } override fun setLevel(level: Level) { 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 1a66a0424..17aa2e953 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 @@ -112,7 +112,7 @@ abstract class AbstractStorageImportExport( } init { - savetables.codec(::filter, ItemFilter.CODEC, FILTER_KEY, Supplier { ItemFilter(MAX_FILTERS) }) + savetablesConfig.codec(::filter, ItemFilter.CODEC, FILTER_KEY, Supplier { ItemFilter(MAX_FILTERS) }) } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyCounterBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyCounterBlockEntity.kt index dbe0da7a2..80b12d46f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyCounterBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyCounterBlockEntity.kt @@ -78,7 +78,7 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat } init { - savetables.int(::displayChartOnBlock) + savetablesConfig.int(::displayChartOnBlock) savetables.stateful(::history5s) savetables.stateful(::history15s) savetables.stateful(::history1m) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/ConfiguratorItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ConfiguratorItem.kt new file mode 100644 index 000000000..b7799e9df --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/ConfiguratorItem.kt @@ -0,0 +1,111 @@ +package ru.dbotthepony.mc.otm.item + +import net.minecraft.nbt.CompoundTag +import net.minecraft.network.chat.Component +import net.minecraft.server.level.ServerPlayer +import net.minecraft.world.InteractionHand +import net.minecraft.world.InteractionResult +import net.minecraft.world.InteractionResultHolder +import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.TooltipFlag +import net.minecraft.world.item.context.UseOnContext +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.Blocks +import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity +import ru.dbotthepony.mc.otm.core.TextComponent +import ru.dbotthepony.mc.otm.core.TranslatableComponent +import ru.dbotthepony.mc.otm.registry.game.MDataComponentTypes +import ru.dbotthepony.mc.otm.server.sendActionBarMessage + +class ConfiguratorItem : MatteryItem(Properties().stacksTo(1)) { + init { + addSimpleDescription() + addSimpleDescription("2") + addSimpleDescription("3") + } + + override fun appendHoverText( + stack: ItemStack, + context: TooltipContext, + components: MutableList, + tooltipType: TooltipFlag + ) { + super.appendHoverText(stack, context, components, tooltipType) + + val tag = getConfiguration(stack) + val block = stack.getOrDefault(MDataComponentTypes.Configurator.BLOCK, Blocks.AIR.defaultBlockState()) + if (!tag.isEmpty && !block.isAir) { + components.add(TranslatableComponent("$descriptionId.desc_saved", block.block.name)) + } + } + + override fun use(level: Level, player: Player, hand: InteractionHand): InteractionResultHolder { + if (player is ServerPlayer && player.isCrouching) { + val stack = player.getItemInHand(hand) + + setConfiguration(stack, CompoundTag()) + stack.set(MDataComponentTypes.Configurator.BLOCK, Blocks.AIR.defaultBlockState()) + + player.sendActionBarMessage(TranslatableComponent("otm.gui.config_cleared")) + + return InteractionResultHolder.success(stack) + } + + return super.use(level, player, hand) + } + + override fun onItemUseFirst(stack: ItemStack, context: UseOnContext): InteractionResult { + val player = context.player + if (player == null) return super.useOn(context) + + val level = context.level + + val tile = level.getBlockEntity(context.clickedPos) + if (tile == null || tile !is MatteryBlockEntity) return super.useOn(context) + + if (player.isCrouching == true) { + if (player is ServerPlayer) { + val tag = CompoundTag() + tile.saveConfiguration(tag, level.registryAccess()) + + if (tag.isEmpty) return super.onItemUseFirst(stack, context) + + setConfiguration(stack, tag) + + val block = level.getBlockState(context.clickedPos) + stack.set(MDataComponentTypes.Configurator.BLOCK, block) + + player.sendActionBarMessage(TranslatableComponent("otm.gui.config_copied", block.block.name)) + } + + return InteractionResult.SUCCESS + } + + val tag = getConfiguration(stack) + if (!tag.isEmpty) { + if (player is ServerPlayer) { + tile.loadConfiguration(tag, level.registryAccess()) + player.sendActionBarMessage(TranslatableComponent("otm.gui.config_pasted")) + } + + return InteractionResult.SUCCESS + } else { + if (player is ServerPlayer) { + player.sendActionBarMessage(TranslatableComponent("otm.gui.config_missing")) + } + + return InteractionResult.FAIL + } + + return super.useOn(context) + } + + fun getConfiguration(stack: ItemStack): CompoundTag { + return stack.getOrDefault(MDataComponentTypes.Configurator.CONFIGURATION, CompoundTag()) + } + + fun setConfiguration(stack: ItemStack, tag: CompoundTag) { + stack.set(MDataComponentTypes.Configurator.CONFIGURATION, tag) + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt index a283cc490..6967c5d02 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MNames.kt @@ -199,6 +199,7 @@ object MNames { const val PLASMA_RIFLE = "plasma_rifle" const val CHEST_UPGRADER = "chest_upgrader" + const val CONFIGURATOR = "configurator" const val WITHERED_STEEL_SWORD = "withered_steel_sword" diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt index b0a70f9d3..0cf69e5f3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt @@ -6,6 +6,7 @@ import net.minecraft.core.BlockPos import net.minecraft.core.cauldron.CauldronInteraction import net.minecraft.core.component.DataComponents import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.nbt.CompoundTag import net.minecraft.world.entity.EntityType import net.minecraft.world.item.DyeColor import net.minecraft.world.item.Item @@ -43,6 +44,7 @@ import ru.dbotthepony.mc.otm.isClient import ru.dbotthepony.mc.otm.item.armor.TritaniumArmorItem import ru.dbotthepony.mc.otm.item.weapon.EnergySwordItem import ru.dbotthepony.mc.otm.item.weapon.FallingSunItem +import ru.dbotthepony.mc.otm.registry.game.MDataComponentTypes import ru.dbotthepony.mc.otm.registry.game.MItems import ru.dbotthepony.mc.otm.registry.game.MStats import ru.dbotthepony.mc.otm.registry.objects.ColoredDecorativeBlock @@ -316,6 +318,11 @@ object MRegistry : IBlockItemRegistryAcceptor { } } } + + ItemProperties.register(MItems.CONFIGURATOR, ResourceLocation(OverdriveThatMatters.MOD_ID, "has_configuration_saved")) { stack, _, _, _ -> + val tag = stack.getOrDefault(MDataComponentTypes.Configurator.CONFIGURATION, CompoundTag()) + if (tag.isEmpty) 0f else 1f + } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MCreativeTabs.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MCreativeTabs.kt index 3bea5d150..0d13a7607 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MCreativeTabs.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MCreativeTabs.kt @@ -263,6 +263,7 @@ private fun addMainCreativeTabItems(consumer: CreativeModeTab.Output) { accept(MItems.GRAVITATIONAL_DISRUPTOR) accept(MItems.CHEST_UPGRADER) + accept(MItems.CONFIGURATOR) accept(MItems.ESSENCE_SERVO) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MDataComponentTypes.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MDataComponentTypes.kt index 21d568866..1817fed3a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MDataComponentTypes.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MDataComponentTypes.kt @@ -5,9 +5,11 @@ import com.mojang.serialization.Codec import net.minecraft.core.UUIDUtil import net.minecraft.core.component.DataComponentType import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.nbt.CompoundTag import net.minecraft.network.RegistryFriendlyByteBuf import net.minecraft.network.codec.StreamCodec import net.minecraft.util.StringRepresentable +import net.minecraft.world.level.block.state.BlockState import net.neoforged.bus.api.IEventBus import net.neoforged.neoforge.fluids.SimpleFluidContent import ru.dbotthepony.mc.otm.capability.FlowDirection @@ -17,6 +19,7 @@ import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.data.codec.DecimalCodec import ru.dbotthepony.mc.otm.item.tool.RedstoneInteractorItem import ru.dbotthepony.mc.otm.network.StreamCodecs +import ru.dbotthepony.mc.otm.network.streamCodec import ru.dbotthepony.mc.otm.registry.MDeferredRegister import java.util.UUID @@ -34,6 +37,16 @@ object MDataComponentTypes { } } + private class CompoundTagComponent : DataComponentType { + override fun codec(): Codec { + return CompoundTag.CODEC + } + + override fun streamCodec(): StreamCodec { + return CompoundTag.CODEC.streamCodec() + } + } + val FLUID_STACK by registry.register("fluid_stack") { object : DataComponentType { override fun codec(): Codec { @@ -81,6 +94,26 @@ object MDataComponentTypes { } } + object Configurator { + val BLOCK: DataComponentType by registry.register("configurator_block") { + object : DataComponentType { + override fun codec(): Codec? { + return BlockState.CODEC + } + + override fun streamCodec(): StreamCodec { + return BlockState.CODEC.streamCodec() + } + + } + } + val CONFIGURATION: DataComponentType by registry.register("configurator_configuration") { CompoundTagComponent() } + } + + init { + Configurator + } + fun register(bus: IEventBus) { registry.register(bus) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MItems.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MItems.kt index fd87871a6..d9b809861 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MItems.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MItems.kt @@ -43,6 +43,7 @@ import ru.dbotthepony.mc.otm.core.collect.SupplierMap import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.item.BatteryItem import ru.dbotthepony.mc.otm.item.ChestUpgraderItem +import ru.dbotthepony.mc.otm.item.ConfiguratorItem import ru.dbotthepony.mc.otm.item.CrudeBatteryItem import ru.dbotthepony.mc.otm.item.EssenceServoItem import ru.dbotthepony.mc.otm.item.FluidCapsuleItem @@ -674,6 +675,8 @@ object MItems { val ROFLITE_ALLOY_INGOT: Item by registry.register(MNames.ROFLITE_ALLOY_INGOT) { Item(DEFAULT_PROPERTIES) } val ROFLITE_ALLOY_BLOCK: BlockItem by registry.register(MNames.ROFLITE_ALLOY_BLOCK) { BlockItem(MBlocks.ROFLITE_ALLOY_BLOCK, DEFAULT_PROPERTIES) } + val CONFIGURATOR: Item by registry.register(MNames.CONFIGURATOR) { ConfiguratorItem() } + init { MRegistry.registerItems(registry) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/server/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/server/Ext.kt new file mode 100644 index 000000000..31f82fd91 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/server/Ext.kt @@ -0,0 +1,9 @@ +package ru.dbotthepony.mc.otm.server + +import net.minecraft.network.chat.Component +import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket +import net.minecraft.server.level.ServerPlayer + +fun ServerPlayer.sendActionBarMessage(component: Component) { + this.connection.send(ClientboundSetActionBarTextPacket(component)) +} diff --git a/src/main/resources/assets/overdrive_that_matters/textures/item/configurator.png b/src/main/resources/assets/overdrive_that_matters/textures/item/configurator.png new file mode 100644 index 0000000000000000000000000000000000000000..e9147615fb9f42120951dbb01165878e6f488f3f GIT binary patch literal 2677 zcmZ8jc{Cg77Ed%JikaxBYEcrYqH5pQ(x`oz5L;1dr_nx3Q%l7XgI0$|thJ4;YO9to zMT)AlXrrOFs??w*4HNqwdC{43-Z}4{bHDq$%Xjbn?)m<>=?-@0LdVY>2LJ#|K$G_1#n$i zU;v04siLN?0xbI{>rqACvVSrWx%h~9xOsVgM51(cxai+oswyf+-ZF{uc4tt}Gw#a~ zmPivP3v0t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