diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 7fb9c53b9..675f5e60f 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -30,8 +30,8 @@ import java.awt.*; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.*; import java.util.List; +import java.util.*; import java.util.function.Consumer; /** @@ -958,6 +958,11 @@ public final class Settings { */ public final Setting> logger = new Setting<>(Minecraft.getInstance().ingameGUI.getChatGUI()::printChatMessage); + /** + * Print out ALL command exceptions as a stack trace to stdout, even simple syntax errors + */ + public final Setting verboseCommandExceptions = new Setting<>(false); + /** * The size of the box that is rendered when the current goal is a GoalYLevel */ diff --git a/src/api/java/baritone/api/utils/BlockOptionalMeta.java b/src/api/java/baritone/api/utils/BlockOptionalMeta.java index ea79192a4..887e153f4 100644 --- a/src/api/java/baritone/api/utils/BlockOptionalMeta.java +++ b/src/api/java/baritone/api/utils/BlockOptionalMeta.java @@ -28,7 +28,6 @@ import net.minecraft.resources.*; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Unit; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; import net.minecraft.world.storage.loot.*; import javax.annotation.Nonnull; @@ -47,6 +46,7 @@ public final class BlockOptionalMeta { private final ImmutableSet stackHashes; private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$"); private static LootTableManager manager; + private static LootPredicateManager predicate = new LootPredicateManager(); private static Map> drops = new HashMap<>(); public BlockOptionalMeta(@Nonnull Block block) { @@ -65,13 +65,7 @@ public final class BlockOptionalMeta { MatchResult matchResult = matcher.toMatchResult(); - ResourceLocation id = new ResourceLocation(matchResult.group(1)); - - if (!Registry.BLOCK.containsKey(id)) { - throw new IllegalArgumentException("Invalid block ID"); - } - - block = Registry.BLOCK.getValue(id).orElse(null); + block = BlockUtils.stringToBlockRequired(matchResult.group(1)); blockstates = getStates(block); stateHashes = getStateHashes(blockstates); stackHashes = getStackHashes(blockstates); @@ -144,7 +138,7 @@ public final class BlockOptionalMeta { rpl.reloadPacksFromFinders(); IResourcePack thePack = ((ResourcePackInfo) rpl.getAllPacks().iterator().next()).getResourcePack(); IReloadableResourceManager resourceManager = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA, null); - manager = new LootTableManager(new LootPredicateManager()); + manager = new LootTableManager(predicate); resourceManager.addReloadListener(manager); try { resourceManager.reloadResourcesAndThen(new ThreadPerTaskExecutor(Thread::new), new ThreadPerTaskExecutor(Thread::new), Collections.singletonList(thePack), CompletableFuture.completedFuture(Unit.INSTANCE)).get(); @@ -155,6 +149,10 @@ public final class BlockOptionalMeta { return manager; } + public static LootPredicateManager getPredicateManager() { + return predicate; + } + private static synchronized List drops(Block b) { return drops.computeIfAbsent(b, block -> { ResourceLocation lootTableLocation = block.getLootTable(); diff --git a/src/launch/java/baritone/launch/mixins/MixinLootContext.java b/src/launch/java/baritone/launch/mixins/MixinLootContext.java index 9c1c8faca..5948f4442 100644 --- a/src/launch/java/baritone/launch/mixins/MixinLootContext.java +++ b/src/launch/java/baritone/launch/mixins/MixinLootContext.java @@ -21,6 +21,7 @@ import baritone.api.utils.BlockOptionalMeta; import net.minecraft.server.MinecraftServer; import net.minecraft.world.server.ServerWorld; import net.minecraft.world.storage.loot.LootContext; +import net.minecraft.world.storage.loot.LootPredicateManager; import net.minecraft.world.storage.loot.LootTableManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -56,4 +57,18 @@ public class MixinLootContext { } return server.getLootTableManager(); } + + @Redirect( + method = "build", + at = @At( + value = "INVOKE", + target = "net/minecraft/server/MinecraftServer.func_229736_aP_()Lnet/minecraft/world/storage/loot/LootPredicateManager;" + ) + ) + private LootPredicateManager getLootPredicateManager(MinecraftServer server) { + if (server == null) { + return BlockOptionalMeta.getPredicateManager(); + } + return server.func_229736_aP_(); + } } diff --git a/src/main/java/baritone/command/argument/ArgConsumer.java b/src/main/java/baritone/command/argument/ArgConsumer.java index f4e7dd524..c4a6df002 100644 --- a/src/main/java/baritone/command/argument/ArgConsumer.java +++ b/src/main/java/baritone/command/argument/ArgConsumer.java @@ -17,7 +17,9 @@ package baritone.command.argument; +import baritone.Baritone; import baritone.api.IBaritone; +import baritone.api.command.argument.IArgConsumer; import baritone.api.command.argument.ICommandArgument; import baritone.api.command.datatypes.IDatatype; import baritone.api.command.datatypes.IDatatypeContext; @@ -27,7 +29,6 @@ import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandInvalidTypeException; import baritone.api.command.exception.CommandNotEnoughArgumentsException; import baritone.api.command.exception.CommandTooManyArgumentsException; -import baritone.api.command.argument.IArgConsumer; import baritone.api.command.manager.ICommandManager; import java.util.ArrayList; @@ -316,6 +317,9 @@ public class ArgConsumer implements IArgConsumer { try { return datatype.apply(this.context, original); } catch (Exception e) { + if (Baritone.settings().verboseCommandExceptions.value) { + e.printStackTrace(); + } throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e); } } @@ -345,6 +349,9 @@ public class ArgConsumer implements IArgConsumer { try { return datatype.get(this.context); } catch (Exception e) { + if (Baritone.settings().verboseCommandExceptions.value) { + e.printStackTrace(); + } throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e); } }