some efficiency fixes to filters + qol for leijurv

This commit is contained in:
Logan Darklock 2019-08-30 12:25:59 -07:00
parent e3c4d06b2b
commit 4354d09c20
No known key found for this signature in database
GPG Key ID: B8C37CEDE1AC60EA
25 changed files with 145 additions and 77 deletions

View File

@ -22,12 +22,12 @@ public class BlockListFilter implements IBlockFilter {
@Override
public boolean selected(@Nonnull IBlockState blockstate) {
return false;
return blocks.contains(blockstate.getBlock());
}
@Override
public List<Block> blocks() {
return null;
return blocks;
}
@Override

View File

@ -17,6 +17,7 @@ import static java.util.Objects.isNull;
public class BlockSelector implements IBlockFilter {
private final Block block;
private final IBlockState blockstate;
private final int damage;
private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$");
public BlockSelector(@Nonnull String selector) {
@ -38,12 +39,12 @@ public class BlockSelector implements IBlockFilter {
block = Block.REGISTRY.getObject(id);
//noinspection deprecation
blockstate = hasData ? block.getStateFromMeta(Integer.parseInt(matchResult.group(2))) : null;
damage = block.damageDropped(blockstate);
}
@Override
public boolean selected(@Nonnull IBlockState blockstate) {
return blockstate.getBlock() == block && (isNull(this.blockstate) ||
block.damageDropped(blockstate) == block.damageDropped(this.blockstate));
return blockstate.getBlock() == block && (isNull(this.blockstate) || block.damageDropped(blockstate) == damage);
}
@Override

View File

@ -5,37 +5,36 @@ import net.minecraft.block.state.IBlockState;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import static java.util.Arrays.asList;
public class CompositeBlockFilter implements IBlockFilter {
List<IBlockFilter> filters = new ArrayList<>();
public CompositeBlockFilter() {
}
private IBlockFilter[] filters;
public CompositeBlockFilter(List<? extends IBlockFilter> filters) {
this.filters.addAll(filters);
this.filters = filters.toArray(new IBlockFilter[0]);
}
public CompositeBlockFilter(IBlockFilter... filters) {
this.filters.addAll(asList(filters));
this.filters = filters;
}
@Override
public boolean selected(@Nonnull IBlockState blockstate) {
return filters.stream()
.map(f -> f.selected(blockstate))
.filter(Boolean::valueOf).findFirst()
.orElse(false);
for (IBlockFilter filter : filters) {
if (filter.selected(blockstate)) {
return true;
}
}
return false;
}
@Override
public List<Block> blocks() {
return filters.stream()
return Arrays.stream(filters)
.map(IBlockFilter::blocks)
.flatMap(Collection::stream)
.collect(Collectors.toCollection(ArrayList::new));
@ -45,7 +44,7 @@ public class CompositeBlockFilter implements IBlockFilter {
public String toString() {
return String.format(
"CompositeBlockFilter{%s}",
String.join(",", filters.stream().map(Object::toString).toArray(String[]::new))
String.join(",", Arrays.stream(filters).map(Object::toString).toArray(String[]::new))
);
}
}

View File

@ -151,7 +151,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
if (setting.getName().equalsIgnoreCase(pair.first())) {
logRanCommand(msg);
CommandManager.execute(String.format("set %s %s", setting.getName(), argc.getS()));
CommandManager.execute(String.format("set %s %s", setting.getName(), argc.getString()));
return true;
}
}
@ -203,11 +203,11 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
return new TabCompleteHelper()
.addCommands()
.addSettings()
.filterPrefix(argc.getS())
.filterPrefix(argc.getString())
.stream();
}
Settings.Setting setting = settings.byLowerName.get(argc.getS().toLowerCase(Locale.US));
Settings.Setting setting = settings.byLowerName.get(argc.getString().toLowerCase(Locale.US));
if (nonNull(setting)) {
if (setting.getValueClass() == Boolean.class) {
@ -219,7 +219,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
helper.append(of("false", "true"));
}
return helper.filterPrefix(argc.getS()).stream();
return helper.filterPrefix(argc.getString()).stream();
} else {
return of(SettingsUtil.settingValueToString(setting));
}

View File

@ -39,7 +39,7 @@ public class CommandArgument {
this.rawRest = rawRest;
}
public <E extends Enum<?>> E getE(Class<E> enumClass) {
public <E extends Enum<?>> E getEnum(Class<E> enumClass) {
//noinspection OptionalGetWithoutIsPresent
return Arrays.stream(enumClass.getEnumConstants())
.filter(e -> e.name().equalsIgnoreCase(value))

View File

@ -16,7 +16,7 @@ public class BlockById implements IDatatypeFor<Block> {
}
public BlockById(ArgConsumer consumer) {
ResourceLocation id = new ResourceLocation(consumer.getS());
ResourceLocation id = new ResourceLocation(consumer.getString());
if ((block = Block.REGISTRY.getObject(id)) == Blocks.AIR) {
throw new RuntimeException("no block found by that id");
@ -36,7 +36,7 @@ public class BlockById implements IDatatypeFor<Block> {
.stream()
.map(Object::toString)
)
.filterPrefixNamespaced(consumer.getS())
.filterPrefixNamespaced(consumer.getString())
.sortAlphabetically()
.stream();
}

View File

@ -18,7 +18,7 @@ public class EntityClassById implements IDatatypeFor<Class<? extends Entity>> {
}
public EntityClassById(ArgConsumer consumer) {
ResourceLocation id = new ResourceLocation(consumer.getS());
ResourceLocation id = new ResourceLocation(consumer.getString());
if (isNull(entity = EntityList.REGISTRY.getObject(id))) {
throw new RuntimeException("no entity found by that id");
@ -38,7 +38,7 @@ public class EntityClassById implements IDatatypeFor<Class<? extends Entity>> {
.stream()
.map(Object::toString)
)
.filterPrefixNamespaced(consumer.getS())
.filterPrefixNamespaced(consumer.getString())
.sortAlphabetically()
.stream();
}

View File

@ -13,7 +13,7 @@ public class ForBlockSelector implements IDatatypeFor<BlockSelector> {
}
public ForBlockSelector(ArgConsumer consumer) {
selector = new BlockSelector(consumer.getS());
selector = new BlockSelector(consumer.getString());
}
@Override

View File

@ -20,7 +20,7 @@ public class PlayerByUsername implements IDatatypeFor<EntityPlayer> {
}
public PlayerByUsername(ArgConsumer consumer) {
String username = consumer.getS();
String username = consumer.getString();
if (isNull(
player = players
@ -46,7 +46,7 @@ public class PlayerByUsername implements IDatatypeFor<EntityPlayer> {
.stream()
.map(EntityPlayer::getName)
)
.filterPrefix(consumer.getS())
.filterPrefix(consumer.getString())
.sortAlphabetically()
.stream();
}

View File

@ -23,7 +23,7 @@ public class RelativeCoordinate implements IDatatypePost<Double, Double> {
throw new RuntimeException("relative coordinate requires an argument");
}
Matcher matcher = PATTERN.matcher(consumer.getS());
Matcher matcher = PATTERN.matcher(consumer.getString());
if (!matcher.matches()) {
throw new RuntimeException("pattern doesn't match");
@ -48,7 +48,7 @@ public class RelativeCoordinate implements IDatatypePost<Double, Double> {
@Override
public Stream<String> tabComplete(ArgConsumer consumer) {
if (!consumer.has(2) && consumer.getS().matches("^(~|$)")) {
if (!consumer.has(2) && consumer.getString().matches("^(~|$)")) {
return Stream.of("~");
}

View File

@ -20,7 +20,7 @@ public class RelativeFile implements IDatatypePost<File, File> {
public RelativeFile(ArgConsumer consumer) {
try {
path = FileSystems.getDefault().getPath(consumer.getS());
path = FileSystems.getDefault().getPath(consumer.getString());
} catch (InvalidPathException e) {
throw new RuntimeException("invalid path");
}
@ -32,7 +32,7 @@ public class RelativeFile implements IDatatypePost<File, File> {
}
public static Stream<String> tabComplete(ArgConsumer consumer, File base) {
String currentPathStringThing = consumer.getS();
String currentPathStringThing = consumer.getString();
Path currentPath = FileSystems.getDefault().getPath(currentPathStringThing);
Path basePath = currentPath.isAbsolute() ? currentPath.getRoot() : base.toPath();
boolean useParent = !currentPathStringThing.isEmpty() && !currentPathStringThing.endsWith(File.separator);

View File

@ -36,7 +36,7 @@ public class BuildCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
String filename = String.format("%s.schematic", args.getS());
String filename = String.format("%s.schematic", args.getString());
BetterBlockPos origin = ctx.playerFeet();
BetterBlockPos buildOrigin;

View File

@ -44,7 +44,7 @@ public class ExploreFilterCommand extends Command {
boolean invert = false;
if (args.has()) {
if (args.getS().equalsIgnoreCase("invert")) {
if (args.getString().equalsIgnoreCase("invert")) {
invert = true;
} else {
throw new CommandInvalidTypeException(args.consumed(), "either \"invert\" or nothing");

View File

@ -57,13 +57,13 @@ public class FollowCommand extends Command {
List<Class<? extends Entity>> classes = new ArrayList<>();
if (args.hasExactlyOne()) {
baritone.getFollowProcess().follow((group = args.getE(FollowGroup.class)).filter);
baritone.getFollowProcess().follow((group = args.getEnum(FollowGroup.class)).filter);
list = null;
} else {
args.requireMin(2);
group = null;
list = args.getE(FollowList.class);
list = args.getEnum(FollowList.class);
while (args.has()) {
//noinspection unchecked
@ -109,13 +109,13 @@ public class FollowCommand extends Command {
return new TabCompleteHelper()
.append(FollowGroup.class)
.append(FollowList.class)
.filterPrefix(args.getS())
.filterPrefix(args.getString())
.stream();
} else {
Class<? extends IDatatype> followType;
try {
followType = args.getE(FollowList.class).datatype;
followType = args.getEnum(FollowList.class).datatype;
} catch (NullPointerException e) {
return Stream.empty();
}

View File

@ -43,7 +43,7 @@ public class GoalCommand extends Command {
protected void executed(String label, ArgConsumer args, Settings settings) {
ICustomGoalProcess goalProcess = baritone.getCustomGoalProcess();
if (args.has() && asList("reset", "clear", "none").contains(args.peekS())) {
if (args.has() && asList("reset", "clear", "none").contains(args.peekString())) {
args.requireMax(1);
if (nonNull(goalProcess.getGoal())) {
@ -83,7 +83,7 @@ public class GoalCommand extends Command {
}
}
return helper.filterPrefix(args.getS()).stream();
return helper.filterPrefix(args.getString()).stream();
}
@Override

View File

@ -89,7 +89,7 @@ public class HelpCommand extends Command {
FORCE_COMMAND_PREFIX + "help %d"
);
} else {
String commandName = args.getS().toLowerCase();
String commandName = args.getString().toLowerCase();
Command command = getCommand(commandName);
if (isNull(command)) {
@ -112,7 +112,7 @@ public class HelpCommand extends Command {
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
if (args.hasExactlyOne()) {
return new TabCompleteHelper().addCommands().filterPrefix(args.getS()).stream();
return new TabCompleteHelper().addCommands().filterPrefix(args.getString()).stream();
}
return Stream.empty();

View File

@ -68,7 +68,7 @@ public class PathCommand extends Command {
if (!args.has(2)) {
return new TabCompleteHelper()
.append("~")
.filterPrefix(args.getS())
.filterPrefix(args.getString())
.stream();
}
}

View File

@ -49,13 +49,13 @@ public class ProcCommand extends Command {
logDirect(String.format(
"Class: %s\n" +
"Priority: %s\n" +
"Temporary: %s\n" +
"Priority: %f\n" +
"Temporary: %b\n" +
"Display name: %s\n" +
"Last command: %s",
process.getClass().getTypeName(),
Double.toString(process.priority()),
Boolean.toString(process.isTemporary()),
process.priority(),
process.isTemporary(),
process.displayName(),
pathingControlManager
.mostRecentCommand()

View File

@ -51,12 +51,12 @@ public class SetCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
String arg = args.has() ? args.getS().toLowerCase(Locale.US) : "list";
String arg = args.has() ? args.getString().toLowerCase(Locale.US) : "list";
boolean viewModified = asList("m", "mod", "modified").contains(arg);
boolean viewAll = asList("all", "l", "list").contains(arg);
boolean paginate = viewModified | viewAll;
if (paginate) {
String search = args.has() && args.peekAsOrNull(Integer.class) == null ? args.getS() : "";
String search = args.has() && args.peekAsOrNull(Integer.class) == null ? args.getString() : "";
args.requireMax(1);
List<? extends Settings.Setting> toPaginate =
@ -122,7 +122,7 @@ public class SetCommand extends Command {
logDirect("Please specify 'all' as an argument to reset to confirm you'd really like to do this");
logDirect("ALL settings will be reset. Use the 'set modified' or 'modified' commands to see what will be reset.");
logDirect("Specify a setting name instead of 'all' to only reset one setting");
} else if (args.peekS().equalsIgnoreCase("all")) {
} else if (args.peekString().equalsIgnoreCase("all")) {
SettingsUtil.modifiedSettings(settings).forEach(Settings.Setting::reset);
logDirect("All settings have been reset to their default values");
@ -134,7 +134,7 @@ public class SetCommand extends Command {
args.requireMin(1);
}
String settingName = doingSomething ? args.getS() : arg;
String settingName = doingSomething ? args.getString() : arg;
Settings.Setting<?> setting = settings.allSettings.stream()
.filter(s -> s.getName().equalsIgnoreCase(settingName))
.findFirst()
@ -166,7 +166,7 @@ public class SetCommand extends Command {
Boolean.toString((Boolean) setting.value)
));
} else {
String newValue = args.getS();
String newValue = args.getString();
try {
SettingsUtil.parseAndApply(settings, arg, newValue);
@ -210,19 +210,19 @@ public class SetCommand extends Command {
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
if (args.has()) {
String arg = args.getS();
String arg = args.getString();
if (args.hasExactlyOne()) {
if (arg.equalsIgnoreCase("reset")) {
return new TabCompleteHelper()
.addModifiedSettings()
.prepend("all")
.filterPrefix(args.getS())
.filterPrefix(args.getString())
.stream();
} else if (arg.equalsIgnoreCase("toggle")) {
return new TabCompleteHelper()
.addToggleableSettings()
.filterPrefix(args.getS())
.filterPrefix(args.getString())
.stream();
}
@ -238,7 +238,7 @@ public class SetCommand extends Command {
helper.append(of("false", "true"));
}
return helper.filterPrefix(args.getS()).stream();
return helper.filterPrefix(args.getString()).stream();
} else {
return Stream.of(settingValueToString(setting));
}

View File

@ -84,21 +84,21 @@ public class ArgConsumer {
return peek().is(type);
}
public String peekS(int index) {
public String peekString(int index) {
return peek(index).value;
}
public String peekS() {
return peekS(0);
public String peekString() {
return peekString(0);
}
public <E extends Enum<?>> E peekE(Class<E> enumClass) {
return peek().getE(enumClass);
public <E extends Enum<?>> E peekEnum(Class<E> enumClass) {
return peek().getEnum(enumClass);
}
public <E extends Enum<?>> E peekEOrNull(Class<E> enumClass) {
public <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass) {
try {
return peekE(enumClass);
return peekEnum(enumClass);
} catch (NoSuchElementException e) {
return null;
}
@ -171,22 +171,22 @@ public class ArgConsumer {
return arg;
}
public String getS() {
public String getString() {
return get().value;
}
public <E extends Enum<?>> E getE(Class<E> enumClass) {
public <E extends Enum<?>> E getEnum(Class<E> enumClass) {
try {
return get().getE(enumClass);
return get().getEnum(enumClass);
} catch (NoSuchElementException e) {
throw new CommandInvalidTypeException(consumed(), enumClass.getSimpleName());
}
}
public <E extends Enum<?>> E getEOrNull(Class<E> enumClass) {
public <E extends Enum<?>> E getEnumOrNull(Class<E> enumClass) {
try {
peekE(enumClass);
return getE(enumClass);
peekEnum(enumClass);
return getEnum(enumClass);
} catch (CommandInvalidTypeException e) {
return null;
}

View File

@ -1,3 +1,20 @@
/*
* 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.launch.mixins;
import net.minecraft.client.gui.GuiChat;

View File

@ -1,3 +1,20 @@
/*
* 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.launch.mixins;
import baritone.utils.accessor.ITabCompleter;

View File

@ -1,3 +1,20 @@
/*
* 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.launch.mixins;
import baritone.api.utils.command.Lol;

View File

@ -1,3 +1,20 @@
/*
* 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.launch.mixins;
import baritone.api.BaritoneAPI;
@ -86,7 +103,7 @@ public abstract class MixinTabCompleter implements ITabCompleter {
@Override
public boolean onGuiChatSetCompletions(String[] newCompl) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(Minecraft.getMinecraft().player);
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
if (isNull(baritone)) {
return false;

View File

@ -10,6 +10,7 @@
"client": [
"MixinAnvilChunkLoader",
"MixinBlockPos",
"MixinChatTabCompleter",
"MixinChunkProviderClient",
"MixinChunkProviderServer",
"MixinChunkRenderContainer",
@ -17,16 +18,15 @@
"MixinEntityLivingBase",
"MixinEntityPlayerSP",
"MixinEntityRenderer",
"MixinGuiChat",
"MixinGuiScreen",
"MixinMinecraft",
"MixinNetHandlerPlayClient",
"MixinNetworkManager",
"MixinRenderChunk",
"MixinRenderList",
"MixinVboRenderList",
"MixinWorldClient",
"MixinTabCompleter",
"MixinGuiChat",
"MixinChatTabCompleter",
"MixinGuiScreen"
"MixinVboRenderList",
"MixinWorldClient"
]
}