Skip to content

Commit

Permalink
basic boss bar / progression, ide run names, use spawn from datapack
Browse files Browse the repository at this point in the history
  • Loading branch information
Rushmead committed Oct 26, 2024
1 parent 63fed06 commit 39d6331
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ neoForge {

configureEach {
logLevel = org.slf4j.event.Level.WARN
ideName = project.name + " - " + ideName.get()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ neo_version=21.0.167
parchment_version=2024.06.23
registrate_version=1.3.0+50
ltlib_version=[1.4.5,1.5)
ltextras_version=1.3.0-release+11
ltextras_version=1.3.0-release+15

org.gradle.jvmargs=-Xmx1G
org.gradle.daemon=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.lovetropics.minigames.LoveTropics;
import com.lovetropics.minigames.client.CustomItemRenderers;
import com.lovetropics.minigames.common.content.river_race.behaviour.StartMicrogamesAction;
import com.lovetropics.minigames.common.content.river_race.behaviour.RiverRaceMerchantBehavior;
import com.lovetropics.minigames.common.content.river_race.behaviour.TriviaBehaviour;
import com.lovetropics.minigames.common.content.river_race.behaviour.VictoryPointsBehavior;
import com.lovetropics.minigames.common.content.river_race.behaviour.*;
import com.lovetropics.minigames.common.content.river_race.block.TriviaBlock;
import com.lovetropics.minigames.common.content.river_race.block.TriviaBlockEntity;
import com.lovetropics.minigames.common.content.river_race.block.TriviaChestBlock;
Expand All @@ -26,6 +23,7 @@ public class RiverRace {
public static final GameBehaviorEntry<StartMicrogamesAction> START_MICROGAMES_ACTION = REGISTRATE.object("start_microgames").behavior(StartMicrogamesAction.CODEC).register();
public static final GameBehaviorEntry<VictoryPointsBehavior> VICTORY_POINTS_BEHAVIOR = REGISTRATE.object("victory_points").behavior(VictoryPointsBehavior.CODEC).register();
public static final GameBehaviorEntry<RiverRaceMerchantBehavior> RIVER_RACE_MERCHANT_BEHAVIOR = REGISTRATE.object("river_race_merchant").behavior(RiverRaceMerchantBehavior.CODEC).register();
public static final GameBehaviorEntry<ProgressBehaviour> RIVER_RACE_PROGRESS_BEHAVIOUR = REGISTRATE.object("river_race_progress").behavior(ProgressBehaviour.CODEC).register();

public static final BlockEntry<TriviaBlock.GateTriviaBlock> TRIVIA_GATE = REGISTRATE
.block("trivia_gate", TriviaBlock.GateTriviaBlock::new)
Expand Down
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;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public TriviaBehaviour(List<TriviaZone> zones, int questionLockout) {

@Override
public void register(IGamePhase game, EventRegistrar events) throws GameException {
BlockBox spawnRegion = game.mapRegions().getOrThrow("spawn");
events.listen(GamePlayerEvents.SPAWN, (playerId, spawn, role) -> {
BlockPos floorPos = spawnRegion.sample(game.level().getRandom());
spawn.teleportTo(game.level(), floorPos.above());
});
events.listen(GamePhaseEvents.TICK, () -> {
scheduler.tick();
Set<Long> longs = lockedOutTriviaBlocks.keySet();
Expand Down

0 comments on commit 39d6331

Please sign in to comment.