diff --git a/src/main/java/me/ellieis/Sabotage/game/custom/SabotageBlocks.java b/src/main/java/me/ellieis/Sabotage/game/custom/SabotageBlocks.java index e6e9cd1..d3d26c6 100644 --- a/src/main/java/me/ellieis/Sabotage/game/custom/SabotageBlocks.java +++ b/src/main/java/me/ellieis/Sabotage/game/custom/SabotageBlocks.java @@ -24,7 +24,7 @@ public class SabotageBlocks { - public static final Block SABOTAGE_CHEST = new SabotageChest(AbstractBlock.Settings.copy(Blocks.CHEST).dropsNothing(), Blocks.CHEST); + public static final SabotageChest SABOTAGE_CHEST = new SabotageChest(AbstractBlock.Settings.copy(Blocks.CHEST).dropsNothing(), Blocks.CHEST); public static final BlockEntityType SABOTAGE_CHEST_ENTITY = FabricBlockEntityTypeBuilder.create(SabotageChestBlockEntity::new, SABOTAGE_CHEST).build(null); public static void register() { @@ -44,14 +44,15 @@ private static ActionResult onBlockUse(PlayerEntity plr, World world, Hand hand, break; } } - if (isInGame) { - if (blockHitResult != null) { - Block block = world.getBlockState(blockHitResult.getBlockPos()).getBlock(); - if (block instanceof SabotageChest) { + + if (blockHitResult != null) { + Block block = world.getBlockState(blockHitResult.getBlockPos()).getBlock(); + if (block instanceof SabotageChest) { + if (isInGame) { plr.playSound(SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 1, 1.2f); world.setBlockState(blockHitResult.getBlockPos(), Blocks.AIR.getDefaultState()); - return ActionResult.FAIL; } + return ActionResult.FAIL; } } return ActionResult.PASS; diff --git a/src/main/java/me/ellieis/Sabotage/game/custom/blocks/SabotageChest.java b/src/main/java/me/ellieis/Sabotage/game/custom/blocks/SabotageChest.java index 68dbf14..ab9f516 100644 --- a/src/main/java/me/ellieis/Sabotage/game/custom/blocks/SabotageChest.java +++ b/src/main/java/me/ellieis/Sabotage/game/custom/blocks/SabotageChest.java @@ -24,6 +24,15 @@ public Block getPolymerBlock(BlockState state) { return this.virtualBlock; } + public Block getPolymerBlock() { + return this.virtualBlock; + } + + @Override + public BlockState getPolymerBlockState(BlockState state) { + return this.virtualBlock.getStateWithProperties(state); + } + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { return new SabotageChestBlockEntity(pos, state); } diff --git a/src/main/java/me/ellieis/Sabotage/game/map/SabotageMap.java b/src/main/java/me/ellieis/Sabotage/game/map/SabotageMap.java index 2adb5a9..d2f5514 100644 --- a/src/main/java/me/ellieis/Sabotage/game/map/SabotageMap.java +++ b/src/main/java/me/ellieis/Sabotage/game/map/SabotageMap.java @@ -3,15 +3,18 @@ import me.ellieis.Sabotage.game.config.SabotageConfig; import me.ellieis.Sabotage.game.custom.blocks.SabotageChest; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.Properties; import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; import net.minecraft.world.gen.chunk.ChunkGenerator; -import xyz.nucleoid.map_templates.BlockBounds; import xyz.nucleoid.map_templates.MapTemplate; import xyz.nucleoid.map_templates.TemplateRegion; import xyz.nucleoid.plasmid.game.GameOpenException; @@ -21,46 +24,53 @@ import java.util.*; import static me.ellieis.Sabotage.game.custom.SabotageBlocks.SABOTAGE_CHEST; +record ChestInfo(BlockPos pos, Direction direction) { +} public class SabotageMap { private final SabotageConfig config; private final MapTemplate template; private final List spawns; + private final List chestSpawns; private final Map playerSpawnPos = new HashMap<>(); + private ServerWorld world; public SabotageMap(MapTemplate template, SabotageConfig config) { this.config = config; this.template = template; this.spawns = template.getMetadata().getRegions("spawn").toList(); + this.chestSpawns = new ArrayList<>(); if (this.spawns.isEmpty()) { throw new GameOpenException(Text.literal("Failed to load spawns")); } // generate chest positions from placed SabotageChests template.getBounds().forEach(blockPos -> { - Block block = template.getBlockState(blockPos).getBlock(); + BlockState blockState = template.getBlockState(blockPos); + Block block = blockState.getBlock(); if (block instanceof SabotageChest) { - template.getMetadata().addRegion("chest", BlockBounds.ofBlock(blockPos)); + // note to self: make your positions immutable in forEach loops.. + chestSpawns.add(new ChestInfo(blockPos.toImmutable(), blockState.get(Properties.HORIZONTAL_FACING))); template.setBlockState(blockPos, Blocks.AIR.getDefaultState()); } }); } + public void setWorld(ServerWorld world) { + this.world = world; + } public void generateChests() { - // Have to make a new ArrayList to make it mutable - List chestSpawns = new ArrayList<>(template.getMetadata().getRegions("chest").toList()); Collections.shuffle(chestSpawns); // Make sure that the chest count doesn't go over the amount of chest positions int chestCount = Math.min(config.chestCount(), chestSpawns.size()); - for (TemplateRegion region : chestSpawns) { + for (ChestInfo chestInfo : chestSpawns) { if (chestCount > 0) { chestCount--; - template.setBlockState(region.getBounds().min(), SABOTAGE_CHEST.getDefaultState()); + world.setBlockState(chestInfo.pos(), SABOTAGE_CHEST.getDefaultState().with(Properties.HORIZONTAL_FACING, chestInfo.direction())); } else { break; } } - // to-do: generate chests from added chest regions } public MapTemplate getTemplate() { return this.template; diff --git a/src/main/java/me/ellieis/Sabotage/game/phase/SabotageActive.java b/src/main/java/me/ellieis/Sabotage/game/phase/SabotageActive.java index 126fbea..5019e6e 100644 --- a/src/main/java/me/ellieis/Sabotage/game/phase/SabotageActive.java +++ b/src/main/java/me/ellieis/Sabotage/game/phase/SabotageActive.java @@ -309,6 +309,7 @@ public static void Open(GameSpace gameSpace, ServerWorld world, SabotageMap map, activity.listen(GamePlayerEvents.REMOVE, game::onPlayerRemove); activity.listen(GamePlayerEvents.OFFER, game::onOffer); activity.listen(GameActivityEvents.DESTROY, game::onDestroy); + map.setWorld(world); map.generateChests(); PlayerSet plrs = game.gameSpace.getPlayers(); plrs.showTitle(Text.literal(Integer.toString(game.config.countdownTime())).formatted(Formatting.GOLD), 20); diff --git a/src/main/resources/data/sabotage/map_templates/testmap.nbt b/src/main/resources/data/sabotage/map_templates/testmap.nbt index 1a406b8..81e5261 100644 Binary files a/src/main/resources/data/sabotage/map_templates/testmap.nbt and b/src/main/resources/data/sabotage/map_templates/testmap.nbt differ