-
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.
basic boss bar / progression, ide run names, use spawn from datapack
- Loading branch information
Showing
5 changed files
with
72 additions
and
10 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
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
68 changes: 68 additions & 0 deletions
68
...java/com/lovetropics/minigames/common/content/river_race/behaviour/ProgressBehaviour.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,68 @@ | ||
package com.lovetropics.minigames.common.content.river_race.behaviour; | ||
|
||
import com.lovetropics.minigames.common.content.river_race.event.RiverRaceEvents; | ||
import com.lovetropics.minigames.common.core.game.GameException; | ||
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.event.EventRegistrar; | ||
import com.lovetropics.minigames.common.core.game.state.team.GameTeam; | ||
import com.lovetropics.minigames.common.core.game.state.team.GameTeamKey; | ||
import com.lovetropics.minigames.common.core.game.state.team.TeamState; | ||
import com.lovetropics.minigames.common.core.game.util.GameBossBar; | ||
import com.lovetropics.minigames.common.core.game.util.GlobalGameWidgets; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.network.chat.CommonComponents; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.util.ExtraCodecs; | ||
import net.minecraft.world.BossEvent; | ||
import net.minecraft.world.item.DyeColor; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ProgressBehaviour implements IGameBehavior { | ||
public static final MapCodec<ProgressBehaviour> CODEC = RecordCodecBuilder.mapCodec(i -> i.group( | ||
Codec.INT.optionalFieldOf("max_points", 1).forGetter(c -> c.maxVictoryPoints) | ||
).apply(i, ProgressBehaviour::new)); | ||
private final int maxVictoryPoints; | ||
private final Map<GameTeamKey, GameBossBar> teamBars = new HashMap<>(); | ||
|
||
public ProgressBehaviour(int maxVictoryPoints) { | ||
this.maxVictoryPoints = maxVictoryPoints; | ||
} | ||
|
||
@Override | ||
public void register(IGamePhase game, EventRegistrar events) throws GameException { | ||
GlobalGameWidgets widgets = GlobalGameWidgets.registerTo(game, events); | ||
TeamState teams = game.instanceState().getOrThrow(TeamState.KEY); | ||
for (GameTeamKey teamKey : teams.getTeamKeys()) { | ||
GameTeam teamByKey = teams.getTeamByKey(teamKey); | ||
if(teamByKey == null){ | ||
continue; | ||
} | ||
GameBossBar bossBar = widgets.openBossBar(teamByKey.config().styledName(), getTeamColour(teamByKey.config().dye()), BossEvent.BossBarOverlay.NOTCHED_20); | ||
bossBar.setProgress(0); | ||
teamBars.put(teamKey, bossBar); | ||
} | ||
events.listen(RiverRaceEvents.VICTORY_POINTS_CHANGED, (team, value, lastValue) -> { | ||
calculateTeamProgress(team, value); | ||
}); | ||
} | ||
|
||
public void calculateTeamProgress(GameTeamKey team, int victoryPoints){ | ||
GameBossBar gameBossBar = teamBars.get(team); | ||
if(gameBossBar != null){ | ||
gameBossBar.setProgress((float) victoryPoints / maxVictoryPoints); | ||
} | ||
} | ||
|
||
private BossEvent.BossBarColor getTeamColour(DyeColor dyeColor){ | ||
return switch (dyeColor){ | ||
case BLUE -> BossEvent.BossBarColor.BLUE; | ||
case RED -> BossEvent.BossBarColor.RED; | ||
default -> BossEvent.BossBarColor.WHITE; | ||
}; | ||
} | ||
} |
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