cursed but fixes blockoptionalmeta
This commit is contained in:
@@ -30,8 +30,8 @@ import java.awt.*;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.*;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -958,6 +958,11 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Consumer<ITextComponent>> logger = new Setting<>(Minecraft.getInstance().ingameGUI.getChatGUI()::printChatMessage);
|
public final Setting<Consumer<ITextComponent>> 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<Boolean> verboseCommandExceptions = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The size of the box that is rendered when the current goal is a GoalYLevel
|
* The size of the box that is rendered when the current goal is a GoalYLevel
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import net.minecraft.resources.*;
|
|||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.Unit;
|
import net.minecraft.util.Unit;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import net.minecraft.world.storage.loot.*;
|
import net.minecraft.world.storage.loot.*;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -47,6 +46,7 @@ public final class BlockOptionalMeta {
|
|||||||
private final ImmutableSet<Integer> stackHashes;
|
private final ImmutableSet<Integer> stackHashes;
|
||||||
private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$");
|
private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$");
|
||||||
private static LootTableManager manager;
|
private static LootTableManager manager;
|
||||||
|
private static LootPredicateManager predicate = new LootPredicateManager();
|
||||||
private static Map<Block, List<Item>> drops = new HashMap<>();
|
private static Map<Block, List<Item>> drops = new HashMap<>();
|
||||||
|
|
||||||
public BlockOptionalMeta(@Nonnull Block block) {
|
public BlockOptionalMeta(@Nonnull Block block) {
|
||||||
@@ -65,13 +65,7 @@ public final class BlockOptionalMeta {
|
|||||||
|
|
||||||
MatchResult matchResult = matcher.toMatchResult();
|
MatchResult matchResult = matcher.toMatchResult();
|
||||||
|
|
||||||
ResourceLocation id = new ResourceLocation(matchResult.group(1));
|
block = BlockUtils.stringToBlockRequired(matchResult.group(1));
|
||||||
|
|
||||||
if (!Registry.BLOCK.containsKey(id)) {
|
|
||||||
throw new IllegalArgumentException("Invalid block ID");
|
|
||||||
}
|
|
||||||
|
|
||||||
block = Registry.BLOCK.getValue(id).orElse(null);
|
|
||||||
blockstates = getStates(block);
|
blockstates = getStates(block);
|
||||||
stateHashes = getStateHashes(blockstates);
|
stateHashes = getStateHashes(blockstates);
|
||||||
stackHashes = getStackHashes(blockstates);
|
stackHashes = getStackHashes(blockstates);
|
||||||
@@ -144,7 +138,7 @@ public final class BlockOptionalMeta {
|
|||||||
rpl.reloadPacksFromFinders();
|
rpl.reloadPacksFromFinders();
|
||||||
IResourcePack thePack = ((ResourcePackInfo) rpl.getAllPacks().iterator().next()).getResourcePack();
|
IResourcePack thePack = ((ResourcePackInfo) rpl.getAllPacks().iterator().next()).getResourcePack();
|
||||||
IReloadableResourceManager resourceManager = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA, null);
|
IReloadableResourceManager resourceManager = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA, null);
|
||||||
manager = new LootTableManager(new LootPredicateManager());
|
manager = new LootTableManager(predicate);
|
||||||
resourceManager.addReloadListener(manager);
|
resourceManager.addReloadListener(manager);
|
||||||
try {
|
try {
|
||||||
resourceManager.reloadResourcesAndThen(new ThreadPerTaskExecutor(Thread::new), new ThreadPerTaskExecutor(Thread::new), Collections.singletonList(thePack), CompletableFuture.completedFuture(Unit.INSTANCE)).get();
|
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;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LootPredicateManager getPredicateManager() {
|
||||||
|
return predicate;
|
||||||
|
}
|
||||||
|
|
||||||
private static synchronized List<Item> drops(Block b) {
|
private static synchronized List<Item> drops(Block b) {
|
||||||
return drops.computeIfAbsent(b, block -> {
|
return drops.computeIfAbsent(b, block -> {
|
||||||
ResourceLocation lootTableLocation = block.getLootTable();
|
ResourceLocation lootTableLocation = block.getLootTable();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import baritone.api.utils.BlockOptionalMeta;
|
|||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraft.world.storage.loot.LootContext;
|
import net.minecraft.world.storage.loot.LootContext;
|
||||||
|
import net.minecraft.world.storage.loot.LootPredicateManager;
|
||||||
import net.minecraft.world.storage.loot.LootTableManager;
|
import net.minecraft.world.storage.loot.LootTableManager;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -56,4 +57,18 @@ public class MixinLootContext {
|
|||||||
}
|
}
|
||||||
return server.getLootTableManager();
|
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_();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
package baritone.command.argument;
|
package baritone.command.argument;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
|
import baritone.api.command.argument.IArgConsumer;
|
||||||
import baritone.api.command.argument.ICommandArgument;
|
import baritone.api.command.argument.ICommandArgument;
|
||||||
import baritone.api.command.datatypes.IDatatype;
|
import baritone.api.command.datatypes.IDatatype;
|
||||||
import baritone.api.command.datatypes.IDatatypeContext;
|
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.CommandInvalidTypeException;
|
||||||
import baritone.api.command.exception.CommandNotEnoughArgumentsException;
|
import baritone.api.command.exception.CommandNotEnoughArgumentsException;
|
||||||
import baritone.api.command.exception.CommandTooManyArgumentsException;
|
import baritone.api.command.exception.CommandTooManyArgumentsException;
|
||||||
import baritone.api.command.argument.IArgConsumer;
|
|
||||||
import baritone.api.command.manager.ICommandManager;
|
import baritone.api.command.manager.ICommandManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -316,6 +317,9 @@ public class ArgConsumer implements IArgConsumer {
|
|||||||
try {
|
try {
|
||||||
return datatype.apply(this.context, original);
|
return datatype.apply(this.context, original);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (Baritone.settings().verboseCommandExceptions.value) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
|
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,6 +349,9 @@ public class ArgConsumer implements IArgConsumer {
|
|||||||
try {
|
try {
|
||||||
return datatype.get(this.context);
|
return datatype.get(this.context);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (Baritone.settings().verboseCommandExceptions.value) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
|
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user