1.14.4 Editing the rays of an explosion

Discussion in 'Spigot Plugin Development' started by Developer932048, Feb 18, 2020.

  1. Hi, I need help with trying to make certain entities act like blocks when an explosion ignites (block explosion damage so other entities behind it don't take as much damage). However I think I need to access the rays of an explosion in order to do so, except I don't know how to do that :[ If you have any other ideas that don't include rays or if you know how to get the rays of explosion please tell me. Info on explosions: https://minecraft.gamepedia.com/Explosion

    also if I cant access the rays is it possible to achieve this effect by adding copies of instances of blocks (their locations are changed to the entity's location) to the blocklist of an explosion so that the game calculates those.

    (idk how to change the location off a block instance though)
  2. i don't know if i get it right, you want to do something like this?
  3. Yes, thats exactly what I want.
  4. How bout hooking into the EntityExplodeEvent, than cancelling that and after that run your own explosion code?

    Or (idea 2) hook into the entity damage event if damaged by explosion see if player center to explosion is clear. If not decrease the damage. You might not only want to check from player center, but also from the head and feet pos.
  5. If I were making my own explosion is it possible to generate rays in Minecraft? Also for the 2nd idea I think you misunderstood me, I don't mean to decrease damage by radius but by something blocking the explosion e.g. an iron golem absorbs all damage from an explosion and you don't get damaged as badly if your behind the golem.
  6. No i got you right with my second idea :p on damage draw a line to explosion center and check if something is blocking.

    To the "own" explosion: you would probably have to take a look on how minecraft does it, but if you want to damage blocks and keep it simple you'll want to go with my second idea.
    If you dont need to damage/destroy blocks you could just find all entities in radius and than draw a line between them and the explosion center.

    To draw a line / cast a ray do the following:
    Take the vector of the explosion center minus the vector of the ray end point (e.g. entity position + 1 on y axis).
    Save the length of that vector to a local variable.
    Normalize that vector with the normalize method.
    Now create a for loop. Start with float i = 0 while i < the length you stored previously. Increase i by some small value 0.2 should be small enough, but if you want to be more precise use a lower value.
    In the loop multiply the vector by i and store the result to a new variable. Check if a block or entity is at that position. If it's an entity check that it's not the player itself. The new vector is the relative position. To turn it into world position set the new vector to itself plus the ray end point from before.
    To check if a position is inside of an entity you'll have to Google a bit. Also make sure the hit entity is not the player itself.
  7. Thanks!