From 5b2a65d2aa6f7c4f5c3f593c28ee40e1d560c115 Mon Sep 17 00:00:00 2001 From: Nilau1998 Date: Sun, 1 Sep 2024 12:17:39 +0200 Subject: [PATCH] [minor] add ability to display bee lore and add Discoverd by tag --- .../forestry/apiculture/genetics/Bee.java | 16 +++++++++++++ .../java/forestry/core/proxy/ProxyCommon.java | 4 ++++ .../core/proxy/ProxyCommonClient.java | 5 ++++ .../java/forestry/core/utils/StringUtil.java | 24 +++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index 917993472..0067162b9 100644 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -65,6 +65,7 @@ import forestry.core.errors.EnumErrorCode; import forestry.core.genetics.Chromosome; import forestry.core.genetics.GenericRatings; import forestry.core.genetics.IndividualLiving; +import forestry.core.proxy.Proxies; import forestry.core.utils.GeneticsUtil; import forestry.core.utils.Log; import forestry.core.utils.StringUtil; @@ -456,6 +457,21 @@ public class Bee extends IndividualLiving implements IBee { if (genome.getTolerantFlyer()) { list.add(EnumChatFormatting.WHITE + StringUtil.localize("gui.flyer.tooltip")); } + + // Add lore and discovered by + String descTokens[] = primary.getDescription().split("\\|"); + if (descTokens.length > 0) { + String speciesLore = descTokens[0]; + if (!speciesLore.isEmpty() && Proxies.common.isCtrlDown()) { + list.addAll(StringUtil.multilineStrings(speciesLore, 50)); + } + } + if (descTokens.length > 2) { + String discoveredBy = descTokens[2]; + if (!discoveredBy.isEmpty()) { + list.add("Discovered by " + discoveredBy); + } + } } @Override diff --git a/src/main/java/forestry/core/proxy/ProxyCommon.java b/src/main/java/forestry/core/proxy/ProxyCommon.java index fa81c312a..b566e2a5e 100755 --- a/src/main/java/forestry/core/proxy/ProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ProxyCommon.java @@ -61,6 +61,10 @@ public class ProxyCommon { return false; } + public boolean isCtrlDown() { + return false; + } + public void playSoundFX(World world, int x, int y, int z, Block block) { Proxies.net.sendNetworkPacket(new PacketFXSignal(PacketFXSignal.SoundFXType.LEAF, x, y, z, block, 0), world); } diff --git a/src/main/java/forestry/core/proxy/ProxyCommonClient.java b/src/main/java/forestry/core/proxy/ProxyCommonClient.java index 97720e1be..83b51590c 100644 --- a/src/main/java/forestry/core/proxy/ProxyCommonClient.java +++ b/src/main/java/forestry/core/proxy/ProxyCommonClient.java @@ -63,6 +63,11 @@ public class ProxyCommonClient extends ProxyCommon { return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); } + @Override + public boolean isCtrlDown() { + return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL); + } + @Override public String getDisplayName(ItemStack itemstack) { return itemstack.getItem().getItemStackDisplayName(itemstack); diff --git a/src/main/java/forestry/core/utils/StringUtil.java b/src/main/java/forestry/core/utils/StringUtil.java index 841966f5d..3f22d5986 100755 --- a/src/main/java/forestry/core/utils/StringUtil.java +++ b/src/main/java/forestry/core/utils/StringUtil.java @@ -8,7 +8,9 @@ ******************************************************************************/ package forestry.core.utils; +import java.util.ArrayList; import java.util.IllegalFormatException; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -116,4 +118,26 @@ public class StringUtil { return lineCount * fontRenderer.FONT_HEIGHT; } + + public static List multilineStrings(String input, int n) { + List result = new ArrayList<>(); + + int start = 0; + while (start < input.length()) { + // Find the end index by starting with n characters ahead + int end = Math.min(start + n, input.length()); + + // If end is not at the end of the string, backtrack to the last space + if (end < input.length() && !Character.isWhitespace(input.charAt(end))) { + int lastSpace = input.lastIndexOf(' ', end); + if (lastSpace > start) { + end = lastSpace; + } + } + + result.add(input.substring(start, end).trim()); + start = end; + } + return result; + } }