simplify, remove setting changed event, always construct new precomputeddata
This commit is contained in:
parent
6b0fb1721b
commit
85ab317c6c
@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.api;
|
||||
|
||||
import baritone.api.event.events.SettingChangedEvent;
|
||||
import baritone.api.utils.NotificationHelper;
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import baritone.api.utils.TypeUtils;
|
||||
@ -35,8 +34,8 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Baritone's settings. Settings apply to all Baritone instances.
|
||||
@ -197,7 +196,7 @@ public final class Settings {
|
||||
* Blocks that Baritone is not allowed to break
|
||||
*/
|
||||
public final Setting<List<Block>> blocksToDisallowBreaking = new Setting<>(new ArrayList<>(
|
||||
// Leave Empty by Default
|
||||
// Leave Empty by Default
|
||||
));
|
||||
|
||||
/**
|
||||
@ -913,7 +912,7 @@ public final class Settings {
|
||||
/**
|
||||
* Only build the selected part of schematics
|
||||
*/
|
||||
public final Setting<Boolean> buildOnlySelection = new Setting<>(false);
|
||||
public final Setting<Boolean> buildOnlySelection = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely
|
||||
@ -1303,13 +1302,6 @@ public final class Settings {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void set(T value) {
|
||||
this.value = value;
|
||||
if (BaritoneAPI.getProvider() != null) {
|
||||
BaritoneAPI.getProvider().getAllBaritones().forEach(iBaritone -> iBaritone.getGameEventHandler().onSettingChanged(new SettingChangedEvent(this)));
|
||||
}
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.event.events;
|
||||
|
||||
import baritone.api.Settings;
|
||||
|
||||
public class SettingChangedEvent {
|
||||
|
||||
private final Settings.Setting<?> setting;
|
||||
|
||||
public SettingChangedEvent(Settings.Setting<?> setting) {
|
||||
this.setting = setting;
|
||||
}
|
||||
|
||||
public Settings.Setting<?> getSetting() {
|
||||
return setting;
|
||||
}
|
||||
}
|
@ -71,7 +71,4 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
||||
|
||||
@Override
|
||||
default void onPathEvent(PathEvent event) {}
|
||||
|
||||
@Override
|
||||
default void onSettingChanged(SettingChangedEvent event) {}
|
||||
}
|
||||
|
@ -144,11 +144,4 @@ public interface IGameEventListener {
|
||||
* @param event The event
|
||||
*/
|
||||
void onPathEvent(PathEvent event);
|
||||
|
||||
/**
|
||||
* When the player changes a setting
|
||||
*
|
||||
* @param event The event
|
||||
*/
|
||||
void onSettingChanged(SettingChangedEvent event);
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ public class SettingsUtil {
|
||||
if (!intendedType.isInstance(parsed)) {
|
||||
throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass());
|
||||
}
|
||||
setting.set(parsed);
|
||||
setting.value = parsed;
|
||||
}
|
||||
|
||||
private interface ISettingParser<T> {
|
||||
|
@ -33,7 +33,6 @@ import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.path.PathExecutor;
|
||||
import baritone.pathing.precompute.PrecomputedData;
|
||||
import baritone.utils.PathRenderer;
|
||||
import baritone.utils.PathingCommandContext;
|
||||
import baritone.utils.pathing.Favoring;
|
||||
@ -75,11 +74,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
|
||||
private final LinkedBlockingQueue<PathEvent> toDispatch = new LinkedBlockingQueue<>();
|
||||
|
||||
public PrecomputedData precomputedData;
|
||||
|
||||
public PathingBehavior(Baritone baritone) {
|
||||
super(baritone);
|
||||
precomputedData = new PrecomputedData();
|
||||
}
|
||||
|
||||
private void queuePathEvent(PathEvent event) {
|
||||
@ -104,10 +100,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
return;
|
||||
}
|
||||
|
||||
if (ticksElapsedSoFar % 200 == 0) {
|
||||
precomputedData = new PrecomputedData(); // This is here for now in case settings aren't changed in normal ways, should mean it is updated whatever once every 10 seconds
|
||||
}
|
||||
|
||||
expectedSegmentStart = pathStart();
|
||||
baritone.getPathingControlManager().preTick();
|
||||
tickPath();
|
||||
@ -268,7 +260,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
if (command instanceof PathingCommandContext) {
|
||||
context = ((PathingCommandContext) command).desiredCalcContext;
|
||||
} else {
|
||||
context = new CalculationContext(baritone, true, precomputedData);
|
||||
context = new CalculationContext(baritone, true);
|
||||
}
|
||||
if (goal == null) {
|
||||
return false;
|
||||
@ -465,11 +457,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
return feet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingChanged(SettingChangedEvent event) {
|
||||
this.precomputedData = new PrecomputedData();
|
||||
}
|
||||
|
||||
/**
|
||||
* In a new thread, pathfind to target blockpos
|
||||
*
|
||||
|
@ -148,7 +148,7 @@ public class SetCommand extends Command {
|
||||
}
|
||||
//noinspection unchecked
|
||||
Settings.Setting<Boolean> asBoolSetting = (Settings.Setting<Boolean>) setting;
|
||||
asBoolSetting.set(!asBoolSetting.value);
|
||||
asBoolSetting.value ^= true;
|
||||
logDirect(String.format(
|
||||
"Toggled setting %s to %s",
|
||||
setting.getName(),
|
||||
|
@ -156,11 +156,6 @@ public final class GameEventHandler implements IEventBus, Helper {
|
||||
listeners.forEach(l -> l.onPathEvent(event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingChanged(SettingChangedEvent event) {
|
||||
listeners.forEach(l -> l.onSettingChanged(event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void registerEventListener(IGameEventListener listener) {
|
||||
this.listeners.add(listener);
|
||||
|
@ -80,11 +80,11 @@ public class CalculationContext {
|
||||
public final PrecomputedData precomputedData;
|
||||
|
||||
public CalculationContext(IBaritone baritone) {
|
||||
this(baritone, false, new PrecomputedData());
|
||||
this(baritone, false);
|
||||
}
|
||||
|
||||
public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread, PrecomputedData precomputedData) {
|
||||
this.precomputedData = precomputedData;
|
||||
public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) {
|
||||
this.precomputedData = new PrecomputedData();
|
||||
this.safeForThreadedUse = forUseOnAnotherThread;
|
||||
this.baritone = baritone;
|
||||
EntityPlayerSP player = baritone.getPlayerContext().player();
|
||||
|
@ -350,7 +350,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false);
|
||||
|
||||
// first and foremost, if allowSprint is off, or if we don't have enough hunger, don't try and sprint
|
||||
if (!new CalculationContext(behavior.baritone, false, null).canSprint) {
|
||||
if (!new CalculationContext(behavior.baritone, false).canSprint) {
|
||||
return false;
|
||||
}
|
||||
IMovement current = path.movements().get(pathPosition);
|
||||
|
@ -17,25 +17,16 @@
|
||||
|
||||
package baritone.pathing.precompute;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import static baritone.pathing.movement.MovementHelper.isFlowing;
|
||||
import static baritone.pathing.movement.MovementHelper.isWater;
|
||||
|
||||
public class PrecomputedData { // TODO add isFullyPassable
|
||||
private final int[] data = new int[Block.BLOCK_STATE_IDS.size()]; // Has to be of type boolean due to otherwise it has a generic type
|
||||
|
||||
private final int[] data = new int[Block.BLOCK_STATE_IDS.size()];
|
||||
|
||||
private final int completedMask = 0b1;
|
||||
private final int canWalkOnMask = 0b10;
|
||||
@ -43,31 +34,27 @@ public class PrecomputedData { // TODO add isFullyPassable
|
||||
private final int canWalkThroughMask = 0b1000;
|
||||
private final int canWalkThroughSpecialMask = 0b10000;
|
||||
|
||||
public PrecomputedData() {
|
||||
Arrays.fill(data, 0);
|
||||
}
|
||||
|
||||
private void fillData(int id, IBlockState state) {
|
||||
Optional<Boolean> canWalkOnState = MovementHelper.canWalkOnBlockState(state);
|
||||
if (canWalkOnState.isPresent()) {
|
||||
if (canWalkOnState.get()) {
|
||||
data[id] = data[id] | canWalkOnMask;
|
||||
data[id] |= canWalkOnMask;
|
||||
}
|
||||
} else {
|
||||
data[id] = data[id] | canWalkOnSpecialMask;
|
||||
data[id] |= canWalkOnSpecialMask;
|
||||
}
|
||||
|
||||
Optional<Boolean> canWalkThroughState = MovementHelper.canWalkThroughBlockState(state);
|
||||
if (canWalkThroughState.isPresent()) {
|
||||
if (canWalkThroughState.get()) {
|
||||
data[id] = data[id] | canWalkThroughMask;
|
||||
data[id] |= canWalkThroughMask;
|
||||
}
|
||||
} else {
|
||||
data[id] = data[id] | canWalkThroughSpecialMask;
|
||||
data[id] |= canWalkThroughSpecialMask;
|
||||
}
|
||||
|
||||
|
||||
data[id] = data[id] | completedMask;
|
||||
data[id] |= completedMask;
|
||||
}
|
||||
|
||||
public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||
@ -92,7 +79,7 @@ public class PrecomputedData { // TODO add isFullyPassable
|
||||
}
|
||||
|
||||
if ((data[id] & canWalkThroughSpecialMask) != 0) {
|
||||
return MovementHelper.canWalkOnPosition(bsi, x, y, z, state);
|
||||
return MovementHelper.canWalkThroughPosition(bsi, x, y, z, state);
|
||||
} else {
|
||||
return (data[id] & canWalkThroughMask) != 0;
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ import baritone.api.process.IBuilderProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.api.schematic.FillSchematic;
|
||||
import baritone.api.schematic.SubstituteSchematic;
|
||||
import baritone.api.schematic.ISchematic;
|
||||
import baritone.api.schematic.IStaticSchematic;
|
||||
import baritone.api.schematic.SubstituteSchematic;
|
||||
import baritone.api.schematic.format.ISchematicFormat;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.RayTraceUtils;
|
||||
@ -38,13 +38,12 @@ import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.precompute.PrecomputedData;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.PathingCommandContext;
|
||||
import baritone.utils.schematic.MapArtSchematic;
|
||||
import baritone.utils.schematic.SelectionSchematic;
|
||||
import baritone.utils.schematic.SchematicSystem;
|
||||
import baritone.utils.schematic.SelectionSchematic;
|
||||
import baritone.utils.schematic.schematica.SchematicaHelper;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@ -607,7 +606,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
}
|
||||
// this is not in render distance
|
||||
if (!observedCompleted.contains(BetterBlockPos.longHash(blockX, blockY, blockZ))
|
||||
&& !Baritone.settings().buildSkipBlocks.value.contains(schematic.desiredState(x, y, z, current, this.approxPlaceable).getBlock())) {
|
||||
&& !Baritone.settings().buildSkipBlocks.value.contains(schematic.desiredState(x, y, z, current, this.approxPlaceable).getBlock())) {
|
||||
// and we've never seen this position be correct
|
||||
// therefore mark as incorrect
|
||||
incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ));
|
||||
@ -894,7 +893,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
private final int originZ;
|
||||
|
||||
public BuilderCalculationContext() {
|
||||
super(BuilderProcess.this.baritone, true, new PrecomputedData()); // wew lad
|
||||
super(BuilderProcess.this.baritone, true); // wew lad
|
||||
this.placeable = approxPlaceable(9);
|
||||
this.schematic = BuilderProcess.this.schematic;
|
||||
this.originX = origin.getX();
|
||||
|
@ -158,7 +158,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
|
||||
public class GetToBlockCalculationContext extends CalculationContext {
|
||||
|
||||
public GetToBlockCalculationContext(boolean forUseOnAnotherThread) {
|
||||
super(GetToBlockProcess.super.baritone, forUseOnAnotherThread, null);
|
||||
super(GetToBlockProcess.super.baritone, forUseOnAnotherThread);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,7 +112,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
|
||||
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
|
||||
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
||||
CalculationContext context = new CalculationContext(baritone, true, new PrecomputedData());
|
||||
CalculationContext context = new CalculationContext(baritone, true);
|
||||
Baritone.getExecutor().execute(() -> rescan(curr, context));
|
||||
}
|
||||
if (Baritone.settings().legitMine.value) {
|
||||
|
Loading…
Reference in New Issue
Block a user