Search in sources :

Example 41 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project BluePower by Qmunity.

the class TileTransposer method suckEntity.

private void suckEntity() {
    ForgeDirection direction = getFacingDirection();
    AxisAlignedBB box = AxisAlignedBB.getBoundingBox(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ, xCoord + direction.offsetX + 1, yCoord + direction.offsetY + 1, zCoord + direction.offsetZ + 1);
    for (EntityItem entity : (List<EntityItem>) worldObj.getEntitiesWithinAABB(EntityItem.class, box)) {
        ItemStack stack = entity.getEntityItem();
        if (isItemAccepted(stack) && !entity.isDead) {
            addItemToOutputBuffer(stack, getAcceptedItemColor(stack));
            entity.setDead();
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 42 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project malmo by Microsoft.

the class BlockDrawingHelper method DrawPrimitive.

/**
     * Draw a solid sphere made up of Minecraft blocks.
     * @param s Contains information about the sphere to be drawn.
     * @param w The world in which to draw.
     * @throws Exception Throws an exception if the block type is not recognised.
     */
private void DrawPrimitive(DrawSphere s, World w) throws Exception {
    XMLBlockState blockType = new XMLBlockState(s.getType(), s.getColour(), null, s.getVariant());
    if (!blockType.isValid())
        throw new Exception("Unrecognised block type: " + s.getType().value());
    int radius = s.getRadius();
    for (int x = s.getX() - radius; x <= s.getX() + radius; x++) {
        for (int y = s.getY() - radius; y <= s.getY() + radius; y++) {
            for (int z = s.getZ() - radius; z <= s.getZ() + radius; z++) {
                if ((z - s.getZ()) * (z - s.getZ()) + (y - s.getY()) * (y - s.getY()) + (x - s.getX()) * (x - s.getX()) <= (radius * radius)) {
                    BlockPos pos = new BlockPos(x, y, z);
                    setBlockState(w, pos, blockType);
                    AxisAlignedBB aabb = new AxisAlignedBB(pos, pos).expand(0.5, 0.5, 0.5);
                    clearEntities(w, aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ);
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) BlockPos(net.minecraft.util.BlockPos)

Example 43 with AxisAlignedBB

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

the class EntityTrackUpgradeHandler method update.

@Override
@SideOnly(Side.CLIENT)
public void update(EntityPlayer player, int rangeUpgrades) {
    ItemStack helmetStack = player.getCurrentArmor(3);
    String entityFilter = "";
    if (helmetStack != null)
        entityFilter = NBTUtil.getString(helmetStack, "entityFilter");
    double entityTrackRange = ENTITY_TRACKING_RANGE + rangeUpgrades * PneumaticValues.RANGE_UPGRADE_HELMET_RANGE_INCREASE;
    AxisAlignedBB bbBox = getAABBFromRange(player, rangeUpgrades);
    List<Entity> mobs = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, bbBox);
    if (mobs.contains(player))
        mobs.remove(player);
    for (int i = 0; i < mobs.size(); i++) {
        if (player.getDistanceToEntity(mobs.get(i)) > entityTrackRange || !PneumaticCraftUtils.isEntityValidForFilter(entityFilter, mobs.get(i)) || MinecraftForge.EVENT_BUS.post(new EntityTrackEvent(mobs.get(i))))
            continue;
        boolean inList = false;
        for (int j = 0; j < targets.size(); j++) {
            if (targets.get(j).entity == mobs.get(i)) {
                inList = true;
                // cancel
                targets.get(j).ticksExisted = Math.abs(targets.get(j).ticksExisted);
                // targets
                break;
            }
        }
        if (!inList) {
            //player.worldObj.playSoundAtEntity(player, Sounds.CANNON_SOUND, 1.0F, 1.0F);
            targets.add(new RenderTarget(mobs.get(i)));
            if (mobs.get(i) instanceof EntityMob && !isEntityWithinPlayerFOV(player, mobs.get(i))) {
            //       HUDHandler.instance().addMessage(new ArmorMessage("A mob is sneaking up on you!", new ArrayList<String>(), 60, 0x70FF0000));
            }
        }
    }
    for (int j = 0; j < targets.size(); j++) {
        RenderTarget target = targets.get(j);
        if (target.entity.isDead || player.getDistanceToEntity(target.entity) > entityTrackRange + 5 || !PneumaticCraftUtils.isEntityValidForFilter(entityFilter, target.entity)) {
            if (target.ticksExisted > 0) {
                target.ticksExisted = -60;
            } else if (target.ticksExisted == -1) {
                targets.remove(target);
                j--;
            }
        }
    }
    if (targets.size() > ENTITY_TRACK_THRESHOLD) {
        if (!shouldStopSpamOnEntityTracking) {
            shouldStopSpamOnEntityTracking = true;
            HUDHandler.instance().addMessage(new ArmorMessage("Stopped spam on Entity Tracker", new ArrayList<String>(), 60, 0x7700AA00));
        }
    } else {
        shouldStopSpamOnEntityTracking = false;
    }
    List<String> text = new ArrayList<String>();
    for (RenderTarget target : targets) {
        boolean wasNegative = target.ticksExisted < 0;
        target.ticksExisted += CommonHUDHandler.getHandlerForPlayer(player).getSpeedFromUpgrades();
        if (target.ticksExisted >= 0 && wasNegative)
            target.ticksExisted = -1;
        target.update();
        if (target.isLookingAtTarget) {
            if (target.isInitialized()) {
                text.add(EnumChatFormatting.GRAY + target.entity.getCommandSenderName());
                text.addAll(target.getEntityText());
            } else {
                text.add(EnumChatFormatting.GRAY + "Acquiring target...");
            }
        }
    }
    if (text.size() == 0) {
        text.add("Filter mode: " + (entityFilter.equals("") ? "None" : entityFilter));
    }
    entityTrackInfo.setText(text);
    //Remove entities that don't need to be tracked anymore.
    Iterator<Entry<Entity, Integer>> iterator = targetingEntities.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<Entity, Integer> entry = iterator.next();
        Entity entity = entry.getKey();
        if (entry.getValue() >= 0)
            entry.setValue(entry.getValue() + 1);
        if (entity.isDead || !player.worldObj.getLoadedEntityList().contains(entity) || entry.getValue() > 50)
            iterator.remove();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityTrackEvent(pneumaticCraft.api.client.pneumaticHelmet.EntityTrackEvent) ArrayList(java.util.ArrayList) EntityMob(net.minecraft.entity.monster.EntityMob) Entry(java.util.Map.Entry) ItemStack(net.minecraft.item.ItemStack) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 44 with AxisAlignedBB

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

the class BlockPressureTube method collisionRayTrace.

@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
    MovingObjectPosition bestMOP = null;
    AxisAlignedBB bestAABB = null;
    setBlockBounds(BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS);
    MovingObjectPosition mop = super.collisionRayTrace(world, x, y, z, origin, direction);
    if (isCloserMOP(origin, bestMOP, mop)) {
        bestMOP = mop;
        bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
    }
    TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
    for (int i = 0; i < 6; i++) {
        if (tube.sidesConnected[i]) {
            setBlockBounds(boundingBoxes[i]);
            mop = super.collisionRayTrace(world, x, y, z, origin, direction);
            if (isCloserMOP(origin, bestMOP, mop)) {
                bestMOP = mop;
                bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
            }
        }
    }
    //unknown indicates we hit the tube.
    if (bestMOP != null)
        bestMOP.hitInfo = ForgeDirection.UNKNOWN;
    TubeModule[] modules = tube.modules;
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (modules[dir.ordinal()] != null) {
            setBlockBounds(modules[dir.ordinal()].boundingBoxes[dir.ordinal()]);
            mop = super.collisionRayTrace(world, x, y, z, origin, direction);
            if (isCloserMOP(origin, bestMOP, mop)) {
                mop.hitInfo = dir;
                bestMOP = mop;
                bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
            }
        }
    }
    if (bestAABB != null)
        setBlockBounds(bestAABB);
    return bestMOP;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) TubeModule(pneumaticCraft.common.block.tubes.TubeModule) ItemTubeModule(pneumaticCraft.common.item.ItemTubeModule) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube)

Example 45 with AxisAlignedBB

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

the class EntityPotionCloud method onUpdate.

@Override
public void onUpdate() {
    age++;
    radius -= 0.001D;
    if (radius <= 0.0D && !worldObj.isRemote) {
        EntityItem seed = new EntityItem(worldObj, posX, posY, posZ, new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.POTION_PLANT_DAMAGE));
        seed.lifespan = 300;
        ItemPlasticPlants.markInactive(seed);
        worldObj.spawnEntityInWorld(seed);
        setDead();
    }
    if (age % 60 == 0) {
        motionX += (rand.nextDouble() - 0.5D) * 0.1D;
        motionY += (rand.nextDouble() - 0.6D) * 0.1D;
        motionZ += (rand.nextDouble() - 0.5D) * 0.1D;
    }
    super.onUpdate();
    moveEntity(motionX, motionY, motionZ);
    if (worldObj.isRemote) {
        int potionColor = getPotionID() < Potion.potionTypes.length && Potion.potionTypes[getPotionID()] != null ? Potion.potionTypes[getPotionID()].getLiquidColor() : 0xFFFFFF;
        for (int i = 0; i < 4; i++) worldObj.spawnParticle("mobSpell", posX + (rand.nextDouble() - 0.5D) * 2 * radius, posY + (rand.nextDouble() - 0.5D) * 2 * radius, posZ + (rand.nextDouble() - 0.5D) * 2 * radius, (potionColor >> 16 & 255) / 255.0F, (potionColor >> 8 & 255) / 255.0F, (potionColor >> 0 & 255) / 255.0F);
    } else if (getPotionID() >= Potion.potionTypes.length) {
        setDead();
    }
    AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(posX - radius, posY - radius, posZ - radius, posX + radius, posY + radius, posZ + radius);
    List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, bbBox);
    for (EntityLivingBase entity : entities) {
        entity.addPotionEffect(new PotionEffect(getPotionID(), 200));
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

AxisAlignedBB (net.minecraft.util.AxisAlignedBB)74 Entity (net.minecraft.entity.Entity)24 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)18 ItemStack (net.minecraft.item.ItemStack)15 TileEntity (net.minecraft.tileentity.TileEntity)14 ArrayList (java.util.ArrayList)13 Vec3 (net.minecraft.util.Vec3)13 List (java.util.List)11 EntityItem (net.minecraft.entity.item.EntityItem)11 Block (net.minecraft.block.Block)10 EntityLivingBase (net.minecraft.entity.EntityLivingBase)9 Pos (com.builtbroken.mc.imp.transform.vector.Pos)7 SideOnly (cpw.mods.fml.relauncher.SideOnly)7 Iterator (java.util.Iterator)4 LPPositionSet (logisticspipes.utils.LPPositionSet)4 World (net.minecraft.world.World)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)4 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3