mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-05 00:38:35 +01:00
Compare commits
No commits in common. "24b1bbd84b197c28a9a2359bafd4a8dfa786a309" and "894fae6b87081503779d1da1ff7736db81136e96" have entirely different histories.
24b1bbd84b
...
894fae6b87
4 changed files with 13 additions and 23 deletions
|
@ -270,10 +270,8 @@ public class PipeBlock extends BaseEntityBlock implements SimpleWaterloggedBlock
|
|||
network.onPipeChanged(pos, state);
|
||||
if (worldIn.getBlockEntity(pos) instanceof PipeBlockEntity pipe) {
|
||||
pipe.getItems().clear();
|
||||
for (var locks : pipe.craftIngredientRequests) {
|
||||
for (var lock : locks.getRight())
|
||||
network.resolveNetworkLock(lock);
|
||||
}
|
||||
for (var lock : pipe.craftIngredientRequests)
|
||||
network.resolveNetworkLock(lock.getRight());
|
||||
}
|
||||
super.onRemove(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
|
|
|
@ -71,9 +71,8 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
PipeBlockEntity.this.setChanged();
|
||||
}
|
||||
};
|
||||
// TODO instead of having these loose lists, it would be nice to have a "ModuleData" system that allows modules to store an object of custom data on the pipe
|
||||
// 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, ingredient request network lock
|
||||
public final List<Pair<Integer, 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;
|
||||
|
@ -106,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("locks", Utility.serializeAll(provider, tuple.getRight()));
|
||||
nbt.put("lock", tuple.getRight().serializeNBT(provider));
|
||||
requests.add(nbt);
|
||||
}
|
||||
compound.put("craft_requests", requests);
|
||||
|
@ -134,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"),
|
||||
Utility.deserializeAll(nbt.getList("locks", Tag.TAG_COMPOUND), c -> new NetworkLock(provider, c))));
|
||||
new NetworkLock(provider, nbt.getCompound("lock"))));
|
||||
}
|
||||
this.craftResultRequests.clear();
|
||||
var results = compound.getList("craft_results", Tag.TAG_COMPOUND);
|
||||
|
|
|
@ -76,8 +76,7 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
network.startProfile("crafting_ingredients");
|
||||
var request = tile.craftIngredientRequests.getFirst();
|
||||
if (request.getLeft() == slot) {
|
||||
var locks = request.getRight();
|
||||
var lock = locks.getFirst();
|
||||
var lock = request.getRight();
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var dest = tile.getAvailableDestination(Direction.values(), lock.stack, true, true);
|
||||
if (dest != null) {
|
||||
|
@ -86,7 +85,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);
|
||||
locks.remove(lock);
|
||||
tile.craftIngredientRequests.remove(request);
|
||||
|
||||
// if we couldn't fit all items into the destination, create another request for the rest
|
||||
var remain = lock.stack.copy();
|
||||
|
@ -95,12 +94,9 @@ 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();
|
||||
locks.add(index, remainRequest);
|
||||
tile.craftIngredientRequests.add(index, Pair.of(slot, remainRequest));
|
||||
network.createNetworkLock(remainRequest);
|
||||
}
|
||||
|
||||
if (locks.isEmpty())
|
||||
tile.craftIngredientRequests.remove(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +186,6 @@ 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--) {
|
||||
|
@ -202,10 +197,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);
|
||||
locks.addAll(ret.getLeft());
|
||||
for (var lock : ret.getLeft())
|
||||
tile.craftIngredientRequests.add(Pair.of(slot, lock));
|
||||
}
|
||||
}
|
||||
tile.craftIngredientRequests.add(Pair.of(slot, locks));
|
||||
|
||||
var remain = stack.copy();
|
||||
remain.shrink(resultAmount * toCraft);
|
||||
|
|
|
@ -217,10 +217,8 @@ 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 locks : otherPipe.craftIngredientRequests) {
|
||||
for (var lock : locks.getRight())
|
||||
network.resolveNetworkLock(lock);
|
||||
}
|
||||
for (var lock : otherPipe.craftIngredientRequests)
|
||||
network.resolveNetworkLock(lock.getRight());
|
||||
otherPipe.craftIngredientRequests.clear();
|
||||
otherPipe.craftResultRequests.clear();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue