-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add powder mining tracker #1065
Merged
AzureAaron
merged 18 commits into
SkyblockerMod:master
from
Emirlol:powder-mining-tracker
Jan 1, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
af13108
Add chat events
Emirlol 5364765
Add powder mining tracker
Emirlol cd7c394
Add ON_PRICE_UPDATE event and re-calculate profit after prices are up…
Emirlol fa3c3ee
Initial config
Emirlol 9095174
Add config screens for filtering the shown items
Emirlol 8675e96
Fix Done button width being only 1 col wide when it's supposed to be 2
Emirlol d2bc9fd
Change to regex because index magic wasn't magic-ing
Emirlol 5e0e1e7
Read and write from file and fix incorrect param used in recalculateAll
Emirlol 8ee0f11
Change literal text to translatable
Emirlol 170120f
Extract `ON_PRICE_UPDATE` event to a separate class under the `events…
Emirlol eed32ec
Simplify switch to use pattern matching
Emirlol 1aefba4
Extract render and chat message lambdas to methods
Emirlol bb13c88
Add PROFILE_INIT event
Emirlol 39fd230
Add support for multiple profiles
Emirlol 053c176
Re-add ItemPrice#init with additional documentation
Emirlol 20c94a2
Prevent rendering profit if there are no rewards
Emirlol 074b818
Format item amounts when rendering
Emirlol 82f1308
Add more documentation
Emirlol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/de/hysky/skyblocker/config/screens/powdertracker/ItemTickList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package de.hysky.skyblocker.config.screens.powdertracker; | ||
|
||
import de.hysky.skyblocker.mixins.accessors.CheckboxWidgetAccessor; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.Element; | ||
import net.minecraft.client.gui.Selectable; | ||
import net.minecraft.client.gui.widget.CheckboxWidget; | ||
import net.minecraft.client.gui.widget.ElementListWidget; | ||
import net.minecraft.text.Text; | ||
|
||
import java.util.List; | ||
|
||
public class ItemTickList extends ElementListWidget<ItemTickList.ItemTickEntry> { | ||
private final List<String> filters; | ||
private final List<String> allItems; | ||
|
||
public ItemTickList(MinecraftClient minecraftClient, int width, int height, int y, int entryHeight, List<String> filters, List<String> allItems) { | ||
super(minecraftClient, width, height, y, entryHeight); | ||
this.filters = filters; | ||
this.allItems = allItems; | ||
} | ||
|
||
public void clearAndInit() { | ||
clearEntries(); | ||
init(); | ||
} | ||
|
||
public ItemTickList init() { | ||
for (String item : allItems) { | ||
ItemTickEntry entry = new ItemTickEntry( | ||
CheckboxWidget.builder(Text.of(item), client.textRenderer) | ||
.checked(!filters.contains(item)) | ||
.callback((checkbox1, checked) -> { | ||
if (checked) filters.remove(item); | ||
else filters.add(item); | ||
}) | ||
.build() | ||
); | ||
addEntry(entry); | ||
} | ||
return this; | ||
} | ||
|
||
public static class ItemTickEntry extends ElementListWidget.Entry<ItemTickEntry> { | ||
private final List<CheckboxWidget> children; | ||
|
||
ItemTickEntry(CheckboxWidget checkboxWidget) { | ||
children = List.of(checkboxWidget); | ||
} | ||
|
||
public void setChecked(boolean checked) { | ||
for (CheckboxWidget child : children) { | ||
((CheckboxWidgetAccessor) child).setChecked(checked); | ||
} | ||
} | ||
|
||
@Override | ||
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { | ||
for (CheckboxWidget child : children) { | ||
child.setX(x); | ||
child.setY(y); | ||
child.setWidth(entryWidth); | ||
child.setHeight(entryHeight); | ||
child.render(context, mouseX, mouseY, tickDelta); | ||
} | ||
} | ||
|
||
@Override | ||
public List<? extends Selectable> selectableChildren() { | ||
return children; | ||
} | ||
|
||
@Override | ||
public List<? extends Element> children() { | ||
return children; | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/de/hysky/skyblocker/config/screens/powdertracker/PowderFilterConfigScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package de.hysky.skyblocker.config.screens.powdertracker; | ||
|
||
import de.hysky.skyblocker.config.SkyblockerConfigManager; | ||
import de.hysky.skyblocker.skyblock.dwarven.PowderMiningTracker; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.client.gui.widget.GridWidget; | ||
import net.minecraft.client.gui.widget.SimplePositioningWidget; | ||
import net.minecraft.screen.ScreenTexts; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PowderFilterConfigScreen extends Screen { | ||
@Nullable | ||
private final Screen parent; | ||
private final List<String> filters; | ||
private final List<String> allItems; | ||
|
||
public PowderFilterConfigScreen(@Nullable Screen parent, List<String> allItems) { | ||
super(Text.of("Powder Mining Tracker Filter Config")); | ||
this.parent = parent; | ||
this.filters = new ArrayList<>(SkyblockerConfigManager.get().mining.crystalHollows.powderTrackerFilter); // Copy the list so we can undo changes when necessary | ||
this.allItems = allItems; | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
addDrawable((context, mouseX, mouseY, delta) -> { | ||
assert client != null; | ||
context.drawCenteredTextWithShadow(client.textRenderer, Text.translatable("skyblocker.config.mining.crystalHollows.powderTrackerFilter.screenTitle").formatted(Formatting.BOLD), width / 2, (32 - client.textRenderer.fontHeight) / 2, 0xFFFFFF); | ||
}); | ||
ItemTickList itemTickList = addDrawableChild(new ItemTickList(MinecraftClient.getInstance(), width, height - 96, 32, 24, filters, allItems).init()); | ||
//Grid code gratuitously stolen from WaypointsScreen. Same goes for the y and heights above. | ||
GridWidget gridWidget = new GridWidget(); | ||
gridWidget.getMainPositioner().marginX(5).marginY(2); | ||
GridWidget.Adder adder = gridWidget.createAdder(2); | ||
|
||
adder.add(ButtonWidget.builder(Text.translatable("text.skyblocker.reset"), button -> { | ||
filters.clear(); | ||
itemTickList.clearAndInit(); | ||
}).build()); | ||
adder.add(ButtonWidget.builder(Text.translatable("text.skyblocker.undo"), button -> { | ||
filters.clear(); | ||
filters.addAll(SkyblockerConfigManager.get().mining.crystalHollows.powderTrackerFilter); | ||
itemTickList.clearAndInit(); | ||
}).build()); | ||
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> { | ||
saveFilters(); | ||
close(); | ||
}) | ||
.width((ButtonWidget.DEFAULT_WIDTH * 2) + 10) | ||
.build(), 2); | ||
gridWidget.refreshPositions(); | ||
SimplePositioningWidget.setPos(gridWidget, 0, this.height - 64, this.width, 64); | ||
gridWidget.forEachChild(this::addDrawableChild); | ||
} | ||
|
||
public void saveFilters() { | ||
SkyblockerConfigManager.get().mining.crystalHollows.powderTrackerFilter = filters; | ||
SkyblockerConfigManager.save(); | ||
PowderMiningTracker.recalculateAll(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
assert client != null; | ||
client.setScreen(parent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package de.hysky.skyblocker.events; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class ChatEvents { | ||
/** | ||
* This will be called when a game message is received, cancelled or not. | ||
* | ||
* @implNote Not fired when {@code overlay} is {@code true}. See {@link de.hysky.skyblocker.mixins.MessageHandlerMixin#skyblocker$monitorGameMessage(Text, boolean, CallbackInfo) the mixin} for more information. | ||
*/ | ||
@SuppressWarnings("JavadocReference") | ||
public static final Event<ChatTextEvent> RECEIVE_TEXT = EventFactory.createArrayBacked(ChatTextEvent.class, listeners -> message -> { | ||
for (ChatTextEvent listener : listeners) { | ||
listener.onMessage(message); | ||
} | ||
}); | ||
|
||
/** | ||
* This will be called when a game message is received, cancelled or not. | ||
* This method is called with the result of {@link Text#getString()} to avoid each listener having to call it. | ||
* | ||
* @implNote Not fired when {@code overlay} is {@code true}. See {@link de.hysky.skyblocker.mixins.MessageHandlerMixin#skyblocker$monitorGameMessage(Text, boolean, CallbackInfo) the mixin} for more information. | ||
*/ | ||
@SuppressWarnings("JavadocReference") | ||
public static final Event<ChatStringEvent> RECEIVE_STRING = EventFactory.createArrayBacked(ChatStringEvent.class, listeners -> message -> { | ||
for (ChatStringEvent listener : listeners) { | ||
listener.onMessage(message); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface ChatTextEvent { | ||
void onMessage(Text message); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface ChatStringEvent { | ||
void onMessage(String message); | ||
AzureAaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/de/hysky/skyblocker/events/ItemPriceUpdateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.hysky.skyblocker.events; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
|
||
@FunctionalInterface | ||
@Environment(EnvType.CLIENT) | ||
public interface ItemPriceUpdateEvent { | ||
void onPriceUpdate(); | ||
|
||
/** | ||
* An event that is fired when all prices are updated. | ||
*/ | ||
Event<ItemPriceUpdateEvent> ON_PRICE_UPDATE = EventFactory.createArrayBacked(ItemPriceUpdateEvent.class, listeners -> () -> { | ||
for (ItemPriceUpdateEvent listener : listeners) { | ||
listener.onPriceUpdate(); | ||
} | ||
}); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for making chat events as opposed to using Fabric's ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fabric's injection is like this:
To listen to every incoming message, you'd have to register a listener to
ALLOW_GAME
that always returns true and never has anything to do with allowing messages or not. On top of that, if any listener before yours inALLOW_GAME
cancels it, your listener does not get called. So you have to register the same listener toGAME_CANCELED
as well and complicate things even more. Oh and the 2 functional interfaces don't match due to their return values ofboolean
andvoid
, so you need 3 whole methods (or lambdas) to achieve this.This is easily solved by adding an event that passes the message to every listener without allowing any modifications, which is what the events I added do. They also don't interfere with fabric's events since they don't modify the message in any way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've talked to fabric maintainers about this. The most probably fix that we can put in fabric is just to make
ALLOW_GAME
not short curcuit. But they're skeptical of such use cases, and it might help if you bring this problem up with them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see why they wouldn't want to make a breaking change like that, and using
ALLOW_GAME
to listen to all incoming messages is still going to be confusing due to the name and the unnecessary return value, so I'm not sure if that's the solution I'd want. Perhaps I could PR this event to fabric, but I can't think of any use cases outside of this either.