Beacon range Effect?

Discussion in 'Spigot Plugin Help' started by ShameMate, Jun 26, 2016.

  1. So i am looking to make a Beacon give you the affects at all Y ranges. So if i was to place the Beacon at Y:0 it would affect the player all 256 blocks up. Is this possible? Been looking thought the internet and have found nothing.
     
  2. I don't thinks so, because the beacon range is a build in minecraft feature. You can't even change the range in coded plugins. Eventually in spigot.yml?
     
  3. Interesting question about beacons... i took a closer look into it and will share my results.

    The following might not be your solution, but it can help other developers, who where also searching for it:

    I found the original place in vanilla Sourcecode [1.8.8] (NMS), where the Beacon effects where triggered and will add some explaining comments to it:
    Code (Java):
    /*
    * ORIGINAL net.minecraft.server.v1_8_R3.TileEntityBeacon#A()
    */

    private void A() {
      if ((this.i) && (this.j > 0) && (!world.isClientSide) && (this.k > 0)) {

        // d0 is the affected radius, calculated by the beacon level (j)
        // -> radius = 10 times the level plus 10
        double d0 = this.j * 10 + 10;

        // b0 is the status effect strength, either 0 (strength = I) or 1 (strength = II)
        // it's affected by the beacon level (j) and whatever "k" and "l" is
        byte b0 = 0;
        if ((this.j >= 4) && (this.k == l)) {
          b0 = 1;
        }

        int i = position.getX();
        int j = position.getY();
        int k = position.getZ();

        // attention! Now the affected range gets calculated!
        AxisAlignedBB axisalignedbb = new AxisAlignedBB(i, j, k, i + 1, j + 1, k + 1).grow(d0, d0, d0).a(0.0D, world.getHeight(), 0.0D);
        // AxisAlignedBB(i, j, k, i + 1, j + 1, k + 1) is the area containing the beacon block only
        // #grow(d0, d0, d0) extends the area within ALL directions (x+, x-, y+, y-, z+, z-) by d0 blocks (d0 explained above)
        // #a(0.0D, world.getHeight(), 0.0D) extends the area 256 blocks up
        // now we got our final effect range

        // this list now contains all human entities within this range
        List list = world.a(EntityHuman.class, axisalignedbb);

        // now the effect will be applied on all these entities
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
          EntityHuman entityhuman = (EntityHuman)iterator.next();
          entityhuman.addEffect(new MobEffect(this.k, 180, b0, true, true));
        }
        if ((this.j >= 4) && (this.k != l) && (l > 0)) {
          iterator = list.iterator();
          while (iterator.hasNext()) {
            EntityHuman entityhuman = (EntityHuman)iterator.next();
            entityhuman.addEffect(new MobEffect(l, 180, 0, true, true));
          }
        }
      }
    }
    Maybe this will be helpful for someone...

    As you see now the affect range is hard-coded into vanilla minecraft sourcecode and can't be changed (at least not without modding the server). Even hooking into NMS and changing some private values won't be sucessfull, because there is no class field you could modify to affect the range vertically only.

    The best alternative would be to find out if you could hook anywhere into the calling method and run a additional, self-implemented status effect add method.

    However this does not solve your problem. I don't know any plugin, that implements this feature, i just tried to offer a way how it could be implemented.

    EDIT: Update: i figured out, when this method "A" gets called. it comes down to "net.minecraft.server.v1_8_R3.MinecraftServer#B()". The task to pocess all beacons is stored somehow within "net.minecraft.server.v1_8_R3.MinecraftServer.p". However i didn't get it managed yet to get a real instance of this field, it's always an empty list somehow... An alternative way, how "A" might get called is somehow within NetworkManager...
     
    #3 Michel_0, Jun 26, 2016
    Last edited: Jun 26, 2016