-
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.
Data-drive weather change notifications
- Loading branch information
Showing
3 changed files
with
53 additions
and
82 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
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
41 changes: 41 additions & 0 deletions
41
...vetropics/minigames/common/core/game/behavior/instances/trigger/WeatherChangeTrigger.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,41 @@ | ||
package com.lovetropics.minigames.common.core.game.behavior.instances.trigger; | ||
|
||
import com.lovetropics.minigames.common.core.game.IGamePhase; | ||
import com.lovetropics.minigames.common.core.game.behavior.IGameBehavior; | ||
import com.lovetropics.minigames.common.core.game.behavior.action.GameActionContext; | ||
import com.lovetropics.minigames.common.core.game.behavior.action.GameActionList; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.EventRegistrar; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.GameWorldEvents; | ||
import com.lovetropics.minigames.common.core.game.weather.WeatherEventType; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import java.util.Map; | ||
|
||
public class WeatherChangeTrigger implements IGameBehavior { | ||
public static final Codec<WeatherChangeTrigger> CODEC = RecordCodecBuilder.create(i -> i.group( | ||
Codec.unboundedMap(WeatherEventType.CODEC, GameActionList.CODEC).fieldOf("events").forGetter(c -> c.eventActions) | ||
).apply(i, WeatherChangeTrigger::new)); | ||
|
||
private final Map<WeatherEventType, GameActionList> eventActions; | ||
|
||
public WeatherChangeTrigger(Map<WeatherEventType, GameActionList> eventActions) { | ||
this.eventActions = eventActions; | ||
} | ||
|
||
@Override | ||
public void register(IGamePhase game, EventRegistrar events) { | ||
for (GameActionList actions : eventActions.values()) { | ||
actions.register(game, events); | ||
} | ||
|
||
events.listen(GameWorldEvents.SET_WEATHER, (lastEvent, event) -> { | ||
if (event != null) { | ||
GameActionList actions = eventActions.get(event.getType()); | ||
if (actions != null) { | ||
actions.apply(game, GameActionContext.EMPTY); | ||
} | ||
} | ||
}); | ||
} | ||
} |