Refactored Generation and class structure
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace.ElytraRaceFactory;
|
||||
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.acidRain.AcidRainFactory;
|
||||
@@ -21,8 +23,10 @@ public enum GameList {
|
||||
BEDWARS(new BedwarsFactory(), GameType.PROTOTYPE),
|
||||
BACKROOMS(new BackroomsFactory(), GameType.PROTOTYPE),
|
||||
TNTRUN(new TntRunFactory(), GameType.OTHER),
|
||||
BLIZZARD(new AcidRainFactory(), GameType.PVE),
|
||||
SPLEEF(new SpleefFactory(), GameType.PVP);
|
||||
ACIDRAIN(new AcidRainFactory(), GameType.PVE),
|
||||
ELYTRARACE(new ElytraRaceFactory(), GameType.PVP),
|
||||
SPLEEF(new SpleefFactory(), GameType.PVP),
|
||||
BOWSPLEEF(new BowSpleefFactory(), GameType.PVP);
|
||||
|
||||
private final GameFactory factory;
|
||||
private final GameType type;
|
||||
|
||||
@@ -5,9 +5,9 @@ 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.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.util.RangeMap;
|
||||
import eu.mhsl.minenet.minigames.util.NumberUtil;
|
||||
import eu.mhsl.minenet.minigames.util.WeatherUtils;
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
@@ -75,7 +75,7 @@ public class AcidRain extends StatelessGame {
|
||||
generatePlatform(generationOffset);
|
||||
|
||||
if(!isRunning) return TaskSchedule.stop();
|
||||
return TaskSchedule.millis(RangeMap.map(50 - difficulty, 0, 50, 100, 1000));
|
||||
return TaskSchedule.millis((long) NumberUtil.map(50 - difficulty, 0, 50, 100, 1000));
|
||||
}, ExecutionType.ASYNC);
|
||||
|
||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.util.GeneratorUtils;
|
||||
import io.github.bloepiloepi.pvp.events.ProjectileHitEvent;
|
||||
import io.github.bloepiloepi.pvp.projectile.CustomEntityProjectile;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.*;
|
||||
import net.minestom.server.entity.metadata.arrow.ArrowMeta;
|
||||
import net.minestom.server.entity.metadata.other.PrimedTntMeta;
|
||||
import net.minestom.server.event.EventListener;
|
||||
import net.minestom.server.event.item.ItemUpdateStateEvent;
|
||||
import net.minestom.server.event.player.PlayerItemAnimationEvent;
|
||||
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.Enchantment;
|
||||
import net.minestom.server.item.ItemHideFlag;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.tag.Tag;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class BowSpleef extends StatelessGame {
|
||||
private static final Tag<Long> CHARGE_BOW_SINCE = Tag.Long("CHARGE_BOW_SINCE");
|
||||
private static final Tag<Boolean> ARROW_FIRST_HIT = Tag.Boolean("ARROW_ALREADY_LIT");
|
||||
private final int radius = 30;
|
||||
private final int totalElevation = 50;
|
||||
public BowSpleef() {
|
||||
super(Dimension.OVERWORLD.DIMENSION, "bowSpleef", new LastWinsScore());
|
||||
|
||||
eventNode().addListener(
|
||||
EventListener
|
||||
.builder(PlayerItemAnimationEvent.class)
|
||||
.handler(playerItemAnimationEvent -> playerItemAnimationEvent.getPlayer().setTag(CHARGE_BOW_SINCE, System.currentTimeMillis()))
|
||||
.filter(playerItemAnimationEvent -> playerItemAnimationEvent.getItemAnimationType() == PlayerItemAnimationEvent.ItemAnimationType.BOW)
|
||||
.build()
|
||||
);
|
||||
|
||||
eventNode().addListener(
|
||||
EventListener
|
||||
.builder(ItemUpdateStateEvent.class)
|
||||
.handler(event -> {
|
||||
final Player player = event.getPlayer();
|
||||
final double chargedFor = (System.currentTimeMillis() - player.getTag(CHARGE_BOW_SINCE)) / 1000D;
|
||||
final double power = MathUtils.clamp((chargedFor * chargedFor + 2 * chargedFor) / 2D, 0, 1);
|
||||
|
||||
if (power > 0.2) {
|
||||
final CustomEntityProjectile projectile = new CustomEntityProjectile(player, EntityType.ARROW, true);
|
||||
final ArrowMeta meta = (ArrowMeta) projectile.getEntityMeta();
|
||||
meta.setCritical(power >= 0.9);
|
||||
projectile.scheduleRemove(Duration.of(100, TimeUnit.SERVER_TICK));
|
||||
projectile.setOnFire(true);
|
||||
|
||||
final Pos position = player.getPosition().add(0, player.getEyeHeight(), 0);
|
||||
projectile.setInstance(Objects.requireNonNull(player.getInstance()), position);
|
||||
|
||||
final Vec direction = projectile.getPosition().direction();
|
||||
projectile.shoot(position.add(direction).sub(0, 0.2, 0), power * 3, 1.0);
|
||||
projectile.setTag(ARROW_FIRST_HIT, true);
|
||||
}
|
||||
})
|
||||
.filter(itemUpdateStateEvent -> itemUpdateStateEvent.getItemStack().material() == Material.BOW)
|
||||
.build()
|
||||
);
|
||||
|
||||
eventNode().addListener(
|
||||
EventListener
|
||||
.builder(ProjectileHitEvent.ProjectileBlockHitEvent.class)
|
||||
.handler(projectileBlockHitEvent -> {
|
||||
CustomEntityProjectile projectile = projectileBlockHitEvent.getEntity();
|
||||
if(!projectile.getTag(ARROW_FIRST_HIT)) {
|
||||
projectile.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
float radius = 0.5F;
|
||||
Point arrowPos = projectile.getPosition();
|
||||
GeneratorUtils.foreachXZ(arrowPos.add(radius), arrowPos.sub(radius), point -> {
|
||||
Point location = point.add(projectile.getVelocity().mul(0.04)).withY(totalElevation);
|
||||
if(!getBlock(location).isAir()) {
|
||||
setBlock(location, Block.AIR);
|
||||
|
||||
Entity fallingTnt = new Entity(EntityType.TNT);
|
||||
PrimedTntMeta fallingTntMeta = (PrimedTntMeta) fallingTnt.getEntityMeta();
|
||||
fallingTntMeta.setFuseTime(20);
|
||||
fallingTnt.setInstance(this, location);
|
||||
fallingTnt.setVelocity(new Vec(0, 3, 0));
|
||||
}
|
||||
});
|
||||
|
||||
projectile.setTag(ARROW_FIRST_HIT, false);
|
||||
})
|
||||
.build()
|
||||
);
|
||||
|
||||
eventNode().addListener(
|
||||
EventListener
|
||||
.builder(ProjectileHitEvent.ProjectileEntityHitEvent.class)
|
||||
.handler(projectileEntityHitEvent -> projectileEntityHitEvent.setCancelled(true))
|
||||
.build()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for(int z = -radius; z <= radius; z++) {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
|
||||
batch.setBlock(x, totalElevation, z, Block.TNT);
|
||||
}
|
||||
}
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
getPlayers().forEach(player -> {
|
||||
player.getInventory().setItemStack(
|
||||
0,
|
||||
ItemStack
|
||||
.builder(Material.BOW)
|
||||
.displayName(TranslatedComponent.byId("bow").getAssembled(player))
|
||||
.meta(builder -> builder.enchantment(Enchantment.FLAME, (short) 1).build())
|
||||
.meta(builder -> builder.hideFlag(ItemHideFlag.HIDE_ENCHANTS))
|
||||
.build()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
if(playerMoveEvent.getNewPosition().y() < totalElevation) {
|
||||
getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, totalElevation + 1, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
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.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BowSpleefFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.BOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatelessGame manufacture(Map<String, Option<?>> configuration) throws Exception {
|
||||
return new BowSpleef();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import io.github.bloepiloepi.pvp.config.AttackConfig;
|
||||
import io.github.bloepiloepi.pvp.config.DamageConfig;
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.message.Countdown;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.message.type.TitleMessage;
|
||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.*;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.featureEnriched.ValeGenerator;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.PlaneTerrainGenerator;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.*;
|
||||
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 net.minestom.server.network.packet.server.play.ParticlePacket;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.particle.ParticleCreator;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
public class ElytraRace extends StatelessGame {
|
||||
private final ValeGenerator vale = new ValeGenerator();
|
||||
|
||||
private final int gameHeight = 0;
|
||||
private final int ringSpacing = 100;
|
||||
private final int ringCount;
|
||||
|
||||
private final Material boostMaterial = Material.FIREWORK_ROCKET;
|
||||
private final Material resetMaterial = Material.RED_DYE;
|
||||
private final int boostMultiplier = 50;
|
||||
private final Material ringMaterial = Material.GOLD_BLOCK;
|
||||
private int generatedUntil = 0;
|
||||
|
||||
private record CheckPointData(int currentCheckpoint, int nextCheckpoint) {
|
||||
public CheckPointData next(int spacing) {
|
||||
return new CheckPointData(nextCheckpoint, nextCheckpoint + spacing);
|
||||
}
|
||||
}
|
||||
private final Map<Player, CheckPointData> playerCheckpoints = new HashMap<>();
|
||||
|
||||
public ElytraRace(int ringCount) {
|
||||
super(Dimension.OVERWORLD.DIMENSION, "ElytraRace", new FirstWinsScore());
|
||||
|
||||
this.ringCount = ringCount;
|
||||
|
||||
setGenerator(vale);
|
||||
vale.setCalculateSeaLevel(point -> -55);
|
||||
vale.setXShiftMultiplier(integer -> NumberUtil.map(integer, 50, 500, 0, 1));
|
||||
vale.addMixIn(new PlaneTerrainGenerator(gameHeight, Block.BARRIER));
|
||||
|
||||
eventNode().addListener(PlayerUseItemEvent.class, playerUseItemEvent -> {
|
||||
Player player = playerUseItemEvent.getPlayer();
|
||||
Material usedMaterial = playerUseItemEvent.getItemStack().material();
|
||||
|
||||
if(usedMaterial.equals(boostMaterial)) {
|
||||
if(!player.isFlyingWithElytra()) return;
|
||||
|
||||
boost(player);
|
||||
InventoryUtil.removeItemFromPlayer(player, boostMaterial, 1);
|
||||
} else if(usedMaterial.equals(resetMaterial)) {
|
||||
toCheckpoint(player);
|
||||
InventoryUtil.removeItemFromPlayer(player, resetMaterial, 1);
|
||||
}
|
||||
});
|
||||
|
||||
eventNode().addListener(PlayerStopFlyingWithElytraEvent.class, playerStopFlyingWithElytraEvent -> {
|
||||
Player player = playerStopFlyingWithElytraEvent.getPlayer();
|
||||
if(Position.blocksBelowPlayer(this, player).contains(ringMaterial.block())) {
|
||||
player.setFlyingWithElytra(true);
|
||||
boost(player);
|
||||
} else {
|
||||
toCheckpoint(player);
|
||||
// getScore().insertResult(playerStopFlyingWithElytraEvent.getPlayer());
|
||||
// playerStopFlyingWithElytraEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
});
|
||||
|
||||
eventNode().addListener(PlayerStartFlyingWithElytraEvent.class, playerStartFlyingWithElytraEvent -> {
|
||||
if(!isRunning) {
|
||||
playerStartFlyingWithElytraEvent.getPlayer().setFlyingWithElytra(false);
|
||||
return;
|
||||
}
|
||||
|
||||
boost(playerStartFlyingWithElytraEvent.getPlayer());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
Point spawnpoint = new Pos(vale.getXShiftAtZ(0), -46, 0);
|
||||
GeneratorUtils.iterateArea(spawnpoint.sub(2, 0, 2), spawnpoint.add(2, 0, 2), point -> {
|
||||
setBlock(point, BlockPallet.STREET.rnd());
|
||||
});
|
||||
|
||||
generateRing(ringSpacing);
|
||||
generateRing(ringSpacing * 2);
|
||||
callback.complete(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
getPlayers().forEach(player -> {
|
||||
player.getInventory().setChestplate(ItemStack.of(Material.ELYTRA));
|
||||
for(int i = 0; i < 3; i++) {
|
||||
player.getInventory().setItemStack(i, ItemStack.builder(boostMaterial).displayName(TranslatedComponent.byId("boost").getAssembled(player)).build());
|
||||
}
|
||||
addResetItemToPlayer(player);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
Player player = playerMoveEvent.getPlayer();
|
||||
Point newPos = playerMoveEvent.getNewPosition();
|
||||
|
||||
playerCheckpoints.putIfAbsent(player, new CheckPointData(ringSpacing, ringSpacing * 2));
|
||||
|
||||
if(newPos.z() > generatedUntil - ringSpacing) {
|
||||
generateRing(generatedUntil + ringSpacing);
|
||||
}
|
||||
|
||||
if(newPos.z() > playerCheckpoints.get(player).nextCheckpoint) {
|
||||
playerCheckpoints.put(player, playerCheckpoints.get(player).next(ringSpacing));
|
||||
boost(player);
|
||||
}
|
||||
|
||||
if(newPos.y() > gameHeight - 5) {
|
||||
Point particlePoint = newPos.withY(gameHeight);
|
||||
ParticlePacket particle = ParticleCreator.createParticlePacket(
|
||||
Particle.WAX_ON,
|
||||
particlePoint.blockX(),
|
||||
particlePoint.blockY(),
|
||||
particlePoint.withZ(z -> z+10).blockZ(),
|
||||
20,
|
||||
0,
|
||||
30,
|
||||
Math.toIntExact((long) NumberUtil.map(newPos.y(), gameHeight - 5, gameHeight, 50, 500))
|
||||
);
|
||||
player.sendPacket(particle);
|
||||
}
|
||||
|
||||
if(getBlock(player.getPosition()).equals(Block.WATER)) {
|
||||
toCheckpoint(player);
|
||||
}
|
||||
|
||||
if(newPos.z() > ringCount * ringSpacing) {
|
||||
getScore().insertResult(player);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(vale.getXShiftAtZ(0), -45, 0);
|
||||
}
|
||||
|
||||
private void addResetItemToPlayer(Player p) {
|
||||
p.getInventory().setItemStack(8, ItemStack.builder(resetMaterial).displayName(TranslatedComponent.byId("reset").getAssembled(p)).build());
|
||||
}
|
||||
|
||||
private Point getRingPositionAtZ(int z) {
|
||||
return new Pos(vale.getXShiftAtZ(z), -45, z);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> generateRing(int zPos) {
|
||||
if(zPos > ringCount * ringSpacing) return null;
|
||||
boolean isLast = (zPos == ringCount * ringSpacing);
|
||||
|
||||
generatedUntil = zPos;
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
|
||||
Point ringPos = getRingPositionAtZ(zPos);
|
||||
GeneratorUtils.iterateArea(
|
||||
ringPos.sub(100, 0, 0).withY(getDimensionType().getMinY()),
|
||||
ringPos.add(100, 0, 0).withY(gameHeight),
|
||||
point -> batch.setBlock(point, Block.BARRIER)
|
||||
);
|
||||
GeneratorUtils.iterateArea(
|
||||
ringPos.sub(3, 3, 0),
|
||||
ringPos.add(3, 3, 0),
|
||||
point -> batch.setBlock(point, isLast ? Block.DIAMOND_BLOCK : ringMaterial.block())
|
||||
);
|
||||
GeneratorUtils.iterateArea(
|
||||
ringPos.sub(2, 2, 0),
|
||||
ringPos.add(2, 2, 0),
|
||||
point -> batch.setBlock(point, Block.AIR)
|
||||
);
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
||||
return null;
|
||||
}
|
||||
|
||||
private void boost(Player player) {
|
||||
player.playSound(Sound.sound(SoundEvent.ENTITY_FIREWORK_ROCKET_LAUNCH, Sound.Source.VOICE, 1f, 1f));
|
||||
|
||||
Vec playerVelocity = player.getPosition().direction();
|
||||
player.setVelocity(
|
||||
player.getVelocity().add(playerVelocity.mul(boostMultiplier))
|
||||
.withY(playerVelocity.withY(v -> v * boostMultiplier).y())
|
||||
);
|
||||
}
|
||||
|
||||
private void toCheckpoint(Player p) {
|
||||
Point checkpointPos = getRingPositionAtZ(playerCheckpoints.get(p).currentCheckpoint);
|
||||
p.setVelocity(Vec.ZERO);
|
||||
p.setFlyingWithElytra(false);
|
||||
p.teleport(Pos.fromPoint(checkpointPos).add(0.5, 0, 0.5));
|
||||
|
||||
p.setFlying(true);
|
||||
p.setFlyingSpeed(0);
|
||||
|
||||
new Countdown(TitleMessage.class)
|
||||
.countdown(
|
||||
Audience.audience(p),
|
||||
3,
|
||||
countdownModifier ->
|
||||
countdownModifier.message = new TitleMessage(
|
||||
Duration.ofMillis(300),
|
||||
Duration.ofMillis(700)
|
||||
)
|
||||
.subtitle(
|
||||
subtitleMessage ->
|
||||
subtitleMessage
|
||||
.appendStatic(Component.text("Launch in ", NamedTextColor.DARK_GREEN))
|
||||
.appendStatic(Component.text(countdownModifier.timeLeft, NamedTextColor.GREEN))
|
||||
.appendStatic(Component.text(" seconds", NamedTextColor.DARK_GREEN))
|
||||
)
|
||||
).thenRun(() -> {
|
||||
p.setFlying(false);
|
||||
p.setFlyingSpeed(1);
|
||||
p.setFlyingWithElytra(true);
|
||||
boost(p);
|
||||
addResetItemToPlayer(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
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.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ElytraRaceFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.ELYTRA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("ringCount", Material.DIAMOND_BLOCK, TranslatedComponent.byId("ringCount"), 5, 10, 20, 30, 40, 50));
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatelessGame manufacture(Map<String, Option<?>> configuration) throws Exception {
|
||||
return new ElytraRace(configuration.get("ringCount").getAsInt());
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,17 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.message.type.ActionBarMessage;
|
||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.util.CommonProperties;
|
||||
import eu.mhsl.minenet.minigames.util.Intersect;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.SquarePlateTerrainGenerator;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
@@ -36,7 +34,7 @@ class Minerun extends StatelessGame {
|
||||
|
||||
public Minerun(int width, int length, int minePercentage) {
|
||||
super(Dimension.THE_END.DIMENSION, "Minerun", new FirstWinsScore());
|
||||
setGenerator(new SquarePlateTerrainGenerator(width, length + preRun + afterFinishLine).setPlateHeight(50));
|
||||
setGenerator(new SquarePlateTerrainGenerator(width, length + preRun + afterFinishLine).setPlateHeight(50).setGenerateBorders(true));
|
||||
|
||||
this.width = width;
|
||||
this.length = length;
|
||||
@@ -83,28 +81,19 @@ class Minerun extends StatelessGame {
|
||||
Player p = playerMoveEvent.getPlayer();
|
||||
Pos middle = playerMoveEvent.getNewPosition();
|
||||
|
||||
if(middle.x() < 0 || middle.x() > width) { //player cannot go sidewards
|
||||
if(isBeforeBeginning && middle.z() > preRun+0.5) { //player cannot go forward before the game start
|
||||
playerMoveEvent.setCancelled(true);
|
||||
new ActionBarMessage().appendStatic(Component.text("Please stay in line!", NamedTextColor.RED)).send(p);
|
||||
}
|
||||
|
||||
if(!isRunning && middle.z() > preRun+0.5) { //player cannot go forward before the game start
|
||||
playerMoveEvent.setCancelled(true);
|
||||
}
|
||||
|
||||
if(middle.z() < preRun + length + afterMines && getScore().hasResult(p)) { // player cannot go back after winning
|
||||
playerMoveEvent.setCancelled(true);
|
||||
new ActionBarMessage().appendStatic(Component.text("You cannot go back on the Field!", NamedTextColor.RED)).send(p);
|
||||
}
|
||||
|
||||
if(Intersect.withPressurePlate(this, BlockPallet.PRESSURE_PLATES, middle)) { //Player died
|
||||
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.PLAYER, 1f, 1f));
|
||||
p.setPose(Entity.Pose.DYING);
|
||||
p.teleport(new Pos(p.getPosition().x(), getSpawn().y(), getSpawn().z()));
|
||||
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.PLAYER, 1f, 1f));
|
||||
}
|
||||
|
||||
if(middle.z() > preRun + length + afterMines) { // Player finished
|
||||
getScore().insertResult(p);
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
|
||||
@@ -6,7 +6,7 @@ import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.util.CommonProperties;
|
||||
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.SquarePlateTerrainGenerator;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
|
||||
@@ -75,7 +75,7 @@ public class Room extends MineNetInstance implements Spawnable {
|
||||
construct();
|
||||
setOwner(owner);
|
||||
this.gameSelector = new GameSelector();
|
||||
this.gameSelector.setInstance(this, new Pos(0.5, 16, 9.5));
|
||||
this.gameSelector.setInstance(this, new Pos(0.5, 50, 19.5));
|
||||
}
|
||||
|
||||
protected Room() {
|
||||
@@ -141,6 +141,6 @@ public class Room extends MineNetInstance implements Spawnable {
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0.5, 16, 0.5);
|
||||
return new Pos(0.5, 50, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user