Search in sources :

Example 16 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class TileEntityBalloon method getRaytraceOffset.

@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
    int xDif = ((TileEntity) link).getPos().getX() - getPos().getX();
    int zDif = ((TileEntity) link).getPos().getZ() - getPos().getZ();
    int yDif = ((TileEntity) link).getPos().getY() - getPos().getY();
    if (yDif < 0) {
        double dist = Math.sqrt(xDif * xDif + zDif * zDif);
        if (dist / Math.abs(yDif) < 2.5)
            return new Vec3d(.5, .09375, .5);
    }
    if (Math.abs(zDif) > Math.abs(xDif))
        return new Vec3d(.5, .09375, zDif > 0 ? .8125 : .1875);
    else
        return new Vec3d(xDif > 0 ? .8125 : .1875, .09375, .5);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Vec3d(net.minecraft.util.math.Vec3d)

Example 17 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class TileEntityBalloon method getConnectionOffset.

@Override
public Vec3d getConnectionOffset(Connection con) {
    int xDif = (con == null || con.start == null || con.end == null) ? 0 : (con.start.equals(this.getPos()) && con.end != null) ? con.end.getX() - getPos().getX() : (con.end.equals(this.getPos()) && con.start != null) ? con.start.getX() - getPos().getX() : 0;
    int zDif = (con == null || con.start == null || con.end == null) ? 0 : (con.start.equals(this.getPos()) && con.end != null) ? con.end.getZ() - getPos().getZ() : (con.end.equals(this.getPos()) && con.start != null) ? con.start.getZ() - getPos().getZ() : 0;
    int yDif = (con == null || con.start == null || con.end == null) ? 0 : (con.start.equals(this.getPos()) && con.end != null) ? con.end.getY() - getPos().getY() : (con.end.equals(this.getPos()) && con.start != null) ? con.start.getY() - getPos().getY() : 0;
    if (yDif < 0) {
        double dist = Math.sqrt(xDif * xDif + zDif * zDif);
        if (dist / Math.abs(yDif) < 2.5)
            return new Vec3d(.5, .09375, .5);
    }
    if (Math.abs(zDif) > Math.abs(xDif))
        return new Vec3d(.5, .09375, zDif > 0 ? .78125 : .21875);
    else
        return new Vec3d(xDif > 0 ? .78125 : .21875, .09375, .5);
}
Also used : Vec3d(net.minecraft.util.math.Vec3d)

Example 18 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class TileEntityTransformer method getConnectionOffset.

@Override
public Vec3d getConnectionOffset(Connection con) {
    boolean b = con.cableType == limitType;
    if (onPost) {
        if (b)
            return new Vec3d(.5 + (facing == EnumFacing.EAST ? .4375 : facing == EnumFacing.WEST ? -.4375 : 0), 1.4375, .5 + (facing == EnumFacing.SOUTH ? .4375 : facing == EnumFacing.NORTH ? -.4375 : 0));
        else
            return new Vec3d(.5 + (facing == EnumFacing.EAST ? -.0625 : facing == EnumFacing.WEST ? .0625 : 0), .25, .5 + (facing == EnumFacing.SOUTH ? -.0625 : facing == EnumFacing.NORTH ? .0625 : 0));
    } else {
        double conRadius = con.cableType.getRenderDiameter() / 2;
        double offset = getIsMirrored() ^ b ? getLowerOffset() : getHigherOffset();
        if (facing == EnumFacing.NORTH)
            return new Vec3d(b ? .8125 : .1875, 2 + offset - conRadius, .5);
        if (facing == EnumFacing.SOUTH)
            return new Vec3d(b ? .1875 : .8125, 2 + offset - conRadius, .5);
        if (facing == EnumFacing.WEST)
            return new Vec3d(.5, 2 + offset - conRadius, b ? .1875 : .8125);
        if (facing == EnumFacing.EAST)
            return new Vec3d(.5, 2 + offset - conRadius, b ? .8125 : .1875);
    }
    return new Vec3d(.5, .5, .5);
}
Also used : Vec3d(net.minecraft.util.math.Vec3d)

Example 19 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class TileEntityTurretGun method activate.

@Override
protected void activate() {
    int energy = IEConfig.Machines.turret_gun_consumption;
    ItemStack bulletStack = inventory[0];
    if (bulletStack != null && this.energyStorage.extractEnergy(energy, true) == energy) {
        String key = ItemNBTHelper.getString(bulletStack, "bullet");
        IBullet bullet = BulletHandler.getBullet(key);
        if (bullet != null && bullet.isValidForTurret()) {
            ItemStack casing = bullet.getCasing(bulletStack);
            if (expelCasings || casing == null || inventory[1] == null || (OreDictionary.itemMatches(casing, inventory[1], false) && inventory[1].stackSize + casing.stackSize <= inventory[1].getMaxStackSize())) {
                this.energyStorage.extractEnergy(energy, false);
                this.sendRenderPacket();
                double dX = target.posX - (getPos().getX() + .5);
                double dY = target.posY - (getPos().getY() + .5);
                double dZ = target.posZ - (getPos().getZ() + .5);
                Vec3d vec = new Vec3d(dX, dY, dZ).normalize();
                int count = bullet.getProjectileCount(null);
                if (count == 1) {
                    Entity entBullet = getBulletEntity(worldObj, vec, bullet);
                    worldObj.spawnEntityInWorld(bullet.getProjectile(null, bulletStack, entBullet, false));
                } else
                    for (int i = 0; i < count; i++) {
                        Vec3d vecDir = vec.addVector(worldObj.rand.nextGaussian() * .1, worldObj.rand.nextGaussian() * .1, worldObj.rand.nextGaussian() * .1);
                        Entity entBullet = getBulletEntity(worldObj, vecDir, bullet);
                        worldObj.spawnEntityInWorld(bullet.getProjectile(null, bulletStack, entBullet, false));
                    }
                if (--bulletStack.stackSize <= 0)
                    inventory[0] = null;
                if (casing != null) {
                    if (expelCasings) {
                        double cX = getPos().getX() + .5;
                        double cY = getPos().getY() + 1.375;
                        double cZ = getPos().getZ() + .5;
                        Vec3d vCasing = vec.rotateYaw(-1.57f);
                        worldObj.spawnParticle(EnumParticleTypes.REDSTONE, cX + vCasing.xCoord, cY + vCasing.yCoord, cZ + vCasing.zCoord, 0, 0, 0, 1, 0);
                        EntityItem entCasing = new EntityItem(worldObj, cX + vCasing.xCoord, cY + vCasing.yCoord, cZ + vCasing.zCoord, casing.copy());
                        entCasing.motionX = 0;
                        entCasing.motionY = -0.01;
                        entCasing.motionZ = 0;
                        worldObj.spawnEntityInWorld(entCasing);
                    } else {
                        if (inventory[1] == null)
                            inventory[1] = casing.copy();
                        else
                            inventory[1].stackSize += casing.stackSize;
                    }
                }
                worldObj.playSound(null, getPos(), IESounds.revolverFire, SoundCategory.BLOCKS, 1, 1);
            }
        }
    }
}
Also used : IBullet(blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet) Entity(net.minecraft.entity.Entity) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) EntityItem(net.minecraft.entity.item.EntityItem)

Example 20 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class TileEntityRazorWire method getConnectionOffset.

@Override
public Vec3d getConnectionOffset(Connection con) {
    int xDif = (con == null || con.start == null || con.end == null) ? 0 : (con.start.equals(Utils.toCC(this)) && con.end != null) ? con.end.getX() - getPos().getX() : (con.end.equals(Utils.toCC(this)) && con.start != null) ? con.start.getX() - getPos().getX() : 0;
    int yDif = (con == null || con.start == null || con.end == null) ? 0 : (con.start.equals(Utils.toCC(this)) && con.end != null) ? con.end.getY() - getPos().getY() : (con.end.equals(Utils.toCC(this)) && con.start != null) ? con.start.getY() - getPos().getY() : 0;
    int zDif = (con == null || con.start == null || con.end == null) ? 0 : (con.start.equals(Utils.toCC(this)) && con.end != null) ? con.end.getZ() - getPos().getZ() : (con.end.equals(Utils.toCC(this)) && con.start != null) ? con.start.getZ() - getPos().getZ() : 0;
    boolean wallL = renderWall(true);
    boolean wallR = renderWall(false);
    if (!isOnGround() || !(wallL || wallR)) {
        if (yDif > 0)
            return new Vec3d(facing.getFrontOffsetX() != 0 ? .5 : xDif < 0 ? .40625 : .59375, .9375, facing.getFrontOffsetZ() != 0 ? .5 : zDif < 0 ? .40625 : .59375);
        else {
            boolean right = facing.rotateY().getAxisDirection().getOffset() == Math.copySign(1, facing.getFrontOffsetX() != 0 ? zDif : xDif);
            int faceX = facing.getFrontOffsetX();
            int faceZ = facing.getFrontOffsetZ();
            return new Vec3d(faceX != 0 ? .5 + (right ? 0 : faceX * .1875) : (xDif < 0 ? 0 : 1), .046875, faceZ != 0 ? .5 + (right ? 0 : faceZ * .1875) : (zDif < 0 ? 0 : 1));
        }
    } else {
        boolean wallN = facing == EnumFacing.NORTH || facing == EnumFacing.EAST ? wallL : wallR;
        return new Vec3d(facing.getFrontOffsetX() != 0 ? .5 : xDif < 0 && wallN ? .125 : .875, .9375, facing.getFrontOffsetZ() != 0 ? .5 : zDif < 0 && wallN ? .125 : .875);
    }
}
Also used : Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Vec3d (net.minecraft.util.math.Vec3d)161 BlockPos (net.minecraft.util.math.BlockPos)44 Entity (net.minecraft.entity.Entity)27 IBlockState (net.minecraft.block.state.IBlockState)21 TileEntity (net.minecraft.tileentity.TileEntity)20 EntityLivingBase (net.minecraft.entity.EntityLivingBase)18 EntityPlayer (net.minecraft.entity.player.EntityPlayer)17 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)17 EnumFacing (net.minecraft.util.EnumFacing)16 ItemStack (net.minecraft.item.ItemStack)13 RayTraceResult (net.minecraft.util.math.RayTraceResult)12 World (net.minecraft.world.World)10 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)8 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)7 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)7 NBTTagList (net.minecraft.nbt.NBTTagList)7 EntityItem (net.minecraft.entity.item.EntityItem)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 Vector (ValkyrienWarfareBase.API.Vector)5 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)5