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);
}
}
}
}
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);
}
}
}
}
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations