Add buildSubstitutes setting to builder
This commit is contained in:
parent
13547781d2
commit
fc1a2a6112
@ -222,6 +222,13 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Map<Block, List<Block>>> buildValidSubstitutes = new Setting<>(new HashMap<>());
|
||||
|
||||
/**
|
||||
* A mapping of blocks to blocks to be built instead
|
||||
* <p>
|
||||
* If a schematic asks for a block on this mapping, Baritone will place the first placeable block in the mapped list
|
||||
*/
|
||||
public final Setting<Map<Block, List<Block>>> buildSubstitutes = new Setting<>(new HashMap<>());
|
||||
|
||||
/**
|
||||
* A list of blocks to become air
|
||||
* <p>
|
||||
|
71
src/api/java/baritone/api/schematic/SubstituteSchematic.java
Normal file
71
src/api/java/baritone/api/schematic/SubstituteSchematic.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.schematic;
|
||||
|
||||
import baritone.api.utils.BlockOptionalMetaLookup;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SubstituteSchematic extends AbstractSchematic {
|
||||
|
||||
private final ISchematic schematic;
|
||||
private final Map<Block, List<Block>> substitutions;
|
||||
|
||||
public SubstituteSchematic(ISchematic schematic, Map<Block,List<Block>> substitutions) {
|
||||
super(schematic.widthX(), schematic.heightY(), schematic.lengthZ());
|
||||
this.schematic = schematic;
|
||||
this.substitutions = substitutions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inSchematic(int x, int y, int z, IBlockState currentState) {
|
||||
return schematic.inSchematic(x, y, z, currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
|
||||
IBlockState desired = schematic.desiredState(x, y, z, current, approxPlaceable);
|
||||
Block desiredBlock = desired.getBlock();
|
||||
if (!substitutions.containsKey(desiredBlock)) {
|
||||
return desired;
|
||||
}
|
||||
List<Block> substitutes = substitutions.get(desiredBlock);
|
||||
if (substitutes.contains(current.getBlock()) && !current.getBlock().equals(Blocks.AIR)) {// don't preserve air, it's almost always there and almost never wanted
|
||||
System.out.println(String.format("%s is already placed", current));
|
||||
return current;
|
||||
}
|
||||
for (Block substitute : substitutes) {
|
||||
if (substitute.equals(Blocks.AIR)) {
|
||||
System.out.println("air, lol");
|
||||
return Blocks.AIR.getDefaultState(); // can always "place" air
|
||||
}
|
||||
for (IBlockState placeable : approxPlaceable) {
|
||||
if (substitute.equals(placeable.getBlock())) {
|
||||
System.out.println(String.format("%s can be placed", placeable));
|
||||
return placeable;
|
||||
}
|
||||
}
|
||||
System.out.println(String.format("%s is not an option", substitute));
|
||||
}
|
||||
System.out.println(String.format("%s fail", substitutes.get(0).getDefaultState()));
|
||||
return substitutes.get(0).getDefaultState();
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ 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.format.ISchematicFormat;
|
||||
@ -84,6 +85,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
this.name = name;
|
||||
this.schematic = schematic;
|
||||
this.realSchematic = null;
|
||||
if (!Baritone.settings().buildSubstitutes.value.isEmpty()) {
|
||||
this.schematic = new SubstituteSchematic(this.schematic, Baritone.settings().buildSubstitutes.value);
|
||||
}
|
||||
int x = origin.getX();
|
||||
int y = origin.getY();
|
||||
int z = origin.getZ();
|
||||
|
Loading…
Reference in New Issue
Block a user