Redstone support for logi drones

This commit is contained in:
70000hp 2024-06-27 18:01:04 -04:00
parent 205b537318
commit 2dc7792860
3 changed files with 10 additions and 6 deletions

View File

@ -70,10 +70,11 @@ public class RequestNetwork {
public static class PathNode {
public BlockPos pos;
public long lease;
public HashedSet<PathNode> reachableNodes = new HashedSet();
public boolean active = true;
public HashedSet<PathNode> reachableNodes;
public PathNode(BlockPos pos, HashedSet<PathNode> reachableNodes) {
this.pos = pos;
this.reachableNodes = new HashedSet(reachableNodes);
this.reachableNodes = new HashedSet<>(reachableNodes);
this.lease = System.currentTimeMillis();
}
@ -108,7 +109,6 @@ public class RequestNetwork {
/** Node created by requesters, lists requested AStacks */
public static class RequestNode extends PathNode {
public List<AStack> request;
public int droneCount;
public RequestNode(BlockPos pos, HashedSet<PathNode> reachableNodes, List<AStack> request) {
super(pos, reachableNodes);
this.request = request;

View File

@ -64,7 +64,7 @@ public class TileEntityDroneDock extends TileEntityRequestNetworkContainer imple
// simply pick the first request node that has unfulfilled requests
for(RequestNode request : requests) {
if(!request.request.isEmpty()) {
if(request.active && !request.request.isEmpty()) {
firstRequest = request;
break;
}
@ -78,7 +78,7 @@ public class TileEntityDroneDock extends TileEntityRequestNetworkContainer imple
outer: for(OfferNode offer : offers) {
for(ItemStack stack : offer.offer) {
if(stack != null && request.matchesRecipe(stack, true)) {
if(offer.active && stack != null && request.matchesRecipe(stack, true)) {
if(tryEmbark(own, firstRequest, offer, request, localNodes)) break attempt; // if the drone can be pathed and spawned, stop doing more attempts
break outer; // if not, simply continue iterating over offer nodes
}

View File

@ -37,14 +37,18 @@ public abstract class TileEntityRequestNetwork extends TileEntity {
if(worldObj.getTotalWorldTime() % 20 == 0) {
BlockPos pos = getCoord();
PathNode newNode = createNode(pos);
if(this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) newNode.active = false;
// push new node
push(worldObj, createNode(pos));
push(worldObj, newNode);
// remove known nodes that no longer exist
// since we can assume a sane number of nodes to exist at any given time, we can run this check in full every second
Iterator<PathNode> it = knownNodes.iterator();
HashedSet<PathNode> localNodes = this.getAllLocalNodes(worldObj, xCoord, zCoord, 2); // this bit may spiral into multiple nested hashtable lookups but it's limited to only a few chunks so it shouldn't be an issue
localNodes.remove(pos);
while(it.hasNext()) {
PathNode node = it.next();
if(!localNodes.contains(node)) {