Does anyone know how to lock a BlockDisplay to the grid? I created a command to spawn a block display however I want it to be even with the grid. How it currently is:
Code: private BlockDisplay spawnHologram(Location spawnLoc) { return (BlockDisplay) spawnLoc.getWorld().spawnEntity(spawnLoc, EntityType.BLOCK_DISPLAY); } This is the code I use
idk if i understood correctly. Code: @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player player) { BlockDisplay block = (BlockDisplay) player.getLocation().getWorld().spawnEntity(player.getLocation(), EntityType.BLOCK_DISPLAY); block.setRotation(0f,0f); block.setBlock(Bukkit.createBlockData(Material.DIAMOND_BLOCK)); block.setCustomName("totally real diamond block"); block.setCustomNameVisible(true); } return true; }
block.setRotation(0f, 0f) is exactly what I needed. Thank you, that worked. For those looking to replicate, I was able to snap it to the grid by getting the location of the block a player is looking at and using that as the reference location for the BlockDisplay spawn location. A block's location is locked to the grid, but not a player's location so a block location is more reliable. So: Code: Location spawnLoc = player.getTargetBlockExact(5).getLocation().add(0, 1, 0); hologram = spawnLoc.getWorld().spawnEntity(spawnLoc, EntityType.BLOCK_DISPLAY); hologram.setRotation(0f,0f);