Skip to content

Instantly share code, notes, and snippets.

@mazetar
Created November 3, 2013 19:01
Show Gist options
  • Save mazetar/7293601 to your computer and use it in GitHub Desktop.
Save mazetar/7293601 to your computer and use it in GitHub Desktop.
package patpunk44.mod;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
public class TileEntityTorch extends TileEntity {
private double angleInDegrees;
public void onUpdate() {
AxisAlignedBB axisalignedbb = AxisAlignedBB
.getAABBPool()
.getAABB((double) this.xCoord, (double) this.yCoord,
(double) this.zCoord, (double) (this.xCoord + 1),
(double) (this.yCoord + 1), (double) (this.zCoord + 1))
.expand(10, 10, 10);
axisalignedbb.maxY = (double) this.worldObj.getHeight();
List list = this.worldObj.getEntitiesWithinAABB(EntityLiving.class,
axisalignedbb);
Iterator iterator = list.iterator();
EntityLiving entityliving;
angleInDegrees = Math.atan2(yCoord, xCoord) * 180 / Math.PI;
while (iterator.hasNext()) {
entityliving = (EntityLiving) iterator.next();
double d01 = entityliving.posX;
double d11 = entityliving.posY;
double d21 = entityliving.posZ;
Vec3 vec3 = entityliving.worldObj.getWorldVec3Pool()
.getVecFromPool(d01, d11, d21);
if (entityliving instanceof EntityMob) {
if (axisalignedbb.isVecInside(vec3)) {
entityliving.motionX = -(Math.sin(Math
.toRadians(this.angleInDegrees)) * 0.050000000000000003D);
entityliving.motionZ = (Math.cos(Math
.toRadians(this.angleInDegrees)) * 0.29999999999999999D);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment