Java Code Examples for net.minecraft.util.math.BlockPos#getAllInBoxMutable()

The following examples show how to use net.minecraft.util.math.BlockPos#getAllInBoxMutable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockTofuFarmLand.java    From TofuCraftReload with MIT License 5 votes vote down vote up
private boolean hasWater(World worldIn, BlockPos pos)
{
    for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-4, 0, -4), pos.add(4, 1, 4)))
    {
        if (worldIn.getBlockState(blockpos$mutableblockpos).getMaterial() == Material.WATER)
        {
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: Area.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** Scan an area for stuff */
public List<BlockPos> scanArea(World world) {
	List<BlockPos> bpl = new ArrayList<BlockPos>();
	Iterable<MutableBlockPos> set = BlockPos.getAllInBoxMutable(startX, startY, startZ, endX, endY, endZ);
	Iterator<MutableBlockPos> in = set.iterator();
	while (in.hasNext()) {
		MutableBlockPos mbp = in.next();
		if (!world.isAirBlock(mbp)) {
			bpl.add(mbp.toImmutable());
		}
	}
	return bpl;
}
 
Example 3
Source File: PotionCrash.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void fall(LivingFallEvent e) {
	EntityLivingBase entitySource = e.getEntityLiving();
	PotionEffect crash = entitySource.getActivePotionEffect(this);
	if (crash == null) return;

	PotionEffect jump = entitySource.getActivePotionEffect(MobEffects.JUMP_BOOST);
	float f = (jump == null) ? 0.0f : (jump.getAmplifier() + 1);
	float damage = MathHelper.clamp((e.getDistance() - 3.0f - f) * e.getDamageMultiplier() * 2, 0, 10f);

	float range = damage / 10f + Math.max(crash.getAmplifier(), 5);

	if (damage > 0.0f) {
		e.setDamageMultiplier(e.getDamageMultiplier() / (crash.getAmplifier() + 2));
		List<EntityLivingBase> entities = entitySource.world.getEntitiesWithinAABB(EntityLivingBase.class, entitySource.getEntityBoundingBox().grow(range * 2));
		entities.stream().filter(entity -> entity != entitySource && entity.onGround).forEach(entity -> {
			entity.attackEntityFrom(damageSourceEarthquake(entitySource), range);
			entity.motionY = range / 10.0;
			entity.velocityChanged = true;
		});

		if (!entitySource.world.isRemote) for (BlockPos pos : BlockPos.getAllInBoxMutable(
				new BlockPos(entitySource.getPositionVector())
						.add(-range,
								-2,
								-range),
				new BlockPos(entitySource.getPositionVector())
						.add(range,
								0,
								range))) {
			IBlockState state = entitySource.world.getBlockState(pos);
			if (state.isFullCube()) entitySource.world.playEvent(2001, pos.toImmutable(), Block.getStateId(state));
		}
	}
}
 
Example 4
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void deleteArea(ItemStack stack, World world, EntityPlayer player, BlockPos posStart, BlockPos posEnd, boolean removeEntities)
{
    if (posStart == null || posEnd == null)
    {
        return;
    }

    if (player.getDistanceSq(posStart) > 160 * 160)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoofar"), true);
        return;
    }

    if (this.isAreaWithinSizeLimit(posStart.subtract(posEnd), stack, player) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoolarge"), true);
        return;
    }

    // Set all blocks to air
    for (BlockPos.MutableBlockPos posMutable : BlockPos.getAllInBoxMutable(posStart, posEnd))
    {
        if (world.isAirBlock(posMutable) == false)
        {
            BlockUtils.setBlockToAirWithoutSpillingContents(world, posMutable, 2);
        }
    }

    // Remove pending block updates from within the area
    BlockPos posMin = PositionUtils.getMinCorner(posStart, posEnd);
    BlockPos posMax = PositionUtils.getMaxCorner(posStart, posEnd).add(1, 1, 1);
    StructureBoundingBox sbb = StructureBoundingBox.createProper(posMin.getX(), posMin.getY(), posMin.getZ(), posMax.getX(), posMax.getY(), posMax.getZ());
    world.getPendingBlockUpdates(sbb, true); // The boolean parameter indicates whether the entries will be removed

    // Remove all entities within the area
    int count = 0;

    if (removeEntities)
    {
        int x1 = Math.min(posStart.getX(), posEnd.getX());
        int y1 = Math.min(posStart.getY(), posEnd.getY());
        int z1 = Math.min(posStart.getZ(), posEnd.getZ());
        int x2 = Math.max(posStart.getX(), posEnd.getX());
        int y2 = Math.max(posStart.getY(), posEnd.getY());
        int z2 = Math.max(posStart.getZ(), posEnd.getZ());

        AxisAlignedBB bb = new AxisAlignedBB(x1, y1, z1, x2 + 1, y2 + 1, z2 + 1);
        List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, bb);

        for (Entity entity : entities)
        {
            if ((entity instanceof EntityPlayer) == false || entity instanceof FakePlayer)
            {
                entity.setDead();
                count++;
            }
        }

        if (count > 0)
        {
            player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.killedentitieswithcount", count), true);
        }
    }
}
 
Example 5
Source File: TemplateEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void takeBlocksFromWorld(World worldIn, BlockPos posStart, BlockPos posEndRelative, boolean takeEntities, boolean cbCrossWorld)
{
    BlockPos endPos = posStart.add(posEndRelative);
    List<TemplateEnderUtilities.TemplateBlockInfo> list = Lists.<TemplateEnderUtilities.TemplateBlockInfo>newArrayList();
    List<TemplateEnderUtilities.TemplateBlockInfo> list1 = Lists.<TemplateEnderUtilities.TemplateBlockInfo>newArrayList();
    List<TemplateEnderUtilities.TemplateBlockInfo> list2 = Lists.<TemplateEnderUtilities.TemplateBlockInfo>newArrayList();

    this.size = PositionUtils.getAreaSizeFromRelativeEndPosition(posEndRelative);

    for (BlockPos.MutableBlockPos posMutable : BlockPos.getAllInBoxMutable(posStart, endPos))
    {
        BlockPos posRelative = posMutable.subtract(posStart);
        IBlockState state = worldIn.getBlockState(posMutable);

        TileEntity te = worldIn.getTileEntity(posMutable);

        if (te != null)
        {
            NBTTagCompound tag = new NBTTagCompound();

            if (cbCrossWorld)
            {
                tag = chiselsAndBitsHandler.writeChiselsAndBitsTileToNBT(tag, te);
            }
            else
            {
                tag = te.writeToNBT(tag);
            }

            tag.removeTag("x");
            tag.removeTag("y");
            tag.removeTag("z");

            list1.add(new TemplateEnderUtilities.TemplateBlockInfo(posRelative, state, tag));
        }
        else if (state.isFullBlock() == false && state.isFullCube() == false)
        {
            list2.add(new TemplateEnderUtilities.TemplateBlockInfo(posRelative, state, null));
        }
        else
        {
            list.add(new TemplateEnderUtilities.TemplateBlockInfo(posRelative, state, null));
        }
    }

    this.blocks.clear();
    this.blocks.addAll(list);
    this.blocks.addAll(list1);
    this.blocks.addAll(list2);

    if (takeEntities)
    {
        this.takeEntitiesFromWorld(worldIn, posStart, posEndRelative);
    }
    else
    {
        this.entities.clear();
    }
}