diff --git a/src/main/java/io/github/haykam821/minefield/game/map/MinefieldMap.java b/src/main/java/io/github/haykam821/minefield/game/map/MinefieldMap.java index 5999ff4..8bdd6c6 100644 --- a/src/main/java/io/github/haykam821/minefield/game/map/MinefieldMap.java +++ b/src/main/java/io/github/haykam821/minefield/game/map/MinefieldMap.java @@ -1,8 +1,12 @@ package io.github.haykam821.minefield.game.map; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import net.minecraft.world.gen.chunk.ChunkGenerator; import xyz.nucleoid.map_templates.BlockBounds; @@ -10,18 +14,60 @@ import xyz.nucleoid.plasmid.game.world.generator.TemplateChunkGenerator; public class MinefieldMap { + private static final BlockState AIR = Blocks.AIR.getDefaultState(); + private final MapTemplate template; + private final BlockBounds start; + private final Box spawnBox; private final Vec3d spawnPos; private final BlockBounds end; private final Vec3d guideTextPos; public MinefieldMap(MapTemplate template, BlockBounds start, BlockBounds end, Vec3d guideTextPos) { this.template = template; + this.start = start; + this.spawnBox = new Box(start.min().add(0, 1, 0), start.max().add(1, 3, 1)); this.spawnPos = start.centerBottom().add(0, 1, 0); this.end = end; this.guideTextPos = guideTextPos; } + public void removeBarrierPerimeter(ServerWorld world) { + BlockPos.Mutable pos = new BlockPos.Mutable(); + + pos.setY(this.start.min().getY() + 2); + + int barrierMinX = this.start.min().getX() - 1; + int barrierMaxX = this.start.max().getX() + 1; + + int barrierMinZ = this.start.min().getZ() - 1; + int barrierMaxZ = this.start.max().getZ() + 1; + + for (int x = barrierMinX; x <= barrierMaxX; x += 1) { + pos.setX(x); + + pos.setZ(barrierMinZ); + world.setBlockState(pos, AIR); + + pos.setZ(barrierMaxZ); + world.setBlockState(pos, AIR); + } + + for (int z = barrierMinZ + 1; z <= barrierMaxZ - 1; z += 1) { + pos.setZ(z); + + pos.setX(barrierMinX); + world.setBlockState(pos, AIR); + + pos.setX(barrierMaxX); + world.setBlockState(pos, AIR); + } + } + + public boolean isInSpawn(ServerPlayerEntity player) { + return this.spawnBox.contains(player.getPos()); + } + public Vec3d getSpawnPos() { return this.spawnPos; } diff --git a/src/main/java/io/github/haykam821/minefield/game/map/MinefieldMapBuilder.java b/src/main/java/io/github/haykam821/minefield/game/map/MinefieldMapBuilder.java index 19ec5b7..4f048c9 100644 --- a/src/main/java/io/github/haykam821/minefield/game/map/MinefieldMapBuilder.java +++ b/src/main/java/io/github/haykam821/minefield/game/map/MinefieldMapBuilder.java @@ -15,6 +15,7 @@ public class MinefieldMapBuilder { private static final BlockState MINES_FLOOR = Blocks.SANDSTONE.getDefaultState(); private static final BlockState MINE = Blocks.STONE_PRESSURE_PLATE.getDefaultState(); private static final BlockState END_FLOOR = Blocks.EMERALD_BLOCK.getDefaultState(); + private static final BlockState BARRIER = Blocks.BARRIER.getDefaultState(); private final MinefieldConfig config; @@ -22,6 +23,38 @@ public MinefieldMapBuilder(MinefieldConfig config) { this.config = config; } + private void placeBarrierPerimeter(MapTemplate template, BlockBounds start) { + BlockPos.Mutable pos = new BlockPos.Mutable(); + + pos.setY(start.min().getY() + 2); + + int barrierMinX = start.min().getX() - 1; + int barrierMaxX = start.max().getX() + 1; + + int barrierMinZ = start.min().getZ() - 1; + int barrierMaxZ = start.max().getZ() + 1; + + for (int x = barrierMinX; x <= barrierMaxX; x += 1) { + pos.setX(x); + + pos.setZ(barrierMinZ); + template.setBlockState(pos, BARRIER); + + pos.setZ(barrierMaxZ); + template.setBlockState(pos, BARRIER); + } + + for (int z = barrierMinZ + 1; z <= barrierMaxZ - 1; z += 1) { + pos.setZ(z); + + pos.setX(barrierMinX); + template.setBlockState(pos, BARRIER); + + pos.setX(barrierMaxX); + template.setBlockState(pos, BARRIER); + } + } + public MinefieldMap create() { MapTemplate template = MapTemplate.createEmpty(); MinefieldMapConfig mapConfig = this.config.getMapConfig(); @@ -51,6 +84,8 @@ public MinefieldMap create() { } } + this.placeBarrierPerimeter(template, start); + return new MinefieldMap(template, start, end, guideTextPos); } } \ No newline at end of file diff --git a/src/main/java/io/github/haykam821/minefield/game/phase/MinefieldActivePhase.java b/src/main/java/io/github/haykam821/minefield/game/phase/MinefieldActivePhase.java index 0e3bbe5..5380ecd 100644 --- a/src/main/java/io/github/haykam821/minefield/game/phase/MinefieldActivePhase.java +++ b/src/main/java/io/github/haykam821/minefield/game/phase/MinefieldActivePhase.java @@ -101,12 +101,13 @@ private void enable() { for (ServerPlayerEntity player : this.players) { player.changeGameMode(GameMode.ADVENTURE); - this.map.spawn(player, this.world); if (!this.singleplayer && this.statistics != null) { this.statistics.forPlayer(player).increment(StatisticKeys.GAMES_PLAYED, 1); } } + + this.map.removeBarrierPerimeter(this.world); } private void tick() { diff --git a/src/main/java/io/github/haykam821/minefield/game/phase/MinefieldWaitingPhase.java b/src/main/java/io/github/haykam821/minefield/game/phase/MinefieldWaitingPhase.java index 998fe5a..f810db6 100644 --- a/src/main/java/io/github/haykam821/minefield/game/phase/MinefieldWaitingPhase.java +++ b/src/main/java/io/github/haykam821/minefield/game/phase/MinefieldWaitingPhase.java @@ -80,7 +80,7 @@ private void enable() { private void tick() { for (ServerPlayerEntity player : this.gameSpace.getPlayers()) { - if (this.map.isBelowPlatform(player)) { + if (!this.map.isInSpawn(player)) { this.map.spawn(player, this.world); } }