@@ -84,8 +84,9 @@ object CrystalAura : Module(
8484
8585 /* Prediction */
8686 private val prediction by setting(" Prediction" , PredictionMode .None ) { page == Page .Prediction }
87- private val predictionPackets by setting(" Prediction Packets" , 1 , 1 .. 20 ) { page == Page .Prediction && prediction.isActive }
88- private val packetLifetime by setting(" Packet Lifetime" , 300L , 50L .. 1000L ) { page == Page .Prediction && prediction.onPlace }
87+ private val packetPredictions by setting(" Packet Predictions" , 1 , 0 .. 20 , 1 ) { page == Page .Prediction && prediction.onPacket }
88+ private val placePredictions by setting(" Place Predictions" , 4 , 1 .. 20 , 1 ) { page == Page .Prediction && prediction.onPlace }
89+ private val packetLifetime by setting(" Packet Lifetime" , 500L , 50L .. 1000L ) { page == Page .Prediction && prediction.onPlace }
8990
9091 /* Targeting */
9192 private val targeting = Targeting .Combat (this , 10.0 ) { page == Page .Targeting }
@@ -169,12 +170,14 @@ object CrystalAura : Module(
169170 }
170171 }
171172
172- // Prediction
173- listen<EntityEvent .EntitySpawn > { event ->
174- // Update last received entity spawn
173+ // Update last received entity spawn
174+ listen<EntityEvent .EntitySpawn >(alwaysListen = true ) { event ->
175175 lastEntityId = event.entity.id
176176 predictionTimer.reset()
177+ }
177178
179+ // Prediction
180+ listen<EntityEvent .EntitySpawn > { event ->
178181 val crystal = event.entity as ? EndCrystalEntity ? : return @listen
179182 val pos = crystal.baseBlockPos
180183
@@ -183,26 +186,18 @@ object CrystalAura : Module(
183186 opportunity.crystal = crystal
184187
185188 // Run packet prediction
186- if (activeOpportunity != opportunity) return @listen
189+ if (! prediction.isActive || activeOpportunity != opportunity) return @listen
187190
188- when {
189- prediction.onPlace -> {
190- explodeInternal(lastEntityId)
191- }
191+ explodeInternal(lastEntityId)
192192
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- }
204- }
193+ if (! prediction.onPacket) return @listen
194+
195+ repeat(packetPredictions) {
196+ placeInternal(pos, Hand .MAIN_HAND )
197+ explodeInternal(++ lastEntityId)
205198 }
199+
200+ placeTimer.reset()
206201 }
207202
208203 listen<EntityEvent .EntityRemoval > { event ->
@@ -441,18 +436,12 @@ object CrystalAura : Module(
441436 if (prediction.onPlace) predictionTimer.runIfNotPassed(packetLifetime, false ) {
442437 val last = lastEntityId
443438
444- repeat(predictionPackets) {
445- if (it != 0 && prediction.postPlace) {
446- placeInternal(blockPos, Hand .MAIN_HAND )
447- }
448-
439+ repeat(placePredictions) {
449440 explodeInternal(++ lastEntityId)
450441 }
451442
452- if (prediction == PredictionMode .StepDeferred ) {
453- lastEntityId = last + 1
454- crystal = null
455- }
443+ lastEntityId = last + 1
444+ crystal = null
456445 }
457446
458447 placeTimer.reset()
@@ -527,18 +516,18 @@ object CrystalAura : Module(
527516 }
528517
529518 @Suppress(" Unused" )
530- private enum class PredictionMode (val onPacket : Boolean , val onPlace : Boolean , val postPlace : Boolean ) {
519+ private enum class PredictionMode (val onPacket : Boolean , val onPlace : Boolean ) {
531520 // Prediction disable
532- None (false , false , false ),
521+ None (false , false ),
533522
534523 // Predict on packet receive
535- SemiPacket (true , false , false ),
536- Packet (true , false , true ),
524+ Packet (true , false ),
537525
538526 // Predict on place
539- SemiDeferred (false , true , false ),
540- Deferred (false , true , true ),
541- StepDeferred (false , true , false ); // the best method
527+ Deferred (false , true ),
528+
529+ // Predict on both timings
530+ Mixed (true , true );
542531
543532 val isActive = onPacket || onPlace
544533 }
0 commit comments