diff --git a/gradle.properties b/gradle.properties index fb3fbb1..57b237a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.21.3 yarn_mappings=1.21.3+build.2 loader_version=0.16.9 # Mod Properties -mod_version=1.6+1.21.3 +mod_version=1.7+1.21.3 maven_group=me.lukasabbe archives_base_name=Bookshelfinspector diff --git a/src/main/java/me/lukasabbe/bookshelfinspector/util/HudRenderer.java b/src/main/java/me/lukasabbe/bookshelfinspector/util/HudRenderer.java index dfe3a95..e61298a 100644 --- a/src/main/java/me/lukasabbe/bookshelfinspector/util/HudRenderer.java +++ b/src/main/java/me/lukasabbe/bookshelfinspector/util/HudRenderer.java @@ -13,7 +13,12 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.item.ItemStack; import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.registry.tag.EnchantmentTags; +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; import net.minecraft.text.Text; +import net.minecraft.text.Texts; +import net.minecraft.util.Formatting; @Environment(EnvType.CLIENT) public class HudRenderer { @@ -30,9 +35,12 @@ public static void hudRender(DrawContext context, MinecraftClient client){ int y = screenHeight / 2; final ItemStack itemStack = currentBookData.itemStack; int color = 0xFFFFFFFF; - if(itemStack.getRarity().getFormatting().getColorValue() != null){ - color = itemStack.getRarity().getFormatting().getColorValue(); + + final Integer colorValue = itemStack.getRarity().getFormatting().getColorValue(); + if(colorValue != null){ + color = colorValue; } + float scaleFactor = ((float) BookshelfinspectorClient.config.scale /10); drawScaledText(context, itemStack.getName(), x,y+((int)(10*scaleFactor)), color, client.textRenderer); @@ -41,10 +49,14 @@ public static void hudRender(DrawContext context, MinecraftClient client){ int i = ((int)(20*scaleFactor)); for(RegistryEntry enchantment : storedComponents.getEnchantments()){ String lvl = ""; - if(storedComponents.getLevel(enchantment) != 1) - lvl = String.valueOf(storedComponents.getLevel(enchantment)); - - drawScaledText(context,enchantment.value().description().copy().append(" " + lvl), x,y+i, 0xFFFFFFFF,client.textRenderer); + final int level = storedComponents.getLevel(enchantment); + if(level != 1) + lvl = String.valueOf(level); + final MutableText append = enchantment.value().description().copy().append(" " + lvl); + if(enchantment.isIn(EnchantmentTags.CURSE)) { + Texts.setStyleIfAbsent(append, Style.EMPTY.withColor(Formatting.RED)); + } + drawScaledText(context, append, x,y+i, 0xFFFFFFFF,client.textRenderer); i+=(int)(10*scaleFactor); } } @@ -61,7 +73,8 @@ private static void drawScaledText(DrawContext context, Text text, int centerX, MatrixStack stack = context.getMatrices(); stack.push(); stack.translate(centerX,y,0); - stack.scale((float) BookshelfinspectorClient.config.scale /10, (float) BookshelfinspectorClient.config.scale /10, (float) BookshelfinspectorClient.config.scale /10); + final float scale = (float) BookshelfinspectorClient.config.scale / 10; + stack.scale(scale, scale, scale); stack.translate(-centerX,-y,0); context.drawCenteredTextWithShadow(textRenderer,text,centerX,y,color); stack.pop(); diff --git a/src/main/java/me/lukasabbe/bookshelfinspector/util/Inspector.java b/src/main/java/me/lukasabbe/bookshelfinspector/util/Inspector.java index 0e95b5f..25cb3db 100644 --- a/src/main/java/me/lukasabbe/bookshelfinspector/util/Inspector.java +++ b/src/main/java/me/lukasabbe/bookshelfinspector/util/Inspector.java @@ -22,30 +22,32 @@ import java.util.Optional; import java.util.OptionalInt; +import static me.lukasabbe.bookshelfinspector.BookshelfinspectorClient.*; + @Environment(EnvType.CLIENT) public class Inspector { public void inspect(MinecraftClient client){ - if(!BookshelfinspectorClient.modAvailable) return; + if(!modAvailable) return; if(client.cameraEntity == null || client.player == null) return; HitResult hit = client.cameraEntity.raycast(5f,0f,false); final HitResult.Type type = hit.getType(); if(type != HitResult.Type.BLOCK) { - BookshelfinspectorClient.bookShelfData.isCurrentBookDataToggled = false; - BookshelfinspectorClient.currentBookData = BookData.empty(); + bookShelfData.isCurrentBookDataToggled = false; + currentBookData = BookData.empty(); } final BlockHitResult blockHitResult = (BlockHitResult) hit; BlockPos pos = blockHitResult.getBlockPos(); if(client.player.getWorld().getBlockState(pos).isOf(Blocks.CHISELED_BOOKSHELF)){ bookShelfInspect(pos, blockHitResult, client); - }else if(client.player.getWorld().getBlockState(pos).isOf(Blocks.LECTERN) && BookshelfinspectorClient.config.lecternToggle){ + }else if(client.player.getWorld().getBlockState(pos).isOf(Blocks.LECTERN) && config.lecternToggle){ lecternInspect(pos, client); }else{ - BookshelfinspectorClient.bookShelfData.isCurrentBookDataToggled = false; - BookshelfinspectorClient.currentBookData = BookData.empty(); - BookshelfinspectorClient.bookShelfData.latestPos = null; - BookshelfinspectorClient.bookShelfData.requestSent = false; + bookShelfData.isCurrentBookDataToggled = false; + currentBookData = BookData.empty(); + bookShelfData.latestPos = null; + bookShelfData.requestSent = false; } } @@ -53,19 +55,19 @@ public void inspect(MinecraftClient client){ private void lecternInspect(BlockPos pos, MinecraftClient client){ Optional optionalLecternBlockEntity = client.player.getWorld().getBlockEntity(pos, BlockEntityType.LECTERN); if(optionalLecternBlockEntity.isEmpty()){ - BookshelfinspectorClient.bookShelfData.isCurrentBookDataToggled = false; - BookshelfinspectorClient.currentBookData = BookData.empty(); + bookShelfData.isCurrentBookDataToggled = false; + currentBookData = BookData.empty(); return; } - if(BookshelfinspectorClient.bookShelfData.latestPos != null && BookshelfinspectorClient.bookShelfData.latestPos.equals(pos)){ + if(bookShelfData.latestPos != null && bookShelfData.latestPos.equals(pos)){ return; } - if(!BookshelfinspectorClient.bookShelfData.requestSent){ - BookshelfinspectorClient.bookShelfData.requestSent = true; + if(!bookShelfData.requestSent){ + bookShelfData.requestSent = true; ClientPlayNetworking.send(new LecternInventoryRequestPayload(pos)); - BookshelfinspectorClient.bookShelfData.latestPos = pos; + bookShelfData.latestPos = pos; } } @@ -73,8 +75,8 @@ private void lecternInspect(BlockPos pos, MinecraftClient client){ private void bookShelfInspect(BlockPos pos, BlockHitResult blockHitResult, MinecraftClient client){ Optional optionalChiseledBookshelfBlockEntity = client.player.getWorld().getBlockEntity(pos, BlockEntityType.CHISELED_BOOKSHELF); if(optionalChiseledBookshelfBlockEntity.isEmpty()){ - BookshelfinspectorClient.bookShelfData.isCurrentBookDataToggled = false; - BookshelfinspectorClient.currentBookData = BookData.empty(); + bookShelfData.isCurrentBookDataToggled = false; + currentBookData = BookData.empty(); return; } @@ -84,25 +86,25 @@ private void bookShelfInspect(BlockPos pos, BlockHitResult blockHitResult, Minec OptionalInt optionalInt = ((BookshelfInvoker)bookshelfBlock).invokerGetSlotForHitPos(blockHitResult,blockState); if(optionalInt.isEmpty()) { - BookshelfinspectorClient.bookShelfData.isCurrentBookDataToggled = false; + bookShelfData.isCurrentBookDataToggled = false; return; } final BookData currentBookData = BookshelfinspectorClient.currentBookData; - int temp = BookshelfinspectorClient.bookShelfData.currentSlotInt; + int temp = bookShelfData.currentSlotInt; final int slotNum = optionalInt.getAsInt(); - BookshelfinspectorClient.bookShelfData.currentSlotInt = slotNum; + bookShelfData.currentSlotInt = slotNum; - if(currentBookData.slotId!= slotNum && currentBookData.slotId!=-2 && !BookshelfinspectorClient.bookShelfData.requestSent){ - BookshelfinspectorClient.bookShelfData.requestSent = true; + if(currentBookData.slotId!= slotNum && currentBookData.slotId!=-2 && !bookShelfData.requestSent){ + bookShelfData.requestSent = true; ClientPlayNetworking.send(new BookShelfInventoryRequestPayload(pos, slotNum)); } else { if(temp == slotNum) - BookshelfinspectorClient.bookShelfData.isCurrentBookDataToggled = currentBookData.slotId != -2; + bookShelfData.isCurrentBookDataToggled = currentBookData.slotId != -2; else{ - BookshelfinspectorClient.bookShelfData.isCurrentBookDataToggled = false; + bookShelfData.isCurrentBookDataToggled = false; BookshelfinspectorClient.currentBookData = BookData.empty(); } }