mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-05 00:38:35 +01:00
allow force-canceling crafts that are in progress
This commit is contained in:
parent
1b0c36d5e5
commit
887bfed229
6 changed files with 30 additions and 16 deletions
|
@ -63,6 +63,19 @@ public class ActiveCraft implements INBTSerializable<CompoundTag> {
|
||||||
this.canceled = nbt.getBoolean("canceled");
|
this.canceled = nbt.getBoolean("canceled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ActiveCraft{" +
|
||||||
|
"pipe=" + this.pipe +
|
||||||
|
", moduleSlot=" + this.moduleSlot +
|
||||||
|
", travelingIngredients=" + this.travelingIngredients +
|
||||||
|
", ingredientsToRequest=" + this.ingredientsToRequest +
|
||||||
|
", resultDestPipe=" + this.resultDestPipe +
|
||||||
|
", resultStackRemain=" + this.resultStackRemain +
|
||||||
|
", inProgress=" + this.inProgress +
|
||||||
|
", canceled=" + this.canceled + '}';
|
||||||
|
}
|
||||||
|
|
||||||
public ItemStack getTravelingIngredient(ItemStack stack, ItemEquality... equalityTypes) {
|
public ItemStack getTravelingIngredient(ItemStack stack, ItemEquality... equalityTypes) {
|
||||||
for (var traveling : this.travelingIngredients) {
|
for (var traveling : this.travelingIngredients) {
|
||||||
if (ItemEquality.compareItems(stack, traveling, equalityTypes))
|
if (ItemEquality.compareItems(stack, traveling, equalityTypes))
|
||||||
|
@ -71,14 +84,14 @@ public class ActiveCraft implements INBTSerializable<CompoundTag> {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean markCanceledOrResolve(PipeNetwork network) {
|
public boolean markCanceledOrResolve(PipeNetwork network, boolean force) {
|
||||||
if (this.inProgress) {
|
if (force || !this.inProgress) {
|
||||||
this.canceled = true;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
for (var lock : this.ingredientsToRequest)
|
for (var lock : this.ingredientsToRequest)
|
||||||
network.resolveNetworkLock(lock);
|
network.resolveNetworkLock(lock);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
this.canceled = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,8 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
|
||||||
",\nnodeToConnectedNodes=" + this.nodeToConnectedNodes +
|
",\nnodeToConnectedNodes=" + this.nodeToConnectedNodes +
|
||||||
",\ntileCache=" + this.tileCache.keySet() +
|
",\ntileCache=" + this.tileCache.keySet() +
|
||||||
",\npipeItems=" + this.pipeItems +
|
",\npipeItems=" + this.pipeItems +
|
||||||
",\nnetworkLocks=" + this.networkLocks + '}';
|
",\nnetworkLocks=" + this.networkLocks +
|
||||||
|
",\nactiveCrafts=" + this.activeCrafts + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -460,7 +461,7 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelCrafts() {
|
public void cancelCrafts() {
|
||||||
this.activeCrafts.entries().removeIf(c -> c.getValue().markCanceledOrResolve(this));
|
this.activeCrafts.entries().removeIf(c -> c.getValue().markCanceledOrResolve(this, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<NetworkEdge> createAllEdges(BlockPos pos, BlockState state, boolean ignoreCurrBlocked) {
|
private List<NetworkEdge> createAllEdges(BlockPos pos, BlockState state, boolean ignoreCurrBlocked) {
|
||||||
|
|
|
@ -127,7 +127,7 @@ public record PacketButton(BlockPos pos, int result, List<Integer> data) impleme
|
||||||
}),
|
}),
|
||||||
CANCEL_CRAFTING((pos, data, player) -> {
|
CANCEL_CRAFTING((pos, data, player) -> {
|
||||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level(), pos);
|
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level(), pos);
|
||||||
tile.cancelCrafting();
|
tile.cancelCrafting(data.getFirst() == 1);
|
||||||
}),
|
}),
|
||||||
TAG_FILTER((pos, data, player) -> {
|
TAG_FILTER((pos, data, player) -> {
|
||||||
var container = (FilterModifierModuleContainer) player.containerMenu;
|
var container = (FilterModifierModuleContainer) player.containerMenu;
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
||||||
if (playersToSync.length > 0) {
|
if (playersToSync.length > 0) {
|
||||||
var clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
var clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
||||||
var clientCraftables = PipeNetwork.get(this.level).getAllCraftables(pipe.getBlockPos()).stream().map(Pair::getRight).collect(Collectors.toList());
|
var clientCraftables = PipeNetwork.get(this.level).getAllCraftables(pipe.getBlockPos()).stream().map(Pair::getRight).collect(Collectors.toList());
|
||||||
var currentlyCrafting = this.getCurrentlyCrafting(false).stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
var currentlyCrafting = this.getCurrentlyCrafting(true).stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
||||||
for (var player : playersToSync) {
|
for (var player : playersToSync) {
|
||||||
if (!(player.containerMenu instanceof ItemTerminalContainer container))
|
if (!(player.containerMenu instanceof ItemTerminalContainer container))
|
||||||
continue;
|
continue;
|
||||||
|
@ -207,7 +207,7 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
||||||
return crafting.stream().map(Pair::getRight).collect(Collectors.toList());
|
return crafting.stream().map(Pair::getRight).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelCrafting() {
|
public void cancelCrafting(boolean force) {
|
||||||
var network = PipeNetwork.get(this.level);
|
var network = PipeNetwork.get(this.level);
|
||||||
var pipe = this.getConnectedPipe();
|
var pipe = this.getConnectedPipe();
|
||||||
if (pipe == null)
|
if (pipe == null)
|
||||||
|
@ -215,7 +215,7 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
||||||
for (var craftable : network.getAllCraftables(pipe.getBlockPos())) {
|
for (var craftable : network.getAllCraftables(pipe.getBlockPos())) {
|
||||||
var otherPipe = network.getPipe(craftable.getLeft());
|
var otherPipe = network.getPipe(craftable.getLeft());
|
||||||
if (otherPipe != null)
|
if (otherPipe != null)
|
||||||
otherPipe.getActiveCrafts().removeIf(c -> c.markCanceledOrResolve(network));
|
otherPipe.getActiveCrafts().removeIf(c -> c.markCanceledOrResolve(network, force));
|
||||||
}
|
}
|
||||||
var lookingPlayers = this.getLookingPlayers();
|
var lookingPlayers = this.getLookingPlayers();
|
||||||
if (lookingPlayers.length > 0)
|
if (lookingPlayers.length > 0)
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
||||||
// and vanilla buttons are activated when the click starts, so we'll always invoke jei accidentally by default
|
// and vanilla buttons are activated when the click starts, so we'll always invoke jei accidentally by default
|
||||||
if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
|
if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
|
||||||
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
||||||
PacketDistributor.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CANCEL_CRAFTING, List.of()));
|
PacketDistributor.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CANCEL_CRAFTING, List.of(hasShiftDown() ? 1 : 0)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
||||||
} else if (search.startsWith("#")) {
|
} else if (search.startsWith("#")) {
|
||||||
// search item description
|
// search item description
|
||||||
var hoverText = s.getLeft().getTooltipLines(Item.TooltipContext.of(this.minecraft.level), this.minecraft.player,
|
var hoverText = s.getLeft().getTooltipLines(Item.TooltipContext.of(this.minecraft.level), this.minecraft.player,
|
||||||
this.minecraft.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL);
|
this.minecraft.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL);
|
||||||
toCompare = hoverText.stream().map(Component::getString).collect(Collectors.joining("\n"));
|
toCompare = hoverText.stream().map(Component::getString).collect(Collectors.joining("\n"));
|
||||||
search = search.substring(1);
|
search = search.substring(1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -364,8 +364,8 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
||||||
|
|
||||||
public Stream<ItemTerminalWidget> streamWidgets() {
|
public Stream<ItemTerminalWidget> streamWidgets() {
|
||||||
return this.renderables.stream()
|
return this.renderables.stream()
|
||||||
.filter(w -> w instanceof ItemTerminalWidget)
|
.filter(w -> w instanceof ItemTerminalWidget)
|
||||||
.map(w -> (ItemTerminalWidget) w);
|
.map(w -> (ItemTerminalWidget) w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int requestModifier() {
|
public static int requestModifier() {
|
||||||
|
|
|
@ -94,7 +94,7 @@
|
||||||
"info.prettypipes.energy": "%s / %s FE",
|
"info.prettypipes.energy": "%s / %s FE",
|
||||||
"info.prettypipes.crafting": "Awaiting",
|
"info.prettypipes.crafting": "Awaiting",
|
||||||
"info.prettypipes.cancel_all": "Cancel",
|
"info.prettypipes.cancel_all": "Cancel",
|
||||||
"info.prettypipes.cancel_all.desc": "Stops waiting for current crafting outputs\nOngoing crafting operations are still completed",
|
"info.prettypipes.cancel_all.desc": "Stops waiting for current crafting outputs\nOngoing crafting operations are still completed\nHold Shift to include ongoing crafting operations,\nwhich may cause partial recipes to stay behind",
|
||||||
"info.prettypipes.no_pipe_connected": "The terminal needs to be connected to a pipe network",
|
"info.prettypipes.no_pipe_connected": "The terminal needs to be connected to a pipe network",
|
||||||
"info.prettypipes.too_many_pipes_connected": "The terminal can only be connected to a single pipe at a time",
|
"info.prettypipes.too_many_pipes_connected": "The terminal can only be connected to a single pipe at a time",
|
||||||
"dir.prettypipes.up": "Up",
|
"dir.prettypipes.up": "Up",
|
||||||
|
|
Loading…
Reference in a new issue