Skip to content

Commit

Permalink
Merge pull request #83 from alt-art/time-event
Browse files Browse the repository at this point in the history
Add a time event
  • Loading branch information
alt-art authored Feb 22, 2024
2 parents 66d7631 + 8cc879e commit e8b30b6
Show file tree
Hide file tree
Showing 2 changed files with 19 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 TimeState timeState = null;

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;
}


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

@SubscribeEvent
Expand Down Expand Up @@ -447,4 +461,7 @@ public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
String playerName = getPlayerName(player);
wsClient.sendEvent(Event.JOIN_WORLD.getValue(), String.format("Jogador \"%s\" entrou no mundo \"%s\"", playerName, worldName));
}
private enum TimeState {
DAY, SUNSET, NIGHT
}
}

0 comments on commit e8b30b6

Please sign in to comment.