Skip to content

Commit

Permalink
Make enchantment cracking cancelable
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Mar 3, 2024
1 parent 8344491 commit 7f4ea9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ private static int cenchant(FabricClientCommandSource source, ItemAndEnchantment
source.sendFeedback(Component.literal("- ").append(ench.enchantment.getFullname(ench.level)));
}
if (!simulate) {
source.sendFeedback(Component.translatable("commands.cenchant.success"));
source.sendFeedback(Component.translatable("commands.cenchant.success")
.append(" ")
.append(getCommandTextComponent("commands.client.cancel", "/ctask stop " + result.taskName())));
}
}
return Command.SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EnchantmentTableBlock;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import java.util.ArrayList;
Expand Down Expand Up @@ -361,7 +362,7 @@ public static ManipulateResult manipulateEnchantments(Item item, Predicate<List<
}

if (simulate) {
return new ManipulateResult(timesNeeded, bookshelvesNeeded, slot, enchantments);
return new ManipulateResult(timesNeeded, bookshelvesNeeded, slot, enchantments, null);
}

LongTaskList taskList = new LongTaskList();
Expand Down Expand Up @@ -423,9 +424,9 @@ public void run() {
}
});

TaskManager.addTask("enchantmentCracker", taskList);
String taskName = TaskManager.addTask("enchantmentCracker", taskList);

return new ManipulateResult(timesNeeded, bookshelvesNeeded, slot, enchantments);
return new ManipulateResult(timesNeeded, bookshelvesNeeded, slot, enchantments, taskName);
}

// MISCELLANEOUS HELPER METHODS & ENCHANTING SIMULATION
Expand Down Expand Up @@ -505,7 +506,7 @@ public static List<EnchantmentInstance> getEnchantmentsInTable(int slot) {
}
}

public record ManipulateResult(int itemThrows, int bookshelves, int slot, List<EnchantmentInstance> enchantments) {}
public record ManipulateResult(int itemThrows, int bookshelves, int slot, List<EnchantmentInstance> enchantments, @Nullable String taskName) {}

public enum CrackState implements StringRepresentable {
UNCRACKED("uncracked"), CRACKED("cracked"), CRACKING("cracking");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/clientcommands/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"commands.cenchant.help.uncrackedPlayerSeed": "Help: you have not fully cracked the player seed",
"commands.cenchant.incompatible": "Incompatible enchantments",
"commands.cenchant.needEnchantingPrediction": "This command requires enchanting prediction to be enabled",
"commands.cenchant.success": "Starting enchantment manipulation",
"commands.cenchant.success": "Starting enchantment manipulation.",
"commands.cenchant.uncracked": "Seed needs to be cracked",

"commands.cfind.found.left": "Found %1$s at ",
Expand Down

0 comments on commit 7f4ea9c

Please sign in to comment.