mirror of https://github.com/cabaletta/baritone
fix items and #click
This commit is contained in:
parent
3e082b21d5
commit
4168401aa1
|
@ -20,26 +20,31 @@ package baritone.api.utils;
|
||||||
import baritone.api.utils.accessor.IItemStack;
|
import baritone.api.utils.accessor.IItemStack;
|
||||||
import baritone.utils.accessors.IServerPackSource;
|
import baritone.utils.accessors.IServerPackSource;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.mojang.authlib.minecraft.client.MinecraftClient;
|
||||||
import io.netty.util.concurrent.ThreadPerTaskExecutor;
|
import io.netty.util.concurrent.ThreadPerTaskExecutor;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||||
import net.minecraft.server.packs.*;
|
import net.minecraft.server.packs.*;
|
||||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
|
||||||
import net.minecraft.server.packs.repository.PackRepository;
|
|
||||||
import net.minecraft.server.packs.repository.ServerPacksSource;
|
import net.minecraft.server.packs.repository.ServerPacksSource;
|
||||||
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
||||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.util.Unit;
|
import net.minecraft.util.Unit;
|
||||||
import net.minecraft.world.flag.FeatureFlags;
|
import net.minecraft.world.flag.FeatureFlagSet;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.CustomSpawner;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.dimension.LevelStem;
|
||||||
|
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||||
|
import net.minecraft.world.level.storage.ServerLevelData;
|
||||||
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import net.minecraft.world.level.storage.loot.LootTables;
|
import net.minecraft.world.level.storage.loot.LootTables;
|
||||||
|
@ -47,11 +52,13 @@ import net.minecraft.world.level.storage.loot.PredicateManager;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.apache.logging.log4j.core.jmx.Server;
|
import sun.misc.Unsafe;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.regex.MatchResult;
|
import java.util.regex.MatchResult;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -63,7 +70,7 @@ public final class BlockOptionalMeta {
|
||||||
private final ImmutableSet<Integer> stateHashes;
|
private final ImmutableSet<Integer> stateHashes;
|
||||||
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 LootTables manager;
|
private static LootTables lootTables;
|
||||||
private static PredicateManager predicate = new PredicateManager();
|
private static PredicateManager predicate = new PredicateManager();
|
||||||
private static Map<Block, List<Item>> drops = new HashMap<>();
|
private static Map<Block, List<Item>> drops = new HashMap<>();
|
||||||
|
|
||||||
|
@ -150,11 +157,11 @@ public final class BlockOptionalMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LootTables getManager() {
|
public static LootTables getManager() {
|
||||||
if (manager == null) {
|
if (lootTables == null) {
|
||||||
MultiPackResourceManager resources = new MultiPackResourceManager(PackType.SERVER_DATA, List.of(((IServerPackSource) new ServerPacksSource()).callCreateVanillaPackSource()));
|
MultiPackResourceManager resources = new MultiPackResourceManager(PackType.SERVER_DATA, List.of(((IServerPackSource) new ServerPacksSource()).callCreateVanillaPackSource()));
|
||||||
ReloadableResourceManager resourceManager = new ReloadableResourceManager(PackType.SERVER_DATA);
|
ReloadableResourceManager resourceManager = new ReloadableResourceManager(PackType.SERVER_DATA);
|
||||||
manager = new LootTables(predicate);
|
lootTables = new LootTables(predicate);
|
||||||
resourceManager.registerReloadListener(manager);
|
resourceManager.registerReloadListener(lootTables);
|
||||||
try {
|
try {
|
||||||
resourceManager.createReload(new ThreadPerTaskExecutor(Thread::new), new ThreadPerTaskExecutor(Thread::new), CompletableFuture.completedFuture(Unit.INSTANCE), resources.listPacks().toList()).done().get();
|
resourceManager.createReload(new ThreadPerTaskExecutor(Thread::new), new ThreadPerTaskExecutor(Thread::new), CompletableFuture.completedFuture(Unit.INSTANCE), resources.listPacks().toList()).done().get();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
|
@ -162,7 +169,7 @@ public final class BlockOptionalMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return manager;
|
return lootTables;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PredicateManager getPredicateManager() {
|
public static PredicateManager getPredicateManager() {
|
||||||
|
@ -176,20 +183,54 @@ public final class BlockOptionalMeta {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
List<Item> items = new ArrayList<>();
|
List<Item> items = new ArrayList<>();
|
||||||
|
try {
|
||||||
// the other overload for generate doesnt work in forge because forge adds code that requires a non null world
|
getManager().get(lootTableLocation).getRandomItems(
|
||||||
getManager().get(lootTableLocation).getRandomItems(
|
new LootContext.Builder(ServerLevelStub.fastCreate())
|
||||||
new LootContext.Builder((ServerLevel null)
|
.withRandom(RandomSource.create())
|
||||||
.withRandom(RandomSource.create())
|
.withParameter(LootContextParams.ORIGIN, Vec3.atLowerCornerOf(BlockPos.ZERO))
|
||||||
.withParameter(LootContextParams.ORIGIN, Vec3.atLowerCornerOf(BlockPos.ZERO))
|
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY)
|
||||||
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY)
|
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, null)
|
||||||
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, null)
|
.withParameter(LootContextParams.BLOCK_STATE, block.defaultBlockState())
|
||||||
.withParameter(LootContextParams.BLOCK_STATE, block.defaultBlockState())
|
.create(LootContextParamSets.BLOCK),
|
||||||
.create(LootContextParamSets.BLOCK),
|
|
||||||
stack -> items.add(stack.getItem())
|
stack -> items.add(stack.getItem())
|
||||||
);
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ServerLevelStub extends ServerLevel {
|
||||||
|
private static Minecraft client = Minecraft.getInstance();
|
||||||
|
private static Unsafe unsafe = getUnsafe();
|
||||||
|
public ServerLevelStub(MinecraftServer $$0, Executor $$1, LevelStorageSource.LevelStorageAccess $$2, ServerLevelData $$3, ResourceKey<Level> $$4, LevelStem $$5, ChunkProgressListener $$6, boolean $$7, long $$8, List<CustomSpawner> $$9, boolean $$10) {
|
||||||
|
super($$0, $$1, $$2, $$3, $$4, $$5, $$6, $$7, $$8, $$9, $$10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureFlagSet enabledFeatures() {
|
||||||
|
return client.level.enabledFeatures();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServerLevelStub fastCreate() {
|
||||||
|
try {
|
||||||
|
return (ServerLevelStub) unsafe.allocateInstance(ServerLevelStub.class);
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Unsafe getUnsafe() {
|
||||||
|
try {
|
||||||
|
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
||||||
|
theUnsafe.setAccessible(true);
|
||||||
|
return (Unsafe) theUnsafe.get(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,7 @@ public class GuiClick extends Screen implements Helper {
|
||||||
HitResult result = player.level.clip(new ClipContext(near.add(viewerPos), far.add(viewerPos), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
|
HitResult result = player.level.clip(new ClipContext(near.add(viewerPos), far.add(viewerPos), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
|
||||||
if (result != null && result.getType() == HitResult.Type.BLOCK) {
|
if (result != null && result.getType() == HitResult.Type.BLOCK) {
|
||||||
currentMouseOver = ((BlockHitResult) result).getBlockPos();
|
currentMouseOver = ((BlockHitResult) result).getBlockPos();
|
||||||
|
System.out.println("currentMouseOver = " + currentMouseOver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,9 +159,13 @@ public class GuiClick extends Screen implements Helper {
|
||||||
y = y * 2 - 1;
|
y = y * 2 - 1;
|
||||||
|
|
||||||
Vector4f pos = new Vector4f((float) x, (float) y, (float) z, 1.0F);
|
Vector4f pos = new Vector4f((float) x, (float) y, (float) z, 1.0F);
|
||||||
projectionViewMatrix.transformProject(pos);
|
projectionViewMatrix.transform(pos);
|
||||||
|
|
||||||
pos.normalize();
|
if (pos.w() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos.mul(1/pos.w());
|
||||||
return new Vec3(pos.x(), pos.y(), pos.z());
|
return new Vec3(pos.x(), pos.y(), pos.z());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
import baritone.gradle.task.CreateDistTask
|
import baritone.gradle.task.CreateDistTask
|
||||||
import baritone.gradle.task.ProguardTask
|
import baritone.gradle.task.ProguardTask
|
||||||
import baritone.gradle.task.TweakerJsonAssembler
|
//import baritone.gradle.task.TweakerJsonAssembler
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "com.github.johnrengelman.shadow" version "7.0.0"
|
id "com.github.johnrengelman.shadow" version "7.0.0"
|
||||||
|
|
Loading…
Reference in New Issue