Compare commits
9 Commits
cbec1ea7f8
...
develop-ja
| Author | SHA1 | Date | |
|---|---|---|---|
| ee7d434d7e | |||
| 410f7b4027 | |||
| e1515200ab | |||
| 27005f4fc4 | |||
| 2808393c23 | |||
| d0825695b3 | |||
| e822a5c5e2 | |||
| bf95c8dcc2 | |||
| 2f70b25e87 |
@@ -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,170 @@
|
||||
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.inventory.InventoryPreClickEvent;
|
||||
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 Block blockLastRound;
|
||||
private double roundTime = 5;
|
||||
private final double multiplierNextRoundTime = 0.9;
|
||||
|
||||
public ColorJump() {
|
||||
super(Dimension.THE_END.key, "ColorJump", new LastWinsScore());
|
||||
this.getScore().setIgnoreLastPlayers(1);
|
||||
|
||||
this.setGenerator(new CircularPlateTerrainGenerator(100));
|
||||
|
||||
this.eventNode().addListener(
|
||||
InventoryPreClickEvent.class,
|
||||
inventoryPreClickEvent -> inventoryPreClickEvent.setCancelled(true)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
this.generate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
this.nextRound();
|
||||
}
|
||||
|
||||
private void nextRound() {
|
||||
this.generate();
|
||||
do {
|
||||
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
||||
} while(this.currentBlock == this.blockLastRound);
|
||||
this.blockLastRound = this.currentBlock;
|
||||
|
||||
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(() -> {
|
||||
if(!this.isRunning) return stop;
|
||||
this.destroyAllExcept(this.currentBlock);
|
||||
|
||||
scheduler.scheduleTask(() -> {
|
||||
if(this.isRunning) this.nextRound();
|
||||
return stop;
|
||||
}, TaskSchedule.seconds(3));
|
||||
return stop;
|
||||
}, TaskSchedule.seconds((long) this.roundTime));
|
||||
this.roundTime = this.roundTime * this.multiplierNextRoundTime;
|
||||
if(this.roundTime <= 1) this.roundTime = 1;
|
||||
|
||||
long totalTicks = (long) (this.roundTime * 20);
|
||||
final long[] remainingTicks = { totalTicks };
|
||||
|
||||
scheduler.scheduleTask(() -> {
|
||||
|
||||
if (!this.isRunning)
|
||||
return stop;
|
||||
|
||||
if (remainingTicks[0] <= 0) {
|
||||
this.getPlayers().forEach(player -> {
|
||||
player.setExp(0f);
|
||||
player.setLevel(0);
|
||||
});
|
||||
return stop;
|
||||
}
|
||||
|
||||
float progress = (float) remainingTicks[0] / totalTicks;
|
||||
|
||||
this.getPlayers().forEach(player -> {
|
||||
player.setExp(progress);
|
||||
player.setLevel((int) Math.ceil(remainingTicks[0] / 20.0));
|
||||
});
|
||||
|
||||
remainingTicks[0]--;
|
||||
return TaskSchedule.tick(1);
|
||||
}, TaskSchedule.tick(1));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -182,4 +182,8 @@ description;Build yourself up with your random blocks to reach your opponents an
|
||||
ns:game_BlockBattle#;;
|
||||
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!
|
||||
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