Skip to content

Commit 1c710ae

Browse files
committed
Fixed & improved predictions
1 parent cb85548 commit 1c710ae

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

common/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,24 @@ object CrystalAura : Module(
183183
opportunity.crystal = crystal
184184

185185
// Run packet prediction
186-
if (!prediction.onPacket || activeOpportunity != opportunity) return@listen
187-
repeat(predictionPackets) {
188-
val offset = if (prediction.postPlace) 0 else it
189-
explodeInternal(lastEntityId + offset)
190-
191-
if (prediction.postPlace) {
192-
placeInternal(pos, Hand.MAIN_HAND)
193-
lastEntityId++
194-
placeTimer.reset()
186+
if (activeOpportunity != opportunity) return@listen
187+
188+
when {
189+
prediction.onPlace -> {
190+
explodeInternal(lastEntityId)
191+
}
192+
193+
prediction.onPacket -> {
194+
repeat(predictionPackets) {
195+
val offset = if (prediction.postPlace) 0 else it
196+
explodeInternal(lastEntityId + offset)
197+
198+
if (prediction.postPlace) {
199+
placeInternal(pos, Hand.MAIN_HAND)
200+
lastEntityId++
201+
placeTimer.reset()
202+
}
203+
}
195204
}
196205
}
197206
}
@@ -428,26 +437,25 @@ object CrystalAura : Module(
428437
*/
429438
fun place() = placeTimer.runSafeIfPassed(placeDelay) {
430439
placeInternal(blockPos, Hand.MAIN_HAND)
431-
if (prediction.onPlace) predictionPlace()
432440

433-
placeTimer.reset()
434-
}
441+
if (prediction.onPlace) predictionTimer.runIfNotPassed(packetLifetime, false) {
442+
val last = lastEntityId
435443

436-
private fun SafeContext.predictionPlace() = predictionTimer.runIfNotPassed(packetLifetime) {
437-
val last = lastEntityId
444+
repeat(predictionPackets) {
445+
if (it != 0 && prediction.postPlace) {
446+
placeInternal(blockPos, Hand.MAIN_HAND)
447+
}
438448

439-
repeat(predictionPackets) {
440-
if (it != 0 && prediction.postPlace) {
441-
placeInternal(blockPos, Hand.MAIN_HAND)
449+
explodeInternal(++lastEntityId)
442450
}
443451

444-
explodeInternal(++lastEntityId)
452+
if (prediction == PredictionMode.StepDeferred) {
453+
lastEntityId = last + 1
454+
crystal = null
455+
}
445456
}
446457

447-
if (prediction == PredictionMode.StepDeferred) {
448-
lastEntityId = last + 1
449-
crystal = null
450-
}
458+
placeTimer.reset()
451459
}
452460

453461
/**

0 commit comments

Comments
 (0)