Advertisement
MrDj200

TileAttractor

Sep 18th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. package me.mrdj.attractor.tiles;
  2.  
  3. import java.util.List;
  4. import me.mrdj.attractor.utils.MiscStuff;
  5. import net.minecraft.entity.EntityLivingBase;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.tileentity.TileEntity;
  8. import net.minecraft.util.ITickable;
  9. import net.minecraft.util.math.AxisAlignedBB;
  10.  
  11. /**
  12.  *
  13.  * @author Dj
  14.  */
  15. public class TileAttractor extends TileEntity implements ITickable
  16. {
  17.     int counter = 0;
  18.            
  19.     @Override
  20.     public void update()
  21.     {        
  22.         if(counter == 10)
  23.         {
  24.            List<EntityLivingBase> list = world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(getPos().add(-5, -5, -5), getPos().add(5, 5, 5)));
  25.            counter = 0;
  26.            if(list.isEmpty())
  27.            {
  28.                return;
  29.            }
  30.            for( EntityLivingBase e : list)
  31.            {
  32.                attract(e);
  33.            }    
  34.         }else{
  35.             counter++;
  36.         }
  37.     }
  38.    
  39.     private void attract(EntityLivingBase entity)
  40.     {
  41.         //  Check if the Entity is a player
  42.         if(entity instanceof EntityPlayer)
  43.         {
  44.             return;
  45.             //  Cancel the action when its a player
  46.         }
  47.        
  48.         MiscStuff.setEntityMotionToBlock(entity, this.getPos(), 0.25F);
  49.     }
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement