Search in sources :

Example 21 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project NetherEx by LogicTechCorp.

the class ItemObsidianBoat method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * 1.0F;
    float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * 1.0F;
    double d0 = player.prevPosX + (player.posX - player.prevPosX) * 1.0D;
    double d1 = player.prevPosY + (player.posY - player.prevPosY) * 1.0D + (double) player.getEyeHeight();
    double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * 1.0D;
    Vec3d vec3d = new Vec3d(d0, d1, d2);
    float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
    float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
    float f5 = -MathHelper.cos(-f1 * 0.017453292F);
    float f6 = MathHelper.sin(-f1 * 0.017453292F);
    float f7 = f4 * f5;
    float f8 = f3 * f5;
    Vec3d vec3d1 = vec3d.addVector((double) f7 * 5.0D, (double) f6 * 5.0D, (double) f8 * 5.0D);
    RayTraceResult raytraceresult = world.rayTraceBlocks(vec3d, vec3d1, true);
    if (raytraceresult == null) {
        return new ActionResult(EnumActionResult.PASS, stack);
    } else {
        Vec3d vec3d2 = player.getLook(1.0F);
        boolean flag = false;
        List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.getEntityBoundingBox().addCoord(vec3d2.xCoord * 5.0D, vec3d2.yCoord * 5.0D, vec3d2.zCoord * 5.0D).expandXyz(1.0D));
        for (Entity entity : entities) {
            if (entity.canBeCollidedWith()) {
                AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expandXyz((double) entity.getCollisionBorderSize());
                if (axisalignedbb.isVecInside(vec3d)) {
                    flag = true;
                }
            }
        }
        if (flag) {
            return new ActionResult(EnumActionResult.PASS, stack);
        } else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK) {
            return new ActionResult(EnumActionResult.PASS, stack);
        } else {
            Block block = world.getBlockState(raytraceresult.getBlockPos()).getBlock();
            boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
            EntityObsidianBoat boat = new EntityObsidianBoat(world, raytraceresult.hitVec.xCoord, flag1 ? raytraceresult.hitVec.yCoord - 0.12D : raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
            boat.rotationYaw = player.rotationYaw;
            if (!world.getCollisionBoxes(boat, boat.getEntityBoundingBox().expandXyz(-0.1D)).isEmpty()) {
                return new ActionResult(EnumActionResult.FAIL, stack);
            } else {
                if (!world.isRemote) {
                    world.spawnEntity(boat);
                }
                if (!player.capabilities.isCreativeMode) {
                    stack.shrink(1);
                }
                return new ActionResult(EnumActionResult.SUCCESS, stack);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityObsidianBoat(nex.entity.item.EntityObsidianBoat) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 22 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Pearcel-Mod by MiningMark48.

the class ItemPearcelMagnet method doUpdate.

private void doUpdate(ItemStack stack, World world, Entity entity) {
    int range = ConfigurationHandler.pearcelMagnetRange;
    float pullSpeed = ConfigurationHandler.pearcelMagnetPullSpeed;
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
        stack.getTagCompound().setBoolean("enabled", false);
        stack.getTagCompound().setString("mode", "Attracts");
    }
    if (entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        if (stack.getTagCompound().getBoolean("enabled") && hasEnoughEnergy(stack, ConfigurationHandler.rfPerTick_magnet, player)) {
            double x = player.posX;
            double y = player.posY;
            double z = player.posZ;
            List<EntityItem> items = entity.world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
            List<EntityXPOrb> xp = entity.world.getEntitiesWithinAABB(EntityXPOrb.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
            for (EntityItem e : items) {
                if (!player.isSneaking()) {
                    if (stack.getTagCompound().getString("mode").equalsIgnoreCase("attracts")) {
                        //Attracts
                        e.addVelocity((x - e.posX) * pullSpeed, (y - e.posY) * pullSpeed, (z - e.posZ) * pullSpeed);
                    } else {
                        //Repels
                        e.addVelocity((e.posX - x) * pullSpeed, (e.posY - y) * pullSpeed, (e.posZ - z) * pullSpeed);
                    }
                    if (ConfigurationHandler.pearcelMagnetParticles) {
                        world.spawnParticle(EnumParticleTypes.SPELL_INSTANT, e.posX, e.posY + 0.3, e.posZ, 0.0D, 0.0D, 0.0D);
                    }
                    useEnergy(stack, ConfigurationHandler.rfPerTick_magnet, false, player);
                }
            }
            for (EntityXPOrb e : xp) {
                if (!player.isSneaking()) {
                    if (stack.getTagCompound().getString("mode").equalsIgnoreCase("attracts")) {
                        //Attracts
                        e.addVelocity((x - e.posX) * pullSpeed, (y - e.posY) * pullSpeed, (z - e.posZ) * pullSpeed);
                    } else {
                        //Repels
                        e.addVelocity((e.posX - x) * pullSpeed, (e.posY - y) * pullSpeed, (e.posZ - z) * pullSpeed);
                    }
                    useEnergy(stack, ConfigurationHandler.rfPerTick_magnet, false, player);
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 23 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project ConvenientAdditions by Necr0.

the class BlockBlastPad method neighborChanged.

@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos from) {
    float str = EntityLaunchingArrow.EnumLaunchingArrowVariant.slime.strength * (float) Math.log(worldIn.isBlockIndirectlyGettingPowered(pos) + 1) * .25f;
    if (state.getValue(READY) && worldIn.isBlockIndirectlyGettingPowered(pos) > 0) {
        List<EntityLivingBase> l = worldIn.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(pos.up()));
        for (EntityLivingBase e : l) {
            e.addVelocity(0, str, 0);
            e.velocityChanged = true;
            if (e.motionY > -.666)
                e.fallDistance = 0;
        }
        worldIn.playSound(null, pos, SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.generic.explode")), SoundCategory.BLOCKS, .15f, 1.25f);
        ModNetworking.spawnParticle(worldIn, EnumParticleTypes.EXPLOSION_LARGE, pos.getX() + .5, pos.getY() + 1.1, pos.getZ() + .5, 1.3, 0, 0);
        worldIn.setBlockState(pos, state.withProperty(READY, false), 6);
    } else if (!state.getValue(READY).booleanValue() && worldIn.isBlockIndirectlyGettingPowered(pos) == 0) {
        worldIn.setBlockState(pos, state.withProperty(READY, true), 6);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 24 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project ConvenientAdditions by Necr0.

the class BlockCompostSoilTilled method onFallenUpon.

@Override
public void onFallenUpon(World world, BlockPos pos, Entity entity, float height) {
    if (!world.isRemote && entity.canTrample(world, this, pos, height)) {
        if (!(entity instanceof EntityPlayer) && !world.getGameRules().getBoolean("mobGriefing")) {
            return;
        }
        world.setBlockState(pos, ModBlocks.compostSoilBlock.getStateFromMeta(this.getMetaFromState(world.getBlockState(pos))));
        AxisAlignedBB axisalignedbb = ModBlocks.compostSoilBlock.getDefaultState().getCollisionBoundingBox(world, pos).offset(pos);
        for (Entity e : world.getEntitiesWithinAABBExcludingEntity((Entity) null, axisalignedbb)) {
            e.setPosition(entity.posX, axisalignedbb.maxY, entity.posZ);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 25 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project ConvenientAdditions by Necr0.

the class TileEntityComposter method update.

@Override
public void update() {
    if (!getWorld().isRemote) {
        for (EntityItem e : getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.getX(), pos.getY() + 1, pos.getZ(), pos.getX() + 1, pos.getY() + 1.5d, pos.getZ() + 1))) {
            if (!e.isDead && !e.getEntityItem().isEmpty()) {
                ItemStack i = e.getEntityItem();
                i.setCount(stackHandler.insertItem(0, i, false).getCount());
                if (i.isEmpty())
                    e.setDead();
            }
        }
    }
    IBlockState state = getWorld().getBlockState(pos);
    Random rnd = new Random();
    if (!getWorld().isRemote) {
        if (content >= ModConfigMisc.composter_progressContent) {
            progress++;
            if (progress >= ModConfigMisc.composter_progressPeriod) {
                progress = 0;
                content -= ModConfigMisc.composter_progressContent;
                if (getWorld().rand.nextFloat() < ModConfigMisc.composter_compostChance)
                    Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemCompost, 1, this.spores ? 1 : 0));
                if (getWorld().rand.nextFloat() < ModConfigMisc.composter_extraCompostChance)
                    Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemCompost, 1, this.spores ? 1 : 0));
                if (getWorld().rand.nextFloat() < ModConfigMisc.composter_dirtChunkChance)
                    Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemDirtChunk));
                if (getWorld().rand.nextFloat() < ModConfigMisc.composter_fertilizerChance)
                    Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemFertilizer));
            }
            if (content >= ModConfigMisc.composter_capacity && ModConfigMisc.composter_overflowSmell) {
                List<EntityPlayer> players = getWorld().getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.getX() - 2, pos.getY() - 2, pos.getZ() - 2, pos.getX() + 3, pos.getY() + 3, pos.getZ() + 3));
                for (EntityPlayer p : players) {
                    switch(rnd.nextInt(120)) {
                        case 0:
                            p.addPotionEffect(new PotionEffect(Potion.getPotionById(9), 200, 0));
                            break;
                        default:
                            break;
                    }
                }
            }
            this.markDirty();
            this.getWorld().notifyBlockUpdate(pos, state, state, 3);
        } else {
            this.progress = 0;
            if (this.content == 0)
                this.spores = false;
            if (processing) {
                this.processing = false;
                this.markDirty();
                this.getWorld().notifyBlockUpdate(pos, state, state, 3);
            }
        }
    } else if (processing) {
        if (rnd.nextInt(10) == 0)
            getWorld().spawnParticle(EnumParticleTypes.SPELL_MOB, pos.getX() + .5 - ((double) (rnd.nextInt(9) - 4) / 10D), pos.getY() + .2 + (double) content / (double) ModConfigMisc.composter_capacity * .75, pos.getZ() + .5 + ((double) (rnd.nextInt(9) - 4) / 10D), 0, 0.6, 0);
        if (content >= ModConfigMisc.composter_capacity)
            getWorld().spawnParticle(EnumParticleTypes.SPELL_MOB, pos.getX() + .5 - ((double) (rnd.nextInt(9) - 4) / 10D), pos.getY() + .2 + (double) content / (double) ModConfigMisc.composter_capacity * .75, pos.getZ() + .5 + ((double) (rnd.nextInt(9) - 4) / 10D), 0, 0.6, 0);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) Random(java.util.Random) PotionEffect(net.minecraft.potion.PotionEffect) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)127 EntityPlayer (net.minecraft.entity.player.EntityPlayer)34 BlockPos (net.minecraft.util.math.BlockPos)31 EntityLivingBase (net.minecraft.entity.EntityLivingBase)30 Entity (net.minecraft.entity.Entity)23 EnumFacing (net.minecraft.util.EnumFacing)22 IBlockState (net.minecraft.block.state.IBlockState)17 Vec3d (net.minecraft.util.math.Vec3d)17 ArrayList (java.util.ArrayList)11 ItemStack (net.minecraft.item.ItemStack)11 TileEntity (net.minecraft.tileentity.TileEntity)10 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)9 World (net.minecraft.world.World)9 Vector (ValkyrienWarfareBase.API.Vector)8 EntityItem (net.minecraft.entity.item.EntityItem)8 PotionEffect (net.minecraft.potion.PotionEffect)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)8 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 Polygon (ValkyrienWarfareBase.Collision.Polygon)5