001/*
002 * This file is part of Baritone.
003 *
004 * Baritone is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU Lesser General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * Baritone is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public License
015 * along with Baritone.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package baritone.api;
019
020import baritone.api.utils.SettingsUtil;
021import baritone.api.utils.TypeUtils;
022import net.minecraft.block.Block;
023import net.minecraft.client.Minecraft;
024import net.minecraft.init.Blocks;
025import net.minecraft.item.Item;
026import net.minecraft.util.math.Vec3i;
027import net.minecraft.util.text.ITextComponent;
028
029import java.awt.*;
030import java.lang.reflect.Field;
031import java.lang.reflect.ParameterizedType;
032import java.lang.reflect.Type;
033import java.util.List;
034import java.util.*;
035import java.util.function.Consumer;
036
037/**
038 * Baritone's settings. Settings apply to all Baritone instances.
039 *
040 * @author leijurv
041 */
042public final class Settings {
043
044    /**
045     * Allow Baritone to break blocks
046     */
047    public final Setting<Boolean> allowBreak = new Setting<>(true);
048
049    /**
050     * Allow Baritone to sprint
051     */
052    public final Setting<Boolean> allowSprint = new Setting<>(true);
053
054    /**
055     * Allow Baritone to place blocks
056     */
057    public final Setting<Boolean> allowPlace = new Setting<>(true);
058
059    /**
060     * Allow Baritone to move items in your inventory to your hotbar
061     */
062    public final Setting<Boolean> allowInventory = new Setting<>(false);
063
064    /**
065     * Disable baritone's auto-tool at runtime, but still assume that another mod will provide auto tool functionality
066     * <p>
067     * Specifically, path calculation will still assume that an auto tool will run at execution time, even though
068     * Baritone itself will not do that.
069     */
070    public final Setting<Boolean> assumeExternalAutoTool = new Setting<>(false);
071
072    /**
073     * If this setting is on, no auto tool will occur at all, not at calculation time nor execution time
074     */
075    public final Setting<Boolean> disableAutoTool = new Setting<>(false);
076
077    /**
078     * It doesn't actually take twenty ticks to place a block, this cost is so high
079     * because we want to generally conserve blocks which might be limited.
080     * <p>
081     * Decrease to make Baritone more often consider paths that would require placing blocks
082     */
083    public final Setting<Double> blockPlacementPenalty = new Setting<>(20D);
084
085    /**
086     * This is just a tiebreaker to make it less likely to break blocks if it can avoid it.
087     * For example, fire has a break cost of 0, this makes it nonzero, so all else being equal
088     * it will take an otherwise equivalent route that doesn't require it to put out fire.
089     */
090    public final Setting<Double> blockBreakAdditionalPenalty = new Setting<>(2D);
091
092    /**
093     * Additional penalty for hitting the space bar (ascend, pillar, or parkour) because it uses hunger
094     */
095    public final Setting<Double> jumpPenalty = new Setting<>(2D);
096
097    /**
098     * Walking on water uses up hunger really quick, so penalize it
099     */
100    public final Setting<Double> walkOnWaterOnePenalty = new Setting<>(3D);
101
102    /**
103     * Allow Baritone to fall arbitrary distances and place a water bucket beneath it.
104     * Reliability: questionable.
105     */
106    public final Setting<Boolean> allowWaterBucketFall = new Setting<>(true);
107
108    /**
109     * Allow Baritone to assume it can walk on still water just like any other block.
110     * This functionality is assumed to be provided by a separate library that might have imported Baritone.
111     */
112    public final Setting<Boolean> assumeWalkOnWater = new Setting<>(false);
113
114    /**
115     * If you have Fire Resistance and Jesus then I guess you could turn this on lol
116     */
117    public final Setting<Boolean> assumeWalkOnLava = new Setting<>(false);
118
119    /**
120     * Assume step functionality; don't jump on an Ascend.
121     */
122    public final Setting<Boolean> assumeStep = new Setting<>(false);
123
124    /**
125     * Assume safe walk functionality; don't sneak on a backplace traverse.
126     * <p>
127     * Warning: if you do something janky like sneak-backplace from an ender chest, if this is true
128     * it won't sneak right click, it'll just right click, which means it'll open the chest instead of placing
129     * against it. That's why this defaults to off.
130     */
131    public final Setting<Boolean> assumeSafeWalk = new Setting<>(false);
132
133    /**
134     * If true, parkour is allowed to make jumps when standing on blocks at the maximum height, so player feet is y=256
135     * <p>
136     * Defaults to false because this fails on constantiam. Please let me know if this is ever disabled. Please.
137     */
138    public final Setting<Boolean> allowJumpAt256 = new Setting<>(false);
139
140    /**
141     * This should be monetized it's so good
142     * <p>
143     * Defaults to true, but only actually takes effect if allowParkour is also true
144     */
145    public final Setting<Boolean> allowParkourAscend = new Setting<>(true);
146
147    /**
148     * Allow descending diagonally
149     * <p>
150     * Safer than allowParkour yet still slightly unsafe, can make contact with unchecked adjacent blocks, so it's unsafe in the nether.
151     * <p>
152     * For a generic "take some risks" mode I'd turn on this one, parkour, and parkour place.
153     */
154    public final Setting<Boolean> allowDiagonalDescend = new Setting<>(false);
155
156    /**
157     * Allow diagonal ascending
158     * <p>
159     * Actually pretty safe, much safer than diagonal descend tbh
160     */
161    public final Setting<Boolean> allowDiagonalAscend = new Setting<>(false);
162
163    /**
164     * Allow mining the block directly beneath its feet
165     * <p>
166     * Turn this off to force it to make more staircases and less shafts
167     */
168    public final Setting<Boolean> allowDownward = new Setting<>(true);
169
170    /**
171     * Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.)
172     */
173    public final Setting<List<Item>> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList(
174            Item.getItemFromBlock(Blocks.DIRT),
175            Item.getItemFromBlock(Blocks.COBBLESTONE),
176            Item.getItemFromBlock(Blocks.NETHERRACK),
177            Item.getItemFromBlock(Blocks.STONE)
178    )));
179
180    /**
181     * Blocks that Baritone will attempt to avoid (Used in avoidance)
182     */
183    public final Setting<List<Block>> blocksToAvoid = new Setting<>(new ArrayList<>(
184            // Leave Empty by Default
185    ));
186
187    /**
188     * Blocks that Baritone is not allowed to break
189     */
190    public final Setting<List<Block>> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( // TODO can this be a HashSet or ImmutableSet?
191            Blocks.CRAFTING_TABLE,
192            Blocks.FURNACE,
193            Blocks.LIT_FURNACE,
194            Blocks.CHEST,
195            Blocks.TRAPPED_CHEST,
196            Blocks.STANDING_SIGN,
197            Blocks.WALL_SIGN
198    )));
199
200    /**
201     * A list of blocks to be treated as if they're air.
202     * <p>
203     * If a schematic asks for air at a certain position, and that position currently contains a block on this list, it will be treated as correct.
204     */
205    public final Setting<List<Block>> buildIgnoreBlocks = new Setting<>(new ArrayList<>(Arrays.asList(
206
207    )));
208
209    /**
210     * A list of blocks to become air
211     * <p>
212     * If a schematic asks for a block on this list, only air will be accepted at that location (and nothing on buildIgnoreBlocks)
213     */
214    public final Setting<List<Block>> okIfAir = new Setting<>(new ArrayList<>(Arrays.asList(
215
216    )));
217
218    /**
219     * If this is true, the builder will treat all non-air blocks as correct. It will only place new blocks.
220     */
221    public final Setting<Boolean> buildIgnoreExisting = new Setting<>(false);
222
223    /**
224     * If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block.
225     * <p>
226     * I.E. it will never trigger cascading sand / gravel falls
227     */
228    public final Setting<Boolean> avoidUpdatingFallingBlocks = new Setting<>(true);
229
230    /**
231     * Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real
232     * pathing scenarios. And they can cause Baritone to get trapped indefinitely in a strange scenario.
233     * <p>
234     * Almost never turn this on lol
235     */
236    public final Setting<Boolean> allowVines = new Setting<>(false);
237
238    /**
239     * Slab behavior is complicated, disable this for higher path reliability. Leave enabled if you have bottom slabs
240     * everywhere in your base.
241     */
242    public final Setting<Boolean> allowWalkOnBottomSlab = new Setting<>(true);
243
244    /**
245     * You know what it is
246     * <p>
247     * But it's very unreliable and falls off when cornering like all the time so.
248     * <p>
249     * It also overshoots the landing pretty much always (making contact with the next block over), so be careful
250     */
251    public final Setting<Boolean> allowParkour = new Setting<>(false);
252
253    /**
254     * Actually pretty reliable.
255     * <p>
256     * Doesn't make it any more dangerous compared to just normal allowParkour th
257     */
258    public final Setting<Boolean> allowParkourPlace = new Setting<>(false);
259
260    /**
261     * For example, if you have Mining Fatigue or Haste, adjust the costs of breaking blocks accordingly.
262     */
263    public final Setting<Boolean> considerPotionEffects = new Setting<>(true);
264
265    /**
266     * Sprint and jump a block early on ascends wherever possible
267     */
268    public final Setting<Boolean> sprintAscends = new Setting<>(true);
269
270    /**
271     * If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway.
272     * <p>
273     * This helps with speed exceeding 20m/s
274     */
275    public final Setting<Boolean> overshootTraverse = new Setting<>(true);
276
277    /**
278     * When breaking blocks for a movement, wait until all falling blocks have settled before continuing
279     */
280    public final Setting<Boolean> pauseMiningForFallingBlocks = new Setting<>(true);
281
282    /**
283     * How many ticks between right clicks are allowed. Default in game is 4
284     */
285    public final Setting<Integer> rightClickSpeed = new Setting<>(4);
286
287    /**
288     * Block reach distance
289     */
290    public final Setting<Float> blockReachDistance = new Setting<>(4.5f);
291
292    /**
293     * How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable
294     */
295    public final Setting<Double> randomLooking = new Setting<>(0.01d);
296
297    /**
298     * This is the big A* setting.
299     * As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path.
300     * 3.5 is always an underestimate, even if you are sprinting.
301     * If you're walking only (with allowSprint off) 4.6 is safe.
302     * Any value below 3.5 is never worth it. It's just more computation to find the same path, guaranteed.
303     * (specifically, it needs to be strictly slightly less than ActionCosts.WALK_ONE_BLOCK_COST, which is about 3.56)
304     * <p>
305     * Setting it at 3.57 or above with sprinting, or to 4.64 or above without sprinting, will result in
306     * faster computation, at the cost of a suboptimal path. Any value above the walk / sprint cost will result
307     * in it going straight at its goal, and not investigating alternatives, because the combined cost / heuristic
308     * metric gets better and better with each block, instead of slightly worse.
309     * <p>
310     * Finding the optimal path is worth it, so it's the default.
311     */
312    public final Setting<Double> costHeuristic = new Setting<>(3.563);
313
314    // a bunch of obscure internal A* settings that you probably don't want to change
315    /**
316     * The maximum number of times it will fetch outside loaded or cached chunks before assuming that
317     * pathing has reached the end of the known area, and should therefore stop.
318     */
319    public final Setting<Integer> pathingMaxChunkBorderFetch = new Setting<>(50);
320
321    /**
322     * Set to 1.0 to effectively disable this feature
323     *
324     * @see <a href="https://github.com/cabaletta/baritone/issues/18">Issue #18</a>
325     */
326    public final Setting<Double> backtrackCostFavoringCoefficient = new Setting<>(0.5);
327
328    /**
329     * Toggle the following 4 settings
330     * <p>
331     * They have a noticeable performance impact, so they default off
332     * <p>
333     * Specifically, building up the avoidance map on the main thread before pathing starts actually takes a noticeable
334     * amount of time, especially when there are a lot of mobs around, and your game jitters for like 200ms while doing so
335     */
336    public final Setting<Boolean> avoidance = new Setting<>(false);
337
338    /**
339     * Set to 1.0 to effectively disable this feature
340     * <p>
341     * Set below 1.0 to go out of your way to walk near mob spawners
342     */
343    public final Setting<Double> mobSpawnerAvoidanceCoefficient = new Setting<>(2.0);
344
345    public final Setting<Integer> mobSpawnerAvoidanceRadius = new Setting<>(16);
346
347    /**
348     * Set to 1.0 to effectively disable this feature
349     * <p>
350     * Set below 1.0 to go out of your way to walk near mobs
351     */
352    public final Setting<Double> mobAvoidanceCoefficient = new Setting<>(1.5);
353
354    public final Setting<Integer> mobAvoidanceRadius = new Setting<>(8);
355
356    /**
357     * When running a goto towards a container block (chest, ender chest, furnace, etc),
358     * right click and open it once you arrive.
359     */
360    public final Setting<Boolean> rightClickContainerOnArrival = new Setting<>(true);
361
362    /**
363     * When running a goto towards a nether portal block, walk all the way into the portal
364     * instead of stopping one block before.
365     */
366    public final Setting<Boolean> enterPortal = new Setting<>(true);
367
368    /**
369     * Don't repropagate cost improvements below 0.01 ticks. They're all just floating point inaccuracies,
370     * and there's no point.
371     */
372    public final Setting<Boolean> minimumImprovementRepropagation = new Setting<>(true);
373
374    /**
375     * After calculating a path (potentially through cached chunks), artificially cut it off to just the part that is
376     * entirely within currently loaded chunks. Improves path safety because cached chunks are heavily simplified.
377     * <p>
378     * This is much safer to leave off now, and makes pathing more efficient. More explanation in the issue.
379     *
380     * @see <a href="https://github.com/cabaletta/baritone/issues/114">Issue #114</a>
381     */
382    public final Setting<Boolean> cutoffAtLoadBoundary = new Setting<>(false);
383
384    /**
385     * If a movement's cost increases by more than this amount between calculation and execution (due to changes
386     * in the environment / world), cancel and recalculate
387     */
388    public final Setting<Double> maxCostIncrease = new Setting<>(10D);
389
390    /**
391     * Stop 5 movements before anything that made the path COST_INF.
392     * For example, if lava has spread across the path, don't walk right up to it then recalculate, it might
393     * still be spreading lol
394     */
395    public final Setting<Integer> costVerificationLookahead = new Setting<>(5);
396
397    /**
398     * Static cutoff factor. 0.9 means cut off the last 10% of all paths, regardless of chunk load state
399     */
400    public final Setting<Double> pathCutoffFactor = new Setting<>(0.9);
401
402    /**
403     * Only apply static cutoff for paths of at least this length (in terms of number of movements)
404     */
405    public final Setting<Integer> pathCutoffMinimumLength = new Setting<>(30);
406
407    /**
408     * Start planning the next path once the remaining movements tick estimates sum up to less than this value
409     */
410    public final Setting<Integer> planningTickLookahead = new Setting<>(150);
411
412    /**
413     * Default size of the Long2ObjectOpenHashMap used in pathing
414     */
415    public final Setting<Integer> pathingMapDefaultSize = new Setting<>(1024);
416
417    /**
418     * Load factor coefficient for the Long2ObjectOpenHashMap used in pathing
419     * <p>
420     * Decrease for faster map operations, but higher memory usage
421     */
422    public final Setting<Float> pathingMapLoadFactor = new Setting<>(0.75f);
423
424    /**
425     * How far are you allowed to fall onto solid ground (without a water bucket)?
426     * 3 won't deal any damage. But if you just want to get down the mountain quickly and you have
427     * Feather Falling IV, you might set it a bit higher, like 4 or 5.
428     */
429    public final Setting<Integer> maxFallHeightNoWater = new Setting<>(3);
430
431    /**
432     * How far are you allowed to fall onto solid ground (with a water bucket)?
433     * It's not that reliable, so I've set it below what would kill an unarmored player (23)
434     */
435    public final Setting<Integer> maxFallHeightBucket = new Setting<>(20);
436
437    /**
438     * Is it okay to sprint through a descend followed by a diagonal?
439     * The player overshoots the landing, but not enough to fall off. And the diagonal ensures that there isn't
440     * lava or anything that's !canWalkInto in that space, so it's technically safe, just a little sketchy.
441     * <p>
442     * Note: this is *not* related to the allowDiagonalDescend setting, that is a completely different thing.
443     */
444    public final Setting<Boolean> allowOvershootDiagonalDescend = new Setting<>(true);
445
446    /**
447     * If your goal is a GoalBlock in an unloaded chunk, assume it's far enough away that the Y coord
448     * doesn't matter yet, and replace it with a GoalXZ to the same place before calculating a path.
449     * Once a segment ends within chunk load range of the GoalBlock, it will go back to normal behavior
450     * of considering the Y coord. The reasoning is that if your X and Z are 10,000 blocks away,
451     * your Y coordinate's accuracy doesn't matter at all until you get much much closer.
452     */
453    public final Setting<Boolean> simplifyUnloadedYCoord = new Setting<>(true);
454
455    /**
456     * Whenever a block changes, repack the whole chunk that it's in
457     */
458    public final Setting<Boolean> repackOnAnyBlockChange = new Setting<>(true);
459
460    /**
461     * If a movement takes this many ticks more than its initial cost estimate, cancel it
462     */
463    public final Setting<Integer> movementTimeoutTicks = new Setting<>(100);
464
465    /**
466     * Pathing ends after this amount of time, but only if a path has been found
467     * <p>
468     * If no valid path (length above the minimum) has been found, pathing continues up until the failure timeout
469     */
470    public final Setting<Long> primaryTimeoutMS = new Setting<>(500L);
471
472    /**
473     * Pathing can never take longer than this, even if that means failing to find any path at all
474     */
475    public final Setting<Long> failureTimeoutMS = new Setting<>(2000L);
476
477    /**
478     * Planning ahead while executing a segment ends after this amount of time, but only if a path has been found
479     * <p>
480     * If no valid path (length above the minimum) has been found, pathing continues up until the failure timeout
481     */
482    public final Setting<Long> planAheadPrimaryTimeoutMS = new Setting<>(4000L);
483
484    /**
485     * Planning ahead while executing a segment can never take longer than this, even if that means failing to find any path at all
486     */
487    public final Setting<Long> planAheadFailureTimeoutMS = new Setting<>(5000L);
488
489    /**
490     * For debugging, consider nodes much much slower
491     */
492    public final Setting<Boolean> slowPath = new Setting<>(false);
493
494    /**
495     * Milliseconds between each node
496     */
497    public final Setting<Long> slowPathTimeDelayMS = new Setting<>(100L);
498
499    /**
500     * The alternative timeout number when slowPath is on
501     */
502    public final Setting<Long> slowPathTimeoutMS = new Setting<>(40000L);
503
504    /**
505     * The big one. Download all chunks in simplified 2-bit format and save them for better very-long-distance pathing.
506     */
507    public final Setting<Boolean> chunkCaching = new Setting<>(true);
508
509    /**
510     * On save, delete from RAM any cached regions that are more than 1024 blocks away from the player
511     * <p>
512     * Temporarily disabled
513     * <p>
514     * Temporarily reenabled
515     *
516     * @see <a href="https://github.com/cabaletta/baritone/issues/248">Issue #248</a>
517     */
518    public final Setting<Boolean> pruneRegionsFromRAM = new Setting<>(true);
519
520    /**
521     * Remember the contents of containers (chests, echests, furnaces)
522     * <p>
523     * Really buggy since the packet stuff is multithreaded badly thanks to brady
524     */
525    public final Setting<Boolean> containerMemory = new Setting<>(false);
526
527    /**
528     * Fill in blocks behind you
529     */
530    public final Setting<Boolean> backfill = new Setting<>(false);
531
532    /**
533     * Shows popup message in the upper right corner, similarly to when you make an advancement
534     */
535    public final Setting<Boolean> logAsToast = new Setting<>(false);
536
537    /**
538     * The time of how long the message in the pop-up will display
539     * <p>
540     * If below 1000L (1sec), it's better to disable this
541     */
542    public final Setting<Long> toastTimer = new Setting<>(5000L);
543
544    /**
545     * Print all the debug messages to chat
546     */
547    public final Setting<Boolean> chatDebug = new Setting<>(false);
548
549    /**
550     * Allow chat based control of Baritone. Most likely should be disabled when Baritone is imported for use in
551     * something else
552     */
553    public final Setting<Boolean> chatControl = new Setting<>(true);
554
555    /**
556     * Some clients like Impact try to force chatControl to off, so here's a second setting to do it anyway
557     */
558    public final Setting<Boolean> chatControlAnyway = new Setting<>(false);
559
560    /**
561     * Render the path
562     */
563    public final Setting<Boolean> renderPath = new Setting<>(true);
564
565    /**
566     * Render the path as a line instead of a frickin thingy
567     */
568    public final Setting<Boolean> renderPathAsLine = new Setting<>(false);
569
570    /**
571     * Render the goal
572     */
573    public final Setting<Boolean> renderGoal = new Setting<>(true);
574
575    /**
576     * Render selection boxes
577     */
578    public final Setting<Boolean> renderSelectionBoxes = new Setting<>(true);
579
580    /**
581     * Ignore depth when rendering the goal
582     */
583    public final Setting<Boolean> renderGoalIgnoreDepth = new Setting<>(true);
584
585    /**
586     * Renders X/Z type Goals with the vanilla beacon beam effect. Combining this with
587     * {@link #renderGoalIgnoreDepth} will cause strange render clipping.
588     */
589    public final Setting<Boolean> renderGoalXZBeacon = new Setting<>(false);
590
591    /**
592     * Ignore depth when rendering the selection boxes (to break, to place, to walk into)
593     */
594    public final Setting<Boolean> renderSelectionBoxesIgnoreDepth = new Setting<>(true);
595
596    /**
597     * Ignore depth when rendering the path
598     */
599    public final Setting<Boolean> renderPathIgnoreDepth = new Setting<>(true);
600
601    /**
602     * Line width of the path when rendered, in pixels
603     */
604    public final Setting<Float> pathRenderLineWidthPixels = new Setting<>(5F);
605
606    /**
607     * Line width of the goal when rendered, in pixels
608     */
609    public final Setting<Float> goalRenderLineWidthPixels = new Setting<>(3F);
610
611    /**
612     * Start fading out the path at 20 movements ahead, and stop rendering it entirely 30 movements ahead.
613     * Improves FPS.
614     */
615    public final Setting<Boolean> fadePath = new Setting<>(false);
616
617    /**
618     * Move without having to force the client-sided rotations
619     */
620    public final Setting<Boolean> freeLook = new Setting<>(true);
621
622    /**
623     * Will cause some minor behavioral differences to ensure that Baritone works on anticheats.
624     * <p>
625     * At the moment this will silently set the player's rotations when using freeLook so you're not sprinting in
626     * directions other than forward, which is picken up by more "advanced" anticheats like AAC, but not NCP.
627     */
628    public final Setting<Boolean> antiCheatCompatibility = new Setting<>(true);
629
630    /**
631     * Exclusively use cached chunks for pathing
632     * <p>
633     * Never turn this on
634     */
635    public final Setting<Boolean> pathThroughCachedOnly = new Setting<>(false);
636
637    /**
638     * Continue sprinting while in water
639     */
640    public final Setting<Boolean> sprintInWater = new Setting<>(true);
641
642    /**
643     * When GetToBlockProcess or MineProcess fails to calculate a path, instead of just giving up, mark the closest instance
644     * of that block as "unreachable" and go towards the next closest. GetToBlock expands this seaarch to the whole "vein"; MineProcess does not.
645     * This is because MineProcess finds individual impossible blocks (like one block in a vein that has gravel on top then lava, so it can't break)
646     * Whereas GetToBlock should blacklist the whole "vein" if it can't get to any of them.
647     */
648    public final Setting<Boolean> blacklistClosestOnFailure = new Setting<>(true);
649
650    /**
651     * 😎 Render cached chunks as semitransparent. Doesn't work with OptiFine 😭 Rarely randomly crashes, see <a href="https://github.com/cabaletta/baritone/issues/327">this issue</a>.
652     * <p>
653     * Can be very useful on servers with low render distance. After enabling, you may need to reload the world in order for it to have an effect
654     * (e.g. disconnect and reconnect, enter then exit the nether, die and respawn, etc). This may literally kill your FPS and CPU because
655     * every chunk gets recompiled twice as much as normal, since the cached version comes into range, then the normal one comes from the server for real.
656     * <p>
657     * Note that flowing water is cached as AVOID, which is rendered as lava. As you get closer, you may therefore see lava falls being replaced with water falls.
658     * <p>
659     * SOLID is rendered as stone in the overworld, netherrack in the nether, and end stone in the end
660     */
661    public final Setting<Boolean> renderCachedChunks = new Setting<>(false);
662
663    /**
664     * 0.0f = not visible, fully transparent (instead of setting this to 0, turn off renderCachedChunks)
665     * 1.0f = fully opaque
666     */
667    public final Setting<Float> cachedChunksOpacity = new Setting<>(0.5f);
668
669    /**
670     * Whether or not to allow you to run Baritone commands with the prefix
671     */
672    public final Setting<Boolean> prefixControl = new Setting<>(true);
673
674    /**
675     * The command prefix for chat control
676     */
677    public final Setting<String> prefix = new Setting<>("#");
678
679    /**
680     * Use a short Baritone prefix [B] instead of [Baritone] when logging to chat
681     */
682    public final Setting<Boolean> shortBaritonePrefix = new Setting<>(false);
683
684    /**
685     * Echo commands to chat when they are run
686     */
687    public final Setting<Boolean> echoCommands = new Setting<>(true);
688
689    /**
690     * Censor coordinates in goals and block positions
691     */
692    public final Setting<Boolean> censorCoordinates = new Setting<>(false);
693
694    /**
695     * Censor arguments to ran commands, to hide, for example, coordinates to #goal
696     */
697    public final Setting<Boolean> censorRanCommands = new Setting<>(false);
698
699    /**
700     * Stop using tools just before they are going to break.
701     */
702    public final Setting<Boolean> itemSaver = new Setting<>(false);
703
704    /**
705     * Always prefer silk touch tools over regular tools. This will not sacrifice speed, but it will always prefer silk
706     * touch tools over other tools of the same speed. This includes always choosing ANY silk touch tool over your hand.
707     */
708    public final Setting<Boolean> preferSilkTouch = new Setting<>(false);
709
710    /**
711     * Don't stop walking forward when you need to break blocks in your way
712     */
713    public final Setting<Boolean> walkWhileBreaking = new Setting<>(true);
714
715    /**
716     * When a new segment is calculated that doesn't overlap with the current one, but simply begins where the current segment ends,
717     * splice it on and make a longer combined path. If this setting is off, any planned segment will not be spliced and will instead
718     * be the "next path" in PathingBehavior, and will only start after this one ends. Turning this off hurts planning ahead,
719     * because the next segment will exist even if it's very short.
720     *
721     * @see #planningTickLookahead
722     */
723    public final Setting<Boolean> splicePath = new Setting<>(true);
724
725    /**
726     * If we are more than 300 movements into the current path, discard the oldest segments, as they are no longer useful
727     */
728    public final Setting<Integer> maxPathHistoryLength = new Setting<>(300);
729
730    /**
731     * If the current path is too long, cut off this many movements from the beginning.
732     */
733    public final Setting<Integer> pathHistoryCutoffAmount = new Setting<>(50);
734
735    /**
736     * Rescan for the goal once every 5 ticks.
737     * Set to 0 to disable.
738     */
739    public final Setting<Integer> mineGoalUpdateInterval = new Setting<>(5);
740
741    /**
742     * After finding this many instances of the target block in the cache, it will stop expanding outward the chunk search.
743     */
744    public final Setting<Integer> maxCachedWorldScanCount = new Setting<>(10);
745
746    /**
747     * Sets the minimum y level whilst mining - set to 0 to turn off.
748     */
749    public final Setting<Integer> minYLevelWhileMining = new Setting<>(0);
750
751    /**
752     * This will only allow baritone to mine exposed ores, can be used to stop ore obfuscators on servers that use them.
753     */
754    public final Setting<Boolean> allowOnlyExposedOres = new Setting<>(false);
755
756    /**
757     * When allowOnlyExposedOres is enabled this is the distance around to search.
758     * <p>
759     * It is recommended to keep this value low, as it dramatically increases calculation times.
760     */
761    public final Setting<Integer> allowOnlyExposedOresDistance = new Setting<>(1);
762
763    /**
764     * When GetToBlock doesn't know any locations for the desired block, explore randomly instead of giving up.
765     */
766    public final Setting<Boolean> exploreForBlocks = new Setting<>(true);
767
768    /**
769     * While exploring the world, offset the closest unloaded chunk by this much in both axes.
770     * <p>
771     * This can result in more efficient loading, if you set this to the render distance.
772     */
773    public final Setting<Integer> worldExploringChunkOffset = new Setting<>(0);
774
775    /**
776     * Take the 10 closest chunks, even if they aren't strictly tied for distance metric from origin.
777     */
778    public final Setting<Integer> exploreChunkSetMinimumSize = new Setting<>(10);
779
780    /**
781     * Attempt to maintain Y coordinate while exploring
782     * <p>
783     * -1 to disable
784     */
785    public final Setting<Integer> exploreMaintainY = new Setting<>(64);
786
787    /**
788     * Replant normal Crops while farming and leave cactus and sugarcane to regrow
789     */
790    public final Setting<Boolean> replantCrops = new Setting<>(true);
791
792    /**
793     * Replant nether wart while farming. This setting only has an effect when replantCrops is also enabled
794     */
795    public final Setting<Boolean> replantNetherWart = new Setting<>(false);
796
797    /**
798     * When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too.
799     * <p>
800     * Only if you have a beefy CPU and automatically mine blocks that are in cache
801     */
802    public final Setting<Boolean> extendCacheOnThreshold = new Setting<>(false);
803
804    /**
805     * Don't consider the next layer in builder until the current one is done
806     */
807    public final Setting<Boolean> buildInLayers = new Setting<>(false);
808
809    /**
810     * false = build from bottom to top
811     * <p>
812     * true = build from top to bottom
813     */
814    public final Setting<Boolean> layerOrder = new Setting<>(false);
815
816    /**
817     * Start building the schematic at a specific layer.
818     * Can help on larger builds when schematic wants to break things its already built
819     */
820    public final Setting<Integer> startAtLayer = new Setting<>(0);
821
822    /**
823     * If a layer is unable to be constructed, just skip it.
824     */
825    public final Setting<Boolean> skipFailedLayers = new Setting<>(false);
826
827    /**
828     * How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely
829     */
830    public final Setting<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0));
831
832    /**
833     * How many times to buildrepeat. -1 for infinite.
834     */
835    public final Setting<Integer> buildRepeatCount = new Setting<>(-1);
836
837    /**
838     * Don't notify schematics that they are moved.
839     * e.g. replacing will replace the same spots for every repetition
840     * Mainly for backward compatibility.
841     */
842    public final Setting<Boolean> buildRepeatSneaky = new Setting<>(true);
843
844    /**
845     * Allow standing above a block while mining it, in BuilderProcess
846     * <p>
847     * Experimental
848     */
849    public final Setting<Boolean> breakFromAbove = new Setting<>(false);
850
851    /**
852     * As well as breaking from above, set a goal to up and to the side of all blocks to break.
853     * <p>
854     * Never turn this on without also turning on breakFromAbove.
855     */
856    public final Setting<Boolean> goalBreakFromAbove = new Setting<>(false);
857
858    /**
859     * Build in map art mode, which makes baritone only care about the top block in each column
860     */
861    public final Setting<Boolean> mapArtMode = new Setting<>(false);
862
863    /**
864     * Override builder's behavior to not attempt to correct blocks that are currently water
865     */
866    public final Setting<Boolean> okIfWater = new Setting<>(false);
867
868    /**
869     * The set of incorrect blocks can never grow beyond this size
870     */
871    public final Setting<Integer> incorrectSize = new Setting<>(100);
872
873    /**
874     * Multiply the cost of breaking a block that's correct in the builder's schematic by this coefficient
875     */
876    public final Setting<Double> breakCorrectBlockPenaltyMultiplier = new Setting<>(10d);
877
878    /**
879     * When this setting is true, build a schematic with the highest X coordinate being the origin, instead of the lowest
880     */
881    public final Setting<Boolean> schematicOrientationX = new Setting<>(false);
882
883    /**
884     * When this setting is true, build a schematic with the highest Y coordinate being the origin, instead of the lowest
885     */
886    public final Setting<Boolean> schematicOrientationY = new Setting<>(false);
887
888    /**
889     * When this setting is true, build a schematic with the highest Z coordinate being the origin, instead of the lowest
890     */
891    public final Setting<Boolean> schematicOrientationZ = new Setting<>(false);
892
893    /**
894     * The fallback used by the build command when no extension is specified. This may be useful if schematics of a
895     * particular format are used often, and the user does not wish to have to specify the extension with every usage.
896     */
897    public final Setting<String> schematicFallbackExtension = new Setting<>("schematic");
898
899    /**
900     * Distance to scan every tick for updates. Expanding this beyond player reach distance (i.e. setting it to 6 or above)
901     * is only necessary in very large schematics where rescanning the whole thing is costly.
902     */
903    public final Setting<Integer> builderTickScanRadius = new Setting<>(5);
904
905    /**
906     * While mining, should it also consider dropped items of the correct type as a pathing destination (as well as ore blocks)?
907     */
908    public final Setting<Boolean> mineScanDroppedItems = new Setting<>(true);
909
910    /**
911     * While mining, wait this number of milliseconds after mining an ore to see if it will drop an item
912     * instead of immediately going onto the next one
913     * <p>
914     * Thanks Louca
915     */
916    public final Setting<Long> mineDropLoiterDurationMSThanksLouca = new Setting<>(250L);
917
918    /**
919     * Trim incorrect positions too far away, helps performance but hurts reliability in very large schematics
920     */
921    public final Setting<Boolean> distanceTrim = new Setting<>(true);
922
923    /**
924     * Cancel the current path if the goal has changed, and the path originally ended in the goal but doesn't anymore.
925     * <p>
926     * Currently only runs when either MineBehavior or FollowBehavior is active.
927     * <p>
928     * For example, if Baritone is doing "mine iron_ore", the instant it breaks the ore (and it becomes air), that location
929     * is no longer a goal. This means that if this setting is true, it will stop there. If this setting were off, it would
930     * continue with its path, and walk into that location. The tradeoff is if this setting is true, it mines ores much faster
931     * since it doesn't waste any time getting into locations that no longer contain ores, but on the other hand, it misses
932     * some drops, and continues on without ever picking them up.
933     * <p>
934     * Also on cosmic prisons this should be set to true since you don't actually mine the ore it just gets replaced with stone.
935     */
936    public final Setting<Boolean> cancelOnGoalInvalidation = new Setting<>(true);
937
938    /**
939     * The "axis" command (aka GoalAxis) will go to a axis, or diagonal axis, at this Y level.
940     */
941    public final Setting<Integer> axisHeight = new Setting<>(120);
942
943    /**
944     * Disconnect from the server upon arriving at your goal
945     */
946    public final Setting<Boolean> disconnectOnArrival = new Setting<>(false);
947
948    /**
949     * Disallow MineBehavior from using X-Ray to see where the ores are. Turn this option on to force it to mine "legit"
950     * where it will only mine an ore once it can actually see it, so it won't do or know anything that a normal player
951     * couldn't. If you don't want it to look like you're X-Raying, turn this on
952     */
953    public final Setting<Boolean> legitMine = new Setting<>(false);
954
955    /**
956     * What Y level to go to for legit strip mining
957     */
958    public final Setting<Integer> legitMineYLevel = new Setting<>(11);
959
960    /**
961     * Magically see ores that are separated diagonally from existing ores. Basically like mining around the ores that it finds
962     * in case there's one there touching it diagonally, except it checks it un-legit-ly without having the mine blocks to see it.
963     * You can decide whether this looks plausible or not.
964     * <p>
965     * This is disabled because it results in some weird behavior. For example, it can """see""" the top block of a vein of iron_ore
966     * through a lava lake. This isn't an issue normally since it won't consider anything touching lava, so it just ignores it.
967     * However, this setting expands that and allows it to see the entire vein so it'll mine under the lava lake to get the iron that
968     * it can reach without mining blocks adjacent to lava. This really defeats the purpose of legitMine since a player could never
969     * do that lol, so thats one reason why its disabled
970     */
971    public final Setting<Boolean> legitMineIncludeDiagonals = new Setting<>(false);
972
973    /**
974     * When mining block of a certain type, try to mine two at once instead of one.
975     * If the block above is also a goal block, set GoalBlock instead of GoalTwoBlocks
976     * If the block below is also a goal block, set GoalBlock to the position one down instead of GoalTwoBlocks
977     */
978    public final Setting<Boolean> forceInternalMining = new Setting<>(true);
979
980    /**
981     * Modification to the previous setting, only has effect if forceInternalMining is true
982     * If true, only apply the previous setting if the block adjacent to the goal isn't air.
983     */
984    public final Setting<Boolean> internalMiningAirException = new Setting<>(true);
985
986    /**
987     * The actual GoalNear is set this distance away from the entity you're following
988     * <p>
989     * For example, set followOffsetDistance to 5 and followRadius to 0 to always stay precisely 5 blocks north of your follow target.
990     */
991    public final Setting<Double> followOffsetDistance = new Setting<>(0D);
992
993    /**
994     * The actual GoalNear is set in this direction from the entity you're following. This value is in degrees.
995     */
996    public final Setting<Float> followOffsetDirection = new Setting<>(0F);
997
998    /**
999     * The radius (for the GoalNear) of how close to your target position you actually have to be
1000     */
1001    public final Setting<Integer> followRadius = new Setting<>(3);
1002
1003    /**
1004     * Turn this on if your exploration filter is enormous, you don't want it to check if it's done,
1005     * and you are just fine with it just hanging on completion
1006     */
1007    public final Setting<Boolean> disableCompletionCheck = new Setting<>(false);
1008
1009    /**
1010     * Cached chunks (regardless of if they're in RAM or saved to disk) expire and are deleted after this number of seconds
1011     * -1 to disable
1012     * <p>
1013     * I would highly suggest leaving this setting disabled (-1).
1014     * <p>
1015     * The only valid reason I can think of enable this setting is if you are extremely low on disk space and you play on multiplayer,
1016     * and can't take (average) 300kb saved for every 512x512 area. (note that more complicated terrain is less compressible and will take more space)
1017     * <p>
1018     * However, simply discarding old chunks because they are old is inadvisable. Baritone is extremely good at correcting
1019     * itself and its paths as it learns new information, as new chunks load. There is no scenario in which having an
1020     * incorrect cache can cause Baritone to get stuck, take damage, or perform any action it wouldn't otherwise, everything
1021     * is rechecked once the real chunk is in range.
1022     * <p>
1023     * Having a robust cache greatly improves long distance pathfinding, as it's able to go around large scale obstacles
1024     * before they're in render distance. In fact, when the chunkCaching setting is disabled and Baritone starts anew
1025     * every time, or when you enter a completely new and very complicated area, it backtracks far more often because it
1026     * has to build up that cache from scratch. But after it's gone through an area just once, the next time will have zero
1027     * backtracking, since the entire area is now known and cached.
1028     */
1029    public final Setting<Long> cachedChunksExpirySeconds = new Setting<>(-1L);
1030
1031    /**
1032     * The function that is called when Baritone will log to chat. This function can be added to
1033     * via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting
1034     * {@link Setting#value};
1035     */
1036    public final Setting<Consumer<ITextComponent>> logger = new Setting<>(Minecraft.getMinecraft().ingameGUI.getChatGUI()::printChatMessage);
1037
1038    /**
1039     * The size of the box that is rendered when the current goal is a GoalYLevel
1040     */
1041    public final Setting<Double> yLevelBoxSize = new Setting<>(15D);
1042
1043    /**
1044     * The color of the current path
1045     */
1046    public final Setting<Color> colorCurrentPath = new Setting<>(Color.RED);
1047
1048    /**
1049     * The color of the next path
1050     */
1051    public final Setting<Color> colorNextPath = new Setting<>(Color.MAGENTA);
1052
1053    /**
1054     * The color of the blocks to break
1055     */
1056    public final Setting<Color> colorBlocksToBreak = new Setting<>(Color.RED);
1057
1058    /**
1059     * The color of the blocks to place
1060     */
1061    public final Setting<Color> colorBlocksToPlace = new Setting<>(Color.GREEN);
1062
1063    /**
1064     * The color of the blocks to walk into
1065     */
1066    public final Setting<Color> colorBlocksToWalkInto = new Setting<>(Color.MAGENTA);
1067
1068    /**
1069     * The color of the best path so far
1070     */
1071    public final Setting<Color> colorBestPathSoFar = new Setting<>(Color.BLUE);
1072
1073    /**
1074     * The color of the path to the most recent considered node
1075     */
1076    public final Setting<Color> colorMostRecentConsidered = new Setting<>(Color.CYAN);
1077
1078    /**
1079     * The color of the goal box
1080     */
1081    public final Setting<Color> colorGoalBox = new Setting<>(Color.GREEN);
1082
1083    /**
1084     * The color of the goal box when it's inverted
1085     */
1086    public final Setting<Color> colorInvertedGoalBox = new Setting<>(Color.RED);
1087
1088    /**
1089     * The color of all selections
1090     */
1091    public final Setting<Color> colorSelection = new Setting<>(Color.CYAN);
1092
1093    /**
1094     * The color of the selection pos 1
1095     */
1096    public final Setting<Color> colorSelectionPos1 = new Setting<>(Color.BLACK);
1097
1098    /**
1099     * The color of the selection pos 2
1100     */
1101    public final Setting<Color> colorSelectionPos2 = new Setting<>(Color.ORANGE);
1102
1103    /**
1104     * The opacity of the selection. 0 is completely transparent, 1 is completely opaque
1105     */
1106    public final Setting<Float> selectionOpacity = new Setting<>(.5f);
1107
1108    /**
1109     * Line width of the goal when rendered, in pixels
1110     */
1111    public final Setting<Float> selectionLineWidth = new Setting<>(2F);
1112
1113    /**
1114     * Render selections
1115     */
1116    public final Setting<Boolean> renderSelection = new Setting<>(true);
1117
1118    /**
1119     * Ignore depth when rendering selections
1120     */
1121    public final Setting<Boolean> renderSelectionIgnoreDepth = new Setting<>(true);
1122
1123    /**
1124     * Render selection corners
1125     */
1126    public final Setting<Boolean> renderSelectionCorners = new Setting<>(true);
1127
1128    /**
1129     * Use sword to mine.
1130     */
1131    public final Setting<Boolean> useSwordToMine = new Setting<>(true);
1132
1133    /**
1134     * Desktop notifications
1135     */
1136    public final Setting<Boolean> desktopNotifications = new Setting<>(false);
1137
1138    /**
1139     * Desktop notification on path complete
1140     */
1141    public final Setting<Boolean> notificationOnPathComplete = new Setting<>(true);
1142
1143    /**
1144     * Desktop notification on farm fail
1145     */
1146    public final Setting<Boolean> notificationOnFarmFail = new Setting<>(true);
1147
1148    /**
1149     * Desktop notification on build finished
1150     */
1151    public final Setting<Boolean> notificationOnBuildFinished = new Setting<>(true);
1152
1153    /**
1154     * Desktop notification on explore finished
1155     */
1156    public final Setting<Boolean> notificationOnExploreFinished = new Setting<>(true);
1157
1158    /**
1159     * Desktop notification on mine fail
1160     */
1161    public final Setting<Boolean> notificationOnMineFail = new Setting<>(true);
1162
1163    /**
1164     * A map of lowercase setting field names to their respective setting
1165     */
1166    public final Map<String, Setting<?>> byLowerName;
1167
1168    /**
1169     * A list of all settings
1170     */
1171    public final List<Setting<?>> allSettings;
1172
1173    public final Map<Setting<?>, Type> settingTypes;
1174
1175    public final class Setting<T> {
1176
1177        public T value;
1178        public final T defaultValue;
1179        private String name;
1180
1181        @SuppressWarnings("unchecked")
1182        private Setting(T value) {
1183            if (value == null) {
1184                throw new IllegalArgumentException("Cannot determine value type class from null");
1185            }
1186            this.value = value;
1187            this.defaultValue = value;
1188        }
1189
1190        /**
1191         * Deprecated! Please use .value directly instead
1192         *
1193         * @return the current setting value
1194         */
1195        @Deprecated
1196        public final T get() {
1197            return value;
1198        }
1199
1200        public final String getName() {
1201            return name;
1202        }
1203
1204        public Class<T> getValueClass() {
1205            // noinspection unchecked
1206            return (Class<T>) TypeUtils.resolveBaseClass(getType());
1207        }
1208
1209        @Override
1210        public String toString() {
1211            return SettingsUtil.settingToString(this);
1212        }
1213
1214        /**
1215         * Reset this setting to its default value
1216         */
1217        public void reset() {
1218            value = defaultValue;
1219        }
1220
1221        public final Type getType() {
1222            return settingTypes.get(this);
1223        }
1224    }
1225
1226    // here be dragons
1227
1228    Settings() {
1229        Field[] temp = getClass().getFields();
1230
1231        Map<String, Setting<?>> tmpByName = new HashMap<>();
1232        List<Setting<?>> tmpAll = new ArrayList<>();
1233        Map<Setting<?>, Type> tmpSettingTypes = new HashMap<>();
1234
1235        try {
1236            for (Field field : temp) {
1237                if (field.getType().equals(Setting.class)) {
1238                    Setting<?> setting = (Setting<?>) field.get(this);
1239                    String name = field.getName();
1240                    setting.name = name;
1241                    name = name.toLowerCase();
1242                    if (tmpByName.containsKey(name)) {
1243                        throw new IllegalStateException("Duplicate setting name");
1244                    }
1245                    tmpByName.put(name, setting);
1246                    tmpAll.add(setting);
1247                    tmpSettingTypes.put(setting, ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]);
1248                }
1249            }
1250        } catch (IllegalAccessException e) {
1251            throw new IllegalStateException(e);
1252        }
1253        byLowerName = Collections.unmodifiableMap(tmpByName);
1254        allSettings = Collections.unmodifiableList(tmpAll);
1255        settingTypes = Collections.unmodifiableMap(tmpSettingTypes);
1256    }
1257
1258    @SuppressWarnings("unchecked")
1259    public <T> List<Setting<T>> getAllValuesByType(Class<T> cla$$) {
1260        List<Setting<T>> result = new ArrayList<>();
1261        for (Setting<?> setting : allSettings) {
1262            if (setting.getValueClass().equals(cla$$)) {
1263                result.add((Setting<T>) setting);
1264            }
1265        }
1266        return result;
1267    }
1268}