-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add mineshaft announcements * update part of the widget parsing code
- Loading branch information
Showing
27 changed files
with
569 additions
and
60 deletions.
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
4 changes: 2 additions & 2 deletions
4
src/main/generated/.cache/cabcb80d088276cffde41e74584028f1c00b99b8
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.21.3 2024-11-17T04:44:52.8413631 cookies-mod/Language (en_us) | ||
797bce4c50d9925c668cd130d03a622e7ac4e1c2 assets\cookies-mod\lang\en_us.json | ||
// 1.21.3 2024-11-17T21:52:35.48846 cookies-mod/Language (en_us) | ||
6e320280d0f984d7ebd402794f17c02815987871 assets/cookies-mod/lang/en_us.json |
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
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
7 changes: 7 additions & 0 deletions
7
src/main/java/codes/cookies/mod/config/categories/mining/shaft/ShaftAnnouncementType.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,7 @@ | ||
package codes.cookies.mod.config.categories.mining.shaft; | ||
|
||
public enum ShaftAnnouncementType { | ||
|
||
OFF, CHAT, PARTY | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/codes/cookies/mod/events/PlayerListEvent.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,18 @@ | ||
package codes.cookies.mod.events; | ||
|
||
import codes.cookies.mod.utils.cookies.CookiesEventUtils; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
|
||
import net.minecraft.client.network.PlayerListEntry; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Event related to the player list, will be called on every update. | ||
*/ | ||
public interface PlayerListEvent { | ||
|
||
Event<Consumer<PlayerListEntry>> EVENT = CookiesEventUtils.consumer(); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/codes/cookies/mod/events/PlayerListWidgetEvent.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,28 @@ | ||
package codes.cookies.mod.events; | ||
|
||
import codes.cookies.mod.utils.cookies.CookiesEventUtils; | ||
|
||
import codes.cookies.mod.utils.skyblock.tab.widgets.PlayerListWidget; | ||
|
||
import codes.cookies.mod.utils.skyblock.tab.widgets.PlayerListWidgets; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Called for all player list widgets that are found in the list. | ||
*/ | ||
public interface PlayerListWidgetEvent { | ||
|
||
Event<Consumer<PlayerListWidget>> EVENT = CookiesEventUtils.consumer(); | ||
|
||
static <T extends PlayerListWidget> void register(PlayerListWidgets.Entry<T> entry, Consumer<T> consumer) { | ||
EVENT.register(widget -> { | ||
if (entry.clazz().isInstance(widget)) { | ||
consumer.accept((T) widget); | ||
} | ||
}); | ||
} | ||
|
||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/codes/cookies/mod/events/mixins/PlayerListMixin.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,31 @@ | ||
package codes.cookies.mod.events.mixins; | ||
|
||
import codes.cookies.mod.events.PlayerListEvent; | ||
|
||
import net.minecraft.client.network.ClientPlayNetworkHandler; | ||
import net.minecraft.client.network.PlayerListEntry; | ||
|
||
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
/** | ||
* Calls events based on player list entries. | ||
*/ | ||
@Mixin(ClientPlayNetworkHandler.class) | ||
public class PlayerListMixin { | ||
|
||
@Inject(method = "handlePlayerListAction", at = @At("RETURN")) | ||
public void playerListEvents( | ||
PlayerListS2CPacket.Action action, | ||
PlayerListS2CPacket.Entry receivedEntry, | ||
PlayerListEntry currentEntry, | ||
CallbackInfo ci | ||
) { | ||
PlayerListEvent.EVENT.invoker().accept(currentEntry); | ||
} | ||
|
||
} |
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
96 changes: 96 additions & 0 deletions
96
src/main/java/codes/cookies/mod/features/mining/shafts/MineshaftAnnouncements.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,96 @@ | ||
package codes.cookies.mod.features.mining.shafts; | ||
|
||
import codes.cookies.mod.config.categories.mining.shaft.ShaftConfig; | ||
import codes.cookies.mod.events.PlayerListWidgetEvent; | ||
import codes.cookies.mod.events.mining.MineshaftEvents; | ||
import codes.cookies.mod.repository.constants.mining.ShaftCorpseLocations; | ||
import codes.cookies.mod.utils.cookies.CookiesUtils; | ||
import codes.cookies.mod.utils.skyblock.PartyUtils; | ||
import codes.cookies.mod.utils.skyblock.tab.widgets.PlayerListWidgets; | ||
import codes.cookies.mod.utils.skyblock.tab.widgets.corpse.CorpseEntry; | ||
import codes.cookies.mod.utils.skyblock.tab.widgets.corpse.CorpseType; | ||
import codes.cookies.mod.utils.skyblock.tab.widgets.corpse.FrozenCorpseWidget; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Sends a message upon joining a mineshaft, that informs about type and corpses in the shaft. | ||
*/ | ||
public class MineshaftAnnouncements { | ||
|
||
private static boolean hasSendMessage = false; | ||
private static ShaftCorpseLocations.ShaftLocations shaftType; | ||
private static long lastShaftFoundAt = -1; | ||
|
||
public static void register() { | ||
MineshaftEvents.JOIN_SHAFT.register(MineshaftAnnouncements::join); | ||
MineshaftEvents.LEAVE.register(MineshaftAnnouncements::leave); | ||
MineshaftEvents.FIND.register(MineshaftAnnouncements::find); | ||
PlayerListWidgetEvent.register(PlayerListWidgets.CORPSE, MineshaftAnnouncements::corpseWidgetUpdate); | ||
} | ||
|
||
private static void find() { | ||
lastShaftFoundAt = System.currentTimeMillis(); | ||
PartyUtils.request(); | ||
} | ||
|
||
private static void join(ShaftCorpseLocations.ShaftLocations shaftLocations) { | ||
if (lastShaftFoundAt + 60 * 1000 < System.currentTimeMillis()) { | ||
return; | ||
} | ||
shaftType = shaftLocations; | ||
hasSendMessage = false; | ||
} | ||
|
||
private static void corpseWidgetUpdate(FrozenCorpseWidget widget) { | ||
if (hasSendMessage || shaftType == null) { | ||
return; | ||
} | ||
|
||
final Map<CorpseType, List<CorpseEntry>> collect = widget.getCorpses() | ||
.stream() | ||
.sorted(Comparator.comparingInt(entry -> entry.corpseType().ordinal())) | ||
.collect(Collectors.groupingBy(CorpseEntry::corpseType)); | ||
|
||
final StringBuilder stringBuilder = new StringBuilder(); | ||
stringBuilder.append("Mineshaft entered | "); | ||
stringBuilder.append(shaftType.id()).append(" | "); | ||
|
||
final List<CorpseEntry> unknown = collect.remove(CorpseType.UNKNOWN); | ||
|
||
if (collect.containsKey(CorpseType.VANGUARD)) { | ||
stringBuilder.append("vang "); | ||
} else { | ||
collect.forEach((type, list) -> stringBuilder.append(list.size()) | ||
.append(type.name().charAt(0)) | ||
.append(" ")); | ||
} | ||
|
||
if (unknown != null) { | ||
stringBuilder.append("| ").append(unknown.size()).append(" Unknown"); | ||
} | ||
|
||
switch (ShaftConfig.getConfig().announcementType.getValue()) { | ||
case CHAT -> CookiesUtils.sendWhiteMessage(stringBuilder.toString()); | ||
case PARTY -> { | ||
if (PartyUtils.isInParty()) { | ||
CookiesUtils.sendInformation("Sending message into party chat!"); | ||
CookiesUtils.sendCommand("pc " + stringBuilder); | ||
} else { | ||
CookiesUtils.sendFailedMessage("Not in a party!"); | ||
CookiesUtils.sendWhiteMessage(stringBuilder.toString()); | ||
} | ||
} | ||
} | ||
hasSendMessage = true; | ||
} | ||
|
||
private static void leave() { | ||
hasSendMessage = true; | ||
shaftType = null; | ||
} | ||
|
||
} |
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
Oops, something went wrong.