use of net.minecraft.util.AxisAlignedBB in project MineFactoryReloaded by powercrystals.
the class EntityRocket method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
_ticksAlive++;
if (_ticksAlive > 200) {
setDead();
}
if (worldObj.isRemote) {
for (int i = 0; i < 4; i++) {
worldObj.spawnParticle("smoke", posX + motionX * i / 4.0D, posY + motionY * i / 4.0D, posZ + motionZ * i / 4.0D, -motionX, -motionY + 0.2D, -motionZ);
}
}
if (!worldObj.isRemote) {
Vec3 pos = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ);
Vec3 nextPos = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
MovingObjectPosition hit = this.worldObj.rayTraceBlocks_do_do(pos, nextPos, false, true);
pos = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX, this.posY, this.posZ);
nextPos = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (hit != null) {
nextPos = this.worldObj.getWorldVec3Pool().getVecFromPool(hit.hitVec.xCoord, hit.hitVec.yCoord, hit.hitVec.zCoord);
}
Entity entityHit = null;
List<?> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double closestRange = 0.0D;
double collisionRange = 0.3D;
for (int i = 0, end = list.size(); i < end; ++i) {
Entity e = (Entity) list.get(i);
if (e.canBeCollidedWith() && (e != _owner)) {
AxisAlignedBB entitybb = e.boundingBox.expand(collisionRange, collisionRange, collisionRange);
MovingObjectPosition entityHitPos = entitybb.calculateIntercept(pos, nextPos);
if (entityHitPos != null) {
double range = pos.distanceTo(entityHitPos.hitVec);
if ((range < closestRange) | closestRange == 0D) {
entityHit = e;
closestRange = range;
}
}
}
}
if (entityHit != null) {
hit = new MovingObjectPosition(entityHit);
}
if (hit != null && hit.entityHit != null && hit.entityHit instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) hit.entityHit;
if (entityplayer.capabilities.disableDamage || (_owner instanceof EntityPlayer && !((EntityPlayer) _owner).func_96122_a(entityplayer))) {
hit = null;
}
}
if (hit != null && !worldObj.isRemote) {
if (hit.entityHit != null) {
// why not spawn explosion at nextPos x/y/z?
worldObj.newExplosion(this, hit.entityHit.posX, hit.entityHit.posY, hit.entityHit.posZ, 4.0F, true, true);
} else {
worldObj.newExplosion(this, hit.blockX, hit.blockY, hit.blockZ, 4.0F, true, true);
}
setDead();
}
}
if (_target != null) {
// At this point, I suspect literally no one on this project actually understands what this does or how it works
Vec3 targetVector = worldObj.getWorldVec3Pool().getVecFromPool(_target.posX - posX, _target.posY - posY, _target.posZ - posZ);
float targetYaw = clampAngle(360 - (float) (Math.atan2(targetVector.xCoord, targetVector.zCoord) * 180.0D / Math.PI), 360, false);
float targetPitch = clampAngle(-(float) (Math.atan2(targetVector.yCoord, Math.sqrt(targetVector.xCoord * targetVector.xCoord + targetVector.zCoord * targetVector.zCoord)) * 180.0D / Math.PI), 360, false);
float yawDifference = clampAngle(targetYaw - rotationYaw, 3, true);
float pitchDifference = clampAngle(targetPitch - rotationPitch, 3, true);
float newYaw;
float newPitch;
if (Math.max(targetYaw, rotationYaw) - Math.min(targetYaw, rotationYaw) > 180) {
newYaw = rotationYaw - yawDifference;
} else {
newYaw = rotationYaw + yawDifference;
}
if (Math.max(targetPitch, rotationPitch) - Math.min(targetPitch, rotationPitch) > 180) {
newPitch = rotationPitch - pitchDifference;
} else {
newPitch = rotationPitch + pitchDifference;
}
rotationYaw = clampAngle(newYaw, 360F, false);
rotationPitch = clampAngle(newPitch, 360F, false);
recalculateVelocity();
}
setPosition(posX + motionX, posY + motionY, posZ + motionZ);
}
use of net.minecraft.util.AxisAlignedBB in project MineFactoryReloaded by powercrystals.
the class ItemSpyglass method rayTrace.
private MovingObjectPosition rayTrace() {
if (Minecraft.getMinecraft().renderViewEntity == null || Minecraft.getMinecraft().theWorld == null) {
return null;
}
double range = MFRConfig.spyglassRange.getInt();
MovingObjectPosition objHit = Minecraft.getMinecraft().renderViewEntity.rayTrace(range, 1.0F);
double blockDist = range;
Vec3 playerPos = Minecraft.getMinecraft().renderViewEntity.getPosition(1.0F);
if (objHit != null) {
blockDist = objHit.hitVec.distanceTo(playerPos);
}
Vec3 playerLook = Minecraft.getMinecraft().renderViewEntity.getLook(1.0F);
Vec3 playerLookRel = playerPos.addVector(playerLook.xCoord * range, playerLook.yCoord * range, playerLook.zCoord * range);
List<?> list = Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity(Minecraft.getMinecraft().renderViewEntity, Minecraft.getMinecraft().renderViewEntity.boundingBox.addCoord(playerLook.xCoord * range, playerLook.yCoord * range, playerLook.zCoord * range).expand(1, 1, 1));
double entityDistTotal = blockDist;
Entity pointedEntity = null;
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity) list.get(i);
if (entity.canBeCollidedWith()) {
double entitySize = entity.getCollisionBorderSize();
AxisAlignedBB axisalignedbb = entity.boundingBox.expand(entitySize, entitySize, entitySize);
MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(playerPos, playerLookRel);
if (axisalignedbb.isVecInside(playerPos)) {
if (0.0D < entityDistTotal || entityDistTotal == 0.0D) {
pointedEntity = entity;
entityDistTotal = 0.0D;
}
} else if (movingobjectposition != null) {
double entityDist = playerPos.distanceTo(movingobjectposition.hitVec);
if (entityDist < entityDistTotal || entityDistTotal == 0.0D) {
pointedEntity = entity;
entityDistTotal = entityDist;
}
}
}
}
if (pointedEntity != null && (entityDistTotal < blockDist || objHit == null)) {
objHit = new MovingObjectPosition(pointedEntity);
}
return objHit;
}
use of net.minecraft.util.AxisAlignedBB in project MineFactoryReloaded by powercrystals.
the class BlockRailPassengerPickup method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if (world.isRemote || !(entity instanceof EntityMinecartEmpty)) {
return;
}
EntityMinecart minecart = (EntityMinecart) entity;
if (minecart.riddenByEntity != null) {
return;
}
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(x - MFRConfig.passengerRailSearchMaxHorizontal.getInt(), y - MFRConfig.passengerRailSearchMaxVertical.getInt(), z - MFRConfig.passengerRailSearchMaxHorizontal.getInt(), x + MFRConfig.passengerRailSearchMaxHorizontal.getInt() + 1, y + MFRConfig.passengerRailSearchMaxVertical.getInt() + 1, z + MFRConfig.passengerRailSearchMaxHorizontal.getInt() + 1);
@SuppressWarnings("rawtypes") List entities = world.getEntitiesWithinAABB(EntityPlayer.class, bb);
for (Object o : entities) {
if (!(o instanceof EntityPlayer)) {
continue;
}
((EntityPlayer) o).mountEntity(minecart);
return;
}
}
use of net.minecraft.util.AxisAlignedBB in project MineFactoryReloaded by powercrystals.
the class BlockRedNetCable method addCollisionBoxesToList.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB collisionTest, List collisionBoxList, Entity entity) {
TileEntity cable = world.getBlockTileEntity(x, y, z);
if (cable instanceof TileEntityRedNetCable) {
for (AxisAlignedBB aabb : getParts((TileEntityRedNetCable) cable)) {
if (aabb == null) {
continue;
}
aabb = AxisAlignedBB.getBoundingBox(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ);
aabb.minX += x;
aabb.maxX += x;
aabb.minY += y;
aabb.maxY += y;
aabb.minZ += z;
aabb.maxZ += z;
if (collisionTest.intersectsWith(aabb)) {
collisionBoxList.add(aabb);
}
}
} else {
super.addCollisionBoxesToList(world, x, y, z, collisionTest, collisionBoxList, entity);
}
}
use of net.minecraft.util.AxisAlignedBB in project MineFactoryReloaded by powercrystals.
the class BlockRedNetCable method setBlockBoundsBasedOnState.
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
float xMin = 1;
float yMin = 1;
float zMin = 1;
float xMax = 0;
float yMax = 0;
float zMax = 0;
TileEntity cable = world.getBlockTileEntity(x, y, z);
if (cable instanceof TileEntityRedNetCable) {
for (AxisAlignedBB aabb : getParts((TileEntityRedNetCable) cable)) {
if (aabb == null) {
continue;
}
xMin = Math.min(xMin, (float) aabb.minX);
yMin = Math.min(yMin, (float) aabb.minY);
zMin = Math.min(zMin, (float) aabb.minZ);
xMax = Math.max(xMax, (float) aabb.maxX);
yMax = Math.max(yMax, (float) aabb.maxY);
zMax = Math.max(zMax, (float) aabb.maxZ);
}
setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax);
} else {
super.setBlockBoundsBasedOnState(world, x, y, z);
}
}
Aggregations