added game length for anvil run
This commit is contained in:
parent
c9ef7197cc
commit
350cf108dd
src/main/java/eu/mhsl/minenet/minigames/instance/game
@ -12,7 +12,6 @@ import eu.mhsl.minenet.minigames.instance.room.Room;
|
|||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.entity.EntityTickEvent;
|
|
||||||
import net.minestom.server.event.item.ItemDropEvent;
|
import net.minestom.server.event.item.ItemDropEvent;
|
||||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
||||||
@ -49,8 +48,7 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
.addListener(PlayerMoveEvent.class, this::onPlayerMove)
|
.addListener(PlayerMoveEvent.class, this::onPlayerMove)
|
||||||
.addListener(PlayerBlockBreakEvent.class, this::onBlockBreak)
|
.addListener(PlayerBlockBreakEvent.class, this::onBlockBreak)
|
||||||
.addListener(PlayerBlockPlaceEvent.class, this::onBlockPlace)
|
.addListener(PlayerBlockPlaceEvent.class, this::onBlockPlace)
|
||||||
.addListener(ItemDropEvent.class, this::onItemDrop)
|
.addListener(ItemDropEvent.class, this::onItemDrop);
|
||||||
.addListener(EntityTickEvent.class, this::onEntityTick);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Game setParent(Room parentRoom) {
|
public Game setParent(Room parentRoom) {
|
||||||
@ -120,11 +118,6 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
protected void onStop() {}
|
protected void onStop() {}
|
||||||
protected void onUnload() {}
|
protected void onUnload() {}
|
||||||
|
|
||||||
|
|
||||||
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import net.minestom.server.timer.TaskSchedule;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@ -26,14 +27,18 @@ class AnvilRun extends StatelessGame {
|
|||||||
|
|
||||||
final int spawnHeight = 30;
|
final int spawnHeight = 30;
|
||||||
final int radius;
|
final int radius;
|
||||||
final int speed;
|
int anvilsPerSecond;
|
||||||
|
final int seconds;
|
||||||
|
final int anvilHeight = 200;
|
||||||
final List<Pos> anvilSpawnPositions = new ArrayList<>();
|
final List<Pos> anvilSpawnPositions = new ArrayList<>();
|
||||||
|
|
||||||
public AnvilRun(int radius, int speed) {
|
public AnvilRun(int radius, int seconds) {
|
||||||
super(Dimension.THE_END.key, "Anvil Run", new LastWinsScore());
|
super(Dimension.OVERWORLD.key, "Anvil Run", new LastWinsScore());
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.speed = speed;
|
this.seconds = seconds;
|
||||||
this.setGenerator(new CircularPlateTerrainGenerator(radius));
|
this.setGenerator(new CircularPlateTerrainGenerator(radius));
|
||||||
|
|
||||||
|
eventNode().addListener(EntityTickEvent.class, this::onEntityTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,14 +49,15 @@ class AnvilRun extends StatelessGame {
|
|||||||
for (int z = -radius; z <= radius; z++) {
|
for (int z = -radius; z <= radius; z++) {
|
||||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||||
|
|
||||||
int height = super.rnd.nextInt(100, 500);
|
anvilSpawnPositions.add(new Pos(x+0.5, anvilHeight, z+0.5));
|
||||||
|
|
||||||
anvilSpawnPositions.add(new Pos(x+0.5, height, z+0.5));
|
|
||||||
|
|
||||||
batch.setBlock(x, spawnHeight-1, z, Block.SNOW_BLOCK);
|
batch.setBlock(x, spawnHeight-1, z, Block.SNOW_BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.anvilsPerSecond = anvilSpawnPositions.size() / this.seconds;
|
||||||
|
Collections.shuffle(anvilSpawnPositions);
|
||||||
|
|
||||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,14 +72,16 @@ class AnvilRun extends StatelessGame {
|
|||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
Scheduler scheduler = MinecraftServer.getSchedulerManager();
|
Scheduler scheduler = MinecraftServer.getSchedulerManager();
|
||||||
scheduler.submitTask(() -> {
|
for(int i=0; i<this.anvilSpawnPositions.size(); i++) {
|
||||||
if(anvilSpawnPositions.isEmpty()) return TaskSchedule.stop();
|
final int j = i;
|
||||||
for(int i = 0; i < speed; i++) {
|
scheduler.scheduleTask(
|
||||||
Pos position = anvilSpawnPositions.remove(super.rnd.nextInt(0, anvilSpawnPositions.size()-1));
|
() -> spawnAnvil(this.anvilSpawnPositions.get(j)),
|
||||||
spawnAnvil(position);
|
TaskSchedule.millis(
|
||||||
}
|
(long) Math.floor((double) i/this.anvilsPerSecond * 1000)
|
||||||
return TaskSchedule.seconds(1);
|
),
|
||||||
});
|
TaskSchedule.stop()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -87,11 +95,11 @@ class AnvilRun extends StatelessGame {
|
|||||||
if(playerMoveEvent.getNewPosition().y() < spawnHeight - 2) getScore().insertResult(playerMoveEvent.getPlayer());
|
if(playerMoveEvent.getNewPosition().y() < spawnHeight - 2) getScore().insertResult(playerMoveEvent.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
||||||
if(!entityTickEvent.getEntity().getEntityType().equals(EntityType.FALLING_BLOCK)) return;
|
if(!entityTickEvent.getEntity().getEntityType().equals(EntityType.FALLING_BLOCK)) return;
|
||||||
Pos anvilPosition = entityTickEvent.getEntity().getPosition();
|
Pos anvilPosition = entityTickEvent.getEntity().getPosition();
|
||||||
if(anvilPosition.y() > spawnHeight + 0.5) return;
|
if(anvilPosition.y() > spawnHeight + 0.5) return;
|
||||||
|
if(anvilPosition.y() < spawnHeight - 3) entityTickEvent.getEntity().remove();
|
||||||
if(this.getBlock(anvilPosition.withY(spawnHeight-1)).isAir()) return;
|
if(this.getBlock(anvilPosition.withY(spawnHeight-1)).isAir()) return;
|
||||||
this.setBlock(anvilPosition.withY(spawnHeight-1), Block.AIR);
|
this.setBlock(anvilPosition.withY(spawnHeight-1), Block.AIR);
|
||||||
}
|
}
|
||||||
|
4
src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/anvilRun/AnvilRunFactory.java
4
src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/anvilRun/AnvilRunFactory.java
@ -26,12 +26,12 @@ public class AnvilRunFactory implements GameFactory {
|
|||||||
public ConfigManager configuration() {
|
public ConfigManager configuration() {
|
||||||
return new ConfigManager()
|
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("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 5, 10, 15, 20, 25, 30))
|
||||||
.addOption(new NumericOption("speed", Material.STICK, TranslatedComponent.byId("game_Deathcube#speed"), 10, 25, 50, 100, 250, 500));
|
.addOption(new NumericOption("seconds", Material.STICK, TranslatedComponent.byId("game_Deathcube#seconds"), 10, 30, 60, 90, 120));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||||
return new AnvilRun(configuration.get("radius").getAsInt(), configuration.get("speed").getAsInt()).setParent(parent);
|
return new AnvilRun(configuration.get("radius").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user