Search in sources :

Example 21 with Vec3

use of net.minecraft.util.Vec3 in project PneumaticCraft by MineMaarten.

the class RenderTarget method isPlayerLookingAtTarget.

private boolean isPlayerLookingAtTarget() {
    // code used from the Enderman player looking code.
    EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
    World world = FMLClientHandler.instance().getClient().theWorld;
    Vec3 vec3 = player.getLook(1.0F).normalize();
    Vec3 vec31 = Vec3.createVectorHelper(entity.posX - player.posX, entity.boundingBox.minY + entity.height / 2.0F - (player.posY + player.getEyeHeight()), entity.posZ - player.posZ);
    double d0 = vec31.lengthVector();
    vec31 = vec31.normalize();
    double d1 = vec3.dotProduct(vec31);
    return d1 > 1.0D - 0.050D / d0;
}
Also used : Vec3(net.minecraft.util.Vec3) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World)

Example 22 with Vec3

use of net.minecraft.util.Vec3 in project PneumaticCraft by MineMaarten.

the class DroneSpecialVariableHandler method getPosForEntity.

private ChunkPosition getPosForEntity(IDrone entity) {
    Vec3 pos = entity.getPosition();
    int x = (int) Math.floor(pos.xCoord);
    int y = (int) Math.floor(pos.yCoord) + 1;
    int z = (int) Math.floor(pos.zCoord);
    return new ChunkPosition(x, y, z);
}
Also used : Vec3(net.minecraft.util.Vec3) ChunkPosition(net.minecraft.world.ChunkPosition)

Example 23 with Vec3

use of net.minecraft.util.Vec3 in project PneumaticCraft by MineMaarten.

the class ModuleAirGrate method update.

@Override
public void update() {
    super.update();
    World worldObj = pressureTube.world();
    int xCoord = pressureTube.x();
    int yCoord = pressureTube.y();
    int zCoord = pressureTube.z();
    Vec3 tileVec = Vec3.createVectorHelper(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D);
    if (!worldObj.isRemote) {
        int oldGrateRange = grateRange;
        grateRange = getRange();
        pressureTube.getAirHandler().addAir((vacuum ? 1 : -1) * grateRange * PneumaticValues.USAGE_AIR_GRATE, ForgeDirection.UNKNOWN);
        if (oldGrateRange != grateRange)
            sendDescriptionPacket();
        checkForPlantsAndFarm(worldObj, xCoord, yCoord, zCoord, grateRange);
        coolHeatSinks(worldObj, xCoord, yCoord, zCoord, grateRange);
    } else {
        rangeLineRenderer.update();
    /*  updateParticleTargets(tileVec, grateRange);
              for(Vec3 particleVec : particleTargets) {

                  //if(worldObj.rand.nextInt(10) == 0) {
                  Vec3 motionVec = particleVec.subtract(tileVec);
                  double force = 0.1D;
                  motionVec.xCoord *= force;
                  motionVec.yCoord *= force;
                  motionVec.zCoord *= force;
                  if(vacuum) {
                      worldObj.spawnParticle("smoke", particleVec.xCoord, particleVec.yCoord, particleVec.zCoord, -motionVec.xCoord, -motionVec.yCoord, -motionVec.zCoord);
                  } else {
                      worldObj.spawnParticle("smoke", tileVec.xCoord, tileVec.yCoord, tileVec.zCoord, motionVec.xCoord, motionVec.yCoord, motionVec.zCoord);
                  }
                  //   }

              }*/
    }
    AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(xCoord - grateRange, yCoord - grateRange, zCoord - grateRange, xCoord + grateRange + 1, yCoord + grateRange + 1, zCoord + grateRange + 1);
    List<Entity> entities = worldObj.selectEntitiesWithinAABB(Entity.class, bbBox, new StringFilterEntitySelector().setFilter(entityFilter));
    double d0 = grateRange + 0.5D;
    for (Entity entity : entities) {
        if (!entity.worldObj.isRemote && entity.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) < 0.6D && entity instanceof EntityItem && !entity.isDead) {
            List<IInventory> inventories = new ArrayList<IInventory>();
            List<Integer> sides = new ArrayList<Integer>();
            for (int i = 0; i < 6; i++) {
                IInventory inventory = TileEntityHopper.func_145893_b(worldObj, xCoord + Facing.offsetsXForSide[i], yCoord + Facing.offsetsYForSide[i], zCoord + Facing.offsetsZForSide[i]);
                if (inventory != null) {
                    inventories.add(inventory);
                    sides.add(i);
                }
            }
            // if there isn't a
            if (inventories.size() == 0)
                continue;
            // inventory attached,
            // stop handling.
            int inventoryIndexSelected = new Random().nextInt(inventories.size());
            IInventory inventory = inventories.get(inventoryIndexSelected);
            int side = sides.get(inventoryIndexSelected);
            side = Facing.oppositeSide[side];
            ItemStack leftoverStack = TileEntityHopper.func_145889_a(inventory, ((EntityItem) entity).getEntityItem(), side);
            if (leftoverStack == null || leftoverStack.stackSize == 0) {
                entity.setDead();
            }
        } else {
            if (!(entity instanceof EntityPlayer) || !((EntityPlayer) entity).capabilities.isCreativeMode) {
                Vec3 entityVec = Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ);
                MovingObjectPosition trace = worldObj.rayTraceBlocks(entityVec, tileVec);
                if (trace != null && trace.blockX == xCoord && trace.blockY == yCoord && trace.blockZ == zCoord) {
                    double d1 = (entity.posX - xCoord - 0.5D) / d0;
                    double d2 = (entity.posY - yCoord - 0.5D) / d0;
                    double d3 = (entity.posZ - zCoord - 0.5D) / d0;
                    double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
                    double d5 = 1.0D - d4;
                    if (d5 > 0.0D) {
                        d5 *= d5;
                        if (!vacuum)
                            d5 *= -1;
                        entity.motionX -= d1 / d4 * d5 * 0.1D;
                        entity.motionY -= d2 / d4 * d5 * 0.1D;
                        entity.motionZ -= d3 / d4 * d5 * 0.1D;
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IInventory(net.minecraft.inventory.IInventory) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) StringFilterEntitySelector(pneumaticCraft.common.ai.StringFilterEntitySelector) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Random(java.util.Random) Vec3(net.minecraft.util.Vec3) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 24 with Vec3

use of net.minecraft.util.Vec3 in project Minechem by iopleke.

the class Vector3 method rayTraceEntities.

/**
 * Does an entity raytrace.
 *
 * @param world - The world object.
 * @param target - The rotation in terms of Vector3. Convert using getDeltaPositionFromRotation()
 * @return The target hit.
 */
public MovingObjectPosition rayTraceEntities(World world, Vector3 target) {
    MovingObjectPosition pickedEntity = null;
    Vec3 startingPosition = this.toVec3();
    Vec3 look = target.toVec3();
    double reachDistance = this.distance(target);
    Vec3 reachPoint = Vec3.createVectorHelper(startingPosition.xCoord + look.xCoord * reachDistance, startingPosition.yCoord + look.yCoord * reachDistance, startingPosition.zCoord + look.zCoord * reachDistance);
    double checkBorder = 1.1 * reachDistance;
    AxisAlignedBB boxToScan = AxisAlignedBB.getBoundingBox(-checkBorder, -checkBorder, -checkBorder, checkBorder, checkBorder, checkBorder).offset(this.x, this.y, this.z);
    @SuppressWarnings("unchecked") List<Entity> entitiesHit = world.getEntitiesWithinAABBExcludingEntity(null, boxToScan);
    double closestEntity = reachDistance;
    if (entitiesHit == null || entitiesHit.isEmpty()) {
        return null;
    }
    for (Entity entityHit : entitiesHit) {
        if (entityHit != null && entityHit.canBeCollidedWith() && entityHit.boundingBox != null) {
            float border = entityHit.getCollisionBorderSize();
            AxisAlignedBB aabb = entityHit.boundingBox.expand(border, border, border);
            MovingObjectPosition hitMOP = aabb.calculateIntercept(startingPosition, reachPoint);
            if (hitMOP != null) {
                if (aabb.isVecInside(startingPosition)) {
                    if (0.0D < closestEntity || closestEntity == 0.0D) {
                        pickedEntity = new MovingObjectPosition(entityHit);
                        pickedEntity.hitVec = hitMOP.hitVec;
                        closestEntity = 0.0D;
                    }
                } else {
                    double distance = startingPosition.distanceTo(hitMOP.hitVec);
                    if (distance < closestEntity || closestEntity == 0.0D) {
                        pickedEntity = new MovingObjectPosition(entityHit);
                        pickedEntity.hitVec = hitMOP.hitVec;
                        closestEntity = distance;
                    }
                }
            }
        }
    }
    return pickedEntity;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3)

Example 25 with Vec3

use of net.minecraft.util.Vec3 in project CodeChickenLib by Chicken-Bones.

the class RayTracer method getEndVec.

public static Vec3 getEndVec(EntityPlayer player) {
    Vec3 headVec = getCorrectedHeadVec(player);
    Vec3 lookVec = player.getLook(1.0F);
    double reach = getBlockReachDistance(player);
    return headVec.addVector(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach);
}
Also used : Vec3(net.minecraft.util.Vec3)

Aggregations

Vec3 (net.minecraft.util.Vec3)132 Block (net.minecraft.block.Block)32 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)26 Entity (net.minecraft.entity.Entity)22 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)19 ArrayList (java.util.ArrayList)13 TileEntity (net.minecraft.tileentity.TileEntity)9 ItemToolBase (club.nsdn.nyasamarailway.item.tool.ItemToolBase)8 ItemStack (net.minecraft.item.ItemStack)7 List (java.util.List)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)6 EntityItem (net.minecraft.entity.item.EntityItem)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 Random (java.util.Random)5 BlockRailBase (net.minecraft.block.BlockRailBase)5 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)4 IBlockState (net.minecraft.block.state.IBlockState)4 Tessellator (net.minecraft.client.renderer.Tessellator)4 InvokeEvent (cc.hyperium.event.InvokeEvent)3