Skip to content

Commit

Permalink
Add some more Block Party flavour
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Nov 15, 2024
1 parent 9463a4c commit c6aa575
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/generated/resources/assets/ltminigames/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
"ltminigames.minigame.biodiversity_blitz_teams": ")sɯɐǝ⟘( zʇıןᗺ ʎʇısɹǝʌıpoıᗺ",
"ltminigames.minigame.block_party": "ʎʇɹɐԀ ʞɔoןᗺ",
"ltminigames.minigame.block_party.break_in_seconds": "spuoɔǝs %s uı ʞɐǝɹᗺ",
"ltminigames.minigame.block_party.knockback_enabled": "¡ʇno ʞooן - pǝןqɐuǝ uǝǝq sɐɥ ʞɔɐqʞɔouʞ",
"ltminigames.minigame.block_party.knockback_enabled.subtitle": "pǝןqɐuǝ uǝǝq sɐɥ ʞɔɐqʞɔouʞ",
"ltminigames.minigame.block_party.knockback_enabled.title": "¡ʇno ʞooꞀ",
"ltminigames.minigame.block_party.stand_on_block": "%s uo puɐʇS",
"ltminigames.minigame.block_party_teams": "sɯɐǝ⟘ ʎʇɹɐԀ ʞɔoןᗺ",
"ltminigames.minigame.build_competition": "uoıʇıʇǝdɯoƆ pןınᗺ",
Expand Down
3 changes: 2 additions & 1 deletion src/generated/resources/assets/ltminigames/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
"ltminigames.minigame.biodiversity_blitz_teams": "Biodiversity Blitz (Teams)",
"ltminigames.minigame.block_party": "Block Party",
"ltminigames.minigame.block_party.break_in_seconds": "Break in %s seconds",
"ltminigames.minigame.block_party.knockback_enabled": "Knockback has been enabled - look out!",
"ltminigames.minigame.block_party.knockback_enabled.subtitle": "Knockback has been enabled",
"ltminigames.minigame.block_party.knockback_enabled.title": "Look out!",
"ltminigames.minigame.block_party.stand_on_block": "Stand on %s",
"ltminigames.minigame.block_party_teams": "Block Party Teams",
"ltminigames.minigame.build_competition": "Build Competition",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.lovetropics.lib.BlockBox;
import com.lovetropics.lib.codec.MoreCodecs;
import com.lovetropics.lib.entity.FireworkPalette;
import com.lovetropics.minigames.common.content.MinigameTexts;
import com.lovetropics.minigames.common.core.game.GameException;
import com.lovetropics.minigames.common.core.game.GameStopReason;
Expand All @@ -15,11 +16,6 @@
import com.lovetropics.minigames.common.core.game.behavior.event.GamePlayerEvents;
import com.lovetropics.minigames.common.core.game.player.PlayerRole;
import com.lovetropics.minigames.common.core.game.player.PlayerSet;
import com.lovetropics.minigames.common.core.game.state.statistics.PlayerKey;
import com.lovetropics.minigames.common.core.game.state.statistics.StatisticKey;
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.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
Expand All @@ -30,11 +26,12 @@
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.FastColor;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionResult;
Expand All @@ -45,10 +42,6 @@
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public final class BlockPartyBehavior implements IGameBehavior {
public static final MapCodec<BlockPartyBehavior> CODEC = RecordCodecBuilder.mapCodec(i -> i.group(
Expand Down Expand Up @@ -125,6 +118,8 @@ public void register(IGamePhase game, EventRegistrar events) {
message = MinigameTexts.PLAYER_WON.apply(winner.name()).withStyle(ChatFormatting.GREEN);
}
game.allPlayers().sendMessage(message);
game.allPlayers().playSound(SoundEvents.RESPAWN_ANCHOR_DEPLETE.value(), SoundSource.PLAYERS, 0.5f, 1.0f);
game.allPlayers().showTitle(MinigameTexts.GAME_OVER, null, 10, 40, 10);

state = new Ending(game.ticks() + SharedConstants.TICKS_PER_SECOND * 5);
});
Expand All @@ -142,8 +137,8 @@ private void spawnPlayer(SpawnBuilder spawn) {
private void onStateChange(State oldState, @Nullable State newState) {
if (hasKnockback(newState) && !hasKnockback(oldState)) {
PlayerSet allPlayers = game.allPlayers();
allPlayers.sendMessage(BlockPartyTexts.KNOCKBACK_ENABLED);
allPlayers.playSound(SoundEvents.GRASS_BREAK, SoundSource.PLAYERS, 1.0f, 1.0f);
allPlayers.showTitle(BlockPartyTexts.KNOCKBACK_ENABLED_TITLE, BlockPartyTexts.KNOCKBACK_ENABLED_SUBTITLE, 10, 40, 10);
allPlayers.playSound(SoundEvents.GLASS_BREAK, SoundSource.PLAYERS, 1.0f, 1.0f);
}
}

Expand All @@ -168,6 +163,7 @@ private void tick() {
double y = player.getY();
if (y < player.level().getMinBuildHeight() || y < floorRegion.min().getY() - 10) {
game.setPlayerRole(player, PlayerRole.SPECTATOR);
game.allPlayers().playSound(SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 1.0f, 1.0f);
game.allPlayers().sendMessage(MinigameTexts.ELIMINATED.apply(player.getDisplayName()));
}
}
Expand All @@ -183,9 +179,9 @@ CountingDown startCountingDown(int round) {
ItemStack targetStack = new ItemStack(target);
targetStack.setCount(64);

Component name = BlockPartyTexts.STAND_ON_BLOCK.apply(targetStack.getDisplayName())
.withStyle(style -> style.withBold(true).withItalic(false));
targetStack.set(DataComponents.CUSTOM_NAME, name);
Component name = BlockPartyTexts.STAND_ON_BLOCK.apply(targetStack.getHoverName())
.withStyle(style -> style.withBold(true));
targetStack.set(DataComponents.ITEM_NAME, name);

for (ServerPlayer player : game.participants()) {
player.getInventory().clearContent();
Expand All @@ -212,6 +208,8 @@ interface State {
}

final class CountingDown implements State {
private static final int FINAL_COUNTDOWN_SECONDS = 3;

private final int round;
private final long breakAt;

Expand All @@ -225,18 +223,29 @@ final class CountingDown implements State {

@Override
public State tick(IGamePhase game) {
PlayerSet players = game.allPlayers();
long time = game.ticks();

if (time % 10 == 0) {
for (ServerPlayer player : game.allPlayers()) {
long remainingTicks = breakAt - time;
Component message = BlockPartyTexts.BREAK_IN_SECONDS.apply(remainingTicks / SharedConstants.TICKS_PER_SECOND).withStyle(ChatFormatting.GOLD);
player.displayClientMessage(message, true);
}
long ticksLeft = breakAt - time;
if (ticksLeft <= 0) {
players.playSound(SoundEvents.NOTE_BLOCK_HARP.value(), SoundSource.PLAYERS, 1.0f, 2.0f);
return startInterval(round, floor);
}

if (time > breakAt) {
return startInterval(round, floor);
long secondsLeft = ticksLeft / SharedConstants.TICKS_PER_SECOND;
if (ticksLeft % 10 == 0) {
Component message = BlockPartyTexts.BREAK_IN_SECONDS.apply(secondsLeft).withStyle(ChatFormatting.GOLD);
players.sendMessage(message, true);
}

if (secondsLeft <= FINAL_COUNTDOWN_SECONDS && ticksLeft % SharedConstants.TICKS_PER_SECOND == 0) {
players.playSound(SoundEvents.NOTE_BLOCK_HARP.value(), SoundSource.PLAYERS, 1.0f, 1.0f);
int color = FastColor.ARGB32.lerp(
Mth.inverseLerp(secondsLeft, FINAL_COUNTDOWN_SECONDS, 1),
0x55ff55, 0xffaa00
);
Component title = Component.literal(".." + secondsLeft).withStyle(Style.EMPTY.withColor(color));
players.showTitle(title, 4, SharedConstants.TICKS_PER_SECOND, 4);
}

return this;
Expand Down Expand Up @@ -278,6 +287,12 @@ public State tick(IGamePhase game) {
if (game.ticks() > endAt) {
return null;
}
for (ServerPlayer player : game.participants()) {
if (!player.isSpectator() && game.random().nextInt(10) == 0) {
BlockPos fireworksPos = BlockPos.containing(player.getEyePosition()).above();
FireworkPalette.DYE_COLORS.spawn(fireworksPos, game.level());
}
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public final class BlockPartyTexts {

public static final TranslationCollector.Fun1 STAND_ON_BLOCK = KEYS.add1("stand_on_block", "Stand on %s");
public static final TranslationCollector.Fun1 BREAK_IN_SECONDS = KEYS.add1("break_in_seconds", "Break in %s seconds");
public static final Component KNOCKBACK_ENABLED = KEYS.add("knockback_enabled", "Knockback has been enabled - look out!").withStyle(ChatFormatting.RED);
public static final Component KNOCKBACK_ENABLED_TITLE = KEYS.add("knockback_enabled.title", "Look out!").withStyle(ChatFormatting.RED);
public static final Component KNOCKBACK_ENABLED_SUBTITLE = KEYS.add("knockback_enabled.subtitle", "Knockback has been enabled").withStyle(ChatFormatting.GOLD);
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ private void triggerGameOver(GameWinner winner) {

game.scheduler().runAfterSeconds(1.5f, () -> {
game.allPlayers().playSound(SoundEvents.RESPAWN_ANCHOR_DEPLETE.value(), SoundSource.PLAYERS, 0.5f, 1.0f);
game.allPlayers().showTitle(MinigameTexts.GAME_OVER, null, 10, 40, 10);

if (winner instanceof GameWinner.Team(GameTeam team)) {
for (ServerPlayer winningPlayer : teams.getPlayersForTeam(team.key())) {
Expand Down

0 comments on commit c6aa575

Please sign in to comment.