Search in sources :

Example 56 with AxisAlignedBB

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;
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityMinecartEmpty(net.minecraft.entity.item.EntityMinecartEmpty) List(java.util.List) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 57 with AxisAlignedBB

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);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)

Example 58 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project MineFactoryReloaded by powercrystals.

the class BlockRedNetCable method getParts.

private AxisAlignedBB[] getParts(TileEntityRedNetCable cable) {
    RedNetConnectionType csu = cable.getConnectionState(ForgeDirection.UP);
    RedNetConnectionType csd = cable.getConnectionState(ForgeDirection.DOWN);
    RedNetConnectionType csn = cable.getConnectionState(ForgeDirection.NORTH);
    RedNetConnectionType css = cable.getConnectionState(ForgeDirection.SOUTH);
    RedNetConnectionType csw = cable.getConnectionState(ForgeDirection.WEST);
    RedNetConnectionType cse = cable.getConnectionState(ForgeDirection.EAST);
    AxisAlignedBB[] parts = new AxisAlignedBB[15];
    parts[0] = AxisAlignedBB.getBoundingBox(csw != RedNetConnectionType.None ? 0 : _wireStart, _wireStart, _wireStart, cse != RedNetConnectionType.None ? 1 : _wireEnd, _wireEnd, _wireEnd);
    parts[1] = AxisAlignedBB.getBoundingBox(_wireStart, csd != RedNetConnectionType.None ? 0 : _wireStart, _wireStart, _wireEnd, csu != RedNetConnectionType.None ? 1 : _wireEnd, _wireEnd);
    parts[2] = AxisAlignedBB.getBoundingBox(_wireStart, _wireStart, csn != RedNetConnectionType.None ? 0 : _wireStart, _wireEnd, _wireEnd, css != RedNetConnectionType.None ? 1 : _wireEnd);
    parts[3] = csw != RedNetConnectionType.PlateSingle && csw != RedNetConnectionType.PlateAll ? null : AxisAlignedBB.getBoundingBox(0, _plateStart, _plateStart, _plateDepth, _plateEnd, _plateEnd);
    parts[4] = cse != RedNetConnectionType.PlateSingle && cse != RedNetConnectionType.PlateAll ? null : AxisAlignedBB.getBoundingBox(1.0F - _plateDepth, _plateStart, _plateStart, 1.0F, _plateEnd, _plateEnd);
    parts[5] = csd != RedNetConnectionType.PlateSingle && csd != RedNetConnectionType.PlateAll ? null : AxisAlignedBB.getBoundingBox(_plateStart, 0, _plateStart, _plateEnd, _plateDepth, _plateEnd);
    parts[6] = csu != RedNetConnectionType.PlateSingle && csu != RedNetConnectionType.PlateAll ? null : AxisAlignedBB.getBoundingBox(_plateStart, 1.0F - _plateDepth, _plateStart, _plateEnd, 1.0F, _plateEnd);
    parts[7] = csn != RedNetConnectionType.PlateSingle && csn != RedNetConnectionType.PlateAll ? null : AxisAlignedBB.getBoundingBox(_plateStart, _plateStart, 0, _plateEnd, _plateEnd, _plateDepth);
    parts[8] = css != RedNetConnectionType.PlateSingle && css != RedNetConnectionType.PlateAll ? null : AxisAlignedBB.getBoundingBox(_plateStart, _plateStart, 1.0F - _plateDepth, _plateEnd, _plateEnd, 1.0F);
    parts[9] = csw != RedNetConnectionType.PlateSingle && csw != RedNetConnectionType.CableSingle ? null : AxisAlignedBB.getBoundingBox(_bandDepthStart, _bandWidthStart, _bandWidthStart, _bandDepthEnd, _bandWidthEnd, _bandWidthEnd);
    parts[10] = cse != RedNetConnectionType.PlateSingle && cse != RedNetConnectionType.CableSingle ? null : AxisAlignedBB.getBoundingBox(1.0F - _bandDepthEnd, _bandWidthStart, _bandWidthStart, 1.0F - _bandDepthStart, _bandWidthEnd, _bandWidthEnd);
    parts[11] = csd != RedNetConnectionType.PlateSingle && csd != RedNetConnectionType.CableSingle ? null : AxisAlignedBB.getBoundingBox(_bandWidthStart, _bandDepthStart, _bandWidthStart, _bandWidthEnd, _bandDepthEnd, _bandWidthEnd);
    parts[12] = csu != RedNetConnectionType.PlateSingle && csu != RedNetConnectionType.CableSingle ? null : AxisAlignedBB.getBoundingBox(_bandWidthStart, 1.0F - _bandDepthEnd, _bandWidthStart, _bandWidthEnd, 1.0F - _bandDepthStart, _bandWidthEnd);
    parts[13] = csn != RedNetConnectionType.PlateSingle && csn != RedNetConnectionType.CableSingle ? null : AxisAlignedBB.getBoundingBox(_bandWidthStart, _bandWidthStart, _bandDepthStart, _bandWidthEnd, _bandWidthEnd, _bandDepthEnd);
    parts[14] = css != RedNetConnectionType.PlateSingle && css != RedNetConnectionType.CableSingle ? null : AxisAlignedBB.getBoundingBox(_bandWidthStart, _bandWidthStart, 1.0F - _bandDepthEnd, _bandWidthEnd, _bandWidthEnd, 1.0F - _bandDepthStart);
    return parts;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) RedNetConnectionType(powercrystals.minefactoryreloaded.api.rednet.RedNetConnectionType)

Example 59 with AxisAlignedBB

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);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)

Example 60 with AxisAlignedBB

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);
}
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

AxisAlignedBB (net.minecraft.util.AxisAlignedBB)123 Entity (net.minecraft.entity.Entity)40 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)24 TileEntity (net.minecraft.tileentity.TileEntity)20 Vec3 (net.minecraft.util.Vec3)20 ArrayList (java.util.ArrayList)16 ItemStack (net.minecraft.item.ItemStack)16 List (java.util.List)15 Block (net.minecraft.block.Block)15 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 EntityItem (net.minecraft.entity.item.EntityItem)13 SideOnly (cpw.mods.fml.relauncher.SideOnly)10 World (net.minecraft.world.World)7 Pos (com.builtbroken.mc.imp.transform.vector.Pos)6 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)6 Iterator (java.util.Iterator)5 BlockPos (net.minecraft.util.BlockPos)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)4