diff --git a/src/main/java/com/lovetropics/minigames/common/content/river_race/RiverRace.java b/src/main/java/com/lovetropics/minigames/common/content/river_race/RiverRace.java index db722ae7..de8d2297 100644 --- a/src/main/java/com/lovetropics/minigames/common/content/river_race/RiverRace.java +++ b/src/main/java/com/lovetropics/minigames/common/content/river_race/RiverRace.java @@ -2,8 +2,7 @@ import com.lovetropics.minigames.LoveTropics; import com.lovetropics.minigames.client.CustomItemRenderers; -import com.lovetropics.minigames.client.render.block.TriviaChestRenderer; -import com.lovetropics.minigames.common.content.river_race.behaviour.MicrogamesBehaviour; +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; @@ -18,15 +17,12 @@ import com.tterrag.registrate.util.entry.BlockEntry; import net.minecraft.core.registries.Registries; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; -import net.minecraft.world.level.material.MapColor; public class RiverRace { private static final LoveTropicsRegistrate REGISTRATE = LoveTropics.registrate(); public static final GameBehaviorEntry TRIVIA_BEHAVIOUR = REGISTRATE.object("trivia").behavior(TriviaBehaviour.CODEC).register(); - public static final GameBehaviorEntry MICROGAMES_BEHAVIOUR = REGISTRATE.object("microgames").behavior(MicrogamesBehaviour.CODEC).register(); + public static final GameBehaviorEntry START_MICROGAMES_ACTION = REGISTRATE.object("start_microgames").behavior(StartMicrogamesAction.CODEC).register(); public static final GameBehaviorEntry VICTORY_POINTS_BEHAVIOR = REGISTRATE.object("victory_points").behavior(VictoryPointsBehavior.CODEC).register(); public static final GameBehaviorEntry RIVER_RACE_MERCHANT_BEHAVIOR = REGISTRATE.object("river_race_merchant").behavior(RiverRaceMerchantBehavior.CODEC).register(); diff --git a/src/main/java/com/lovetropics/minigames/common/content/river_race/behaviour/MicrogamesBehaviour.java b/src/main/java/com/lovetropics/minigames/common/content/river_race/behaviour/StartMicrogamesAction.java similarity index 56% rename from src/main/java/com/lovetropics/minigames/common/content/river_race/behaviour/MicrogamesBehaviour.java rename to src/main/java/com/lovetropics/minigames/common/content/river_race/behaviour/StartMicrogamesAction.java index 30779d53..75fdfe26 100644 --- a/src/main/java/com/lovetropics/minigames/common/content/river_race/behaviour/MicrogamesBehaviour.java +++ b/src/main/java/com/lovetropics/minigames/common/content/river_race/behaviour/StartMicrogamesAction.java @@ -1,41 +1,34 @@ package com.lovetropics.minigames.common.content.river_race.behaviour; import com.lovetropics.minigames.common.core.game.GameException; -import com.lovetropics.minigames.common.core.game.GamePhaseType; 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.behavior.event.GamePlayerEvents; -import com.lovetropics.minigames.common.core.game.config.GameConfig; -import com.lovetropics.minigames.common.core.game.config.GameConfigs; -import com.lovetropics.minigames.common.core.game.impl.GamePhase; +import com.lovetropics.minigames.common.core.game.behavior.event.GameActionEvents; import com.lovetropics.minigames.common.core.game.impl.MultiGamePhase; import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.network.chat.PlayerChatMessage; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.ExtraCodecs; import java.util.ArrayList; import java.util.Collections; import java.util.List; -public record MicrogamesBehaviour(List gameConfigs, int gamesPerRound) implements IGameBehavior { +public record StartMicrogamesAction(List gameConfigs, int gamesPerRound) implements IGameBehavior { - public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group( - ExtraCodecs.nonEmptyList(ResourceLocation.CODEC.listOf()).fieldOf("games").forGetter(MicrogamesBehaviour::gameConfigs), + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group( + ExtraCodecs.nonEmptyList(ResourceLocation.CODEC.listOf()).fieldOf("games").forGetter(StartMicrogamesAction::gameConfigs), Codec.INT.optionalFieldOf("games_per_round", 1).forGetter(c -> c.gamesPerRound) - ).apply(i, MicrogamesBehaviour::new)); + ).apply(i, StartMicrogamesAction::new)); @Override public void register(IGamePhase game, EventRegistrar events) throws GameException { - events.listen(GamePlayerEvents.CHAT, (ServerPlayer player, PlayerChatMessage message) -> { + events.listen(GameActionEvents.APPLY, context -> { queueMicrogames(game); - //startMicrogame(game); startQueuedMicrogame(game); - return false; + return true; }); } @@ -54,13 +47,4 @@ public void startQueuedMicrogame(final IGamePhase game) { multiGamePhase.startNextQueuedMicrogame(true); } } - - public void startMicrogame(IGamePhase game, String gameName){ - if (game instanceof MultiGamePhase multiGamePhase) { - GameConfig gameConfig = GameConfigs.REGISTRY.get(ResourceLocation.parse(gameName)); - GamePhase.create(multiGamePhase.game(), gameConfig.getPlayingPhase(), GamePhaseType.PLAYING).thenAccept((result) -> { - multiGamePhase.setActivePhase(result.getOk(), true); - }); - } - } }