From 69f8a05bed95472b9c4656b5ec2cba9f8d9c7549 Mon Sep 17 00:00:00 2001 From: lars Date: Fri, 5 Jul 2024 20:01:43 +0200 Subject: [PATCH] tested making block displays smaller --- src/main/java/commands/ChessCommand.java | 51 ++++++++++++++---------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/java/commands/ChessCommand.java b/src/main/java/commands/ChessCommand.java index 94318b7..1c36cfe 100644 --- a/src/main/java/commands/ChessCommand.java +++ b/src/main/java/commands/ChessCommand.java @@ -6,42 +6,51 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.BlockDisplay; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.util.Transformation; import org.jetbrains.annotations.NotNull; public class ChessCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if(sender instanceof Player p) { - Location playerLocation = p.getLocation(); + Location playerLocation = p.getLocation().toBlockLocation(); + double scale = (double) 1/16; - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 16; i++) { int finalI = i+1; - for (int j = 0; j < 8; j++) { + for (int j = 0; j < 16; j++) { int finalJ = j+1; - p.getWorld().spawn( - new Location(p.getWorld(), - playerLocation.x()+i, - playerLocation.y(), - playerLocation.z()+j), - BlockDisplay.class, blockDisplay -> { - if(finalI % 2 == 0 && finalJ % 2 == 0) { - blockDisplay.setBlock(Material.BLACK_CONCRETE.createBlockData()); - } else if(finalI % 2 != 0 && finalJ % 2 != 0) { - blockDisplay.setBlock(Material.BLACK_CONCRETE.createBlockData()); - } else { - blockDisplay.setBlock(Material.WHITE_CONCRETE.createBlockData()); - } - blockDisplay.setDisplayHeight(0.5f); - blockDisplay.setDisplayWidth(0.5f); - } + + double blockPositionX = playerLocation.x()+i*scale; + double blockPositionY = playerLocation.y(); + double blockPositionZ = playerLocation.z()+j*scale; + + BlockDisplay bd; + bd = (BlockDisplay) p.getWorld().spawnEntity( + new Location(p.getWorld(), blockPositionX, blockPositionY, blockPositionZ), + EntityType.BLOCK_DISPLAY ); + + if(finalI % 2 == 0 && finalJ % 2 == 0) { + bd.setBlock(Material.BLACK_CONCRETE.createBlockData()); + } else if(finalI % 2 != 0 && finalJ % 2 != 0) { + bd.setBlock(Material.BLACK_CONCRETE.createBlockData()); + } else { + bd.setBlock(Material.WHITE_CONCRETE.createBlockData()); + } + + Transformation transform = bd.getTransformation(); + transform.getScale().set(scale); + bd.setTransformation(transform); + } } } else { - return(true); + sender.sendMessage("This command is only for real Players!"); } - return true; + return(true); } }