This commit is contained in:
Leijurv
2019-07-23 15:39:19 -07:00
parent 4c8907c629
commit 9f951f261d
9 changed files with 112 additions and 105 deletions

View File

@@ -35,6 +35,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.crash.CrashReport;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@@ -219,23 +220,6 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
return true;
}
/*if (msg.equals("fullpath")) {
if (pathingBehavior.getGoal() == null) {
logDirect("No goal.");
} else {
logDirect("Started segmented calculator");
SegmentedCalculator.calculateSegmentsThreaded(pathingBehavior.pathStart(), pathingBehavior.getGoal(), new CalculationContext(baritone, true), ipath -> {
logDirect("Found a path");
logDirect("Ends at " + ipath.getDest());
logDirect("Length " + ipath.length());
logDirect("Estimated time " + ipath.ticksRemainingFrom(0));
pathingBehavior.secretCursedFunctionDoNotCall(ipath); // it's okay when *I* do it
}, () -> {
logDirect("Path calculation failed, no path");
});
}
return true;
}*/
if (msg.equals("proc")) {
Optional<IBaritoneProcess> proc = baritone.getPathingControlManager().mostRecentInControl();
if (!proc.isPresent()) {
@@ -418,10 +402,10 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
logDirect("Following any players");
return true;
}
/*if (msg.startsWith("followentity")) {
if (msg.startsWith("followentity")) {
String name = msg.substring(12).trim();
Optional<Entity> toFollow = Optional.empty();
for (Entity entity : ctx.world().loadedEntityList) {
for (Entity entity : ctx.entities()) {
String entityName = entity.getName().getFormattedText().trim().toLowerCase();
if ((entityName.contains(name) || name.contains(entityName)) && !(entity instanceof ItemEntity || entity instanceof PlayerEntity)) { // We dont want it following players while `#follow` exists.
toFollow = Optional.of(entity);
@@ -435,7 +419,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
baritone.getFollowProcess().follow(effectivelyFinal::equals);
logDirect("Following entity " + toFollow.get());
return true;
}*/
}
if (msg.startsWith("follow")) {
String name = msg.substring(6).trim();
Optional<Entity> toFollow = Optional.empty();

View File

@@ -1,39 +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.launch.mixins;
import baritone.utils.accessor.IChunkProviderClient;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(ClientChunkProvider.class)
public class MixinClientChunkProvider implements IChunkProviderClient {
@Shadow
@Final
private Long2ObjectMap<Chunk> loadedChunks;
@Override
public Long2ObjectMap<Chunk> loadedChunks() {
return this.loadedChunks;
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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.process.MineProcess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootTableManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(LootContext.Builder.class)
public class MixinLootContext {
@Redirect(
method = "build",
at = @At(
value = "INVOKE",
target = "net/minecraft/world/server/ServerWorld.getServer()Lnet/minecraft/server/MinecraftServer;"
)
)
private MinecraftServer getServer(ServerWorld world) {
if (world == null) {
return null;
}
return world.getServer();
}
@Redirect(
method = "build",
at = @At(
value = "INVOKE",
target = "net/minecraft/server/MinecraftServer.getLootTableManager()Lnet/minecraft/world/storage/loot/LootTableManager;"
)
)
private LootTableManager getLootTableManager(MinecraftServer server) {
if (server == null) {
return MineProcess.getManager();
}
return server.getLootTableManager();
}
}

View File

@@ -32,7 +32,6 @@ import net.minecraft.client.world.ClientWorld;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Mixin;

View File

@@ -12,8 +12,10 @@
"MixinClientPlayerEntity",
"MixinClientPlayNetHandler",
"MixinEntity",
"MixinEntityRenderManager",
"MixinGameRenderer",
"MixinLivingEntity",
"MixinLootContext",
"MixinMinecraft",
"MixinNetworkManager"
]

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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();
}