Search in sources :

Example 76 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Wizardry by TeamWizardry.

the class ModuleShapeZone method run.

@Override
@SuppressWarnings("unused")
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    World world = spell.world;
    Vec3d position = spell.getData(ORIGIN);
    Entity caster = spell.getCaster();
    Vec3d targetPos = spell.getTarget();
    if (targetPos == null)
        return false;
    double aoe = spellRing.getAttributeValue(AttributeRegistry.AREA, spell);
    double strength = spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell);
    double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
    spellRing.multiplyMultiplierForAll((float) (aoe / 7.0 * strength / 15.0 * range / 15.0));
    List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(new BlockPos(targetPos)).grow(aoe, 1, aoe));
    if (RandUtil.nextInt((int) ((70 - strength))) == 0) {
        if (!spellRing.taxCaster(spell))
            return false;
        for (Entity entity : entities) {
            if (entity.getDistance(targetPos.x, targetPos.y, targetPos.z) <= aoe) {
                Vec3d vec = targetPos.addVector(RandUtil.nextDouble(-strength, strength), RandUtil.nextDouble(range), RandUtil.nextDouble(-strength, strength));
                SpellData copy = spell.copy();
                copy.processEntity(entity, false);
                copy.addData(YAW, entity.rotationYaw);
                copy.addData(PITCH, entity.rotationPitch);
                copy.addData(ORIGIN, vec);
                if (spellRing.getChildRing() != null) {
                    spellRing.getChildRing().runSpellRing(spell);
                }
            }
        }
    }
    if (RandUtil.nextInt((int) ((40 - strength))) != 0)
        return false;
    ArrayList<Vec3d> blocks = new ArrayList<>();
    for (double i = -aoe; i < aoe; i++) for (double j = 0; j < range; j++) for (double k = -aoe; k < aoe; k++) {
        Vec3d pos = targetPos.addVector(i, j, k);
        if (pos.distanceTo(targetPos) <= aoe) {
            // BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(new BlockPos(pos));
            blocks.add(pos);
        }
    }
    if (blocks.isEmpty())
        return false;
    if (!spellRing.taxCaster(spell))
        return false;
    Vec3d pos = blocks.get(RandUtil.nextInt(blocks.size() - 1));
    SpellData copy = spell.copy();
    copy.addData(ORIGIN, pos);
    copy.processBlock(new BlockPos(pos), EnumFacing.UP, pos);
    copy.addData(YAW, RandUtil.nextFloat(-180, 180));
    copy.addData(PITCH, RandUtil.nextFloat(-50, 50));
    if (spellRing.getChildRing() != null) {
        spellRing.getChildRing().runSpellRing(copy);
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) SpellData(com.teamwizardry.wizardry.api.spell.SpellData) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d)

Example 77 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project BaseMetals by MinecraftModDevelopmentMods.

the class BlockHumanDetector method computeRedstoneStrength.

@Override
protected int computeRedstoneStrength(final World worldIn, final BlockPos pos) {
    final AxisAlignedBB axisalignedbb = PRESSURE_AABB.offset(pos);
    final List<? extends Entity> list = worldIn.<Entity>getEntitiesWithinAABB(EntityPlayer.class, axisalignedbb);
    if (!list.isEmpty()) {
        return 15;
    }
    return 0;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity)

Example 78 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Wizardry by TeamWizardry.

the class ModuleEffectLightning method run.

@Override
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    World world = spell.world;
    Vec3d target = spell.getTarget();
    Entity caster = spell.getCaster();
    float yaw = spell.getData(YAW, 0F);
    float pitch = spell.getData(PITCH, 0F);
    if (target == null)
        return false;
    Vec3d origin = target;
    if (caster != null) {
        float offX = 0.5f * (float) Math.sin(Math.toRadians(-90.0f - yaw));
        float offZ = 0.5f * (float) Math.cos(Math.toRadians(-90.0f - yaw));
        origin = new Vec3d(offX, caster.getEyeHeight(), offZ).add(target);
    }
    double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
    double strength = spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell) / 2.0;
    if (!spellRing.taxCaster(spell))
        return false;
    RayTraceResult traceResult = new RayTrace(world, PosUtils.vecFromRotations(pitch, yaw), target, range).setSkipBlocks(true).setSkipEntities(true).trace();
    long seed = RandUtil.nextLong(100, 100000);
    spell.addData(SEED, seed);
    LightningGenerator generator = new LightningGenerator(origin, traceResult.hitVec, new RandUtilSeed(seed));
    ArrayList<Vec3d> points = generator.generate();
    spell.world.playSound(null, new BlockPos(traceResult.hitVec), ModSounds.LIGHTNING, SoundCategory.NEUTRAL, 0.5f, RandUtil.nextFloat(1, 1.5f));
    for (Vec3d point : points) {
        List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(caster, new AxisAlignedBB(new BlockPos(point)).contract(0.2, 0.2, 0.2));
        if (!entityList.isEmpty()) {
            for (Entity entity : entityList) {
                LightningTracker.INSTANCE.addEntity(origin, entity, caster, (int) strength);
            }
        }
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed) Vec3d(net.minecraft.util.math.Vec3d) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) BlockPos(net.minecraft.util.math.BlockPos) LightningGenerator(com.teamwizardry.wizardry.api.LightningGenerator)

Example 79 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project ForestryMC by ForestryMC.

the class BlockEngine method collisionRayTrace.

@Override
public RayTraceResult collisionRayTrace(IBlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) {
    EnumFacing orientation = blockState.getValue(FACING);
    List<AxisAlignedBB> boundingBoxes = boundingBoxesForDirections.get(orientation);
    if (boundingBoxes == null) {
        return super.collisionRayTrace(blockState, worldIn, pos, start, end);
    }
    RayTraceResult nearestIntersection = null;
    for (AxisAlignedBB boundingBoxBase : boundingBoxes) {
        AxisAlignedBB boundingBox = boundingBoxBase.offset(pos.getX(), pos.getY(), pos.getZ());
        RayTraceResult intersection = boundingBox.calculateIntercept(start, end);
        if (intersection != null) {
            if (nearestIntersection == null || intersection.hitVec.distanceTo(start) < nearestIntersection.hitVec.distanceTo(start)) {
                nearestIntersection = intersection;
            }
        }
    }
    if (nearestIntersection != null) {
        Object hitInfo = nearestIntersection.hitInfo;
        Entity entityHit = nearestIntersection.entityHit;
        nearestIntersection = new RayTraceResult(nearestIntersection.typeOfHit, nearestIntersection.hitVec, nearestIntersection.sideHit, pos);
        nearestIntersection.hitInfo = hitInfo;
        nearestIntersection.entityHit = entityHit;
    }
    return nearestIntersection;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult)

Example 80 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project ForestryMC by ForestryMC.

the class BlockEngine method addCollisionBoxToList.

@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_) {
    EnumFacing orientation = state.getValue(FACING);
    List<AxisAlignedBB> boundingBoxes = boundingBoxesForDirections.get(orientation);
    if (boundingBoxes == null) {
        return;
    }
    for (AxisAlignedBB boundingBoxBase : boundingBoxes) {
        AxisAlignedBB boundingBox = boundingBoxBase.offset(pos.getX(), pos.getY(), pos.getZ());
        if (entityBox.intersects(boundingBox)) {
            collidingBoxes.add(boundingBox);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumFacing(net.minecraft.util.EnumFacing)

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