added scheduled task for anvil run
This commit is contained in:
parent
40f02449d9
commit
c9ef7197cc
@ -23,6 +23,7 @@ public class StatelessGame extends Game {
|
||||
|
||||
private int timeLimit = 0;
|
||||
private int timePlayed = 0;
|
||||
|
||||
public StatelessGame(DynamicRegistry.Key<DimensionType> dimensionType, String gameName, Score score) {
|
||||
super(dimensionType);
|
||||
this.score = score;
|
||||
|
@ -5,6 +5,7 @@ import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
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.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
@ -13,6 +14,8 @@ import net.minestom.server.event.entity.EntityTickEvent;
|
||||
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.timer.Scheduler;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -23,11 +26,13 @@ class AnvilRun extends StatelessGame {
|
||||
|
||||
final int spawnHeight = 30;
|
||||
final int radius;
|
||||
final List<Entity> anvils = new ArrayList<>();
|
||||
final int speed;
|
||||
final List<Pos> anvilSpawnPositions = new ArrayList<>();
|
||||
|
||||
public AnvilRun(int radius, int pvpEnabled) {
|
||||
public AnvilRun(int radius, int speed) {
|
||||
super(Dimension.THE_END.key, "Anvil Run", new LastWinsScore());
|
||||
this.radius = radius;
|
||||
this.speed = speed;
|
||||
this.setGenerator(new CircularPlateTerrainGenerator(radius));
|
||||
}
|
||||
|
||||
@ -40,12 +45,8 @@ class AnvilRun extends StatelessGame {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
|
||||
int height = super.rnd.nextInt(100, 500);
|
||||
Entity anvil = new Entity(EntityType.FALLING_BLOCK);
|
||||
((FallingBlockMeta) anvil.getEntityMeta()).setBlock(Block.ANVIL);
|
||||
anvil.setNoGravity(true);
|
||||
anvil.setInstance(this, new Pos(x+0.5, height, z+0.5));
|
||||
|
||||
anvils.add(anvil);
|
||||
anvilSpawnPositions.add(new Pos(x+0.5, height, z+0.5));
|
||||
|
||||
batch.setBlock(x, spawnHeight-1, z, Block.SNOW_BLOCK);
|
||||
}
|
||||
@ -54,11 +55,25 @@ class AnvilRun extends StatelessGame {
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
protected void spawnAnvil(Pos spawnPosition) {
|
||||
Entity anvil = new Entity(EntityType.FALLING_BLOCK);
|
||||
((FallingBlockMeta) anvil.getEntityMeta()).setBlock(Block.ANVIL);
|
||||
anvil.setInstance(this, spawnPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
anvils.forEach(anvil -> anvil.setNoGravity(false));
|
||||
Scheduler scheduler = MinecraftServer.getSchedulerManager();
|
||||
scheduler.submitTask(() -> {
|
||||
if(anvilSpawnPositions.isEmpty()) return TaskSchedule.stop();
|
||||
for(int i = 0; i < speed; i++) {
|
||||
Pos position = anvilSpawnPositions.remove(super.rnd.nextInt(0, anvilSpawnPositions.size()-1));
|
||||
spawnAnvil(position);
|
||||
}
|
||||
return TaskSchedule.seconds(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,13 +26,12 @@ public class AnvilRunFactory implements GameFactory {
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 5, 10, 15, 20, 25, 30))
|
||||
.addOption(new NumericOption("pvpEnabled", Material.STICK, TranslatedComponent.byId("game_Deathcube#optionPvpEnabled"), 1, 0));
|
||||
|
||||
.addOption(new NumericOption("speed", Material.STICK, TranslatedComponent.byId("game_Deathcube#speed"), 10, 25, 50, 100, 250, 500));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new AnvilRun(configuration.get("radius").getAsInt(), configuration.get("pvpEnabled").getAsInt()).setParent(parent);
|
||||
return new AnvilRun(configuration.get("radius").getAsInt(), configuration.get("speed").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ class Deathcube extends StatelessGame {
|
||||
this.radius = radius;
|
||||
this.height = height + 49;
|
||||
this.percentage = percentage;
|
||||
this.setGenerator(new CircularPlateTerrainGenerator(radius+10).setPlateHeight(50).setGenerateBorders(true));
|
||||
this.setGenerator(new CircularPlateTerrainGenerator(radius+10).setPlateHeight(50));
|
||||
|
||||
// if(pvpEnabled == 1) eventNode().addChild( // TODO update
|
||||
// PvPConfig.emptyBuilder()
|
||||
@ -57,12 +57,20 @@ class Deathcube extends StatelessGame {
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
super.onPlayerMove(playerMoveEvent);
|
||||
if(isBeforeBeginning) if(playerMoveEvent.getNewPosition().y() > 51.5) playerMoveEvent.setCancelled(true);
|
||||
if(playerMoveEvent.getNewPosition().y() < 48) {
|
||||
playerMoveEvent.setCancelled(true);
|
||||
playerMoveEvent.getPlayer().teleport(getSpawn());
|
||||
return;
|
||||
}
|
||||
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() > 51.5) {
|
||||
playerMoveEvent.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if(playerMoveEvent.getNewPosition().y() > height) getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, radius+5, 30);
|
||||
return new Pos(0, 50, -(radius+5));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user