rememberedInventories = new HashMap<>();
+ private BlockPos neighboringConnectedBlock(BlockPos in) {
+ BlockStateInterface bsi = new CalculationContext(baritone).bsi();
+ Block block = bsi.get0(in).getBlock();
+ if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) {
+ return null; // other things that have contents, but can be placed adjacent without combining
+ }
+ for (int i = 0; i < 4; i++) {
+ BlockPos adj = in.offset(EnumFacing.byHorizontalIndex(i));
+ if (bsi.get0(adj).getBlock() == block) {
+ return adj;
+ }
+ }
+ return null;
}
/**
@@ -198,43 +195,7 @@ public final class MemoryBehavior extends Behavior implements IMemoryBehavior {
this.slots = slots;
this.type = type;
this.pos = pos;
- }
- }
-
- /**
- * An inventory that we are aware of.
- *
- * Associated with a {@link BlockPos} in {@link WorldDataContainer#rememberedInventories}.
- */
- public static class RememberedInventory implements IRememberedInventory {
-
- /**
- * The list of items in the inventory
- */
- private final List items;
-
- /**
- * The last known window ID of the inventory
- */
- private int windowId;
-
- /**
- * The size of the inventory
- */
- private int size;
-
- private RememberedInventory() {
- this.items = new ArrayList<>();
- }
-
- @Override
- public final List getContents() {
- return Collections.unmodifiableList(this.items);
- }
-
- @Override
- public final int getSize() {
- return this.size;
+ System.out.println("Future inventory created " + time + " " + slots + " " + type + " " + pos);
}
}
}
diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java
new file mode 100644
index 00000000..30f2480b
--- /dev/null
+++ b/src/main/java/baritone/cache/ContainerMemory.java
@@ -0,0 +1,106 @@
+/*
+ * 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 .
+ */
+
+package baritone.cache;
+
+import baritone.api.cache.IContainerMemory;
+import baritone.api.cache.IRememberedInventory;
+import baritone.api.utils.IPlayerContext;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.math.BlockPos;
+
+import java.nio.file.Path;
+import java.util.*;
+
+public class ContainerMemory implements IContainerMemory {
+ public ContainerMemory(Path saveTo) {
+ // eventually
+ }
+
+ /**
+ * The current remembered inventories
+ */
+ private final Map inventories = new HashMap<>();
+
+ public synchronized void setup(BlockPos pos, int windowId, int slotCount) {
+ RememberedInventory inventory = inventories.computeIfAbsent(pos, x -> new RememberedInventory());
+ inventory.windowId = windowId;
+ inventory.size = slotCount;
+ }
+
+ public synchronized Optional getInventoryFromWindow(int windowId) {
+ return inventories.values().stream().filter(i -> i.windowId == windowId).findFirst();
+ }
+
+ @Override
+ public final synchronized RememberedInventory getInventoryByPos(BlockPos pos) {
+ return inventories.get(pos);
+ }
+
+ @Override
+ public final synchronized Map getRememberedInventories() {
+ // make a copy since this map is modified from the packet thread
+ return new HashMap<>(inventories);
+ }
+
+ /**
+ * An inventory that we are aware of.
+ *
+ * Associated with a {@link BlockPos} in {@link WorldDataContainer#rememberedInventories}.
+ */
+ public static class RememberedInventory implements IRememberedInventory {
+
+ /**
+ * The list of items in the inventory
+ */
+ private final List items;
+
+ /**
+ * The last known window ID of the inventory
+ */
+ private int windowId;
+
+ /**
+ * The size of the inventory
+ */
+ private int size;
+
+ private RememberedInventory() {
+ this.items = new ArrayList<>();
+ }
+
+ @Override
+ public final List getContents() {
+ return Collections.unmodifiableList(this.items);
+ }
+
+ @Override
+ public final int getSize() {
+ return this.size;
+ }
+
+ public int getWindowId() {
+ return this.windowId;
+ }
+
+ public void updateFromOpenWindow(IPlayerContext ctx) {
+ items.clear();
+ items.addAll(ctx.player().openContainer.getInventory().subList(0, size));
+ System.out.println("Saved " + items);
+ }
+ }
+}
diff --git a/src/main/java/baritone/cache/WorldData.java b/src/main/java/baritone/cache/WorldData.java
index 897a0d87..84fd6ff1 100644
--- a/src/main/java/baritone/cache/WorldData.java
+++ b/src/main/java/baritone/cache/WorldData.java
@@ -19,6 +19,7 @@ package baritone.cache;
import baritone.Baritone;
import baritone.api.cache.ICachedWorld;
+import baritone.api.cache.IContainerMemory;
import baritone.api.cache.IWaypointCollection;
import baritone.api.cache.IWorldData;
@@ -33,6 +34,7 @@ public class WorldData implements IWorldData {
public final CachedWorld cache;
private final Waypoints waypoints;
+ private final ContainerMemory containerMemory;
//public final MapData map;
public final Path directory;
public final int dimension;
@@ -41,6 +43,7 @@ public class WorldData implements IWorldData {
this.directory = directory;
this.cache = new CachedWorld(directory.resolve("cache"), dimension);
this.waypoints = new Waypoints(directory.resolve("waypoints"));
+ this.containerMemory = new ContainerMemory(directory.resolve("containers"));
this.dimension = dimension;
}
@@ -60,4 +63,9 @@ public class WorldData implements IWorldData {
public IWaypointCollection getWaypoints() {
return this.waypoints;
}
+
+ @Override
+ public IContainerMemory getContainerMemory() {
+ return this.containerMemory;
+ }
}