Solved How to prevent a witherskull interacting with an entity so it keeps on flying

Discussion in 'Spigot Plugin Development' started by Dramatically, Jan 11, 2020.

Thread Status:
Not open for further replies.
  1. Title explains it, I am trying to shoot a witherskull at the direction I am facing and if I face down it explodes on me and I cannot adjust the position as then it could clip through walls and blocks
     
  2. if you are facing down, simply prohibit the shooting of a wither skull?
    What would the expected behavior be? If you are looking down; you are most likely looking at a solid block where the skull would explode...
     
    • Agree Agree x 1
  3. You could change the spawning position to not be directly on the player
     
  4. Where would I move it since the witherskull must be fired from the player, the current code I am using is
    Code (Text):

    Location ahead = player.getEyeLocation().clone().add(player.getEyeLocation().getDirection().multiply(3));
    if (ahead.getBlock().getType() != Material.AIR) {
        ahead = player.getEyeLocation().clone();
    }
    ahead.setY(player.getLocation().getY());

    RayTrace rayTrace = new RayTrace(player.getEyeLocation().toVector(),ahead.toVector());
    ArrayList<Vector> positions = rayTrace.traverse(10,0.01);
    for(int i = 0; i < positions.size();i++){
        Location position = positions.get(i).toLocation(player.getWorld());
        Block block = player.getWorld().getBlockAt(position);

        if(block != null && block.getType() != Material.AIR && rayTrace.intersects(new BoundingBox(block),10,0.01)){
            ahead = player.getEyeLocation().clone();
            break;
        }
    }
     
    RayTracing and BoundingBox is from a public resource on spigot that I added so the skulls do not go through blocks
     
  5. I think it's quite expected for the wither skull to blow up the ground beneath the player if the player is looking at the ground. You could just not fire it if the player is looking at a block below them, but that's your choice :p
    Currently 1.8.8 on SpigotMC is not a supported version as well, as stated directly from md_5
     
  6. There are still popular 1.8 servers but okay, I will leave it be.
     
  7. From a quick look at EntityWitherSkull it looks like EntityWitherSkull#a(MovingObjectPosition) handles collisions with entities, so your best bet might be to spawn in your own EntityWitherSkull and override that method and add your own logic so it doesn't explode. I tested this on 1.14.4, I don't know if this method has the same name or even exists on 1.8 though.
     
  8. How would I do that, haven't made custom non player entities in a long time
     
    #9 Dramatically, Jan 11, 2020
    Last edited: Jan 11, 2020
  9. No offense, but that is a terrible way to test for ray-box intersection. I don't even know why it's still a thing on that one raytracing guide on this site.

    This should help you. It's way more efficient i.e. way faster and way more accurate. https://gist.github.com/aadnk/7123926
     
  10. set a minimum pitch so that even if the player is looking down itll go forward? but if theyre looking up itll go up?
     
  11. That actually helped so thanks, anyways thread solved by cancelling entitydamage from the witherskull which had the desired metadata
     
Thread Status:
Not open for further replies.