added pillars and block battle #10
@@ -14,6 +14,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge.Fastbr
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.highGround.HighGroundFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.jumpDive.JumpDiveFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun.MinerunFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.pillars.PillarsFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spaceSnake.SpaceSnakeFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef.SpleefFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight.StickFightFactory;
|
||||
@@ -46,7 +47,8 @@ public enum GameList {
|
||||
FASTBRIDGE(new FastbridgeFactory(), GameType.OTHER),
|
||||
BLOCKBREAKRACE(new BlockBreakRaceFactory(), GameType.OTHER),
|
||||
SPACESNAKE(new SpaceSnakeFactory(), GameType.PVP),
|
||||
BOATRACE(new BoatRaceFactory(), GameType.OTHER);
|
||||
BOATRACE(new BoatRaceFactory(), GameType.OTHER),
|
||||
PILLARS(new PillarsFactory(), GameType.PROTOTYPE);
|
||||
|
||||
private final GameFactory factory;
|
||||
private final GameType type;
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.pillars;
|
||||
|
||||
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.Position;
|
||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.item.ItemDropEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
class Pillars extends StatelessGame {
|
||||
private int spawnPosx = 0;
|
||||
private int spawnPosz = 0;
|
||||
private final int pillarSpacing = 10;
|
||||
private final int pillarRowCount = 5;
|
||||
public Pillars() {
|
||||
|
jannis marked this conversation as resolved
Outdated
|
||||
super(Dimension.THE_END.key, "Pillars", new LastWinsScore());
|
||||
this.getScore().setIgnoreLastPlayers(1);
|
||||
|
||||
this.eventNode().addChild(
|
||||
CombatFeatures.empty()
|
||||
.add(CombatFeatures.VANILLA_ATTACK)
|
||||
.add(CombatFeatures.VANILLA_DAMAGE)
|
||||
.add(CombatFeatures.VANILLA_KNOCKBACK)
|
||||
.build().createNode()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onPlayerJoin(Player p) {
|
||||
Pos pos = new Pos(this.spawnPosx * this.pillarSpacing, 100, this.spawnPosz * this.pillarSpacing);
|
||||
this.setBlock(pos.sub(0, 1, 0), Block.BEDROCK);
|
||||
|
||||
if(this.spawnPosx >= this.pillarRowCount) {
|
||||
this.spawnPosx = 0;
|
||||
this.spawnPosz++;
|
||||
}
|
||||
this.spawnPosx++;
|
||||
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> p.teleport(pos.add(0.5, 0, 0.5)));
|
||||
|
||||
return super.onPlayerJoin(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {}
|
||||
|
||||
@Override
|
||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {}
|
||||
|
||||
@Override
|
||||
protected void onItemDrop(@NotNull ItemDropEvent itemDropEvent) {}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, 105, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
if(this.isBeforeBeginning && Position.hasPositionChanged(playerMoveEvent.getPlayer().getPosition(), playerMoveEvent.getNewPosition()))
|
||||
|
jannis marked this conversation as resolved
Pupsi
commented
Eigene Variable für playerMoveEvent.getPlayer(), das wiederholt sich sonst. Eigene Variable für playerMoveEvent.getPlayer(), das wiederholt sich sonst.
|
||||
playerMoveEvent.setCancelled(true);
|
||||
|
||||
if(playerMoveEvent.getNewPosition().y() < 80) {
|
||||
this.getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
playerMoveEvent.getPlayer().teleport(this.getSpawn());
|
||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
jannis marked this conversation as resolved
Outdated
Pupsi
commented
Hier kann auch player anstatt playerMoveEvent.getPlayer() hin. Hier kann auch player anstatt playerMoveEvent.getPlayer() hin.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
this.getPlayers().forEach(player -> player.setGameMode(GameMode.SURVIVAL));
|
||||
|
||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||
List<Material> materials = Material.values().stream()
|
||||
.filter(material -> !material.equals(Material.AIR))
|
||||
.toList();
|
||||
this.getPlayers().forEach(player -> {
|
||||
ItemStack item = ItemStack.of(materials.get(new Random().nextInt(Material.values().toArray().length)));
|
||||
|
jannis marked this conversation as resolved
Pupsi
commented
new Random() als eigene Variable in Pillars, damit nicht immer ein neues Objekt erstellt wird. new Random() als eigene Variable in Pillars, damit nicht immer ein neues Objekt erstellt wird.
Alternativ geht ThreadLocalRandom.current()
MineTec
commented
nimm ThreadLocalRandom.current() nimm ThreadLocalRandom.current()
|
||||
player.getInventory().addItemStack(item);
|
||||
});
|
||||
|
||||
return TaskSchedule.seconds(5);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.pillars;
|
||||
|
||||
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 PillarsFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Pillars#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.BEDROCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new Pillars().setParent(parent);
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,15 @@ public class Position {
|
||||
public static List<Block> blocksBelowPlayer(Instance instance, Player p) {
|
||||
Point playerPos = p.getPosition();
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
GeneratorUtils.foreachXZ(playerPos.sub(0.5, 1, 0.5), playerPos.add(0.5, -1, 0.5), point -> {
|
||||
blocks.add(instance.getBlock(point));
|
||||
});
|
||||
GeneratorUtils.foreachXZ(
|
||||
playerPos.sub(0.5, 1, 0.5),
|
||||
playerPos.add(0.5, -1, 0.5),
|
||||
point -> blocks.add(instance.getBlock(point))
|
||||
);
|
||||
return blocks.stream().distinct().toList();
|
||||
}
|
||||
|
||||
public static boolean hasPositionChanged(Pos oldPos, Pos newPos) {
|
||||
return !oldPos.withView(0, 0).equals(newPos.withView(0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,3 +174,6 @@ startSpeed;Start Speed;Startgeschwindigkeit
|
||||
ns:game_BoatRace#;;
|
||||
name;Boatrace;Bootrennen
|
||||
description;;
|
||||
;;
|
||||
ns:game_Pillars#;;
|
||||
name;Pillars;Pillars
|
||||
|
Reference in New Issue
Block a user
Leerzeile davor