Skip to content

Commit 2df9c04

Browse files
committed
Add bookshelf count to the enchantment table screen, and fix bookshelf detection for 1.19
1 parent 1ee4a5b commit 2df9c04

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/net/earthcomputer/clientcommands/features/EnchantmentCracker.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public static void drawEnchantmentGUIOverlay(DrawContext context) {
114114

115115
lines.add("");
116116

117+
if (enchantingTablePos != null) {
118+
lines.add(I18n.translate("enchCrack.bookshelfCount", getEnchantPower(MinecraftClient.getInstance().world, enchantingTablePos)));
119+
lines.add("");
120+
}
121+
117122
if (crackState == CrackState.CRACKED) {
118123
lines.add(I18n.translate("enchCrack.enchantments"));
119124
} else {
@@ -451,13 +456,21 @@ public static boolean isEnchantingPredictionEnabled() {
451456
private static int getEnchantPower(World world, BlockPos tablePos) {
452457
int power = 0;
453458

459+
int protocolVersion = MultiVersionCompat.INSTANCE.getProtocolVersion();
460+
454461
for (BlockPos bookshelfOffset : EnchantingTableBlock.POWER_PROVIDER_OFFSETS) {
455-
if (MultiVersionCompat.INSTANCE.getProtocolVersion() <= MultiVersionCompat.V1_18) {
462+
if (protocolVersion <= MultiVersionCompat.V1_18) {
456463
// old bookshelf detection method
457464
BlockPos obstructionPos = tablePos.add(MathHelper.clamp(bookshelfOffset.getX(), -1, 1), 0, MathHelper.clamp(bookshelfOffset.getZ(), -1, 1));
458465
if (world.getBlockState(tablePos.add(bookshelfOffset)).isOf(Blocks.BOOKSHELF) && world.getBlockState(obstructionPos).isAir()) {
459466
power++;
460467
}
468+
} else if (protocolVersion < MultiVersionCompat.V1_20) {
469+
// any non-air block used to obstruct bookshelves
470+
BlockPos obstructionPos = tablePos.add(bookshelfOffset.getX() / 2, bookshelfOffset.getY(), bookshelfOffset.getZ() / 2);
471+
if (world.getBlockState(tablePos.add(bookshelfOffset)).isOf(Blocks.BOOKSHELF) && world.getBlockState(obstructionPos).isAir()) {
472+
power++;
473+
}
461474
} else {
462475
if (EnchantingTableBlock.canAccessPowerProvider(world, tablePos, bookshelfOffset)) {
463476
power++;

src/main/resources/assets/clientcommands/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
"enchCrack.enchantments": "Enchantments:",
237237
"enchCrack.clues": "Clues:",
238238
"enchCrack.slot": "Slot %d:",
239+
"enchCrack.bookshelfCount": "Bookshelf Count: %d",
239240

240241
"enchCrack.xpSeed.one": "XP Seed: %08X",
241242
"enchCrack.xpSeed.many": "Possible XP seeds: %d",

0 commit comments

Comments
 (0)