Bounding Box of Armor Stands

Discussion in 'Spigot Plugin Development' started by 97WaterPolo, May 13, 2015.

Thread Status:
Not open for further replies.
  1. How would I go about removing the Bounding Box of an Armor Stand. I am currently using one as a hologram of sorts, but the issue is the player who tries to hit through the hologram ends up hitting the invisible armor stand. Is there a way to allow the hit to just pass through the armor stand like an arrow would a player on the same team? I was thinking if you remove the bounding box on the Armor Stand, the player then won't be able to hit it at all, but is there another way of doing it?

    tl;dr: How do you prevent a player hitting an invisible Armor Stand while hitting an enemy behind it.
     
  2. clip

    Benefactor

    I am pretty sure you could achieve this using packets. Specifically
    PacketPlayOutSpawnEntityLiving
     
    #2 clip, May 13, 2015
    Last edited: May 13, 2015
  3. Wouldn't the bounding box still be there? Or is that handled through the server?
     
  4. clip

    Benefactor

    I am pretty sure that it would not be recognized by the server. @inventivetalent created an Api to send holograms which utilizes sending packets. You could try testing by writing a simple plugin to spawn a hologram using his API if you don't want to write something up yourself to test it, or maybe he could give a bit of information on this as he has a bit of experience working with armor stands using packets.
     
    • Informative Informative x 1
  5. [​IMG]

    I tried spawning in the Armor Stand with the name and that worked pretty well, but for the client who sees it, they can't hit through it, yet the one who doesn't see it can still hit through it.

    So I can NOT hit SourCreamKitty, but SourCreamKitty can still hit me from the exact same spot. Is there anyway at all around this?
     
  6. In the underlying NMS entity class, there is a AABoundingBox field that is used by the server for any collisions/physics. You may be able to use reflection to replace this with a box that has no volume, however you will need to implement the entity in question and overload multiple methods in regards to physics (that way you can avoid odd things with the entity falling through the ground and what not).

    Any other method of removing server-side collision will probably require similar hacky methods.

    Now in your instance, we're talking about entity interaction packets being send to the server, which are calculated client-sided, thus making the above process redundant (bounding boxes on the client side). I don't think there's any way around this.

    EDIT: Actually, I'm wrong. There is a way, if you want to ignore the interaction event and do a lot of math to see if the player would have been interacting with other adjacent entities given that the armour stand didn't exist. I actually wrote a post on the process a while back, you can see it here:

    https://bukkit.org/threads/advanced...yer-is-looking-at-and-nearby-entities.283824/
     
    #6 Jarcode, May 13, 2015
    Last edited: May 13, 2015
    • Informative Informative x 1
  7. So in reality, there is no way to have a hologram between two player's and allow them to hit at each other?
     
  8. See my edit. If you want to go through a process of either doing the collision yourself (line w/ AABox intersection), or using approximation (see my post), this is entirely possible, you just end up cancelling the interaction or damage event and trying to find another target by calculating what the player is looking at on the server side.
     
  9. Thanks for that, by chance would the following process work for damaging the player on the other side of the armor stand?

    Player attacker,victim;

    if attacker's location is less than 4 blocks from the victim
    if isLookingAt(victim, attacker.getEyeLocation)
    victim.damage(event'sdamage)
     
  10. That should work, given you are using the isLookingAt method I had in that gist.
     
  11. There's an NBT tag called "Marker" for armorstands, which should make them invisible and shrink the hitbox. At Minecraft Wiki they say that it's only for 1.8.1pre and up, so you should use the 1.8.3 version of spigot for this. I haven't tested it yet myself, but i think it should be worth a try.
     
    • Like Like x 1
    • Agree Agree x 1
  12. Code (Text):
            net.minecraft.server.v1_8_R2.Entity nmsEntity = ((CraftEntity) as).getHandle();
            NBTTagCompound tag = nmsEntity.getNBTTag();
            if (tag == null) {
                tag = new NBTTagCompound();
            }
            nmsEntity.c(tag);
            tag.setInt("Marker", 1);
            tag.setInt("Invisible", 1);
            nmsEntity.f(tag);
    Tried that, it indeed makes the entity invisible, but I still have the issue where I can't hit through the entity :L Any other possible ideas?
     
  13. You could create a class which extends AxisAlignedBB with the following values:
    Code (Text):
    public class CustomBoundingBox extends AxisAlignedBB {
      public CustomBoundingBox() {
        super(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
      }

      public double a() {
        return 0.0D;
      }

      public double a(AxisAlignedBB arg0, double arg1) {
        return 0.0D;
      }
      public AxisAlignedBB a(AxisAlignedBB arg0) {
        return this;
      }

      public AxisAlignedBB a(double arg0, double arg1, double arg2) {
        return this;
      }

      public MovingObjectPosition a(Vec3D arg0, Vec3D arg1) {
        return super.a(arg0, arg1);
      }

      public boolean a(Vec3D arg0) {
        return false;
      }

      public double b(AxisAlignedBB arg0, double arg1){
        return 0.0D;
      }

      public boolean b(AxisAlignedBB arg0) {
        return false;
      }

      public double c(AxisAlignedBB arg0, double arg1) {
        return 0.0D;
      }

      public AxisAlignedBB c(double arg0, double arg1, double arg2) {
        return this;
      }

      public AxisAlignedBB grow(double arg0, double arg1, double arg2) {
        return this;
      }

      public AxisAlignedBB shrink(double arg0, double arg1, double arg2) {
        return this;
      }
    }
    Then, create a method in your class which extends EntityArmorStand:
    Code (Text):
    public void setBoundingBox(AxisAlignedBB boundingBox) {
        super.a(boundingBox);
    }
    Now all you have to do is put this in the constructor of your ArmorStand:
    Code (Text):
    setBoundingBox(new CustomBoundingBox());
     
    • Useful Useful x 1
  14. Well i just tried the "Marker" tag, and it works perfectly fine for me:

    Code (Text):
                ArmorStand armorstand = (ArmorStand) player.getWorld().spawnEntity(player.getLocation(), EntityType.ARMOR_STAND);
             
                EntityArmorStand nmsarmorstand = ((CraftArmorStand) armorstand).getHandle();
             
                NBTTagCompound compoundTag = new NBTTagCompound();
                nmsarmorstand.c(compoundTag);
                compoundTag.setBoolean("Marker", true);
                compoundTag.setString("CustomName", "Testificate");
                compoundTag.setBoolean("CustomNameVisible", true);
                compoundTag.setBoolean("Invisible", true);
                nmsarmorstand.f(compoundTag);
    This shows the name tag of the armorstand on the ground though, you might have to adjust the location where you want to spawn it:
    [​IMG]

    Edit: I searched a bit in nms code, and i found this:
    [​IMG]
    So calling this method might be a bit useless in 1.8.3. You should get the NBTTagCompound with Entity#c(NBTTagCompound tag).
     
    #14 Querz, May 13, 2015
    Last edited: May 13, 2015
  15. I did this on 1.8.3, I wasn't sure if my NBT methods were correct, I will test this a bit more when I get home, maybe I made a stupid mistake

    EDIT: Also, what were those pictures? I don't see anything there?
     
    #15 97WaterPolo, May 13, 2015
    Last edited: May 14, 2015
    • Optimistic Optimistic x 1
Thread Status:
Not open for further replies.