Compare commits
18 Commits
develop-ja
...
develop-te
| Author | SHA1 | Date | |
|---|---|---|---|
| 56f56d48b6 | |||
| 991e51bc10 | |||
| ffba86ac41 | |||
| f95c670514 | |||
| 0b3c757ce0 | |||
| 76df6643db | |||
| 7186b4dbea | |||
| 24d79d7a11 | |||
| 70fd5bafdb | |||
| 11ddd01470 | |||
| 7d5fb025bd | |||
| 05240660f2 | |||
| d0031b4ea5 | |||
| 360266339d | |||
| 325fba2a53 | |||
| 73ab137ae4 | |||
| 9a9e646288 | |||
| 728dc92fc8 |
@@ -5,6 +5,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain.AcidRain
|
|||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun.AnvilRunFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun.AnvilRunFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms.BackroomsFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms.BackroomsFactory;
|
||||||
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.blockBattle.BlockBattleFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace.BlockBreakRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace.BlockBreakRaceFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace.BoatRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace.BoatRaceFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
|
||||||
@@ -14,6 +15,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.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;
|
||||||
|
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.spaceSnake.SpaceSnakeFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef.SpleefFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef.SpleefFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight.StickFightFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight.StickFightFactory;
|
||||||
@@ -46,7 +48,9 @@ public enum GameList {
|
|||||||
FASTBRIDGE(new FastbridgeFactory(), GameType.OTHER),
|
FASTBRIDGE(new FastbridgeFactory(), GameType.OTHER),
|
||||||
BLOCKBREAKRACE(new BlockBreakRaceFactory(), GameType.OTHER),
|
BLOCKBREAKRACE(new BlockBreakRaceFactory(), GameType.OTHER),
|
||||||
SPACESNAKE(new SpaceSnakeFactory(), GameType.PVP),
|
SPACESNAKE(new SpaceSnakeFactory(), GameType.PVP),
|
||||||
BOATRACE(new BoatRaceFactory(), GameType.OTHER);
|
BOATRACE(new BoatRaceFactory(), GameType.OTHER),
|
||||||
|
PILLARS(new PillarsFactory(), GameType.PROTOTYPE),
|
||||||
|
BLOCKBATTLE(new BlockBattleFactory(), GameType.PROTOTYPE);
|
||||||
|
|
||||||
private final GameFactory factory;
|
private final GameFactory factory;
|
||||||
private final GameType type;
|
private final GameType type;
|
||||||
|
|||||||
@@ -0,0 +1,207 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
|
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||||
|
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||||
|
import io.github.togar2.pvp.events.FinalAttackEvent;
|
||||||
|
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.entity.GameMode;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
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.batch.AbsoluteBlockBatch;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
|
import net.minestom.server.item.ItemStack;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class BlockBattle extends StatelessGame {
|
||||||
|
private final Team teamBlue = new Team(new Pos(0,101,20).add(0.5).withView(180, 0), Team.Color.BLUE);
|
||||||
|
private final Team teamRed = new Team(new Pos(0, 101, -20).add(0.5), Team.Color.RED);
|
||||||
|
private final int itemCount;
|
||||||
|
|
||||||
|
private final Map<Player, Team> teams = new WeakHashMap<>();
|
||||||
|
|
||||||
|
public BlockBattle(int itemCount) {
|
||||||
|
super(Dimension.THE_END.key, "Block Battle", new FirstWinsScore());
|
||||||
|
|
||||||
|
this.itemCount = itemCount;
|
||||||
|
|
||||||
|
this.eventNode().addChild(
|
||||||
|
CombatFeatures.empty()
|
||||||
|
.add(CombatFeatures.VANILLA_ATTACK)
|
||||||
|
.add(CombatFeatures.VANILLA_DAMAGE)
|
||||||
|
.add(CombatFeatures.VANILLA_KNOCKBACK)
|
||||||
|
.build().createNode()
|
||||||
|
);
|
||||||
|
|
||||||
|
this.eventNode().addListener(FinalAttackEvent.class, finalAttackEvent -> {
|
||||||
|
if(this.isBeforeBeginning) finalAttackEvent.setCancelled(true);
|
||||||
|
finalAttackEvent.setBaseDamage(0);
|
||||||
|
((Player) finalAttackEvent.getTarget()).setHealth(20);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
|
this.generatePlatform(new Pos(0, 100, 0), Block.GOLD_BLOCK, Block.YELLOW_CONCRETE_POWDER);
|
||||||
|
this.generatePlatform(new Pos(0, 101, 0), Block.AIR, Block.SANDSTONE_SLAB);
|
||||||
|
this.generatePlatform(new Pos(0, 100, 20), Block.BLUE_CONCRETE, Block.BLUE_CONCRETE_POWDER);
|
||||||
|
this.generatePlatform(new Pos(0, 100, -20), Block.RED_CONCRETE, Block.RED_CONCRETE_POWDER);
|
||||||
|
this.generatePlatform(new Pos(-5, 101, -14), Block.RED_STAINED_GLASS, Block.AIR);
|
||||||
|
this.generatePlatform(new Pos(5, 101, 14), Block.BLUE_STAINED_GLASS, Block.AIR);
|
||||||
|
|
||||||
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
|
||||||
|
Pos[] positionsRedGlass = {
|
||||||
|
new Pos(2, 102, -9),
|
||||||
|
new Pos(-1, 103, -9),
|
||||||
|
new Pos(-2, 104, -6),
|
||||||
|
new Pos(-5, 103, -7),
|
||||||
|
new Pos(-7, 102, -10),
|
||||||
|
new Pos(3, 102, -12),
|
||||||
|
new Pos(5, 101, -15)
|
||||||
|
};
|
||||||
|
|
||||||
|
Pos[] positionsBlueGlass = {
|
||||||
|
new Pos(-5, 101, 15),
|
||||||
|
new Pos(-3, 102, 12),
|
||||||
|
new Pos(-2, 102, 9),
|
||||||
|
new Pos(1, 103, 9),
|
||||||
|
new Pos(2, 104, 6),
|
||||||
|
new Pos(5, 103, 7),
|
||||||
|
new Pos(7, 102, 10)
|
||||||
|
};
|
||||||
|
|
||||||
|
for(Pos pos : positionsRedGlass)
|
||||||
|
batch.setBlock(pos, Block.RED_STAINED_GLASS);
|
||||||
|
|
||||||
|
for(Pos pos : positionsBlueGlass)
|
||||||
|
batch.setBlock(pos, Block.BLUE_STAINED_GLASS);
|
||||||
|
|
||||||
|
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {
|
||||||
|
Pos posGoldBlock = new Pos(playerBlockPlaceEvent.getBlockPosition()).sub(0, 1, 0);
|
||||||
|
Block goldBlock = playerBlockPlaceEvent.getInstance().getBlock(posGoldBlock);
|
||||||
|
|
||||||
|
playerBlockPlaceEvent.setCancelled(goldBlock != Block.GOLD_BLOCK);
|
||||||
|
|
||||||
|
playerBlockPlaceEvent.getInstance().scheduler().scheduleNextTick(() -> {
|
||||||
|
Pos middle = new Pos(0, 101, 0);
|
||||||
|
boolean validBlue = true;
|
||||||
|
boolean validRed = true;
|
||||||
|
|
||||||
|
for(int x = middle.blockX()-1; x < middle.blockX()+2; x++) {
|
||||||
|
for(int z = middle.blockZ()-1; z < middle.blockZ()+2; z++) {
|
||||||
|
if(playerBlockPlaceEvent.getInstance().getBlock(x, 101, z) != Block.BLUE_WOOL) {
|
||||||
|
validBlue = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!validBlue)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int x = middle.blockX()-1; x < middle.blockX()+2; x++) {
|
||||||
|
for(int z = middle.blockZ()-1; z < middle.blockZ()+2; z++) {
|
||||||
|
if(playerBlockPlaceEvent.getInstance().getBlock(x, 101, z) != Block.RED_WOOL) {
|
||||||
|
validRed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!validRed)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!validBlue && !validRed) return;
|
||||||
|
var winningTeam = validBlue ? Team.Color.BLUE : Team.Color.RED;
|
||||||
|
var winningPlayers = this.teams.entrySet().stream()
|
||||||
|
.filter(entry -> entry.getValue().color().equals(winningTeam))
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
this.getScore().insertMultiple(winningPlayers);
|
||||||
|
super.stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
||||||
|
boolean isAllowed = Arrays.stream(Team.Color.values())
|
||||||
|
.map(Team.Color::getMaterial)
|
||||||
|
.map(Material::block)
|
||||||
|
.toList()
|
||||||
|
.contains(playerBlockBreakEvent.getBlock());
|
||||||
|
if(!isAllowed) playerBlockBreakEvent.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
|
if(playerMoveEvent.getNewPosition().y() < 95) {
|
||||||
|
var player = playerMoveEvent.getPlayer();
|
||||||
|
|
||||||
|
player.teleport(
|
||||||
|
this.isBeforeBeginning
|
||||||
|
? this.getSpawn()
|
||||||
|
: this.teams.get(player).spawnPosition()
|
||||||
|
);
|
||||||
|
|
||||||
|
this.giveItems(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
this.setTeams();
|
||||||
|
this.getPlayers().forEach(player -> player.teleport(this.teams.get(player).spawnPosition()).thenRun(() -> {
|
||||||
|
this.giveItems(player);
|
||||||
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generatePlatform(Pos center, Block inner, Block outer) {
|
||||||
|
for(int x = center.blockX()-2; x < center.blockX()+3; x++) {
|
||||||
|
for(int z = center.blockZ()-2; z < center.blockZ()+3; z++) {
|
||||||
|
this.setBlock(x, center.blockY(), z, outer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int x = center.blockX()-1; x < center.blockX()+2; x++) {
|
||||||
|
for(int z = center.blockZ()-1; z < center.blockZ()+2; z++) {
|
||||||
|
this.setBlock(x, center.blockY(), z, inner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTeams() {
|
||||||
|
List<Player> players = new ArrayList<>(this.getPlayers());
|
||||||
|
Collections.shuffle(players);
|
||||||
|
int halfPlayers = players.size()/2;
|
||||||
|
players.subList(0, halfPlayers).forEach(player -> this.teams.put(player, this.teamBlue));
|
||||||
|
players.subList(halfPlayers, players.size()).forEach(player -> this.teams.put(player, this.teamRed));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pos getSpawn() {
|
||||||
|
return new Pos(0, 101, 0).add(0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void giveItems(Player player) {
|
||||||
|
player.getInventory().clear();
|
||||||
|
ItemStack item = ItemStack.of(
|
||||||
|
this.teams.get(player).color().getMaterial(),
|
||||||
|
this.itemCount
|
||||||
|
);
|
||||||
|
player.getInventory().addItemStack(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
||||||
|
|
||||||
|
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.NumericOption;
|
||||||
|
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 BlockBattleFactory implements GameFactory {
|
||||||
|
@Override
|
||||||
|
public TranslatedComponent name() {
|
||||||
|
return TranslatedComponent.byId("game_BlockBattle#name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TranslatedComponent description() {
|
||||||
|
return TranslatedComponent.byId("game_BlockBattle#description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigManager configuration() {
|
||||||
|
return new ConfigManager()
|
||||||
|
.addOption(new NumericOption("itemCount", Material.WHITE_WOOL, TranslatedComponent.byId("game_BlockBattle#itemCount"), 1, 2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material symbol() {
|
||||||
|
return Material.GREEN_CONCRETE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||||
|
return new BlockBattle(configuration.get("itemCount").getAsInt()).setParent(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
|
|
||||||
|
public record Team(Pos spawnPosition, Color color) {
|
||||||
|
public enum Color {
|
||||||
|
RED(Material.RED_WOOL),
|
||||||
|
BLUE(Material.BLUE_WOOL);
|
||||||
|
|
||||||
|
private final Material block;
|
||||||
|
|
||||||
|
Color(Material block) {
|
||||||
|
this.block = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getMaterial() {
|
||||||
|
return this.block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
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.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
class Pillars extends StatelessGame {
|
||||||
|
private int spawnPosx = 0;
|
||||||
|
private int spawnPosz = 0;
|
||||||
|
private final int pillarSpacing = 10;
|
||||||
|
private final int pillarRowCount = 5;
|
||||||
|
|
||||||
|
public Pillars() {
|
||||||
|
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) {
|
||||||
|
var player = playerMoveEvent.getPlayer();
|
||||||
|
|
||||||
|
if(this.isBeforeBeginning && Position.hasPositionChanged(player.getPosition(), playerMoveEvent.getNewPosition()))
|
||||||
|
playerMoveEvent.setCancelled(true);
|
||||||
|
|
||||||
|
if(playerMoveEvent.getNewPosition().y() < 80) {
|
||||||
|
this.getScore().insertResult(player);
|
||||||
|
player.teleport(this.getSpawn());
|
||||||
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(ThreadLocalRandom.current().nextInt(Material.values().toArray().length)));
|
||||||
|
player.getInventory().addItemStack(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
return TaskSchedule.seconds(5);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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 TranslatedComponent description() {
|
||||||
|
return TranslatedComponent.byId("game_Pillars#description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material symbol() {
|
||||||
|
return Material.BEDROCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||||
|
return new Pillars().setParent(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,18 +6,20 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetri
|
|||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetromino;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetromino;
|
||||||
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
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.GameMode;
|
import net.minestom.server.entity.GameMode;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.entity.metadata.display.BlockDisplayMeta;
|
||||||
import net.minestom.server.event.player.PlayerHandAnimationEvent;
|
import net.minestom.server.event.player.PlayerHandAnimationEvent;
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerTickEvent;
|
import net.minestom.server.event.player.PlayerTickEvent;
|
||||||
import net.minestom.server.event.player.PlayerUseItemEvent;
|
import net.minestom.server.event.player.PlayerUseItemEvent;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
import net.minestom.server.potion.Potion;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
import net.minestom.server.potion.PotionEffect;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -78,45 +80,31 @@ class Tetris extends StatelessGame {
|
|||||||
p.setGameMode(GameMode.SURVIVAL);
|
p.setGameMode(GameMode.SURVIVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
event.setItemUseTime(0);
|
||||||
Player player = event.getPlayer();
|
this.tetrisGames.get(event.getPlayer()).pressedButtonRaw(TetrisGame.Button.mouseRight);
|
||||||
Pos currentPosition = event.getNewPosition();
|
|
||||||
|
|
||||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
|
||||||
|
|
||||||
if(tetrisGame == null) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(tetrisGame.lost) return;
|
|
||||||
if(player.getGameMode() == GameMode.SPECTATOR) return;
|
|
||||||
|
|
||||||
if(player.inputs().forward()) tetrisGame.pressedButton(TetrisGame.Button.W);
|
|
||||||
if(player.inputs().backward()) tetrisGame.pressedButton(TetrisGame.Button.S);
|
|
||||||
if(player.inputs().right()) tetrisGame.pressedButton(TetrisGame.Button.D);
|
|
||||||
if(player.inputs().left()) tetrisGame.pressedButton(TetrisGame.Button.A);
|
|
||||||
if(player.inputs().jump()) tetrisGame.pressedButton(TetrisGame.Button.space);
|
|
||||||
|
|
||||||
event.setNewPosition(tetrisGame.getPlayerSpawnPosition().withView(currentPosition));
|
|
||||||
player.setSprinting(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
|
private void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
|
||||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseRight);
|
this.tetrisGames.get(event.getPlayer()).pressedButtonRaw(TetrisGame.Button.mouseLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
|
private void onPlayerTick(PlayerTickEvent event) {
|
||||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseLeft);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPlayerTick(PlayerTickEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||||
if(tetrisGame == null) return;
|
if(tetrisGame == null) return;
|
||||||
if(tetrisGame.lost && player.getGameMode() != GameMode.SPECTATOR) {
|
if(tetrisGame.lost) {
|
||||||
this.letPlayerLoose(player);
|
this.letPlayerLoose(player);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(player.getGameMode() == GameMode.SPECTATOR) return;
|
||||||
|
|
||||||
|
if(player.inputs().forward()) tetrisGame.pressedButtonRaw(TetrisGame.Button.W);
|
||||||
|
if(player.inputs().backward()) tetrisGame.pressedButtonRaw(TetrisGame.Button.S);
|
||||||
|
if(player.inputs().right()) tetrisGame.pressedButtonRaw(TetrisGame.Button.D);
|
||||||
|
if(player.inputs().left()) tetrisGame.pressedButtonRaw(TetrisGame.Button.A);
|
||||||
|
if(player.inputs().jump()) tetrisGame.pressedButtonRaw(TetrisGame.Button.space);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void letPlayerLoose(Player player) {
|
private void letPlayerLoose(Player player) {
|
||||||
@@ -124,6 +112,7 @@ class Tetris extends StatelessGame {
|
|||||||
if(!this.getScore().hasResult(player)) {
|
if(!this.getScore().hasResult(player)) {
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
player.setInvisible(true);
|
player.setInvisible(true);
|
||||||
|
if(player.getVehicle() != null) player.getVehicle().removePassenger(player);
|
||||||
this.getScore().insertResult(player, tetrisGame.getScore());
|
this.getScore().insertResult(player, tetrisGame.getScore());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +149,16 @@ class Tetris extends StatelessGame {
|
|||||||
|
|
||||||
p.teleport(tetrisGame.getPlayerSpawnPosition());
|
p.teleport(tetrisGame.getPlayerSpawnPosition());
|
||||||
tetrisGame.sidebar.addViewer(p);
|
tetrisGame.sidebar.addViewer(p);
|
||||||
p.addEffect(new Potion(PotionEffect.SLOWNESS, 4, Potion.INFINITE_DURATION));
|
|
||||||
|
MinecraftServer.getSchedulerManager().scheduleTask(() -> {
|
||||||
|
Entity ghostBlock = new Entity(EntityType.BLOCK_DISPLAY);
|
||||||
|
((BlockDisplayMeta) ghostBlock.getEntityMeta()).setBlockState(Block.AIR);
|
||||||
|
ghostBlock.setNoGravity(true);
|
||||||
|
ghostBlock.setInstance(this, tetrisGame.getPlayerSpawnPosition());
|
||||||
|
ghostBlock.addPassenger(p);
|
||||||
|
return TaskSchedule.stop();
|
||||||
|
}, TaskSchedule.nextTick());
|
||||||
|
|
||||||
|
|
||||||
return super.onPlayerJoin(p);
|
return super.onPlayerJoin(p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game;
|
||||||
|
|
||||||
|
public enum Orientation {
|
||||||
|
NONE,
|
||||||
|
RIGHT,
|
||||||
|
LEFT,
|
||||||
|
UPSIDE_DOWN;
|
||||||
|
|
||||||
|
public Orientation rotated(boolean clockwise) {
|
||||||
|
switch(this) {
|
||||||
|
case NONE -> {
|
||||||
|
return clockwise ? Orientation.RIGHT : Orientation.LEFT;
|
||||||
|
}
|
||||||
|
case RIGHT -> {
|
||||||
|
return clockwise ? Orientation.UPSIDE_DOWN : Orientation.NONE;
|
||||||
|
}
|
||||||
|
case UPSIDE_DOWN -> {
|
||||||
|
return clockwise ? Orientation.LEFT : Orientation.RIGHT;
|
||||||
|
}
|
||||||
|
case LEFT -> {
|
||||||
|
return clockwise ? Orientation.NONE : Orientation.UPSIDE_DOWN;
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return Orientation.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
public final class RotationChecker {private static final Map<Orientation, int[][]> STANDARD_WALL_KICKS = Map.of(
|
||||||
|
Orientation.NONE, new int[][] {{0,0}, {0,0}, {0,0}, {0,0}, {0,0}},
|
||||||
|
Orientation.RIGHT, new int[][] {{0,0}, {1,0}, {1,-1}, {0,2}, {1,2}},
|
||||||
|
Orientation.UPSIDE_DOWN, new int[][] {{0,0}, {0,0}, {0,0}, {0,0}, {0,0}},
|
||||||
|
Orientation.LEFT, new int[][] {{0,0}, {-1,0}, {-1,-1}, {0,2}, {-1,2}}
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final Map<Orientation, int[][]> I_WALL_KICKS = Map.of(
|
||||||
|
Orientation.NONE, new int[][] {{0,0}, {-1,0}, {2,0}, {-1,0}, {2,0}},
|
||||||
|
Orientation.RIGHT, new int[][] {{-1,0}, {0,0}, {0,0}, {0,1}, {0,-2}},
|
||||||
|
Orientation.UPSIDE_DOWN, new int[][] {{-1,1}, {1,1}, {-2,1}, {1,0}, {-2,0}},
|
||||||
|
Orientation.LEFT, new int[][] {{0,1}, {0,1}, {0,1}, {0,-1}, {0,2}}
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final Map<Orientation, int[][]> O_WALL_KICKS = Map.of(
|
||||||
|
Orientation.NONE, new int[][] {{0,0}},
|
||||||
|
Orientation.RIGHT, new int[][] {{0,-1}},
|
||||||
|
Orientation.UPSIDE_DOWN, new int[][] {{-1,-1}},
|
||||||
|
Orientation.LEFT, new int[][] {{-1,0}}
|
||||||
|
);
|
||||||
|
|
||||||
|
public static int[][] getKicksArray(Orientation from, Orientation to, Tetromino.Shape shape) {
|
||||||
|
int[][] firstOffsets = getOffsetData(from, shape);
|
||||||
|
int[][] secondOffsets = getOffsetData(to, shape);
|
||||||
|
int[][] result = new int[firstOffsets.length][2];
|
||||||
|
|
||||||
|
for(int i = 0; i < firstOffsets.length; i++) {
|
||||||
|
result[i] = subtractInt(firstOffsets[i], secondOffsets[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int[] subtractInt(int[] first, int[] second) {
|
||||||
|
return IntStream.range(0, first.length)
|
||||||
|
.map(i -> first[i] - second[i])
|
||||||
|
.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int[][] getOffsetData(Orientation orientation, Tetromino.Shape shape) {
|
||||||
|
return switch(shape) {
|
||||||
|
case J, L, S, T, Z -> STANDARD_WALL_KICKS.get(orientation);
|
||||||
|
case I -> I_WALL_KICKS.get(orientation);
|
||||||
|
case O -> O_WALL_KICKS.get(orientation);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,9 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game;
|
|||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minestom.server.MinecraftServer;
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.scoreboard.Sidebar;
|
import net.minestom.server.scoreboard.Sidebar;
|
||||||
import net.minestom.server.timer.Scheduler;
|
import net.minestom.server.timer.Task;
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -23,6 +22,8 @@ public class TetrisGame {
|
|||||||
private final Map<Button, Long> lastPresses = new HashMap<>();
|
private final Map<Button, Long> lastPresses = new HashMap<>();
|
||||||
private final List<TetrisGame> otherTetrisGames = new ArrayList<>();
|
private final List<TetrisGame> otherTetrisGames = new ArrayList<>();
|
||||||
private final Random random;
|
private final Random random;
|
||||||
|
private Task tetrominoLockTask;
|
||||||
|
private Task hardTetrominoLockTask;
|
||||||
public boolean lost = false;
|
public boolean lost = false;
|
||||||
public boolean paused = true;
|
public boolean paused = true;
|
||||||
public Tetromino currentTetromino;
|
public Tetromino currentTetromino;
|
||||||
@@ -53,25 +54,28 @@ public class TetrisGame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pressedButton(Button button) {
|
public void pressedButtonRaw(Button button) {
|
||||||
final int standardButtonDelay = 100;
|
final int standardButtonDelay = 95;
|
||||||
final int buttonDebounce = 70;
|
final int wsButtonDebounce = 70;
|
||||||
|
|
||||||
if(this.lastPresses.getOrDefault(button, 0L) >= System.currentTimeMillis() - standardButtonDelay) return;
|
if(this.lastPresses.getOrDefault(button, 0L) >= System.currentTimeMillis() - standardButtonDelay) return;
|
||||||
|
|
||||||
this.lastPresses.put(button, System.currentTimeMillis());
|
switch(button) {
|
||||||
if(button == Button.W) this.lastPresses.put(button, System.currentTimeMillis() + buttonDebounce);
|
case W -> this.lastPresses.put(button, System.currentTimeMillis() + wsButtonDebounce);
|
||||||
if(button == Button.S) this.lastPresses.put(button, System.currentTimeMillis() - buttonDebounce);
|
case S -> this.lastPresses.put(button, System.currentTimeMillis() - wsButtonDebounce);
|
||||||
|
case mouseLeft, mouseRight -> this.lastPresses.put(button, 0L);
|
||||||
|
default -> this.lastPresses.put(button, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
if(this.lost || this.paused) return;
|
if(this.lost || this.paused) return;
|
||||||
|
|
||||||
switch(button) {
|
switch(button) {
|
||||||
case A -> this.currentTetromino.moveLeft();
|
case A -> this.moveLeft();
|
||||||
case S -> this.moveDown();
|
case S -> this.moveDown();
|
||||||
case D -> this.currentTetromino.moveRight();
|
case D -> this.moveRight();
|
||||||
case W -> this.hardDrop();
|
case W -> this.hardDrop();
|
||||||
case mouseLeft -> this.currentTetromino.rotate(false);
|
case mouseLeft -> this.rotate(false);
|
||||||
case mouseRight -> this.currentTetromino.rotate(true);
|
case mouseRight -> this.rotate(true);
|
||||||
case space -> this.switchHold();
|
case space -> this.switchHold();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,8 +86,7 @@ public class TetrisGame {
|
|||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
Scheduler scheduler = MinecraftServer.getSchedulerManager();
|
this.instance.scheduler().submitTask(() -> {
|
||||||
scheduler.submitTask(() -> {
|
|
||||||
if(this.lost) return TaskSchedule.stop();
|
if(this.lost) return TaskSchedule.stop();
|
||||||
int standardTickDelay = 40;
|
int standardTickDelay = 40;
|
||||||
if(this.isFast) standardTickDelay = 20;
|
if(this.isFast) standardTickDelay = 20;
|
||||||
@@ -111,8 +114,9 @@ public class TetrisGame {
|
|||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
if(this.lost || this.paused) return;
|
if(this.lost || this.paused) return;
|
||||||
|
if(!this.currentTetromino.isGrounded()) this.stopTetrominoLockTask(true);
|
||||||
if(!this.currentTetromino.moveDown()) {
|
if(!this.currentTetromino.moveDown()) {
|
||||||
this.setActiveTetrominoDown();
|
this.scheduleTetrominoLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,33 +143,42 @@ public class TetrisGame {
|
|||||||
this.lost = true;
|
this.lost = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean moveDown() {
|
private void moveDown() {
|
||||||
if(!this.currentTetromino.moveDown()) {
|
if(!this.currentTetromino.moveDown()) {
|
||||||
this.setActiveTetrominoDown();
|
this.scheduleTetrominoLock();
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
this.score += 1;
|
this.score += 1;
|
||||||
this.updateInfo();
|
this.updateInfo();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hardDrop() {
|
private void moveLeft() {
|
||||||
|
if(this.currentTetromino.moveLeft()) this.stopTetrominoLockTask(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveRight() {
|
||||||
|
if(this.currentTetromino.moveRight()) this.stopTetrominoLockTask(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rotate(boolean clockwise) {
|
||||||
|
if(this.currentTetromino.rotate(clockwise)) this.stopTetrominoLockTask(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hardDrop() {
|
||||||
if(!this.currentTetromino.moveDown()) {
|
if(!this.currentTetromino.moveDown()) {
|
||||||
this.setActiveTetrominoDown();
|
this.lockActiveTetromino();
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
do {
|
||||||
this.score += 2;
|
this.score += 2;
|
||||||
|
} while(this.currentTetromino.moveDown());
|
||||||
this.updateInfo();
|
this.updateInfo();
|
||||||
while(this.currentTetromino.moveDown()) {
|
this.lockActiveTetromino();
|
||||||
this.score += 2;
|
|
||||||
this.updateInfo();
|
|
||||||
}
|
|
||||||
this.setActiveTetrominoDown();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean switchHold() {
|
private void switchHold() {
|
||||||
if(!this.holdPossible) return false;
|
if(!this.holdPossible) return;
|
||||||
|
this.stopTetrominoLockTask(true);
|
||||||
|
|
||||||
Tetromino newCurrentTetromino;
|
Tetromino newCurrentTetromino;
|
||||||
if(this.holdTetromino == null) {
|
if(this.holdTetromino == null) {
|
||||||
@@ -189,7 +202,6 @@ public class TetrisGame {
|
|||||||
this.holdTetromino.setPosition(this.holdPosition.add(xChange, 0, 0));
|
this.holdTetromino.setPosition(this.holdPosition.add(xChange, 0, 0));
|
||||||
this.holdTetromino.drawAsEntities();
|
this.holdTetromino.drawAsEntities();
|
||||||
this.holdPossible = false;
|
this.holdPossible = false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateNextTetrominoes() {
|
private void updateNextTetrominoes() {
|
||||||
@@ -235,7 +247,40 @@ public class TetrisGame {
|
|||||||
this.sidebar.updateLineScore("2", this.level);
|
this.sidebar.updateLineScore("2", this.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setActiveTetrominoDown() {
|
private void scheduleTetrominoLock() {
|
||||||
|
if(this.tetrominoLockTask == null || !this.tetrominoLockTask.isAlive())
|
||||||
|
this.tetrominoLockTask = this.instance.scheduler().scheduleTask(() -> {
|
||||||
|
if(this.currentTetromino.isGrounded()) {
|
||||||
|
this.lockActiveTetromino();
|
||||||
|
} else {
|
||||||
|
this.stopTetrominoLockTask(true);
|
||||||
|
}
|
||||||
|
return TaskSchedule.stop();
|
||||||
|
}, TaskSchedule.millis(500));
|
||||||
|
if(this.hardTetrominoLockTask == null || !this.hardTetrominoLockTask.isAlive())
|
||||||
|
this.hardTetrominoLockTask = this.instance.scheduler().scheduleTask(() -> {
|
||||||
|
if(this.currentTetromino.isGrounded()) {
|
||||||
|
this.lockActiveTetromino();
|
||||||
|
} else {
|
||||||
|
this.stopTetrominoLockTask(true);
|
||||||
|
}
|
||||||
|
return TaskSchedule.stop();
|
||||||
|
}, TaskSchedule.millis(6000));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopTetrominoLockTask(boolean resetHard) {
|
||||||
|
if(this.tetrominoLockTask != null) {
|
||||||
|
this.tetrominoLockTask.cancel();
|
||||||
|
this.tetrominoLockTask = null;
|
||||||
|
}
|
||||||
|
if(resetHard && this.hardTetrominoLockTask != null) {
|
||||||
|
this.hardTetrominoLockTask.cancel();
|
||||||
|
this.hardTetrominoLockTask = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lockActiveTetromino() {
|
||||||
|
this.stopTetrominoLockTask(true);
|
||||||
this.currentTetromino.removeOwnEntities();
|
this.currentTetromino.removeOwnEntities();
|
||||||
this.currentTetromino = this.nextTetrominoes.removeFirst();
|
this.currentTetromino = this.nextTetrominoes.removeFirst();
|
||||||
this.currentTetromino.remove();
|
this.currentTetromino.remove();
|
||||||
|
|||||||
@@ -8,14 +8,12 @@ import net.minestom.server.entity.metadata.other.FallingBlockMeta;
|
|||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.tag.Tag;
|
import net.minestom.server.tag.Tag;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Tetromino {
|
public class Tetromino {
|
||||||
private final static EntityType ghostEntityType = EntityType.FALLING_BLOCK;
|
private final static EntityType ghostEntityType = EntityType.FALLING_BLOCK;
|
||||||
private final static Tag<String> uuidTag = Tag.String("uuid");
|
private final static Tag<String> uuidTag = Tag.String("uuid");
|
||||||
|
private Orientation orientation = Orientation.NONE;
|
||||||
private final Shape shape;
|
private final Shape shape;
|
||||||
private final StatelessGame instance;
|
private final StatelessGame instance;
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
@@ -28,10 +26,10 @@ public class Tetromino {
|
|||||||
this.uuid = UUID.randomUUID();
|
this.uuid = UUID.randomUUID();
|
||||||
|
|
||||||
switch(this.shape) {
|
switch(this.shape) {
|
||||||
case I -> this.shapeArray = new int[][]{{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}};
|
case I -> this.shapeArray = new int[][]{{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 1, 1, 1, 1}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}};
|
||||||
case J -> this.shapeArray = new int[][]{{1, 0, 0}, {1, 1, 1}, {0, 0, 0}};
|
case J -> this.shapeArray = new int[][]{{1, 0, 0}, {1, 1, 1}, {0, 0, 0}};
|
||||||
case L -> this.shapeArray = new int[][]{{0, 0, 1}, {1, 1, 1}, {0, 0, 0}};
|
case L -> this.shapeArray = new int[][]{{0, 0, 1}, {1, 1, 1}, {0, 0, 0}};
|
||||||
case O -> this.shapeArray = new int[][]{{1, 1}, {1, 1}};
|
case O -> this.shapeArray = new int[][]{{0, 1, 1}, {0, 1, 1}, {0, 0, 0}};
|
||||||
case S -> this.shapeArray = new int[][]{{0, 1, 1}, {1, 1, 0}, {0, 0, 0}};
|
case S -> this.shapeArray = new int[][]{{0, 1, 1}, {1, 1, 0}, {0, 0, 0}};
|
||||||
case T -> this.shapeArray = new int[][]{{0, 1, 0}, {1, 1, 1}, {0, 0, 0}};
|
case T -> this.shapeArray = new int[][]{{0, 1, 0}, {1, 1, 1}, {0, 0, 0}};
|
||||||
case Z -> this.shapeArray = new int[][]{{1, 1, 0}, {0, 1, 1}, {0, 0, 0}};
|
case Z -> this.shapeArray = new int[][]{{1, 1, 0}, {0, 1, 1}, {0, 0, 0}};
|
||||||
@@ -43,12 +41,23 @@ public class Tetromino {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(Pos newPosition) {
|
public void setPosition(Pos newPosition) {
|
||||||
this.position = newPosition;
|
this.position = new Pos(newPosition.x(), newPosition.y(), newPosition.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean rotate(boolean clockwise) {
|
public boolean rotate(boolean clockwise) {
|
||||||
int[][] newShapeArray = this.getTurnedShapeArray(clockwise);
|
int[][] newShapeArray = this.getTurnedShapeArray(clockwise);
|
||||||
return this.checkCollisionAndMove(this.position, newShapeArray);
|
Orientation newOrientation = this.orientation.rotated(clockwise);
|
||||||
|
|
||||||
|
int[][] kicksArray = RotationChecker.getKicksArray(this.orientation, newOrientation, this.shape);
|
||||||
|
for(int[] k : kicksArray) {
|
||||||
|
Pos candidate = new Pos(this.position.x() + k[0], this.position.y() + k[1], this.position.z());
|
||||||
|
if(this.checkCollisionAndMove(candidate, newShapeArray)) {
|
||||||
|
this.orientation = newOrientation;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean moveDown() {
|
public boolean moveDown() {
|
||||||
@@ -73,7 +82,7 @@ public class Tetromino {
|
|||||||
public void draw(boolean withGhost) {
|
public void draw(boolean withGhost) {
|
||||||
if(withGhost) {
|
if(withGhost) {
|
||||||
Pos ghostPos = this.position;
|
Pos ghostPos = this.position;
|
||||||
while(!this.checkCollision(ghostPos.sub(0, 1, 0), this.shapeArray)) {
|
while(!this.hasCollision(ghostPos.sub(0, 1, 0), this.shapeArray)) {
|
||||||
ghostPos = ghostPos.sub(0, 1, 0);
|
ghostPos = ghostPos.sub(0, 1, 0);
|
||||||
}
|
}
|
||||||
Pos positionChange = this.position.sub(ghostPos);
|
Pos positionChange = this.position.sub(ghostPos);
|
||||||
@@ -182,7 +191,7 @@ public class Tetromino {
|
|||||||
|
|
||||||
private boolean isPartOfTetromino(Pos position) {
|
private boolean isPartOfTetromino(Pos position) {
|
||||||
return this.getBlockPositions().stream()
|
return this.getBlockPositions().stream()
|
||||||
.anyMatch(pos -> pos.equals(position));
|
.anyMatch(pos -> pos.sameBlock(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Pos> getBlockPositions() {
|
private List<Pos> getBlockPositions() {
|
||||||
@@ -198,10 +207,10 @@ public class Tetromino {
|
|||||||
for(int x = 0; x < arrayLength; x++) {
|
for(int x = 0; x < arrayLength; x++) {
|
||||||
for(int y = 0; y < arrayLength; y++) {
|
for(int y = 0; y < arrayLength; y++) {
|
||||||
if(shapeArray[arrayLength - 1 - y][x] == 1) {
|
if(shapeArray[arrayLength - 1 - y][x] == 1) {
|
||||||
switch(this.shape) {
|
if(Objects.requireNonNull(this.shape) == Shape.I) {
|
||||||
case I -> returnList.add(position.add(x - 1, y - 2, 0));
|
returnList.add(position.add(x - 2, y - 2, 0));
|
||||||
case O -> returnList.add(position.add(x, y, 0));
|
} else {
|
||||||
default -> returnList.add(position.add(x - 1, y - 1, 0));
|
returnList.add(position.add(x - 1, y - 1, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +219,7 @@ public class Tetromino {
|
|||||||
return returnList;
|
return returnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkCollision(Pos newPosition, int[][] newShapeArray) {
|
private boolean hasCollision(Pos newPosition, int[][] newShapeArray) {
|
||||||
List<Pos> newBlockPositions = this.getBlockPositions(newPosition, newShapeArray);
|
List<Pos> newBlockPositions = this.getBlockPositions(newPosition, newShapeArray);
|
||||||
|
|
||||||
for(Pos pos : newBlockPositions) {
|
for(Pos pos : newBlockPositions) {
|
||||||
@@ -222,16 +231,18 @@ public class Tetromino {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isGrounded() {
|
||||||
|
return this.hasCollision(this.position.sub(0, 1, 0), this.shapeArray);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean checkCollisionAndMove(Pos newPosition, int[][] newShapeArray) {
|
private boolean checkCollisionAndMove(Pos newPosition, int[][] newShapeArray) {
|
||||||
if(!this.checkCollision(newPosition, newShapeArray)) {
|
if(this.hasCollision(newPosition, newShapeArray)) return false;
|
||||||
this.remove();
|
this.remove();
|
||||||
this.shapeArray = Arrays.stream(newShapeArray).map(int[]::clone).toArray(int[][]::new);
|
this.shapeArray = Arrays.stream(newShapeArray).map(int[]::clone).toArray(int[][]::new);
|
||||||
this.setPosition(newPosition);
|
this.setPosition(newPosition);
|
||||||
this.draw();
|
this.draw();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Shape {
|
public enum Shape {
|
||||||
I,
|
I,
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ public abstract class Score {
|
|||||||
throw new NotImplementedException("This Score type is not able to process points");
|
throw new NotImplementedException("This Score type is not able to process points");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insertMultiple(Set<Player> p) {
|
||||||
|
p.forEach(player -> this.insertResultProcessor(player, () -> {}));
|
||||||
|
this.insertResultImplementation(p);
|
||||||
|
}
|
||||||
|
|
||||||
public void insertResult(Player p) {
|
public void insertResult(Player p) {
|
||||||
this.insertResultProcessor(p, () -> this.insertResultImplementation(Set.of(p)));
|
this.insertResultProcessor(p, () -> this.insertResultImplementation(Set.of(p)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,15 @@ public class Position {
|
|||||||
public static List<Block> blocksBelowPlayer(Instance instance, Player p) {
|
public static List<Block> blocksBelowPlayer(Instance instance, Player p) {
|
||||||
Point playerPos = p.getPosition();
|
Point playerPos = p.getPosition();
|
||||||
List<Block> blocks = new ArrayList<>();
|
List<Block> blocks = new ArrayList<>();
|
||||||
GeneratorUtils.foreachXZ(playerPos.sub(0.5, 1, 0.5), playerPos.add(0.5, -1, 0.5), point -> {
|
GeneratorUtils.foreachXZ(
|
||||||
blocks.add(instance.getBlock(point));
|
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();
|
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,12 @@ startSpeed;Start Speed;Startgeschwindigkeit
|
|||||||
ns:game_BoatRace#;;
|
ns:game_BoatRace#;;
|
||||||
name;Boatrace;Bootrennen
|
name;Boatrace;Bootrennen
|
||||||
description;;
|
description;;
|
||||||
|
;;
|
||||||
|
ns:game_Pillars#;;
|
||||||
|
name;Pillars;Pillars
|
||||||
|
description;Build yourself up with your random blocks to reach your opponents and push them down!;Baue dich mit deinen zufälligen Blöcken zu deinen Gegnern und schupse sie runter!
|
||||||
|
;;
|
||||||
|
ns:game_BlockBattle#;;
|
||||||
|
name;Block Battle;Block Kampf
|
||||||
|
description;The team that fills the center with their color first wins!;Das Team, welches als erstes die Mitte mit seiner Farbe gefüllt hat, gewinnt!
|
||||||
|
itemCount;Block Count;Block Anzahl
|
||||||
|
Reference in New Issue
Block a user