Skip to content

Commit 3b445f2

Browse files
committed
improve block update checks in managers
1 parent b02a452 commit 3b445f2

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ data class PlaceContext(
3838
override val rotation: RotationRequest,
3939
override var hotbarIndex: Int,
4040
override val blockPos: BlockPos,
41-
override val cachedState: BlockState,
41+
override var cachedState: BlockState,
4242
override val expectedState: BlockState,
4343
val sneak: Boolean,
4444
val insideBlock: Boolean,

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import com.lambda.graphics.renderer.esp.builders.buildOutline
3333
import com.lambda.interaction.construction.blueprint.Blueprint.Companion.toStructure
3434
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
3535
import com.lambda.interaction.construction.context.BreakContext
36-
import com.lambda.interaction.construction.processing.ProcessorRegistry
3736
import com.lambda.interaction.construction.result.BreakResult
3837
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
3938
import com.lambda.interaction.construction.verify.TargetState
@@ -70,8 +69,6 @@ import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
7069
import com.lambda.util.BlockUtils.isEmpty
7170
import com.lambda.util.BlockUtils.isNotBroken
7271
import com.lambda.util.BlockUtils.isNotEmpty
73-
import com.lambda.util.BlockUtils.matches
74-
import com.lambda.util.Communication.warn
7572
import com.lambda.util.item.ItemUtils.block
7673
import com.lambda.util.math.lerp
7774
import com.lambda.util.player.gamemode
@@ -189,21 +186,16 @@ object BreakManager : RequestHandler<BreakRequest>(
189186
val currentState = info.context.cachedState
190187
// if not broken
191188
if (isNotBroken(currentState, event.newState)) {
192-
// check to see if its just some small property changes, e.g. redstone ore changing the LIT property
193-
if (!currentState.matches(event.newState, ProcessorRegistry.postProcessedProperties))
194-
this@BreakManager.warn("Server updated breaking block at ${event.pos.toShortString()} with a new state: ${event.newState}")
195189
// update the cached state
196190
info.context.cachedState = event.newState
197191
return@listen
198192
}
199193
destroyBlock(info)
200194
info.request.onStop?.invoke(info.context.blockPos)
201195
info.internalOnBreak()
202-
if (!info.callbacksCompleted) {
203-
info.startPending()
204-
} else {
196+
if (info.callbacksCompleted)
205197
ReBreakManager.offerReBreak(info)
206-
}
198+
else info.startPending()
207199
info.nullify()
208200
}
209201
}

common/src/main/kotlin/com/lambda/interaction/request/breaking/BrokenBlockHandler.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ object BrokenBlockHandler : PostActionHandler<BreakInfo>() {
8383
return@listen
8484
}
8585

86-
if (!pending.isReBreaking) {
86+
if (pending.isReBreaking) {
87+
pending.context.cachedState = event.newState
88+
} else {
8789
this@BrokenBlockHandler.warn("Broken block at ${event.pos.toShortString()} was rejected with ${event.newState} instead of ${pending.context.cachedState.emptyState}")
8890
pending.stopPending()
89-
} else {
90-
pending.context.cachedState = event.newState
9191
}
9292
return@listen
9393
}

common/src/main/kotlin/com/lambda/interaction/request/interacting/InteractedBlockHandler.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.Lambda.mc
2121
import com.lambda.config.groups.InteractionConfig
2222
import com.lambda.event.events.WorldEvent
2323
import com.lambda.event.listener.SafeListener.Companion.listen
24+
import com.lambda.interaction.construction.processing.ProcessorRegistry
2425
import com.lambda.interaction.request.PostActionHandler
2526
import com.lambda.module.modules.client.TaskFlowModule
2627
import com.lambda.util.BlockUtils.matches
@@ -44,13 +45,20 @@ object InteractedBlockHandler : PostActionHandler<InteractionInfo>() {
4445
pendingActions
4546
.firstOrNull { it.context.blockPos == event.pos }
4647
?.let { pending ->
47-
pending.stopPending()
48-
4948
if (!pending.context.expectedState.matches(event.newState)) {
49+
if (pending.context.cachedState.matches(event.newState, ProcessorRegistry.postProcessedProperties)) {
50+
pending.context.cachedState = event.newState
51+
return@listen
52+
}
53+
54+
pending.stopPending()
55+
5056
this@InteractedBlockHandler.warn("Interacted block at ${event.pos.toShortString()} was rejected with ${event.newState} instead of ${pending.context.expectedState}")
5157
return@listen
5258
}
5359

60+
pending.stopPending()
61+
5462
//ToDo: reliable way to recreate the sounds played when interacting with any given block
5563
// if (pending.interactConfirmationMode == InteractionConfig.InteractConfirmationMode.AwaitThenInteract)
5664
// with (pending.context) {

common/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object InteractionManager : RequestHandler<InteractRequest>(
9292

9393
if (!ctx.requestDependencies(request)) return
9494

95-
if (request.interactConfirmationMode == InteractionConfig.InteractConfirmationMode.None) {
95+
if (request.interactConfirmationMode != InteractionConfig.InteractConfirmationMode.None) {
9696
InteractionInfo(ctx, request.pendingInteractionsList, request).startPending()
9797
}
9898
if (request.interactConfirmationMode != InteractionConfig.InteractConfirmationMode.AwaitThenInteract) {

common/src/main/kotlin/com/lambda/interaction/request/placing/PlacedBlockHandler.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.lambda.interaction.request.placing
2020
import com.lambda.Lambda.mc
2121
import com.lambda.event.events.WorldEvent
2222
import com.lambda.event.listener.SafeListener.Companion.listen
23+
import com.lambda.interaction.construction.processing.ProcessorRegistry
2324
import com.lambda.interaction.request.PostActionHandler
2425
import com.lambda.interaction.request.placing.PlaceManager.placeSound
2526
import com.lambda.module.modules.client.TaskFlowModule
@@ -46,14 +47,20 @@ object PlacedBlockHandler : PostActionHandler<PlaceInfo>() {
4647
pendingActions
4748
.firstOrNull { it.context.blockPos == event.pos }
4849
?.let { pending ->
49-
pending.stopPending()
50-
51-
// return if the block wasn't placed properly
5250
if (!pending.context.expectedState.matches(event.newState)) {
53-
this@PlacedBlockHandler.warn("Place at ${event.pos.toShortString()} was rejected with ${event.newState} instead of ${pending.context.expectedState}")
51+
if (pending.context.cachedState.matches(event.newState, ProcessorRegistry.postProcessedProperties)) {
52+
pending.context.cachedState = event.newState
53+
return@listen
54+
}
55+
56+
pending.stopPending()
57+
58+
this@PlacedBlockHandler.warn("Placed block at ${event.pos.toShortString()} was rejected with ${event.newState} instead of ${pending.context.expectedState}")
5459
return@listen
5560
}
5661

62+
pending.stopPending()
63+
5764
if (pending.placeConfig.placeConfirmationMode == PlaceConfig.PlaceConfirmationMode.AwaitThenPlace)
5865
with (pending.context) {
5966
placeSound(expectedState.block.item as BlockItem, expectedState, blockPos)

0 commit comments

Comments
 (0)