How to put block based on ItemStack?

Discussion in 'Plugin Development' started by mogadanez, Dec 5, 2016.

Thread Status:
Not open for further replies.
  1. now I use follow snippet to
    Code:
     
    public void onPlayerUse(PlayerInteractEvent event){
      if ( !event.hasBlock() && event.getClickedBlock()== null || event.getBlockFace() != BlockFace.UP   ) {
                    return;
                }
    
                World world = event.getClickedBlock().getLocation().getWorld();
                Location loc = event.getClickedBlock().getLocation();
    
                Block blockToChange = world.getBlockAt(loc.getBlockX(), loc.getBlockY()+1, loc.getBlockZ()); // get the block with the current coordinates
                blockToChange.setType(Material.SKULL);
    
    
    now I want use <Edit by Moderator: Redacted not allowed paid resource url> and customize created blocks

    Code:
     
    ItemStack item = new SkullMaker().withSkinUrl(PLAY_URL).build();
    
    how can I put this item in yhe world by coordinates?
     
    Last edited by a moderator: Nov 25, 2017
  2. Offline

    Zombie_Striker

    @mogadanez
    There is no way to directly turn an itemstack into a block. You will need to take the util, decompile it, find the method for creating the itemstack. Copy that method to your plugin and make it apply the changes to a block.
     
  3. @mogadanez
    I think the only way to place the block from an ItemStack without manually carrying over all the values is to make the player place it using the ItemStack.placeItem() (nms) method. If you just want to deal with one type of block, I'd suggest doing it manually, as this NMS method gets quite messy.
     
  4. What you mean by "manually"?
     
  5. Online

    timtower Administrator Administrator Moderator

    @mogadanez Get and set the block type, data en skull owner by hand instead of 1 simple method.
     
  6. Offline

    renaud444

    I'm pretty sure there are different ids for the skull item and skull block.
     
Thread Status:
Not open for further replies.

Share This Page