Search in sources :

Example 96 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project EnderIO by SleepyTrousers.

the class BlockTelePad method getSelectedBoundingBox.

@Deprecated
@Override
@Nonnull
public AxisAlignedBB getSelectedBoundingBox(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos) {
    if (bs.getBlock() == this) {
        BlockType bt = bs.getValue(BLOCK_TYPE);
        if (bt != BlockType.SINGLE) {
            BlockPos masterLoc = bt.getLocationOfMaster(pos);
            AxisAlignedBB res = new AxisAlignedBB(masterLoc.south().south().west(), masterLoc.north().east().east().up());
            return res;
        }
    }
    return super.getSelectedBoundingBox(bs, world, pos);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockType(crazypants.enderio.machines.machine.teleport.telepad.render.BlockType) BlockPos(net.minecraft.util.math.BlockPos) Nonnull(javax.annotation.Nonnull)

Example 97 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project HorsePower by GoryMoon.

the class BlockHPBase method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = playerIn.getHeldItem(hand);
    TileEntityHPBase te = (TileEntityHPBase) worldIn.getTileEntity(pos);
    TileEntityHPHorseBase teH = null;
    if (te == null)
        return false;
    if (te instanceof TileEntityHPHorseBase)
        teH = (TileEntityHPHorseBase) te;
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    EntityCreature creature = null;
    if (teH != null) {
        ArrayList<Class<? extends EntityCreature>> clazzes = Utils.getCreatureClasses();
        search: for (Class<? extends Entity> clazz : clazzes) {
            for (Object entity : worldIn.getEntitiesWithinAABB(clazz, new AxisAlignedBB((double) x - 7.0D, (double) y - 7.0D, (double) z - 7.0D, (double) x + 7.0D, (double) y + 7.0D, (double) z + 7.0D))) {
                if (entity instanceof EntityCreature) {
                    EntityCreature tmp = (EntityCreature) entity;
                    if ((tmp.getLeashed() && tmp.getLeashHolder() == playerIn)) {
                        creature = tmp;
                        break search;
                    }
                }
            }
        }
    }
    if (teH != null && ((stack.getItem() instanceof ItemLead && creature != null) || creature != null)) {
        if (!teH.hasWorker()) {
            creature.clearLeashed(true, false);
            teH.setWorker(creature);
            onWorkerAttached(playerIn, creature);
            return true;
        } else {
            return false;
        }
    } else if (!stack.isEmpty() && te.isItemValidForSlot(0, stack)) {
        ItemStack itemStack = te.getStackInSlot(0);
        boolean flag = false;
        if (itemStack.isEmpty()) {
            te.setInventorySlotContents(0, stack.copy());
            stack.setCount(stack.getCount() - te.getInventoryStackLimit(stack));
            flag = true;
        } else if (TileEntityHPBase.canCombine(itemStack, stack)) {
            int i = Math.min(te.getInventoryStackLimit(stack), stack.getMaxStackSize()) - itemStack.getCount();
            int j = Math.min(stack.getCount(), i);
            stack.shrink(j);
            itemStack.grow(j);
            flag = j > 0;
        }
        if (flag)
            return true;
    }
    int slot = getSlot(state.getBlock().getExtendedState(state, worldIn, pos), hitX, hitY, hitZ);
    ItemStack result = ItemStack.EMPTY;
    if (slot > -1) {
        result = te.removeStackFromSlot(slot);
    } else if (slot > -2) {
        result = te.removeStackFromSlot(1);
        if (result.isEmpty()) {
            result = te.removeStackFromSlot(2);
            if (result.isEmpty() && stack.isEmpty() && hand != EnumHand.OFF_HAND) {
                result = te.removeStackFromSlot(0);
            }
        }
        if (!result.isEmpty())
            emptiedOutput(worldIn, pos);
    }
    if (result.isEmpty()) {
        if (!stack.isEmpty())
            return false;
        if (teH != null)
            teH.setWorkerToPlayer(playerIn);
    }
    if (!result.isEmpty())
        ItemHandlerHelper.giveItemToPlayer(playerIn, result, EntityEquipmentSlot.MAINHAND.getSlotIndex());
    te.markDirty();
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TileEntityHPBase(se.gory_moon.horsepower.tileentity.TileEntityHPBase) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ItemLead(net.minecraft.item.ItemLead) ItemStack(net.minecraft.item.ItemStack) EntityCreature(net.minecraft.entity.EntityCreature) TileEntityHPHorseBase(se.gory_moon.horsepower.tileentity.TileEntityHPHorseBase)

Example 98 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project EnderIO by SleepyTrousers.

the class TileRelocatorObelisk method processTasks.

@Override
protected boolean processTasks(boolean redstoneCheck) {
    if (!relocationQueue.isEmpty()) {
        AxisAlignedBB targetBB = new AxisAlignedBB(getPos(), getPos().add(1, 1, 1)).expand(4, 1, 4);
        Iterator<EntityLivingBase> iterator = relocationQueue.keySet().iterator();
        while (iterator.hasNext()) {
            EntityLivingBase mob = iterator.next();
            if (mob == null || mob.isDead || world.getEntityByID(mob.getEntityId()) == null || mob.ticksExisted > 2 * 60 * 20 || relocationQueue.size() > 100) {
                iterator.remove();
            } else if (hasPower() && rand.nextFloat() < .025f) {
                AxisAlignedBB mobbb = mob.getEntityBoundingBox();
                if (targetBB.intersects(mobbb)) {
                    iterator.remove();
                } else {
                    double x = getPos().getX() + .5 + Math.random() * 8d - 4.0;
                    double y = getPos().getY() + .5 + Math.random() * 3d - 1.5;
                    double z = getPos().getZ() + .5 + Math.random() * 8d - 4.0;
                    double dx = mobbb.maxX - mobbb.minX;
                    double dy = mobbb.maxY - mobbb.minY;
                    double dz = mobbb.maxZ - mobbb.minZ;
                    AxisAlignedBB bb = new AxisAlignedBB(x - dx / 2, y, z - dz / 2, x + dx / 2, y + dy, z + dz / 2);
                    boolean spaceClear = world.checkNoEntityCollision(bb, mob) && world.getCollisionBoxes(mob, bb).isEmpty() && (world.containsAnyLiquid(bb) == mob.isCreatureType(EnumCreatureType.WATER_CREATURE, false));
                    if (spaceClear) {
                        PacketSpawnParticles.create(mob, EnumParticleTypes.PORTAL, EnumParticleTypes.PORTAL, EnumParticleTypes.PORTAL);
                        mob.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
                        mob.setPositionAndUpdate(x - dx / 2, y + .05, z - dz / 2);
                        mob.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
                        PacketSpawnParticles.create(mob, EnumParticleTypes.PORTAL, EnumParticleTypes.PORTAL, EnumParticleTypes.PORTAL);
                        iterator.remove();
                    }
                }
            }
        }
    }
    return super.processTasks(redstoneCheck);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 99 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project HorsePower by GoryMoon.

the class TileEntityHPHorseBase method update.

@Override
public void update() {
    validationTimer--;
    if (validationTimer <= 0) {
        valid = validateArea();
        if (valid)
            validationTimer = 220;
        else
            validationTimer = 60;
    }
    boolean flag = false;
    if (!hasWorker())
        locateHorseTimer--;
    if (!hasWorker() && nbtWorker != null && locateHorseTimer <= 0) {
        UUID uuid = nbtWorker.getUniqueId("UUID");
        int x = pos.getX();
        int y = pos.getY();
        int z = pos.getZ();
        ArrayList<Class<? extends EntityCreature>> clazzes = Utils.getCreatureClasses();
        search: for (Class<? extends Entity> clazz : clazzes) {
            for (Object entity : world.getEntitiesWithinAABB(clazz, new AxisAlignedBB((double) x - 7.0D, (double) y - 7.0D, (double) z - 7.0D, (double) x + 7.0D, (double) y + 7.0D, (double) z + 7.0D))) {
                if (entity instanceof EntityCreature) {
                    EntityCreature creature = (EntityCreature) entity;
                    if (creature.getUniqueID().equals(uuid)) {
                        setWorker(creature);
                        flag = true;
                        break search;
                    }
                }
            }
        }
    }
    if (locateHorseTimer <= 0)
        locateHorseTimer = 220;
    if (!world.isRemote && valid) {
        if (!running && canWork()) {
            running = true;
        } else if (running && !canWork()) {
            running = false;
        }
        if (running != wasRunning) {
            target = getClosestTarget();
            wasRunning = running;
        }
        if (hasWorker()) {
            if (running) {
                Vec3d pos = getPathPosition(target);
                double x = pos.x;
                double y = pos.y;
                double z = pos.z;
                if (searchAreas[target] == null)
                    searchAreas[target] = new AxisAlignedBB(x - 0.5D, y - 0.5D, z - 0.5D, x + 0.5D, y + 0.5D, z + 0.5D);
                if (worker.getEntityBoundingBox().intersects(searchAreas[target])) {
                    int next = target + 1;
                    int previous = target - 1;
                    if (next >= path.length)
                        next = 0;
                    if (previous < 0)
                        previous = path.length - 1;
                    if (origin != target && target != previous) {
                        origin = target;
                        flag = targetReached();
                    }
                    target = next;
                }
                if (worker instanceof AbstractHorse && ((AbstractHorse) worker).isEatingHaystack()) {
                    ((AbstractHorse) worker).setEatingHaystack(false);
                }
                if (target != -1 && worker.getNavigator().noPath()) {
                    pos = getPathPosition(target);
                    x = pos.x;
                    y = pos.y;
                    z = pos.z;
                    worker.getNavigator().tryMoveToXYZ(x, y, z, 1D);
                }
            }
        }
    }
    if (flag) {
        markDirty();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) AbstractHorse(net.minecraft.entity.passive.AbstractHorse) UUID(java.util.UUID) EntityCreature(net.minecraft.entity.EntityCreature) Vec3d(net.minecraft.util.math.Vec3d)

Example 100 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project minecolonies by Minecolonies.

the class TileEntityMultiBlock method pushEntitiesIfNecessary.

private void pushEntitiesIfNecessary(final BlockPos posToGo, final BlockPos pos) {
    final List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(posToGo));
    final BlockPos vector = posToGo.subtract(pos);
    final BlockPos posTo = posToGo.offset(getFacingFromVector(vector.getX(), vector.getY(), vector.getZ()));
    for (final Entity entity : entities) {
        entity.setPositionAndUpdate(posTo.getX() + HALF_BLOCK, posTo.getY() + HALF_BLOCK, posTo.getZ() + HALF_BLOCK);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)597 BlockPos (net.minecraft.util.math.BlockPos)194 Entity (net.minecraft.entity.Entity)133 EntityPlayer (net.minecraft.entity.player.EntityPlayer)119 IBlockState (net.minecraft.block.state.IBlockState)110 Vec3d (net.minecraft.util.math.Vec3d)95 EntityLivingBase (net.minecraft.entity.EntityLivingBase)93 EnumFacing (net.minecraft.util.EnumFacing)88 ItemStack (net.minecraft.item.ItemStack)77 World (net.minecraft.world.World)69 TileEntity (net.minecraft.tileentity.TileEntity)67 List (java.util.List)48 ArrayList (java.util.ArrayList)47 RayTraceResult (net.minecraft.util.math.RayTraceResult)45 EntityItem (net.minecraft.entity.item.EntityItem)43 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)41 Block (net.minecraft.block.Block)36 PotionEffect (net.minecraft.potion.PotionEffect)36 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)25 Nullable (javax.annotation.Nullable)24