Skip to content

Commit 4924408

Browse files
authored
0.24.0 Farming Stuff (#1948)
* Fix nullability warning * Reorder HeadTextures + add Firefly Pest * Don't highlight Stero disks if the crop is unknown * Firefly Flash Texture * Add hoes * Mark null fields for components * Add Dragonfly Pest and Praying Mantis Pest * Add to GardenConstants * Remove unnecessary null check
1 parent c18242f commit 4924408

File tree

11 files changed

+68
-29
lines changed

11 files changed

+68
-29
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package de.hysky.skyblocker.skyblock.garden;
22

3+
import org.jspecify.annotations.Nullable;
4+
35
/**
46
* Used by {@link de.hysky.skyblocker.skyblock.entity.glow.adder.GardenGlowAdder} and {@link StereoHarmonyHelper}
57
*/
68
public final class CurrentJacobCrop {
79
private CurrentJacobCrop() {}
810

9-
public static String CURRENT_CROP_CONTEST;
11+
public static @Nullable String CURRENT_CROP_CONTEST;
1012
}

src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static void init() {
6767

6868
assert client.player != null;
6969
ItemStack stack = client.player.getMainHandItem();
70-
if (stack == null || tryGetCounter(stack, CounterType.CULTIVATING) && tryGetCounter(stack, CounterType.COUNTER)) {
70+
if (tryGetCounter(stack, CounterType.CULTIVATING) && tryGetCounter(stack, CounterType.COUNTER)) {
7171
counterType = CounterType.NONE;
7272
}
7373
}

src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.minecraft.util.Mth;
2121
import net.minecraft.world.entity.Entity;
2222
import net.minecraft.world.item.ItemStack;
23+
import org.jspecify.annotations.Nullable;
2324

2425
@RegisterWidget
2526
public class FarmingHudWidget extends ComponentBasedWidget {
@@ -38,6 +39,12 @@ public class FarmingHudWidget extends ComponentBasedWidget {
3839
Map.entry("THEORETICAL_HOE_CANE_1", "SUGAR_CANE"),
3940
Map.entry("THEORETICAL_HOE_CANE_2", "SUGAR_CANE"),
4041
Map.entry("THEORETICAL_HOE_CANE_3", "SUGAR_CANE"),
42+
Map.entry("THEORETICAL_HOE_SUNFLOWER_1", "DOUBLE_PLANT"),
43+
Map.entry("THEORETICAL_HOE_SUNFLOWER_2", "DOUBLE_PLANT"),
44+
Map.entry("THEORETICAL_HOE_SUNFLOWER_3", "DOUBLE_PLANT"),
45+
Map.entry("THEORETICAL_HOE_WILD_ROSE_1", "WILD_ROSE"),
46+
Map.entry("THEORETICAL_HOE_WILD_ROSE_2", "WILD_ROSE"),
47+
Map.entry("THEORETICAL_HOE_WILD_ROSE_3", "WILD_ROSE"),
4148
Map.entry("THEORETICAL_HOE_WARTS_1", "NETHER_STALK"),
4249
Map.entry("THEORETICAL_HOE_WARTS_2", "NETHER_STALK"),
4350
Map.entry("THEORETICAL_HOE_WARTS_3", "NETHER_STALK"),
@@ -53,7 +60,7 @@ public class FarmingHudWidget extends ComponentBasedWidget {
5360
Map.entry("BASIC_GARDENING_HOE", ""),
5461
Map.entry("ADVANCED_GARDENING_HOE", "")
5562
);
56-
private static FarmingHudWidget instance = null;
63+
private static @Nullable FarmingHudWidget instance = null;
5764

5865
public static FarmingHudWidget getInstance() {
5966
if (instance == null) instance = new FarmingHudWidget();
@@ -80,7 +87,6 @@ public void updateContent() {
8087
return;
8188
}
8289
ItemStack farmingToolStack = client.player.getMainHandItem();
83-
if (farmingToolStack == null) return;
8490
String itemId = farmingToolStack.getSkyblockId();
8591
String cropItemId = FARMING_TOOLS.getOrDefault(itemId, "");
8692
ItemStack cropStack = ItemRepository.getItemStack(cropItemId.replace(":", "-")); // Hacky conversion to neu id since ItemUtils.getNeuId requires an item stack.

src/main/java/de/hysky/skyblocker/skyblock/garden/GardenConstants.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public interface GardenConstants {
1919
entry("Moth", "Cocoa Beans"),
2020
entry("Beetle", "Nether Wart"),
2121
entry("Mite", "Cactus"),
22-
entry("Slug", "Mushroom"));
22+
entry("Slug", "Mushroom"),
23+
entry("Firefly", "Moonflower"),
24+
entry("Dragonfly", "Sunflower"),
25+
entry("Praying Mantis", "Wild Rose")
26+
);
2327

2428
Multimap<String, String> PEST_HEAD_BY_CROP = Util.make(ArrayListMultimap.create(), map -> {
2529
map.put("Wheat", HeadTextures.FLY_PEST);
@@ -33,5 +37,9 @@ public interface GardenConstants {
3337
map.put("Nether Wart", HeadTextures.BEETLE_PEST);
3438
map.put("Cactus", HeadTextures.MITE_PEST);
3539
map.put("Mushroom", HeadTextures.SLUG_PEST);
40+
map.put("Moonflower", HeadTextures.FIREFLY_PEST);
41+
map.put("Moonflower", HeadTextures.FIREFLY_PEST_FLASH);
42+
map.put("Sunflower", HeadTextures.DRAGONFLY_PEST);
43+
map.put("Wild Rose", HeadTextures.PRAYING_MANTIS_PEST);
3644
});
3745
}

src/main/java/de/hysky/skyblocker/skyblock/garden/StereoHarmonyHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public List<ColorHighlight> getColors(Int2ObjectMap<ItemStack> slots) {
3434
if (matcher != null) {
3535
String pestName = matcher.group("name").trim();
3636
String crop = GardenConstants.CROP_BY_PEST.get(pestName);
37+
if (crop == null) continue;
3738
boolean isPlaying = ItemUtils.getLoreLineIf(entry.getValue(), text -> text.equals("PLAYING")) != null;
3839

3940
if (Objects.equals(crop, CurrentJacobCrop.CURRENT_CROP_CONTEST)) {

src/main/java/de/hysky/skyblocker/skyblock/item/HeadTextures.java

Lines changed: 24 additions & 9 deletions
Large diffs are not rendered by default.

src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ComponentBasedWidget.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import de.hysky.skyblocker.skyblock.tabhud.widget.component.Component;
99
import de.hysky.skyblocker.skyblock.tabhud.widget.component.Components;
1010
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
11+
import org.jspecify.annotations.Nullable;
1112
import org.slf4j.Logger;
1213

1314
import java.util.ArrayList;
@@ -31,7 +32,7 @@ public abstract class ComponentBasedWidget extends HudWidget {
3132

3233
private static final Font txtRend = Minecraft.getInstance().font;
3334

34-
private String lastError = null;
35+
private @Nullable String lastError = null;
3536
private static final List<Component> ERROR_COMPONENTS = List.of(new PlainTextComponent(net.minecraft.network.chat.Component.literal("An error occurred! Please check logs.").withColor(0xFFFF0000)));
3637

3738
private final ArrayList<Component> components = new ArrayList<>();
@@ -90,17 +91,17 @@ public final void update() {
9091
* added as such:
9192
* [ico] [string] [textB.formatted(fmt)]
9293
*/
93-
public final void addSimpleIcoText(ItemStack ico, String string, ChatFormatting fmt, int idx) {
94+
public final void addSimpleIcoText(@Nullable ItemStack ico, String string, ChatFormatting fmt, int idx) {
9495
net.minecraft.network.chat.Component txt = simpleEntryText(idx, string, fmt);
9596
this.addComponent(Components.iconTextComponent(ico, txt));
9697
}
9798

98-
public final void addSimpleIcoText(ItemStack ico, String string, ChatFormatting fmt, String content) {
99+
public final void addSimpleIcoText(@Nullable ItemStack ico, String string, ChatFormatting fmt, String content) {
99100
net.minecraft.network.chat.Component txt = simpleEntryText(content, string, fmt);
100101
this.addComponent(Components.iconTextComponent(ico, txt));
101102
}
102103

103-
public final void addSimpleIconTranslatableText(ItemStack icon, @Translatable String translationKey, ChatFormatting formatting, String content) {
104+
public final void addSimpleIconTranslatableText(@Nullable ItemStack icon, @Translatable String translationKey, ChatFormatting formatting, String content) {
104105
net.minecraft.network.chat.Component text = simpleEntryTranslatableText(translationKey, content, formatting);
105106
this.addComponent(Components.iconTextComponent(icon, text));
106107
}
@@ -181,7 +182,7 @@ private void drawVLine(GuiGraphics context, int xpos, int ypos, int height) {
181182
* returned:
182183
* [entryName] [textB.formatted(contentFmt)]
183184
*/
184-
public static net.minecraft.network.chat.Component simpleEntryText(int idx, String entryName, ChatFormatting contentFmt) {
185+
public static net.minecraft.network.chat.@Nullable Component simpleEntryText(int idx, String entryName, ChatFormatting contentFmt) {
185186

186187
String src = PlayerListManager.strAt(idx);
187188

src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/Components.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import net.minecraft.network.chat.MutableComponent;
66
import net.minecraft.world.item.ItemStack;
77
import org.jetbrains.annotations.Range;
8+
import org.jspecify.annotations.Nullable;
89

910
public class Components {
1011
public static Component iconTextComponent() {
1112
return iconTextComponent(null, null);
1213
}
1314

14-
public static Component iconTextComponent(ItemStack icon, net.minecraft.network.chat.Component text) {
15+
public static Component iconTextComponent(@Nullable ItemStack icon, net.minecraft.network.chat.@Nullable Component text) {
1516
if (SkyblockerConfigManager.get().uiAndVisuals.tabHud.displayIcons) {
1617
return new IcoTextComponent(icon, text);
1718
} else {
@@ -23,7 +24,7 @@ public static de.hysky.skyblocker.skyblock.tabhud.widget.component.Component ico
2324
return iconFatTextComponent(null, null, null);
2425
}
2526

26-
public static de.hysky.skyblocker.skyblock.tabhud.widget.component.Component iconFatTextComponent(ItemStack icon, net.minecraft.network.chat.Component line1, net.minecraft.network.chat.Component line2) {
27+
public static de.hysky.skyblocker.skyblock.tabhud.widget.component.Component iconFatTextComponent(@Nullable ItemStack icon, net.minecraft.network.chat.@Nullable Component line1, net.minecraft.network.chat.@Nullable Component line2) {
2728
if (SkyblockerConfigManager.get().uiAndVisuals.tabHud.displayIcons) {
2829
return new IcoFatTextComponent(icon, line1, line2);
2930
} else {

src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.minecraft.client.gui.GuiGraphics;
66
import net.minecraft.util.CommonColors;
77
import net.minecraft.world.item.ItemStack;
8+
import org.jspecify.annotations.Nullable;
89

910
/**
1011
* Component that consists of an icon and two lines of text
@@ -14,15 +15,16 @@ class IcoFatTextComponent extends Component {
1415
private ItemStack ico;
1516
private net.minecraft.network.chat.Component line1, line2;
1617

17-
IcoFatTextComponent(ItemStack ico, net.minecraft.network.chat.Component l1, net.minecraft.network.chat.Component l2) {
18+
IcoFatTextComponent(@Nullable ItemStack ico, net.minecraft.network.chat.@Nullable Component l1, net.minecraft.network.chat.@Nullable Component l2) {
1819
this.ico = (ico == null) ? Ico.BARRIER : ico;
19-
this.line1 = l1;
20-
this.line2 = l2;
2120

2221
if (l1 == null || l2 == null) {
2322
this.ico = Ico.BARRIER;
2423
this.line1 = net.minecraft.network.chat.Component.literal("No data").withStyle(ChatFormatting.GRAY);
2524
this.line2 = net.minecraft.network.chat.Component.literal("No data").withStyle(ChatFormatting.GRAY);
25+
} else {
26+
this.line1 = l1;
27+
this.line2 = l2;
2628
}
2729

2830
this.width = ICO_DIM.get() + PAD_L + Math.max(txtRend.width(this.line1), txtRend.width(this.line2));

src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.client.gui.GuiGraphics;
77
import net.minecraft.util.CommonColors;
88
import net.minecraft.world.item.ItemStack;
9+
import org.jspecify.annotations.Nullable;
910

1011
/**
1112
* Component that consists of an icon and a line of text.
@@ -14,11 +15,12 @@ class IcoTextComponent extends Component {
1415
private ItemStack ico;
1516
private net.minecraft.network.chat.Component text;
1617

17-
IcoTextComponent(ItemStack ico, net.minecraft.network.chat.Component txt) {
18+
IcoTextComponent(@Nullable ItemStack ico, net.minecraft.network.chat.@Nullable Component txt) {
1819
this.ico = (ico == null) ? Ico.BARRIER : ico;
19-
this.text = txt;
2020

21-
if (txt == null) {
21+
if (txt != null) {
22+
this.text = txt;
23+
} else {
2224
this.ico = Ico.BARRIER;
2325
this.text = net.minecraft.network.chat.Component.literal("No data").withStyle(ChatFormatting.GRAY);
2426
}

0 commit comments

Comments
 (0)