Advertisement
jayhillx

binding effect

Jan 29th, 2024
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. public void performEffect(LivingEntity entity, int amplifier) {
  2.         entity.level().getEntities(entity, entity.getBoundingBox().inflate(2.0D)).stream().filter(e -> e instanceof Player).map(e -> (Player) e).filter(nearbyPlayer -> nearbyPlayer.hasEffect(MobEffects.ABSORPTION)).forEach(nearbyPlayer -> {
  3.             Set<Player> playersSet = new HashSet<>(List.of(nearbyPlayer, (Player) entity));
  4.  
  5.             if (entity.getServer() != null) {
  6.                 ServerLevel overworld = entity.getServer().getLevel(Level.OVERWORLD);
  7.  
  8.                 overworld.getCapability(BindingCapability.BOUND).ifPresent(bound -> {
  9.                     playersSet.forEach(player -> {
  10.                         bound.getPlayers().computeIfAbsent(player.getUniqueID(), orNewId -> {
  11.                             PlayerData data = new PlayerData(new CompoundNBT());
  12.                             data.setId(player.getUniqueID().toString());
  13.                             data.setName(player.getName().getString());
  14.  
  15.                             data.getBoundPlayer().setName(playersSet.stream().filter(p -> p != player).findFirst().orElse(player).getName().getString());
  16.                             data.getBoundPlayer().setId(playersSet.stream().filter(p -> p != player).findFirst().orElse(player).getUniqueID());
  17.                             return data;
  18.                         });
  19.                     });
  20.  
  21.                     playersSet.forEach(player -> {
  22.                         player.removePotionEffect(this);
  23.  
  24.                         if (!player.world.isRemote) {
  25.                             player.world.playSound(null, player.getPosition(), SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.HOSTILE, 0.5F, 1.0F);
  26.                             overworld.spawnParticle(ParticleTypes.EXPLOSION, player.posX, player.posY, player.posZ, 24, 2.0D, 2.0D, 2.0D, 0.0D);
  27.                         }
  28.                     });
  29.                 });
  30.             }
  31.         });
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement