finished basic anvil run
This commit is contained in:
parent
e71dccb98d
commit
40f02449d9
@ -12,6 +12,7 @@ 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;
|
||||||
@ -48,7 +49,8 @@ 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) {
|
||||||
@ -119,6 +121,10 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
protected void onUnload() {}
|
protected void onUnload() {}
|
||||||
|
|
||||||
|
|
||||||
|
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,15 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun;
|
|||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
|
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.EntityType;
|
||||||
import net.minestom.server.entity.metadata.other.FallingBlockMeta;
|
import net.minestom.server.entity.metadata.other.FallingBlockMeta;
|
||||||
|
import net.minestom.server.event.entity.EntityTickEvent;
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
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.instance.block.Block;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -18,17 +21,20 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
|
|
||||||
class AnvilRun extends StatelessGame {
|
class AnvilRun extends StatelessGame {
|
||||||
|
|
||||||
|
final int spawnHeight = 30;
|
||||||
final int radius;
|
final int radius;
|
||||||
final List<Entity> anvils = new ArrayList<>();
|
final List<Entity> anvils = new ArrayList<>();
|
||||||
|
|
||||||
public AnvilRun(int radius, int pvpEnabled) {
|
public AnvilRun(int radius, int pvpEnabled) {
|
||||||
super(Dimension.THE_END.key, "Deathcube", new LastWinsScore());
|
super(Dimension.THE_END.key, "Anvil Run", new LastWinsScore());
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.setGenerator(new CircularPlateTerrainGenerator(radius).setPlateHeight(50));
|
this.setGenerator(new CircularPlateTerrainGenerator(radius));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
|
||||||
for(int x = -radius; x <= radius; x++) {
|
for(int x = -radius; x <= radius; x++) {
|
||||||
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;
|
||||||
@ -37,10 +43,15 @@ class AnvilRun extends StatelessGame {
|
|||||||
Entity anvil = new Entity(EntityType.FALLING_BLOCK);
|
Entity anvil = new Entity(EntityType.FALLING_BLOCK);
|
||||||
((FallingBlockMeta) anvil.getEntityMeta()).setBlock(Block.ANVIL);
|
((FallingBlockMeta) anvil.getEntityMeta()).setBlock(Block.ANVIL);
|
||||||
anvil.setNoGravity(true);
|
anvil.setNoGravity(true);
|
||||||
|
anvil.setInstance(this, new Pos(x+0.5, height, z+0.5));
|
||||||
|
|
||||||
anvils.add(anvil);
|
anvils.add(anvil);
|
||||||
|
|
||||||
|
batch.setBlock(x, spawnHeight-1, z, Block.SNOW_BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,15 +64,25 @@ class AnvilRun extends StatelessGame {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
super.onPlayerMove(playerMoveEvent);
|
super.onPlayerMove(playerMoveEvent);
|
||||||
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() < 48.5) {
|
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() < spawnHeight - 2) {
|
||||||
playerMoveEvent.setCancelled(true);
|
playerMoveEvent.setCancelled(true);
|
||||||
playerMoveEvent.getPlayer().teleport(getSpawn());
|
playerMoveEvent.getPlayer().teleport(getSpawn());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if(playerMoveEvent.getNewPosition().y() < 48.5) getScore().insertResult(playerMoveEvent.getPlayer());
|
if(playerMoveEvent.getNewPosition().y() < spawnHeight - 2) getScore().insertResult(playerMoveEvent.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
||||||
|
if(!entityTickEvent.getEntity().getEntityType().equals(EntityType.FALLING_BLOCK)) return;
|
||||||
|
Pos anvilPosition = entityTickEvent.getEntity().getPosition();
|
||||||
|
if(anvilPosition.y() > spawnHeight + 0.5) return;
|
||||||
|
if(this.getBlock(anvilPosition.withY(spawnHeight-1)).isAir()) return;
|
||||||
|
this.setBlock(anvilPosition.withY(spawnHeight-1), Block.AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
return new Pos(0, 0, 30);
|
return new Pos(0, spawnHeight, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class AnvilRunFactory implements GameFactory {
|
|||||||
@Override
|
@Override
|
||||||
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"), 10, 20, 30))
|
.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("pvpEnabled", Material.STICK, TranslatedComponent.byId("game_Deathcube#optionPvpEnabled"), 1, 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class CircularPlateTerrainGenerator extends PlateTerrainGenerator {
|
|||||||
double distance = bottom.distance(new Pos(0, 0, 0));
|
double distance = bottom.distance(new Pos(0, 0, 0));
|
||||||
|
|
||||||
if(distance <= this.size && generatePlate()) {
|
if(distance <= this.size && generatePlate()) {
|
||||||
unit.modifier().fill(bottom, bottom.add(1, 50, 1), platePallet.rnd());
|
unit.modifier().fill(bottom, bottom.add(1, plateHeight, 1), platePallet.rnd());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user