Search in sources :

Example 51 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project Engine by VoltzEngine-Project.

the class BlockTile method addCollisionBoxesToList.

@Override
@SuppressWarnings("unchecked")
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) {
    Tile tile = inject(world, x, y, z);
    Iterable<Cube> bounds = tile.getCollisionBoxes(new Cube(aabb).subtract(new Pos(x, y, z)), entity);
    eject();
    if (bounds != null) {
        for (Cube cuboid : bounds) {
            AxisAlignedBB bb = cuboid.toAABB().offset(x, y, z);
            if (aabb.intersectsWith(bb)) {
                list.add(bb);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Cube(com.builtbroken.mc.lib.transform.region.Cube) Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 52 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project BetterStorage by copygirl.

the class ClientProxy method drawBlockHighlight.

@SubscribeEvent
public void drawBlockHighlight(DrawBlockHighlightEvent event) {
    EntityPlayer player = event.player;
    World world = player.worldObj;
    MovingObjectPosition target = WorldUtils.rayTrace(player, event.partialTicks);
    if ((target == null) || (target.typeOfHit != MovingObjectType.BLOCK))
        return;
    int x = target.blockX;
    int y = target.blockY;
    int z = target.blockZ;
    AxisAlignedBB box = null;
    Block block = world.getBlock(x, y, z);
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (block instanceof TileArmorStand)
        box = getArmorStandHighlightBox(player, world, x, y, z, target.hitVec);
    else if (block == Blocks.iron_door)
        box = getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block);
    else if (tileEntity instanceof IHasAttachments)
        box = getAttachmentPointsHighlightBox(player, tileEntity, target);
    if (box == null)
        return;
    double xOff = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.partialTicks;
    double yOff = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.partialTicks;
    double zOff = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.partialTicks;
    box.offset(-xOff, -yOff, -zOff);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
    GL11.glLineWidth(2.0F);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDepthMask(false);
    RenderGlobal.drawOutlinedBoundingBox(box, -1);
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_BLEND);
    event.setCanceled(true);
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) TileArmorStand(net.mcft.copy.betterstorage.tile.stand.TileArmorStand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) World(net.minecraft.world.World) IHasAttachments(net.mcft.copy.betterstorage.attachment.IHasAttachments) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 53 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project BetterStorage by copygirl.

the class CommonProxy method getIronDoorHightlightBox.

protected AxisAlignedBB getIronDoorHightlightBox(EntityPlayer player, World world, int x, int y, int z, Vec3 hitVec, Block block) {
    if (!StackUtils.isLock(player.getCurrentEquippedItem()))
        return null;
    int meta = world.getBlockMetadata(x, y, z);
    boolean isMirrored;
    if (meta >= 8) {
        isMirrored = meta == 9;
        y -= 1;
        meta = world.getBlockMetadata(x, y, z);
    } else
        isMirrored = world.getBlockMetadata(x, y + 1, z) == 9;
    boolean isOpen = (meta & 4) == 4;
    int rotation = (meta & 3);
    rotation = isMirrored ? (rotation == 0 ? 3 : rotation == 1 ? 0 : rotation == 2 ? 1 : 2) : rotation;
    isOpen = isMirrored ? !isOpen : isOpen;
    AxisAlignedBB box;
    switch(rotation) {
        case 0:
            if (!isOpen)
                box = AxisAlignedBB.getBoundingBox(x - 0.005 / 16F, y + 14.5 / 16F, z + 10 / 16F, x + 3.005 / 16F, y + 20.5 / 16F, z + 15 / 16F);
            else
                box = AxisAlignedBB.getBoundingBox(x + 10 / 16F, y + 14.5 / 16F, z - 0.005 / 16F, x + 15 / 16F, y + 20.5 / 16F, z + 3.005 / 16F);
            break;
        case 1:
            if (!isOpen)
                box = AxisAlignedBB.getBoundingBox(x + 1 / 16F, y + 14.5 / 16F, z - 0.005 / 16F, x + 6 / 16F, y + 20.5 / 16F, z + 3.005 / 16F);
            else
                box = AxisAlignedBB.getBoundingBox(x + 12.995 / 16F, y + 14.5 / 16F, z + 10 / 16F, x + 16.005 / 16F, y + 20.5 / 16F, z + 15 / 16F);
            break;
        case 2:
            if (!isOpen)
                box = AxisAlignedBB.getBoundingBox(x + 12.995 / 16F, y + 14.5 / 16F, z + 1 / 16F, x + 16.005 / 16F, y + 20.5 / 16F, z + 6 / 16F);
            else
                box = AxisAlignedBB.getBoundingBox(x + 1 / 16F, y + 14.5 / 16F, z + 12.995 / 16F, x + 6 / 16F, y + 20.5 / 16F, z + 16.005 / 16F);
            break;
        default:
            if (!isOpen)
                box = AxisAlignedBB.getBoundingBox(x + 10 / 16F, y + 14.5 / 16F, z + 12.995 / 16F, x + 15 / 16F, y + 20.5 / 16F, z + 16.005 / 16F);
            else
                box = AxisAlignedBB.getBoundingBox(x - 0.005 / 16F, y + 14.5 / 16F, z + 1 / 16F, x + 3.005 / 16F, y + 20.5 / 16F, z + 6 / 16F);
            break;
    }
    return box.isVecInside(hitVec) ? box : null;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB)

Example 54 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project BetterStorage by copygirl.

the class LockAttachment method use.

private boolean use(EntityPlayer player, ItemStack holding) {
    if (player.worldObj.isRemote)
        return false;
    ILockable lockable = (ILockable) tileEntity;
    ItemStack lock = lockable.getLock();
    if (lock == null) {
        if (StackUtils.isLock(holding) && lockable.isLockValid(holding)) {
            lockable.setLock(holding);
            player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
            return true;
        }
    } else if (StackUtils.isKey(holding)) {
        IKey keyType = (IKey) holding.getItem();
        ILock lockType = (ILock) lock.getItem();
        boolean success = keyType.unlock(holding, lock, true);
        lockType.onUnlock(lock, holding, lockable, player, success);
        if (!success)
            return true;
        if (player.isSneaking()) {
            AxisAlignedBB box = getHighlightBox();
            double x = (box.minX + box.maxX) / 2;
            double y = (box.minY + box.maxY) / 2;
            double z = (box.minZ + box.maxZ) / 2;
            EntityItem item = WorldUtils.spawnItem(player.worldObj, x, y, z, lock);
            lockable.setLock(null);
        } else
            lockable.useUnlocked(player);
        return true;
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IKey(net.mcft.copy.betterstorage.api.lock.IKey) ItemStack(net.minecraft.item.ItemStack) ILock(net.mcft.copy.betterstorage.api.lock.ILock) EntityItem(net.minecraft.entity.item.EntityItem) ILockable(net.mcft.copy.betterstorage.api.lock.ILockable)

Example 55 with AxisAlignedBB

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

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