[Util] Making FallingBlocks doing damage on fall

Discussion in 'Resources' started by ArthurMaker, Jun 21, 2014.

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


    I was playing around with some packets and NMS stuff to make an API weeks ago, and then I found how to make fallingblocks doing damage on fall just using reflection. It just do damage ON FALL (if you want to make a falling block act like a projectile, you have to use runnables and other stuff).

    1. public void setFallingBlockDamage(FallingBlock block, float mindamage, int maxdamage){
    2. EntityFallingBlock efb = ((CraftFallingSand)block).getHandle();
    3. try{
    4. Field f = EntityFallingBlock.class.getDeclaredField("hurtEntities");
    5. f.setAccessible(true);
    6. f.setBoolean(efb, true);
    7. f.setAccessible(false);
    8. f = EntityFallingBlock.class.getDeclaredField("fallHurtAmount");
    9. f.setAccessible(true);
    10. f.setFloat(efb, mindamage);
    11. f.setAccessible(false);
    12. f = EntityFallingBlock.class.getDeclaredField("fallHurtMax");
    13. f.setAccessible(true);
    14. f.setInt(efb, maxdamage);
    15. f.setAccessible(false);
    16. }catch (Exception e){
    17. e.printStackTrace();
    18. }
    19. }

    Default values:
    - mindamage = 2.0F
    - maxdamage = 40;
  2. Offline


    Don't work
  3. Offline


    Umm, you're going to have to be specific one what the damage is
  4. Offline


    This is much easier to do with the "EntityChangeBlockEvent"...
  5. Not only that - but that also prevents future errors since CraftBukkit can re-factor variable names whenever they want, and may need to change stuff if Minecraft's internal code changes a lot (such as 1.8).

    Edit: As a wise man once said (yesterday + Comphenix):

    Phasesaber likes this.
Thread Status:
Not open for further replies.

Share This Page