1.17.x Spawn Falling Anvil Entity

Discussion in 'Spigot Plugin Development' started by UberSuperBoss, Jul 15, 2021.

  1. Hello I have a few questions.

    1. How would I create a falling anvil entity.
    2. How would I change the amount of damage it does.
    3. How would I make it so players cannot take the anvil once it has fallen.
     
  2. 1. you summon a falling sand with anvil properties at the specified coordinates.
    2 & 3. you want to make a listener for the damage a player/entity takes, check if its an anvil that has damaged the player/entity then set the damage to either 0 or whatever amount
     
  3. Yes, I've tried to spawn a falling block however could you explain how to do that and make it an anvil? Thanks.
     
  4. You'll wanna get the world the player is in

    For Example:
    Code (Java):
    public void onEvent(Event e) {

      World world = Bukkit.getWorld("world"); //Get the world you want to spawn the entity in

      world.spawnEntity(Location, EntityType.<Type>);
    }
    EDIT: I am unsure if this will work in newer versions, but you can use:
    world.spawnFallingBlock(Location, Material) as well
     
  5. Thank you! However world.spawnFallingBlock() has 3 possible types of parameters. If I try spawnFallingBlock(Location, Material, byte) I'm not sure what byte means.
     
  6. According to the JavaDocs, world.spawnFallingBlock(Location, Material, byte) is deprecated and shouldn't be used.
    Instead use spawnFallingBlock(Location, BlockData).
     
  7. Yeah I stated that I wasn't sure if it was still... "Applicable" but hey ho
     
  8. Is it possible to change the amount of damage that the anvil does without checking to see if someone is damaged by the anvil?

    Thanks
     
  9. Probably not without NMS. Using events would be the best way to do it.
     
  10. As @UberSuperBoss states above, unless you wanna dive into NMS, you cant change the damage of an anvil until it has hit the Player/Entity