mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-04 16:28:34 +01:00
store craft ingredient requests bundled together
This commit is contained in:
parent
894fae6b87
commit
f6ca9297dd
4 changed files with 22 additions and 13 deletions
|
@ -270,8 +270,10 @@ public class PipeBlock extends BaseEntityBlock implements SimpleWaterloggedBlock
|
|||
network.onPipeChanged(pos, state);
|
||||
if (worldIn.getBlockEntity(pos) instanceof PipeBlockEntity pipe) {
|
||||
pipe.getItems().clear();
|
||||
for (var lock : pipe.craftIngredientRequests)
|
||||
network.resolveNetworkLock(lock.getRight());
|
||||
for (var locks : pipe.craftIngredientRequests) {
|
||||
for (var lock : locks.getRight())
|
||||
network.resolveNetworkLock(lock);
|
||||
}
|
||||
}
|
||||
super.onRemove(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
|
|
|
@ -71,8 +71,8 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
PipeBlockEntity.this.setChanged();
|
||||
}
|
||||
};
|
||||
// crafting module slot, ingredient request network lock
|
||||
public final List<Pair<Integer, NetworkLock>> craftIngredientRequests = new ArrayList<>();
|
||||
// crafting module slot, ingredient request network locks (one list for each recipe)
|
||||
public final List<Pair<Integer, List<NetworkLock>>> craftIngredientRequests = new ArrayList<>();
|
||||
// crafting module slot, destination pipe for the result, result item
|
||||
public final List<Triple<Integer, BlockPos, ItemStack>> craftResultRequests = new ArrayList<>();
|
||||
public PressurizerBlockEntity pressurizer;
|
||||
|
@ -105,7 +105,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
for (var tuple : this.craftIngredientRequests) {
|
||||
var nbt = new CompoundTag();
|
||||
nbt.putInt("module_slot", tuple.getLeft());
|
||||
nbt.put("lock", tuple.getRight().serializeNBT(provider));
|
||||
nbt.put("locks", Utility.serializeAll(provider, tuple.getRight()));
|
||||
requests.add(nbt);
|
||||
}
|
||||
compound.put("craft_requests", requests);
|
||||
|
@ -133,7 +133,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
var nbt = requests.getCompound(i);
|
||||
this.craftIngredientRequests.add(Pair.of(
|
||||
nbt.getInt("module_slot"),
|
||||
new NetworkLock(provider, nbt.getCompound("lock"))));
|
||||
Utility.deserializeAll(nbt.getList("locks", Tag.TAG_COMPOUND), c -> new NetworkLock(provider, c))));
|
||||
}
|
||||
this.craftResultRequests.clear();
|
||||
var results = compound.getList("craft_results", Tag.TAG_COMPOUND);
|
||||
|
|
|
@ -76,7 +76,8 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
network.startProfile("crafting_ingredients");
|
||||
var request = tile.craftIngredientRequests.getFirst();
|
||||
if (request.getLeft() == slot) {
|
||||
var lock = request.getRight();
|
||||
var locks = request.getRight();
|
||||
var lock = locks.getFirst();
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var dest = tile.getAvailableDestination(Direction.values(), lock.stack, true, true);
|
||||
if (dest != null) {
|
||||
|
@ -85,7 +86,7 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
if (!ensureItemOrder || network.getPipeItemsOnTheWay(dest.getLeft()).findAny().isEmpty()) {
|
||||
var requestRemain = network.requestExistingItem(lock.location, tile.getBlockPos(), dest.getLeft(), lock, dest.getRight(), equalityTypes);
|
||||
network.resolveNetworkLock(lock);
|
||||
tile.craftIngredientRequests.remove(request);
|
||||
locks.remove(lock);
|
||||
|
||||
// if we couldn't fit all items into the destination, create another request for the rest
|
||||
var remain = lock.stack.copy();
|
||||
|
@ -94,9 +95,12 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
var remainRequest = new NetworkLock(lock.location, remain);
|
||||
// if we're ensuring item order, we need to insert the remaining request at the start so that it gets processed first
|
||||
var index = ensureItemOrder ? 0 : tile.craftResultRequests.size();
|
||||
tile.craftIngredientRequests.add(index, Pair.of(slot, remainRequest));
|
||||
locks.add(index, remainRequest);
|
||||
network.createNetworkLock(remainRequest);
|
||||
}
|
||||
|
||||
if (locks.isEmpty())
|
||||
tile.craftIngredientRequests.remove(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -186,6 +190,7 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
var craftableCrafts = Mth.ceil(craftableAmount / (float) resultAmount);
|
||||
var toCraft = Math.min(craftableCrafts, requiredCrafts);
|
||||
|
||||
var locks = new ArrayList<NetworkLock>();
|
||||
var contents = module.get(Contents.TYPE);
|
||||
// if we're ensuring item order, all items for a single recipe should be sent in order first before starting on the next one!
|
||||
for (var c = contents.ensureItemOrder ? toCraft : 1; c > 0; c--) {
|
||||
|
@ -197,10 +202,10 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
if (!contents.ensureItemOrder)
|
||||
copy.setCount(in.getCount() * toCraft);
|
||||
var ret = ItemTerminalBlockEntity.requestItemLater(tile.getLevel(), tile.getBlockPos(), items, unavailableConsumer, copy, CraftingModuleItem.addDependency(dependencyChain, module), equalityTypes);
|
||||
for (var lock : ret.getLeft())
|
||||
tile.craftIngredientRequests.add(Pair.of(slot, lock));
|
||||
locks.addAll(ret.getLeft());
|
||||
}
|
||||
}
|
||||
tile.craftIngredientRequests.add(Pair.of(slot, locks));
|
||||
|
||||
var remain = stack.copy();
|
||||
remain.shrink(resultAmount * toCraft);
|
||||
|
|
|
@ -217,8 +217,10 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
for (var craftable : network.getAllCraftables(pipe.getBlockPos())) {
|
||||
var otherPipe = network.getPipe(craftable.getLeft());
|
||||
if (otherPipe != null) {
|
||||
for (var lock : otherPipe.craftIngredientRequests)
|
||||
network.resolveNetworkLock(lock.getRight());
|
||||
for (var locks : otherPipe.craftIngredientRequests) {
|
||||
for (var lock : locks.getRight())
|
||||
network.resolveNetworkLock(lock);
|
||||
}
|
||||
otherPipe.craftIngredientRequests.clear();
|
||||
otherPipe.craftResultRequests.clear();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue