Merge remote-tracking branch 'remote/master' into 1.16.2

This commit is contained in:
CDAGaming 2020-08-17 18:15:59 -05:00
commit 6eaa3a27f2
No known key found for this signature in database
GPG Key ID: 0304C9C2F35557FB
4 changed files with 81 additions and 22 deletions

View File

@ -190,6 +190,15 @@ public final class Settings {
)));
/**
* A list of blocks to become air
* <p>
* If a schematic asks for a block on this list, only air will be accepted at that location (and nothing on buildIgnoreBlocks)
*/
public final Setting<List<Block>> okIfAir = new Setting<>(new ArrayList<>(Arrays.asList(
)));
/**
* If this is true, the builder will treat all non-air blocks as correct. It will only place new blocks.
*/
@ -432,6 +441,11 @@ public final class Settings {
*/
public final Setting<Boolean> simplifyUnloadedYCoord = new Setting<>(true);
/**
* Whenever a block changes, repack the whole chunk that it's in
*/
public final Setting<Boolean> repackOnAnyBlockChange = new Setting<>(true);
/**
* If a movement takes this many ticks more than its initial cost estimate, cancel it
*/

View File

@ -17,15 +17,19 @@
package baritone.launch.mixins;
import baritone.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.ChunkEvent;
import baritone.api.event.events.type.EventState;
import baritone.cache.CachedChunk;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.network.play.ClientPlayNetHandler;
import net.minecraft.network.play.server.SChangeBlockPacket;
import net.minecraft.network.play.server.SChunkDataPacket;
import net.minecraft.network.play.server.SCombatPacket;
import net.minecraft.network.play.server.SUnloadChunkPacket;
import net.minecraft.network.play.server.SMultiBlockChangePacket;
import net.minecraft.util.math.ChunkPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -83,30 +87,62 @@ public class MixinClientPlayNetHandler {
}
@Inject(
method = "processChunkUnload",
at = @At("HEAD")
method = "handleBlockChange",
at = @At("RETURN")
)
private void preChunkUnload(SUnloadChunkPacket packet, CallbackInfo ci) {
private void postHandleBlockChange(SChangeBlockPacket packetIn, CallbackInfo ci) {
if (!Baritone.settings().repackOnAnyBlockChange.value) {
return;
}
if (!CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(packetIn.getState().getBlock())) {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ClientPlayerEntity player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(EventState.PRE, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ())
new ChunkEvent(
EventState.POST,
ChunkEvent.Type.POPULATE_FULL,
packetIn.getPos().getX() >> 4,
packetIn.getPos().getZ() >> 4
)
);
}
}
}
@Inject(
method = "processChunkUnload",
method = "handleMultiBlockChange",
at = @At("RETURN")
)
private void postChunkUnload(SUnloadChunkPacket packet, CallbackInfo ci) {
private void postHandleMultiBlockChange(SMultiBlockChangePacket packetIn, CallbackInfo ci) {
if (!Baritone.settings().repackOnAnyBlockChange.value) {
return;
}
if (packetIn.getChangedBlocks().length == 0) {
return;
}
https://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.15
{
for (SMultiBlockChangePacket.BlockUpdateData update : packetIn.getChangedBlocks()) {
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(update.getBlockState().getBlock())) {
break https;
}
}
return;
}
ChunkPos pos = new ChunkPos(packetIn.getChangedBlocks()[0].getPos());
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ClientPlayerEntity player = ibaritone.getPlayerContext().player();
if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(EventState.POST, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ())
new ChunkEvent(
EventState.POST,
ChunkEvent.Type.POPULATE_FULL,
pos.x,
pos.z
)
);
}
}

View File

@ -27,7 +27,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import java.io.IOException;
@ -35,6 +35,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
/**
@ -58,7 +60,17 @@ public final class CachedWorld implements ICachedWorld, Helper {
*/
private final String directory;
private final LinkedBlockingQueue<Chunk> toPack = new LinkedBlockingQueue<>();
/**
* Queue of positions to pack. Refers to the toPackMap, in that every element of this queue will be a
* key in that map.
*/
private final LinkedBlockingQueue<ChunkPos> toPackQueue = new LinkedBlockingQueue<>();
/**
* All chunk positions pending packing. This map will be updated in-place if a new update to the chunk occurs
* while waiting in the queue for the packer thread to get to it.
*/
private final Map<ChunkPos, Chunk> toPackMap = new ConcurrentHashMap<>();
private final RegistryKey<World> dimension;
@ -91,10 +103,8 @@ public final class CachedWorld implements ICachedWorld, Helper {
@Override
public final void queueForPacking(Chunk chunk) {
try {
toPack.put(chunk);
} catch (InterruptedException e) {
e.printStackTrace();
if (toPackMap.put(chunk.getPos(), chunk) == null) {
toPackQueue.add(chunk.getPos());
}
}
@ -295,13 +305,9 @@ public final class CachedWorld implements ICachedWorld, Helper {
public void run() {
while (true) {
// TODO: Add CachedWorld unloading to remove the redundancy of having this
LinkedBlockingQueue<Chunk> queue = toPack;
if (queue == null) {
break;
}
try {
Chunk chunk = queue.take();
ChunkPos pos = toPackQueue.take();
Chunk chunk = toPackMap.remove(pos);
CachedChunk cached = ChunkPacker.pack(chunk);
CachedWorld.this.updateCachedChunk(cached);
//System.out.println("Processed chunk at " + chunk.x + "," + chunk.z);

View File

@ -791,10 +791,13 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
if (desired == null) {
return true;
}
if (current.getBlock() instanceof AirBlock && desired.getBlock() instanceof AirBlock) {
if (current.getBlock() instanceof BlockLiquid && Baritone.settings().okIfWater.value) {
return true;
}
if ((current.getBlock() == Blocks.WATER || current.getBlock() == Blocks.LAVA) && Baritone.settings().okIfWater.value) {
if (current.getBlock() instanceof BlockAir && Baritone.settings().okIfAir.value.contains(desired.getBlock())) {
return true;
}
if (desired.getBlock() instanceof BlockAir && Baritone.settings().buildIgnoreBlocks.value.contains(current.getBlock())) {
return true;
}
// TODO more complicated comparison logic I guess