added color jump #12
@@ -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.boatRace.BoatRaceFactory;
|
||||
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.elytraRace.ElytraRaceFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge.FastbridgeFactory;
|
||||
@@ -50,7 +51,8 @@ public enum GameList {
|
||||
SPACESNAKE(new SpaceSnakeFactory(), GameType.PVP),
|
||||
BOATRACE(new BoatRaceFactory(), GameType.OTHER),
|
||||
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 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.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.onStart();
|
||||
return stop;
|
||||
|
jannis marked this conversation as resolved
Outdated
|
||||
}, TaskSchedule.seconds(3));
|
||||
return stop;
|
||||
}, TaskSchedule.seconds((long) this.roundTime));
|
||||
if(this.roundTime > 0.5)
|
||||
this.roundTime = this.roundTime *0.9;
|
||||
|
||||
|
jannis marked this conversation as resolved
Outdated
Pupsi
commented
Leerzeichen hinter dem * Leerzeichen hinter dem *
|
||||
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(this.isBeforeBeginning && playerMoveEvent.getNewPosition().y() < 29)
|
||||
player.teleport(this.getSpawn());
|
||||
|
jannis marked this conversation as resolved
Outdated
Pupsi
commented
early return: early return:
if(playerMoveEvent.getNewPosition().y() >= 29) return;
player.teleport(this.getSpawn());
if(this.isRunning) ......
|
||||
|
||||
if(this.isRunning && playerMoveEvent.getNewPosition().y() < 29) {
|
||||
this.getScore().insertResult(player);
|
||||
player.teleport(this.getSpawn());
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user
this.nextRound()