Skip to content

Commit

Permalink
feat: Add a time event
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-art committed Feb 22, 2024
1 parent 66d7631 commit 41a9f0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Event(StrEnum):
ITEM_SMELTED = "item_smelted"
MOB_KILLED = "mob_killed"
DIMENSION_CHANGED = "dimension_changed"
TIME_CHANGED = "time_changed"
PLAYER_CHAT = "player_chat"
PLAYER_ATE = "player_ate"
RIDING = "riding"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.advancements.DisplayInfo;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -56,6 +55,7 @@ public class EventSubscriber {
private static Set<String> lastInventory = null;
private static boolean isRiding = false;
private static boolean isFishing = false;
private static String timeState = "";

public enum Event {
ITEM_CRAFTED("item_crafted"),
Expand All @@ -68,6 +68,7 @@ public enum Event {
ITEM_SMELTED("item_smelted"),
MOB_KILLED("mob_killed"),
DIMENSION_CHANGED("dimension_changed"),
TIME_CHANGED("time_changed"),
PLAYER_CHAT("player_chat"),
PLAYER_ATE("player_ate"),
RIDING("riding"),
Expand Down Expand Up @@ -173,6 +174,19 @@ public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
} else {
isRiding = false;
}

// Custom time event
long time = event.player.level().dayTime();
if (0 == time && !timeState.equals("day")) {
wsClient.sendEvent(Event.TIME_CHANGED.getValue(), "O sol nasceu no minecraft");
timeState = "day";
} else if (12000 == time && !timeState.equals("sunset")) {
wsClient.sendEvent(Event.TIME_CHANGED.getValue(), "O sol está se pondo no minecraft");
timeState = "sunset";
} else if (13000 == time && !timeState.equals("night")) {
wsClient.sendEvent(Event.TIME_CHANGED.getValue(), "O sol se pôs no minecraft e está escuro");
timeState = "night";
}
}

@SubscribeEvent
Expand Down

0 comments on commit 41a9f0c

Please sign in to comment.