fixes
This commit is contained in:
@@ -39,12 +39,15 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.resources.*;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Unit;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.loot.LootContext;
|
||||
import net.minecraft.world.storage.loot.LootParameters;
|
||||
import net.minecraft.world.storage.loot.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
||||
@@ -66,6 +69,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
private int desiredQuantity;
|
||||
private int tickCount;
|
||||
|
||||
private static LootTableManager manager;
|
||||
private static Map<Block, List<Item>> drops;
|
||||
|
||||
public MineProcess(Baritone baritone) {
|
||||
super(baritone);
|
||||
}
|
||||
@@ -143,6 +149,35 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
return command;
|
||||
}
|
||||
|
||||
public static LootTableManager getManager() {
|
||||
if (manager == null) {
|
||||
ResourcePackList rpl = new ResourcePackList<>(ResourcePackInfo::new);
|
||||
rpl.addPackFinder(new ServerPackFinder());
|
||||
rpl.reloadPacksFromFinders();
|
||||
IResourcePack thePack = ((ResourcePackInfo) rpl.getAllPacks().iterator().next()).getResourcePack();
|
||||
IReloadableResourceManager resourceManager = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA, null);
|
||||
manager = new LootTableManager();
|
||||
resourceManager.addReloadListener(manager);
|
||||
try {
|
||||
resourceManager.reloadResourcesAndThen(Baritone.getExecutor(), Baritone.getExecutor(), Collections.singletonList(thePack), CompletableFuture.completedFuture(Unit.INSTANCE)).get();
|
||||
} catch (Exception exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
private static List<Item> drops(Block b) {
|
||||
return drops.computeIfAbsent(b, block -> {
|
||||
ResourceLocation lootTableLocation = block.getLootTable();
|
||||
if (lootTableLocation == LootTables.EMPTY) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return getManager().getLootTableFromLocation(lootTableLocation).generate(new LootContext.Builder(null).withRandom(new Random()).withParameter(LootParameters.POSITION, BlockPos.ZERO).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withNullableParameter(LootParameters.BLOCK_ENTITY, null).withParameter(LootParameters.BLOCK_STATE, block.getDefaultState()).build(LootParameterSets.BLOCK)).stream().map(ItemStack::getItem).collect(Collectors.toList());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLostControl() {
|
||||
mine(0, (Block[]) null);
|
||||
@@ -283,9 +318,6 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Item> drops(Block block) {
|
||||
return block.getDefaultState().getDrops(new LootContext.Builder(null).withRandom(new Random()).withParameter(LootParameters.POSITION, BlockPos.ZERO).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withNullableParameter(LootParameters.BLOCK_ENTITY, null)).stream().map(ItemStack::getItem).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<BlockPos> droppedItemsScan(List<Block> mining, World world) {
|
||||
if (!Baritone.settings().mineScanDroppedItems.value) {
|
||||
|
||||
@@ -21,18 +21,16 @@ import baritone.Baritone;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.cache.CachedRegion;
|
||||
import baritone.cache.WorldData;
|
||||
import baritone.utils.accessor.IChunkProviderClient;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientChunkProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.ChunkSection;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
|
||||
/**
|
||||
* Wraps get for chuck caching capability
|
||||
@@ -41,7 +39,7 @@ import net.minecraft.world.chunk.ChunkSection;
|
||||
*/
|
||||
public class BlockStateInterface {
|
||||
|
||||
private final Long2ObjectMap<Chunk> loadedChunks;
|
||||
private final ClientChunkProvider provider;
|
||||
private final WorldData worldData;
|
||||
|
||||
private Chunk prev = null;
|
||||
@@ -61,11 +59,9 @@ public class BlockStateInterface {
|
||||
|
||||
public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) {
|
||||
this.worldData = worldData;
|
||||
Long2ObjectMap<Chunk> worldLoaded = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks();
|
||||
if (copyLoadedChunks) {
|
||||
this.loadedChunks = new Long2ObjectOpenHashMap<>(worldLoaded); // make a copy that we can safely access from another thread
|
||||
} else {
|
||||
this.loadedChunks = worldLoaded; // this will only be used on the main thread
|
||||
this.provider = (ClientChunkProvider) world.getChunkProvider();
|
||||
if (copyLoadedChunks) { // todo
|
||||
System.out.println("Really gotta do this");
|
||||
}
|
||||
this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.value;
|
||||
if (!Minecraft.getInstance().isOnExecutionThread()) {
|
||||
@@ -74,7 +70,7 @@ public class BlockStateInterface {
|
||||
}
|
||||
|
||||
public boolean worldContainsLoadedChunk(int blockX, int blockZ) {
|
||||
return loadedChunks.containsKey(ChunkPos.asLong(blockX >> 4, blockZ >> 4));
|
||||
return provider.chunkExists(blockX >> 4, blockZ >> 4);
|
||||
}
|
||||
|
||||
public static Block getBlock(IPlayerContext ctx, BlockPos pos) { // won't be called from the pathing thread because the pathing thread doesn't make a single blockpos pog
|
||||
@@ -109,8 +105,7 @@ public class BlockStateInterface {
|
||||
if (cached != null && cached.getPos().x == x >> 4 && cached.getPos().z == z >> 4) {
|
||||
return getFromChunk(cached, x, y, z);
|
||||
}
|
||||
Chunk chunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4));
|
||||
|
||||
Chunk chunk = provider.getChunk(x >> 4, z >> 4, ChunkStatus.FULL, false);
|
||||
if (chunk != null && !chunk.isEmpty()) {
|
||||
prev = chunk;
|
||||
return getFromChunk(chunk, x, y, z);
|
||||
@@ -142,7 +137,7 @@ public class BlockStateInterface {
|
||||
if (prevChunk != null && prevChunk.getPos().x == x >> 4 && prevChunk.getPos().z == z >> 4) {
|
||||
return true;
|
||||
}
|
||||
prevChunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4));
|
||||
prevChunk = provider.getChunk(x >> 4, z >> 4, ChunkStatus.FULL, false);
|
||||
if (prevChunk != null && !prevChunk.isEmpty()) {
|
||||
prev = prevChunk;
|
||||
return true;
|
||||
|
||||
@@ -27,7 +27,8 @@ public class PlayerMovementInput extends MovementInput {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void updatePlayerMoveState() {
|
||||
@Override
|
||||
public void tick(boolean p_217607_1_, boolean p_217607_2_) {
|
||||
this.moveStrafe = 0.0F;
|
||||
this.moveForward = 0.0F;
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* 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.utils.accessor;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public interface IChunkProviderClient {
|
||||
Long2ObjectMap<Chunk> loadedChunks();
|
||||
}
|
||||
Reference in New Issue
Block a user