Skip to content

Commit

Permalink
[minor] add ability to display bee lore and add Discoverd by tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilau1998 committed Sep 1, 2024
1 parent a172cb3 commit 5b2a65d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/forestry/apiculture/genetics/Bee.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
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;
Expand Down Expand Up @@ -456,6 +457,21 @@ public void addTooltip(List<String> list) {
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
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/forestry/core/proxy/ProxyCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public boolean isShiftDown() {
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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/forestry/core/proxy/ProxyCommonClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public boolean isShiftDown() {
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);
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/forestry/core/utils/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,4 +118,26 @@ public static int getLineHeight(int maxWidth, String... strings) {

return lineCount * fontRenderer.FONT_HEIGHT;
}

public static List<String> multilineStrings(String input, int n) {
List<String> 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;
}
}

0 comments on commit 5b2a65d

Please sign in to comment.