Merge pull request 'added color jump' (#12) from develop-colorjump into develop
Reviewed-on: #12 Reviewed-by: Lars Neuhaus <larslukasneuhaus@gmx.de>
This commit was merged in pull request #12.
This commit is contained in:
@@ -9,6 +9,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle.Block
|
|||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace.BlockBreakRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace.BlockBreakRaceFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace.BoatRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace.BoatRaceFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.colorJump.ColorJumpFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace.ElytraRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace.ElytraRaceFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge.FastbridgeFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge.FastbridgeFactory;
|
||||||
@@ -50,7 +51,8 @@ public enum GameList {
|
|||||||
SPACESNAKE(new SpaceSnakeFactory(), GameType.PVP),
|
SPACESNAKE(new SpaceSnakeFactory(), GameType.PVP),
|
||||||
BOATRACE(new BoatRaceFactory(), GameType.OTHER),
|
BOATRACE(new BoatRaceFactory(), GameType.OTHER),
|
||||||
PILLARS(new PillarsFactory(), GameType.PROTOTYPE),
|
PILLARS(new PillarsFactory(), GameType.PROTOTYPE),
|
||||||
BLOCKBATTLE(new BlockBattleFactory(), GameType.PROTOTYPE);
|
BLOCKBATTLE(new BlockBattleFactory(), GameType.PVP),
|
||||||
|
COLORJUMP(new ColorJumpFactory(), GameType.PROTOTYPE);
|
||||||
|
|
||||||
private final GameFactory factory;
|
private final GameFactory factory;
|
||||||
private final GameType type;
|
private final GameType type;
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.colorJump;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
|
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||||
|
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||||
|
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.entity.GameMode;
|
||||||
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
|
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
|
import net.minestom.server.item.ItemStack;
|
||||||
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
public class ColorJump extends StatelessGame {
|
||||||
|
private final List<Block> blocks = List.of(
|
||||||
|
Block.RED_CONCRETE,
|
||||||
|
Block.ORANGE_CONCRETE,
|
||||||
|
Block.YELLOW_CONCRETE,
|
||||||
|
Block.LIME_CONCRETE,
|
||||||
|
Block.LIGHT_BLUE_CONCRETE,
|
||||||
|
Block.BLUE_CONCRETE,
|
||||||
|
Block.PURPLE_CONCRETE,
|
||||||
|
Block.PINK_CONCRETE
|
||||||
|
);
|
||||||
|
private Block currentBlock;
|
||||||
|
private double roundTime = 5;
|
||||||
|
|
||||||
|
public ColorJump() {
|
||||||
|
super(Dimension.THE_END.key, "ColorJump", new LastWinsScore());
|
||||||
|
this.getScore().setIgnoreLastPlayers(1);
|
||||||
|
|
||||||
|
this.setGenerator(new CircularPlateTerrainGenerator(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
|
this.generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
this.nextRound();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextRound() {
|
||||||
|
this.generate();
|
||||||
|
|
||||||
|
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
||||||
|
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
|
||||||
|
this.getPlayers().forEach(player -> {
|
||||||
|
player.getInventory().clear();
|
||||||
|
for(int i = 0; i < 9; i++) {
|
||||||
|
player.getInventory().setItemStack(i, item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var scheduler = MinecraftServer.getSchedulerManager();
|
||||||
|
TaskSchedule stop = TaskSchedule.stop();
|
||||||
|
|
||||||
|
scheduler.scheduleTask(() -> {
|
||||||
|
this.destroyAllExcept(this.currentBlock);
|
||||||
|
|
||||||
|
scheduler.scheduleTask(() -> {
|
||||||
|
this.nextRound();
|
||||||
|
return stop;
|
||||||
|
}, TaskSchedule.seconds(3));
|
||||||
|
return stop;
|
||||||
|
}, TaskSchedule.seconds((long) this.roundTime));
|
||||||
|
if(this.roundTime > 0.5)
|
||||||
|
this.roundTime = this.roundTime * 0.9;
|
||||||
|
|
||||||
|
long secondsLeft = Math.max(0, (long) this.roundTime);
|
||||||
|
|
||||||
|
for (int i = Math.min(3, (int) secondsLeft); i >= 0; i--) {
|
||||||
|
int level = i;
|
||||||
|
scheduler.scheduleTask(() -> {
|
||||||
|
this.getPlayers().forEach(player -> player.setLevel(level));
|
||||||
|
return stop;
|
||||||
|
}, TaskSchedule.seconds(secondsLeft-i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generate() {
|
||||||
|
int y = 30;
|
||||||
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
|
||||||
|
for (int x = -20; x <= 21; x += 2) {
|
||||||
|
for (int z = -11; z <= 10; z += 2) {
|
||||||
|
Block randomBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
||||||
|
|
||||||
|
for (int dx = 0; dx < 2; dx++) {
|
||||||
|
for (int dz = 0; dz < 2; dz++) {
|
||||||
|
batch.setBlock(x + dx, y, z + dz, randomBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyAllExcept(Block block) {
|
||||||
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
int y = 30;
|
||||||
|
|
||||||
|
for (int x = -20; x <= 21; x++) {
|
||||||
|
for(int z = -11; z <= 10; z++) {
|
||||||
|
Pos blockPos = new Pos(x, y, z);
|
||||||
|
if(this.getBlock(blockPos) != block)
|
||||||
|
batch.setBlock(blockPos, Block.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pos getSpawn() {
|
||||||
|
return new Pos(0, 31, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
|
var player = playerMoveEvent.getPlayer();
|
||||||
|
|
||||||
|
if(playerMoveEvent.getNewPosition().y() >= 29)
|
||||||
|
return;
|
||||||
|
player.teleport(this.getSpawn());
|
||||||
|
if(this.isRunning) {
|
||||||
|
this.getScore().insertResult(player);
|
||||||
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.colorJump;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||||
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ColorJumpFactory implements GameFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TranslatedComponent name() {
|
||||||
|
return TranslatedComponent.byId("game_ColorJump#name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material symbol() {
|
||||||
|
return Material.PINK_CONCRETE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TranslatedComponent description() {
|
||||||
|
return TranslatedComponent.byId("game_ColorJump#description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||||
|
return new ColorJump().setParent(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -183,3 +183,7 @@ ns:game_BlockBattle#;;
|
|||||||
name;Block Battle;Block Kampf
|
name;Block Battle;Block Kampf
|
||||||
description;The team that fills the center with their color first wins!;Das Team, welches als erstes die Mitte mit seiner Farbe gefüllt hat, gewinnt!
|
description;The team that fills the center with their color first wins!;Das Team, welches als erstes die Mitte mit seiner Farbe gefüllt hat, gewinnt!
|
||||||
itemCount;Block Count;Block Anzahl
|
itemCount;Block Count;Block Anzahl
|
||||||
|
;;
|
||||||
|
ns:game_ColorJump#;;
|
||||||
|
name;Color Jump;Farbsprung
|
||||||
|
description;Jump on the right color!;Springe auf die richtige Farbe!
|
||||||
|
Reference in New Issue
Block a user