Compare commits
3 Commits
develop-ja
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 73ab137ae4 | |||
| 9a9e646288 | |||
| 728dc92fc8 |
@@ -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.score.PointsWinScore;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
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.PlayerMoveEvent;
|
||||
import net.minestom.server.event.player.PlayerTickEvent;
|
||||
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.Material;
|
||||
import net.minestom.server.potion.Potion;
|
||||
import net.minestom.server.potion.PotionEffect;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -78,18 +80,24 @@ class Tetris extends StatelessGame {
|
||||
p.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||
private void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
|
||||
event.setItemUseTime(0);
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseRight);
|
||||
}
|
||||
|
||||
private void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseLeft);
|
||||
}
|
||||
|
||||
private void onPlayerTick(PlayerTickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Pos currentPosition = event.getNewPosition();
|
||||
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||
|
||||
if(tetrisGame == null) {
|
||||
event.setCancelled(true);
|
||||
if(tetrisGame == null) return;
|
||||
if(tetrisGame.lost) {
|
||||
this.letPlayerLoose(player);
|
||||
return;
|
||||
}
|
||||
if(tetrisGame.lost) return;
|
||||
|
||||
if(player.getGameMode() == GameMode.SPECTATOR) return;
|
||||
|
||||
if(player.inputs().forward()) tetrisGame.pressedButton(TetrisGame.Button.W);
|
||||
@@ -97,26 +105,6 @@ class Tetris extends StatelessGame {
|
||||
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) {
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseRight);
|
||||
}
|
||||
|
||||
protected void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseLeft);
|
||||
}
|
||||
|
||||
protected void onPlayerTick(PlayerTickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||
if(tetrisGame == null) return;
|
||||
if(tetrisGame.lost && player.getGameMode() != GameMode.SPECTATOR) {
|
||||
this.letPlayerLoose(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void letPlayerLoose(Player player) {
|
||||
@@ -124,6 +112,7 @@ class Tetris extends StatelessGame {
|
||||
if(!this.getScore().hasResult(player)) {
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.setInvisible(true);
|
||||
if(player.getVehicle() != null) player.getVehicle().removePassenger(player);
|
||||
this.getScore().insertResult(player, tetrisGame.getScore());
|
||||
}
|
||||
|
||||
@@ -160,7 +149,16 @@ class Tetris extends StatelessGame {
|
||||
|
||||
p.teleport(tetrisGame.getPlayerSpawnPosition());
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user