Search in sources :

Example 16 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition 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 17 with MovingObjectPosition

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

the class ItemPlasticPlants method onItemRightClick.

/**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    BlockPneumaticPlantBase plant = (BlockPneumaticPlantBase) getPlantBlockIDFromSeed(stack.getItemDamage());
    if (plant == Blockss.squidPlant) {
        MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world, player, true);
        if (mop != null) {
            int x = mop.blockX;
            int y = mop.blockY;
            int z = mop.blockZ;
            if (player.canPlayerEdit(x, y, z, 1, stack) && player.canPlayerEdit(x, y + 1, z, 1, stack)) {
                if (plant.canBlockStay(world, x, y + 1, z) && world.isAirBlock(x, y + 1, z)) {
                    stack.stackSize--;
                    world.setBlock(x, y + 1, z, Blockss.squidPlant, 7, 3);
                }
            }
        }
    }
    return stack;
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) BlockPneumaticPlantBase(pneumaticCraft.common.block.pneumaticPlants.BlockPneumaticPlantBase)

Example 18 with MovingObjectPosition

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

the class TileEntityPressureTube method printManometerMessage.

@Override
public void printManometerMessage(EntityPlayer player, List<String> text) {
    super.printManometerMessage(player, text);
    MovingObjectPosition mop = PneumaticCraftUtils.getEntityLookedObject(player);
    if (mop != null && mop.hitInfo instanceof ForgeDirection) {
        ForgeDirection dir = (ForgeDirection) mop.hitInfo;
        if (dir != ForgeDirection.UNKNOWN && modules[dir.ordinal()] != null) {
            modules[dir.ordinal()].addInfo(text);
        }
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 19 with MovingObjectPosition

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

the class TileEntitySentryTurret method canSeeEntity.

private boolean canSeeEntity(Entity entity) {
    Vec3 entityVec = Vec3.createVectorHelper(entity.posX + entity.width / 2, entity.posY + entity.height / 2, entity.posZ + entity.width / 2);
    Vec3 tileVec = Vec3.createVectorHelper(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
    MovingObjectPosition trace = worldObj.rayTraceBlocks(entityVec, tileVec);
    return trace != null && trace.blockX == xCoord && trace.blockY == yCoord && trace.blockZ == zCoord;
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3)

Example 20 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition 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);
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

MovingObjectPosition (net.minecraft.util.MovingObjectPosition)60 Vec3 (net.minecraft.util.Vec3)19 Entity (net.minecraft.entity.Entity)17 EntityPlayer (net.minecraft.entity.player.EntityPlayer)17 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)17 ItemStack (net.minecraft.item.ItemStack)16 TileEntity (net.minecraft.tileentity.TileEntity)16 ArrayList (java.util.ArrayList)11 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)10 Block (net.minecraft.block.Block)8 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 AMVector3 (am2.api.math.AMVector3)5 World (net.minecraft.world.World)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 List (java.util.List)4 SpellCastResult (am2.api.spell.enums.SpellCastResult)3 ParticleApproachPoint (am2.particles.ParticleApproachPoint)3 IBlockState (net.minecraft.block.state.IBlockState)3 AMParticle (am2.particles.AMParticle)2 PacketPlayerItem (com.builtbroken.mc.core.network.packet.PacketPlayerItem)2