Compare commits
2 Commits
develop-ha
...
develop-tu
Author | SHA1 | Date | |
---|---|---|---|
d98cebd86f | |||
c87d318421 |
@@ -8,7 +8,6 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms.Backroo
|
|||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars.BedwarsFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars.BedwarsFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain.AcidRainFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain.AcidRainFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge.FastbridgeFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.highGround.HighGroundFactory;
|
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.jumpDive.JumpDiveFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun.MinerunFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun.MinerunFactory;
|
||||||
@@ -19,6 +18,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.sumo.SumoFactory;
|
|||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tntrun.TntRunFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tntrun.TntRunFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.TowerdefenseFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.TowerdefenseFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace.TrafficLightRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace.TrafficLightRaceFactory;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.turtleGame.TurtleGameFactory;
|
||||||
|
|
||||||
public enum GameList {
|
public enum GameList {
|
||||||
DEATHCUBE(new DeathcubeFactory(), GameType.JUMPNRUN),
|
DEATHCUBE(new DeathcubeFactory(), GameType.JUMPNRUN),
|
||||||
@@ -29,6 +29,7 @@ public enum GameList {
|
|||||||
BEDWARS(new BedwarsFactory(), GameType.PROTOTYPE),
|
BEDWARS(new BedwarsFactory(), GameType.PROTOTYPE),
|
||||||
BACKROOMS(new BackroomsFactory(), GameType.PROTOTYPE),
|
BACKROOMS(new BackroomsFactory(), GameType.PROTOTYPE),
|
||||||
BOWSPLEEF(new BowSpleefFactory(), GameType.PROTOTYPE),
|
BOWSPLEEF(new BowSpleefFactory(), GameType.PROTOTYPE),
|
||||||
|
TURTLEGAME(new TurtleGameFactory(), GameType.PROTOTYPE),
|
||||||
TETRIS(new TetrisFactory(), GameType.OTHER),
|
TETRIS(new TetrisFactory(), GameType.OTHER),
|
||||||
TNTRUN(new TntRunFactory(), GameType.OTHER),
|
TNTRUN(new TntRunFactory(), GameType.OTHER),
|
||||||
ANVILRUN(new AnvilRunFactory(), GameType.PVE),
|
ANVILRUN(new AnvilRunFactory(), GameType.PVE),
|
||||||
@@ -37,8 +38,7 @@ public enum GameList {
|
|||||||
SPLEEF(new SpleefFactory(), GameType.PVP),
|
SPLEEF(new SpleefFactory(), GameType.PVP),
|
||||||
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN),
|
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN),
|
||||||
SUMO(new SumoFactory(), GameType.PVP),
|
SUMO(new SumoFactory(), GameType.PVP),
|
||||||
HIGHGROUND(new HighGroundFactory(), GameType.PVP),
|
HIGHGROUND(new HighGroundFactory(), GameType.PVP);
|
||||||
FASTBRIDGE(new FastbridgeFactory(), GameType.PROTOTYPE);
|
|
||||||
|
|
||||||
private final GameFactory factory;
|
private final GameFactory factory;
|
||||||
private final GameType type;
|
private final GameType type;
|
||||||
|
@@ -1,64 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
|
||||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.entity.GameMode;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
|
||||||
import net.minestom.server.instance.Chunk;
|
|
||||||
import net.minestom.server.inventory.PlayerInventory;
|
|
||||||
import net.minestom.server.item.ItemStack;
|
|
||||||
import net.minestom.server.item.Material;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class Fastbridge extends StatelessGame {
|
|
||||||
private int currentSpawn = 0;
|
|
||||||
|
|
||||||
public Fastbridge() {
|
|
||||||
super(Dimension.OVERWORLD.key, "Fastbridge", new FirstWinsScore());
|
|
||||||
this.setGenerator(new FastbridgeChunkgenerator());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
|
||||||
Player player = playerMoveEvent.getPlayer();
|
|
||||||
Pos newPos = playerMoveEvent.getNewPosition();
|
|
||||||
if(this.getScore().hasResult(player)) return;
|
|
||||||
if(newPos.y() < -65) {
|
|
||||||
player.teleport(getSpawn());
|
|
||||||
if(!isBeforeBeginning) this.resetPlayer(player);
|
|
||||||
}
|
|
||||||
if(newPos.x() > 53) {
|
|
||||||
this.getScore().insertResult(player);
|
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
getPlayers().forEach(player -> {
|
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
|
||||||
resetPlayer(player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {
|
|
||||||
if(isBeforeBeginning) playerBlockPlaceEvent.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetPlayer(Player player) {
|
|
||||||
if(isBeforeBeginning) return;
|
|
||||||
PlayerInventory inventory = player.getInventory();
|
|
||||||
inventory.clear();
|
|
||||||
inventory.addItemStack(ItemStack.of(Material.WHITE_WOOL, 64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized Pos getSpawn() {
|
|
||||||
return new Pos(24, -60, currentSpawn++*Chunk.CHUNK_SIZE_Z*2-8, -90, 0);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,23 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge;
|
|
||||||
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import net.minestom.server.instance.generator.GenerationUnit;
|
|
||||||
import net.minestom.server.instance.generator.Generator;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class FastbridgeChunkgenerator implements Generator {
|
|
||||||
@Override
|
|
||||||
public void generate(@NotNull GenerationUnit unit) {
|
|
||||||
if (unit.absoluteStart().chunkZ() % 2 == 0) {
|
|
||||||
unit.modifier().fill(Block.BARRIER);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit.absoluteStart().chunkX() != 1 && unit.absoluteStart().chunkX() != 3) return;
|
|
||||||
for (int x = 5; x <= 10; x++){
|
|
||||||
for (int z = 5; z <= 10; z++){
|
|
||||||
unit.modifier().setRelative(x, 2, z, unit.absoluteStart().chunkX() == 3 ? Block.GOLD_BLOCK : Block.GRASS_BLOCK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,22 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge;
|
|
||||||
|
|
||||||
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 java.util.Map;
|
|
||||||
|
|
||||||
public class FastbridgeFactory implements GameFactory {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent name() {
|
|
||||||
return TranslatedComponent.byId("game_Fastbridge#name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
|
||||||
return new Fastbridge().setParent(parent);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,70 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.turtleGame;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.turtleGame.game.TurtleGameInstance;
|
||||||
|
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.entity.EntityCreature;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.entity.attribute.Attribute;
|
||||||
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
|
import net.minestom.server.item.ItemStack;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
class TurtleGame extends StatelessGame {
|
||||||
|
private final boolean firstPerson;
|
||||||
|
private final Map<Player, TurtleGameInstance> gameInstances = new WeakHashMap<>();
|
||||||
|
|
||||||
|
public TurtleGame(boolean firstPerson) {
|
||||||
|
super(Dimension.OVERWORLD.key, "Tetris", new PointsWinScore());
|
||||||
|
this.firstPerson = firstPerson;
|
||||||
|
|
||||||
|
this.eventNode()
|
||||||
|
.addListener(PlayerMoveEvent.class, this::onPlayerMove);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||||
|
TurtleGameInstance gameInstance = this.gameInstances.get(event.getPlayer());
|
||||||
|
gameInstance.getTurtle().setView(event.getPlayer().getPosition().yaw(), gameInstance.getTurtle().getPosition().pitch());
|
||||||
|
if(this.isRunning()) gameInstance.moveTurtle(event.getPlayer().getPosition().direction());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean onPlayerJoin(Player p) {
|
||||||
|
p.getInventory().setItemStack(0, ItemStack.builder(Material.BARRIER).customName(Component.text("Reset")).build());
|
||||||
|
|
||||||
|
if(this.gameInstances.get(p) == null) {
|
||||||
|
this.gameInstances.put(p, new TurtleGameInstance(
|
||||||
|
this,
|
||||||
|
this.getSpawn().sub(6, 8, 15).add(this.gameInstances.size()*50, 0, 0)
|
||||||
|
));
|
||||||
|
this.gameInstances.get(p).generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
TurtleGameInstance gameInstance = this.gameInstances.get(p);
|
||||||
|
|
||||||
|
p.teleport(gameInstance.getPlayerSpawnPosition());
|
||||||
|
|
||||||
|
EntityCreature turtle = gameInstance.getTurtle();
|
||||||
|
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> {
|
||||||
|
turtle.setInstance(this);
|
||||||
|
turtle.teleport(gameInstance.getPlayerSpawnPosition());
|
||||||
|
turtle.addPassenger(p);
|
||||||
|
turtle.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(0.15);
|
||||||
|
});
|
||||||
|
|
||||||
|
return super.onPlayerJoin(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
this.gameInstances.forEach(((player, gameInstance) -> gameInstance.moveTurtle(player.getPosition().direction())));
|
||||||
|
// this.gameInstances.forEach(((player, turtleGameInstance) -> turtleGameInstance.start()));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.turtleGame;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||||
|
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.game.stateless.config.common.BoolOption;
|
||||||
|
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 TurtleGameFactory implements GameFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TranslatedComponent name() {
|
||||||
|
return TranslatedComponent.byId("game_TurtleGame#name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TranslatedComponent description() {
|
||||||
|
return TranslatedComponent.byId("game_TurtleGame#description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigManager configuration() {
|
||||||
|
return new ConfigManager()
|
||||||
|
.addOption(new BoolOption("firstPerson", Material.SPYGLASS, TranslatedComponent.byId("game_TurtleGame#firstPerson")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||||
|
return new TurtleGame(configuration.get("firstPerson").getAsBoolean());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material symbol() {
|
||||||
|
return Material.TURTLE_EGG;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,53 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.turtleGame.game;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
|
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
|
import net.minestom.server.entity.EntityCreature;
|
||||||
|
import net.minestom.server.entity.EntityType;
|
||||||
|
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class TurtleGameInstance {
|
||||||
|
private final StatelessGame instance;
|
||||||
|
private final Pos startPosition;
|
||||||
|
private final EntityCreature turtle = new EntityCreature(EntityType.TURTLE);
|
||||||
|
|
||||||
|
public TurtleGameInstance(StatelessGame instance, Pos startPosition) {
|
||||||
|
this.instance = instance;
|
||||||
|
this.startPosition = startPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTurtle(Vec direction) {
|
||||||
|
Vec targetDirection = direction.withY(0).normalize().mul(100);
|
||||||
|
Pos targetPosition = this.turtle.getPosition().add(targetDirection);
|
||||||
|
this.turtle.getNavigator().setPathTo(targetPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate() {
|
||||||
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
|
||||||
|
for (int z = -1; z < 66; z++) {
|
||||||
|
for (int x = -1; x < 44; x++) {
|
||||||
|
if(z < 0 || z >= 65 || x < 0 || x >= 43) {
|
||||||
|
batch.setBlock(this.startPosition.add(x, 1, z), Block.STONE);
|
||||||
|
batch.setBlock(this.startPosition.add(x, 2, z), Block.STONE_SLAB);
|
||||||
|
}
|
||||||
|
batch.setBlock(this.startPosition.add(x, 0, z), Block.SAND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BatchUtil.loadAndApplyBatch(batch, this.instance, () -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pos getPlayerSpawnPosition() {
|
||||||
|
return this.startPosition.add(20, 1, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityCreature getTurtle() {
|
||||||
|
return this.turtle;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user