Solved Lock BlockDisplay To Grid

Discussion in 'Plugin Development' started by Smeary_Subset, Aug 3, 2024.

Thread Status:
Not open for further replies.
  1. Offline

    Smeary_Subset

    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:
    BlockDisplay.png
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Smeary_Subset

    Code:
        private BlockDisplay spawnHologram(Location spawnLoc) {
            return (BlockDisplay) spawnLoc.getWorld().spawnEntity(spawnLoc, EntityType.BLOCK_DISPLAY);
        }
    This is the code I use
     
  4. Offline

    timtower Administrator Administrator Moderator

    What is spawnloc?
     
  5. Offline

    Smeary_Subset

    player.getLocation() of the player who runs the command
     
  6. Offline

    DopeBrot

    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;
        }
     

    Attached Files:

  7. Offline

    Smeary_Subset


    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);
     
    AustinAdkins and DopeBrot like this.
Thread Status:
Not open for further replies.

Share This Page