Skip to content

Commit d75b9ee

Browse files
committed
fix preprocessing bug causing some state processing issues
1 parent 0130e72 commit d75b9ee

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/ProcessorRegistry.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,29 @@ object ProcessorRegistry : Loadable {
147147
context(safeContext: SafeContext)
148148
private fun preProcess(pos: BlockPos, state: BlockState, targetState: BlockState, itemStack: ItemStack) =
149149
PreProcessingInfoAccumulator(targetState, itemStack.item).run {
150+
var stateProcessing = false
150151
stateProcessors.forEach { processor ->
151152
if (processor.acceptsState(state, targetState)) {
152153
with(processor) { preProcess(state, targetState, pos) }
154+
stateProcessing = true
153155
}
154156
}
155157
if (!omitInteraction) {
156158
if (state.block != expectedState.block) {
157-
if (!state.isReplaceable) return@run null
158-
propertyPreProcessors.forEach { processor ->
159-
if (processor.acceptsState(state, expectedState)) {
160-
with(processor) { preProcess(state, expectedState, pos) }
159+
if (state.isReplaceable) {
160+
propertyPreProcessors.forEach { processor ->
161+
if (processor.acceptsState(state, expectedState)) {
162+
with(processor) { preProcess(state, expectedState, pos) }
163+
}
161164
}
162-
}
165+
} else if (!stateProcessing) return@run null
163166
} else {
164167
propertyPostProcessors.forEach { processor ->
165168
if (processor.acceptsState(state, expectedState)) {
166169
with(processor) { preProcess(state, expectedState, pos) }
167170
}
168171
}
169-
if (!state.matches(expectedState, ignore)) return@run null
172+
if (!state.matches(expectedState, ignore) && !stateProcessing) return@run null
170173
}
171174
}
172175
complete()

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/state/BambooPreProcessor.kt renamed to src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/state/BambooStateProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import net.minecraft.util.math.BlockPos
2929

3030
// Collected using reflections and then accessed from a collection in ProcessorRegistry
3131
@Suppress("unused")
32-
object BambooPreProcessor : StateProcessor {
32+
object BambooStateProcessor : StateProcessor {
3333
override fun acceptsState(state: BlockState, targetState: BlockState) =
3434
(state.isReplaceable || state.block == Blocks.BAMBOO_SAPLING) && targetState.block == Blocks.BAMBOO
3535

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/state/FirePreProcessor.kt renamed to src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/state/FireStateProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import net.minecraft.util.math.BlockPos
2727

2828
// Collected using reflections and then accessed from a collection in ProcessorRegistry
2929
@Suppress("unused")
30-
object FirePreProcessor : StateProcessor {
30+
object FireStateProcessor : StateProcessor {
3131
override fun acceptsState(state: BlockState, targetState: BlockState) =
3232
state.isReplaceable && targetState.block == Blocks.FIRE
3333

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/state/FlowerPotPreProcessor.kt renamed to src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/state/FlowerPotStateProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import net.minecraft.util.math.BlockPos
2828

2929
// Collected using reflections and then accessed from a collection in ProcessorRegistry
3030
@Suppress("unused")
31-
object FlowerPotPreProcessor : StateProcessor {
31+
object FlowerPotStateProcessor : StateProcessor {
3232
override fun acceptsState(state: BlockState, targetState: BlockState) =
3333
(state.isReplaceable || state.block == Blocks.FLOWER_POT) &&
3434
(targetState.block is FlowerPotBlock && targetState.block != Blocks.FLOWER_POT)

src/main/kotlin/com/lambda/interaction/managers/breaking/BreakManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,9 @@ object BreakManager : Manager<BreakRequest>(
799799
if (instantBreakable) {
800800
info.vanillaInstantBreakable = progress >= 1
801801
onBlockBreak(info)
802+
val breakDelay = breakConfig.breakDelay
802803
if (!info.vanillaInstantBreakable)
803-
breakCooldown = if (breakConfig.breakDelay == 0) 0 else breakConfig.breakDelay + 1
804+
breakCooldown = if (breakDelay == 0) 0 else breakDelay + 1
804805
} else {
805806
info.apply {
806807
breaking = true

src/main/kotlin/com/lambda/interaction/managers/interacting/InteractManager.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import com.lambda.util.player.gamemode
4848
import com.lambda.util.player.isItemOnCooldown
4949
import com.lambda.util.player.swingHand
5050
import net.minecraft.block.BlockState
51+
import net.minecraft.block.SculkVeinBlock.place
5152
import net.minecraft.block.pattern.CachedBlockPosition
5253
import net.minecraft.client.network.ClientPlayerEntity
5354
import net.minecraft.item.BlockItem
@@ -139,8 +140,7 @@ object InteractManager : Manager<InteractRequest>(
139140

140141
val iterator = potentialPlacements.iterator()
141142
while (iterator.hasNext()) {
142-
if (interactCooldown > 0) break
143-
if (placementsThisTick + 1 > maxPlacementsThisTick) break
143+
if (!canInteractThisTick()) break
144144
val ctx = iterator.next()
145145

146146
shouldSneak = ctx.sneak
@@ -152,7 +152,7 @@ object InteractManager : Manager<InteractRequest>(
152152
fun doAction() {
153153
val hand = if (interactConfig.airPlace == AirPlaceMode.Grim) Hand.OFF_HAND else Hand.MAIN_HAND
154154
actionResult = if (ctx.preProcessingInfo.placing) placeBlock(ctx, request, hand)
155-
else interaction.interactBlock(player, Hand.MAIN_HAND, ctx.hitResult)
155+
else interaction.interactBlock(player, if (ctx.preProcessingInfo.item != null) hand else Hand.MAIN_HAND, ctx.hitResult)
156156
}
157157

158158
//ToDo: Once we add 30bps placements we will need to move the air place bypass logic out of the loop to avoid excess packet spam
@@ -174,7 +174,8 @@ object InteractManager : Manager<InteractRequest>(
174174
mc.gameRenderer.firstPersonRenderer.resetEquipProgress(Hand.MAIN_HAND)
175175
}
176176
}
177-
interactCooldown = ctx.interactConfig.interactDelay + 1
177+
val interactDelay = ctx.interactConfig.interactDelay
178+
interactCooldown = if (interactDelay == 0) 0 else interactDelay + 1
178179
placementsThisTick++
179180
iterator.remove()
180181
}
@@ -183,6 +184,9 @@ object InteractManager : Manager<InteractRequest>(
183184
}
184185
}
185186

187+
fun canInteractThisTick() =
188+
interactCooldown <= 0 && placementsThisTick < maxPlacementsThisTick
189+
186190
/**
187191
* Filters the [request]'s [InteractContext]s, placing them into the [potentialPlacements] collection, and
188192
* setting other configurations.

0 commit comments

Comments
 (0)