Skip to content

Commit

Permalink
Added colors to curses
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasabbe committed Nov 12, 2024
1 parent c1f32f5 commit 147168e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);

Expand All @@ -41,10 +49,14 @@ public static void hudRender(DrawContext context, MinecraftClient client){
int i = ((int)(20*scaleFactor));
for(RegistryEntry<Enchantment> 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);
}
}
Expand All @@ -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();
Expand Down
48 changes: 25 additions & 23 deletions src/main/java/me/lukasabbe/bookshelfinspector/util/Inspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,61 @@
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;
}
}


private void lecternInspect(BlockPos pos, MinecraftClient client){
Optional<LecternBlockEntity> 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;
}
}


private void bookShelfInspect(BlockPos pos, BlockHitResult blockHitResult, MinecraftClient client){
Optional<ChiseledBookshelfBlockEntity> 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;
}

Expand All @@ -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();
}
}
Expand Down

0 comments on commit 147168e

Please sign in to comment.