simple-tech

Minecraft: Better than Adventure! mod that adds simple blocks to automate tasks
git clone git://memoryshards.xyz/simple-tech.git
Log | Files | Refs | README | LICENSE

TileEntityFan.java (2716B)


      1 package ambos.simpletech.block.entity;
      2 
      3 import net.minecraft.core.block.entity.TileEntity;
      4 import net.minecraft.core.entity.Entity;
      5 import net.minecraft.core.entity.EntityItem;
      6 import net.minecraft.core.util.phys.AABB;
      7 import net.minecraft.core.world.World;
      8 
      9 import java.util.List;
     10 
     11 import ambos.simpletech.SimpleTech;
     12 
     13 public class TileEntityFan extends TileEntity {
     14     private final int range;
     15 
     16     public TileEntityFan(int range) {
     17         this.range = range;
     18     }
     19 
     20     public TileEntityFan() {
     21         // Always define the default constructor when working with tile entities.
     22         this(SimpleTech.FAN_RANGE);
     23     }
     24 
     25     @Override
     26     public void tick() {
     27         if (worldObj.isBlockIndirectlyGettingPowered(x, y, z) ||
     28                 worldObj.isBlockIndirectlyGettingPowered(x, y + 1, z)) {
     29             this.blow(worldObj, x, y, z);
     30         }
     31     }
     32 
     33     private void blow(World world, int x, int y, int z) {
     34         int dx = -SimpleTech.getDirectionX(world, x, y, z);
     35         int dy = -SimpleTech.getDirectionY(world, x, y, z);
     36         int dz = -SimpleTech.getDirectionZ(world, x, y, z);
     37 
     38         int px = x;
     39         int py = y;
     40         int pz = z;
     41 
     42         for (int i = 0; i < this.range; ++i) {
     43             px += dx;
     44             py += dy;
     45             pz += dz;
     46 
     47             if (world.isBlockOpaqueCube(px, py, pz)) {
     48                 break;
     49             }
     50 
     51             List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AABB.getBoundingBoxFromPool(
     52                     px, py, pz, px + 1, py + 1, pz + 1));
     53 
     54             for (Entity entity : entities) {
     55                 if (entity instanceof EntityItem) {
     56                     this.pushEntity(entity, dx, dy, dz);
     57                 }
     58             }
     59         }
     60     }
     61 
     62     private void pushEntity(Entity entity, int dx, int dy, int dz) {
     63         double maxspeed = 0.4;
     64         double boost = 0.1;
     65 
     66         if (Math.abs(dx) != 0) {
     67             if (entity.xd * (double) dx < 0.0) {
     68                 entity.xd = 0.0;
     69             }
     70 
     71             if (entity.xd * (double) dx <= maxspeed) {
     72                 entity.xd += (double) dx * boost;
     73             }
     74         } else if (Math.abs(dy) != 0) {
     75             if (entity.yd * (double) dy < 0.0) {
     76                 entity.yd = 0.0;
     77             }
     78 
     79             if (dy > 0) {
     80                 boost *= 0.5;
     81             }
     82 
     83             if (entity.yd * (double) dy <= maxspeed) {
     84                 entity.yd += (double) dy * boost;
     85             }
     86         } else if (Math.abs(dz) != 0) {
     87             if (entity.zd * (double) dz < 0.0) {
     88                 entity.zd = 0.0;
     89             }
     90 
     91             if (entity.zd * (double) dz <= maxspeed) {
     92                 entity.zd += (double) dz * boost;
     93             }
     94         }
     95     }
     96 }