Advertisement
jayhillx

binding effect

May 17th, 2023
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. package com.lifebinding.effect;
  2.  
  3. import com.lifebinding.capability.binding.BindingCapability;
  4. import com.lifebinding.capability.data.EntityData;
  5. import net.minecraft.entity.LivingEntity;
  6. import net.minecraft.nbt.CompoundNBT;
  7. import net.minecraft.potion.Effect;
  8. import net.minecraft.potion.EffectType;
  9. import net.minecraft.world.dimension.DimensionType;
  10.  
  11. public class BindingEffect extends Effect {
  12.  
  13.     public BindingEffect() {
  14.         super(EffectType.HARMFUL, 13315412);
  15.     }
  16.  
  17.     public void performEffect(LivingEntity entity, int amplifier) {
  18.  
  19.         if (entity.isPotionActive(this)) {
  20.             for (LivingEntity nearbyEntity : entity.world.getEntitiesWithinAABB(LivingEntity.class, entity.getBoundingBox().grow(2.5D))) {
  21.  
  22.                 if (entity.isPotionActive(this) && nearbyEntity.isPotionActive(this)) {
  23.                     if (entity.getServer() != null) {
  24.                         entity.getServer().getWorld(DimensionType.OVERWORLD).getCapability(BindingCapability.BOUND).ifPresent((bound) -> {
  25.  
  26.                             if (nearbyEntity != entity) {
  27.                                 bound.getEntities().computeIfAbsent(entity.getUniqueID(), (orNewId) -> {
  28.                                     EntityData data = new EntityData(new CompoundNBT());
  29.                                     data.setId(entity.getUniqueID().toString());
  30.                                     data.setName(entity.getName().getString());
  31.  
  32.                                     data.getBoundPlayer().setName(nearbyEntity.getName().getString());
  33.                                     data.getBoundPlayer().setId(nearbyEntity.getUniqueID());
  34.                                     return data;
  35.                                 });
  36.  
  37.                                 bound.getEntities().computeIfAbsent(nearbyEntity.getUniqueID(), (orNewId) -> {
  38.                                     EntityData data = new EntityData(new CompoundNBT());
  39.                                     data.setId(nearbyEntity.getUniqueID().toString());
  40.                                     data.setName(nearbyEntity.getName().getString());
  41.  
  42.                                     data.getBoundPlayer().setName(entity.getName().getString());
  43.                                     data.getBoundPlayer().setId(entity.getUniqueID());
  44.                                     return data;
  45.                                 });
  46.  
  47.                                 entity.removePotionEffect(this);
  48.                                 nearbyEntity.removePotionEffect(this);
  49.                             }
  50.                         });
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.     }
  56.  
  57.     public boolean isReady(int duration, int amplifier) {
  58.         return true;
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement