From af24f391df9e9215b9fe9c15c84e65c8d339d879 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 26 Mar 2025 23:00:18 +0700 Subject: [PATCH] Fix blocks without menu still behaving like being interacted with clientside --- .../ru/dbotthepony/mc/otm/block/MatteryBlock.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 cc5bd8684..ffe8b684a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt @@ -16,7 +16,6 @@ import net.minecraft.network.chat.Component import net.minecraft.network.chat.ComponentSerialization import net.minecraft.server.level.ServerLevel import net.minecraft.util.RandomSource -import net.minecraft.world.Containers import net.minecraft.world.InteractionResult import net.minecraft.world.MenuProvider import net.minecraft.world.entity.LivingEntity @@ -36,8 +35,6 @@ import net.minecraft.world.phys.shapes.VoxelShape import org.apache.logging.log4j.LogManager import ru.dbotthepony.mc.otm.block.entity.IRedstoneControlled import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity -import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity -import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity.Companion import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.core.TooltipList import ru.dbotthepony.mc.otm.core.TranslatableComponent @@ -149,6 +146,9 @@ open class MatteryBlock(properties: Properties = DEFAULT_PROPERTIES) : Block(pro return getShapeForEachState(ArrayList(stateDefinition.properties), mapper) } + protected open val neverOpensAMenu: Boolean + get() = false + override fun useWithoutItem( blockState: BlockState, level: Level, @@ -156,18 +156,17 @@ open class MatteryBlock(properties: Properties = DEFAULT_PROPERTIES) : Block(pro ply: Player, blockHitResult: BlockHitResult ): InteractionResult { - if (this is EntityBlock && !level.isClientSide) { + if (!neverOpensAMenu && this is EntityBlock) { val tile = level.getBlockEntity(blockPos) if (tile is MenuProvider) { - ply.openMenu(tile) - return InteractionResult.CONSUME + if (!level.isClientSide) + ply.openMenu(tile) + + return InteractionResult.sidedSuccess(level.isClientSide) } } - if (this is EntityBlock && level.isClientSide) - return InteractionResult.SUCCESS - return super.useWithoutItem(blockState, level, blockPos, ply, blockHitResult) }