removed sidebar, added names for items

This commit is contained in:
2025-10-04 18:32:27 +02:00
parent 61aa7543be
commit 75314748da
2 changed files with 14 additions and 44 deletions

View File

@@ -6,6 +6,7 @@ import eu.mhsl.minenet.minigames.score.PointsWinScore;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
@@ -18,7 +19,6 @@ import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.network.packet.server.play.ParticlePacket;
import net.minestom.server.particle.Particle;
import net.minestom.server.scoreboard.Sidebar;
import net.minestom.server.sound.SoundEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -30,18 +30,15 @@ class TurtleGame extends StatelessGame {
private final int radius;
private final Map<Player, EntityCreature> turtlePlayerMap = new WeakHashMap<>();
private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
private final Map<Player, Sidebar> sidebarMap = new HashMap<>();
private final ArrayList<Entity> snacks = new ArrayList<>();
private final ArrayList<Entity> bombs = new ArrayList<>();
private final Block snackBlock = Block.SUNFLOWER.withProperty("half", "upper");
private double speed;
private final double maxSpeedIncrease;
public TurtleGame(int radius, int startSpeed) {
super(Dimension.OVERWORLD.key, "Turtle Game", new PointsWinScore());
this.radius = radius;
this.speed = startSpeed;
this.maxSpeedIncrease = (double) this.radius / 4;
this.eventNode()
.addListener(PlayerTickEvent.class, this::onPlayerTick);
@@ -84,7 +81,10 @@ class TurtleGame extends StatelessGame {
.forEach(snack -> {
this.eat(p, snack);
this.generateNewSnack();
if(this.scoreMap.values().stream().mapToInt(Integer::intValue).sum() % 4 == 0) this.generateNewBomb();
if(this.scoreMap.values().stream().mapToInt(Integer::intValue).sum() % 4 == 0) {
this.generateNewBomb();
this.speed += 0.4;
}
});
this.bombs.stream()
.filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox()))
@@ -92,10 +92,7 @@ class TurtleGame extends StatelessGame {
.forEach(bomb -> {
this.explode(p, bomb);
this.generateNewBomb(2);
this.speed += this.maxSpeedIncrease / this.getPlayers().size();
this.sidebarMap.values().forEach(sidebar -> sidebar.updateLineContent("1",
Component.text("Speed: ").color(NamedTextColor.BLUE)
.append(Component.text(String.format("%3d", (int) this.speed)).color(NamedTextColor.RED))));
this.speed += 0.3;
});
}
}
@@ -108,9 +105,7 @@ class TurtleGame extends StatelessGame {
this.snacks.remove(snack);
snack.remove();
this.scoreMap.put(p, this.scoreMap.get(p) + 1);
this.sidebarMap.get(p).updateLineContent("0",
Component.text("Score: ").color(NamedTextColor.GREEN)
.append(Component.text(String.format("%3d", this.scoreMap.get(p))).color(NamedTextColor.RED)));
p.setLevel(this.scoreMap.get(p));
}
protected void explode(Player p, Entity bomb) {
@@ -126,9 +121,6 @@ class TurtleGame extends StatelessGame {
this.getScore().insertResult(p, this.scoreMap.get(p));
this.bombs.remove(bomb);
bomb.remove();
this.sidebarMap.values().forEach(sidebar -> sidebar.updateLineContent("2",
Component.text("Players: ").color(NamedTextColor.AQUA)
.append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED))));
}
@Override
@@ -138,33 +130,7 @@ class TurtleGame extends StatelessGame {
this.turtlePlayerMap.put(p, turtle);
}
this.scoreMap.putIfAbsent(p, 0);
this.sidebarMap.putIfAbsent(p, new Sidebar(Component.text("Info:").color(NamedTextColor.GOLD)));
Sidebar sidebar = this.sidebarMap.get(p);
sidebar.createLine(new Sidebar.ScoreboardLine(
"0",
Component.text("Score: ").color(NamedTextColor.GREEN)
.append(Component.text(String.format("%3d", this.scoreMap.get(p))).color(NamedTextColor.RED)),
3,
Sidebar.NumberFormat.blank()
));
sidebar.createLine(new Sidebar.ScoreboardLine(
"1",
Component.text("Speed: ").color(NamedTextColor.BLUE)
.append(Component.text(String.format("%3d", (int) this.speed)).color(NamedTextColor.RED)),
2,
Sidebar.NumberFormat.blank()
));
sidebar.createLine(new Sidebar.ScoreboardLine(
"2",
Component.text("Players: ").color(NamedTextColor.AQUA)
.append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED)),
1,
Sidebar.NumberFormat.blank()
));
sidebar.addViewer(p);
this.sidebarMap.values().forEach(bar -> bar.updateLineContent("2",
Component.text("Players: ").color(NamedTextColor.AQUA)
.append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED))));
p.setLevel(this.scoreMap.get(p));
EntityCreature turtle = this.turtlePlayerMap.get(p);
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> {
@@ -181,7 +147,6 @@ class TurtleGame extends StatelessGame {
protected void onPlayerLeave(Player p) {
EntityCreature turtle = this.turtlePlayerMap.get(p);
turtle.remove();
this.sidebarMap.get(p).removeViewer(p);
}
@Override
@@ -205,6 +170,9 @@ class TurtleGame extends StatelessGame {
Entity snack = new Entity(EntityType.FALLING_BLOCK);
FallingBlockMeta meta = (FallingBlockMeta) snack.getEntityMeta();
meta.setBlock(this.snackBlock.withProperty("half", "upper"));
meta.setCustomName(Component.text("Snack").color(NamedTextColor.WHITE));
meta.setCustomNameVisible(true);
meta.setHasGlowingEffect(true);
snack.setInstance(this);
Pos spawnPosition = this.newSpawnPosition(snack);
if(spawnPosition == null) {
@@ -225,6 +193,8 @@ class TurtleGame extends StatelessGame {
Entity bomb = new Entity(EntityType.FALLING_BLOCK);
FallingBlockMeta meta = (FallingBlockMeta) bomb.getEntityMeta();
meta.setBlock(Block.TNT);
meta.setCustomName(Component.text("Bomb").color(NamedTextColor.RED).decorate(TextDecoration.BOLD));
meta.setCustomNameVisible(true);
bomb.setInstance(this);
Pos spawnPosition = this.newSpawnPosition(bomb, 2);
if(spawnPosition == null) {

View File

@@ -27,7 +27,7 @@ public class TurtleGameFactory implements GameFactory {
public ConfigManager configuration() {
return new ConfigManager()
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 10, 20, 30, 40))
.addOption(new NumericOption("startSpeed", Material.LEATHER_BOOTS, TranslatedComponent.byId("game_TurtleGame#startSpeed"), 2, 4, 6, 8));
.addOption(new NumericOption("startSpeed", Material.LEATHER_BOOTS, TranslatedComponent.byId("game_TurtleGame#startSpeed"), 2, 4, 6, 8, 10));
}
@Override