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

The following examples show how to use net.minecraft.util.math.BlockPos#up() . 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: BlockEngineeringTable.java    From Cyberware with MIT License 6 votes vote down vote up
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
	BlockPos blockpos = pos.down();
	BlockPos blockpos1 = pos.up();

	if (player.capabilities.isCreativeMode && state.getValue(HALF) == EnumEngineeringHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this)
	{
		worldIn.setBlockToAir(blockpos);
	}

	if (state.getValue(HALF) == EnumEngineeringHalf.LOWER && worldIn.getBlockState(blockpos1).getBlock() == this)
	{
		if (player.capabilities.isCreativeMode)
		{
			worldIn.setBlockToAir(pos);
		}

		worldIn.setBlockToAir(blockpos1);
	}
}
 
Example 2
Source File: MetaTileEntityItemCollector.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void update() {
    super.update();

    if(getWorld().isRemote) {
        return;
    }

    boolean isWorkingNow = energyContainer.getEnergyStored() >= getEnergyConsumedPerTick() && isBlockRedstonePowered();

    if (isWorkingNow) {
        energyContainer.removeEnergy(getEnergyConsumedPerTick());
        BlockPos selfPos = getPos();
        if (areaCenterPos == null || areaBoundingBox == null || areaCenterPos.getX() != selfPos.getX() ||
            areaCenterPos.getZ() != selfPos.getZ() || areaCenterPos.getY() != selfPos.getY() + 1) {
            this.areaCenterPos = selfPos.up();
            this.areaBoundingBox = new AxisAlignedBB(areaCenterPos).grow(itemSuckingRange, 1.0, itemSuckingRange);
        }
        moveItemsInEffectRange();
    }

    if(isWorkingNow != isWorking) {
        this.isWorking = isWorkingNow;
        writeCustomData(100, buffer -> buffer.writeBoolean(isWorkingNow));
    }
}
 
Example 3
Source File: EntityAIWanderHex.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
private static BlockPos moveAboveSolid(BlockPos pos, EntityCreature entity)
{
	if (!entity.world.getBlockState(pos).getMaterial().isSolid())
	{
		return pos;
	}
	else
	{
		BlockPos blockpos;

		for (blockpos = pos.up(); blockpos.getY() < entity.world.getHeight() && entity.world.getBlockState(blockpos).getMaterial().isSolid(); blockpos = blockpos.up())
		{
			;
		}

		return blockpos;
	}
}
 
Example 4
Source File: LargeSkeletalTreeFeature.java    From the-hallow with MIT License 6 votes vote down vote up
protected boolean generateBranch(Set<BlockPos> set, ModifiableTestableWorld world, Random random, BlockPos pos, BlockBox mibb, int maxBranchouts, Direction lastDir) {
	int baseHeight = random.nextInt(4) + 2;
	
	for (int int_4 = 0; int_4 < baseHeight; ++int_4) {
		BlockPos blockPos = pos.up(int_4 + 1);
		if (!isSurroundedByAir(world, blockPos, null)) {
			return true;
		}
		addLog(set, world, blockPos, Direction.Axis.Y, mibb);
	}
	
	int int_5 = random.nextInt(4) + 1;
	int int_1 = 8;
	
	if (maxBranchouts > 0)
		for (int int_6 = 0; int_6 < int_5; ++int_6) {
			Direction direction_1 = Direction.Type.HORIZONTAL.random(random);
			if (direction_1 == lastDir) continue;
			BlockPos blockPos_4 = pos.up(baseHeight).offset(direction_1);
			if (Math.abs(blockPos_4.getX() - pos.getX()) < int_1 && Math.abs(blockPos_4.getZ() - pos.getZ()) < int_1 && isAir(world, blockPos_4) && isAir(world, blockPos_4.down()) && isSurroundedByAir(world, blockPos_4, direction_1.getOpposite())) {
				addLog(set, world, blockPos_4, direction_1.getAxis(), mibb);
				generateBranch(set, world, random, blockPos_4, mibb, maxBranchouts - 1, direction_1.getOpposite());
			}
		}
	return true;
}
 
Example 5
Source File: WorldGenBamboo.java    From Sakura_mod with MIT License 6 votes vote down vote up
@Override
public boolean generate(World worldIn, Random rand, BlockPos position) {
    int i = 9 + rand.nextInt(9);

    for (int i2 = 0; i2 < i; ++i2) {
        BlockPos blockpos = position.up(i2);
        if ((BlockLoader.BAMBOOSHOOT.canBlockStay(worldIn, blockpos)||
        		worldIn.getBlockState(blockpos.down()).getBlock() instanceof BlockPlantBamboo) && 
        (worldIn.isAirBlock(blockpos) || 
        		worldIn.getBlockState(blockpos).getMaterial() == Material.PLANTS
        		&& !(worldIn.getBlockState(blockpos).getBlock() instanceof BlockLeaves))) {
            worldIn.setBlockState(blockpos, BlockLoader.BAMBOO.getDefaultState(), 2);
        }
    }
    return true;
}
 
Example 6
Source File: SurfaceBlockPopulator.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void populateChunk(World world, int chunkX, int chunkZ, Random random, OreDepositDefinition definition, GridEntryInfo gridEntryInfo) {
    if (world.getWorldType() != WorldType.FLAT) {
        int stonesCount = minIndicatorAmount + (minIndicatorAmount >= maxIndicatorAmount ? 0 : random.nextInt(maxIndicatorAmount - minIndicatorAmount));
        for (int i = 0; i < stonesCount; i++) {
            int randomX = chunkX * 16 + random.nextInt(16);
            int randomZ = chunkZ * 16 + random.nextInt(16);
            BlockPos topBlockPos = new BlockPos(randomX, 0, randomZ);
            topBlockPos = world.getTopSolidOrLiquidBlock(topBlockPos).down();
            IBlockState blockState = world.getBlockState(topBlockPos);
            if (blockState.getBlockFaceShape(world, topBlockPos, EnumFacing.UP) != BlockFaceShape.SOLID ||
                !blockState.isOpaqueCube() || !blockState.isFullBlock())
                continue;
            BlockPos surfaceRockPos = topBlockPos.up();
            world.setBlockState(surfaceRockPos, this.blockState, 16);
        }
    }
}
 
Example 7
Source File: ItemEngineeringTable.java    From Cyberware with MIT License 5 votes vote down vote up
public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door)
{
	BlockPos blockpos = pos.offset(facing.rotateY());
	BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
	int i = (worldIn.getBlockState(blockpos1).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).isNormalCube() ? 1 : 0);
	int j = (worldIn.getBlockState(blockpos).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos.up()).isNormalCube() ? 1 : 0);
	BlockPos blockpos2 = pos.up();
	
	IBlockState iblockstate = door.getDefaultState().withProperty(BlockEngineeringTable.FACING, facing);
	worldIn.setBlockState(pos, iblockstate.withProperty(BlockEngineeringTable.HALF, BlockEngineeringTable.EnumEngineeringHalf.LOWER), 2);
	worldIn.setBlockState(blockpos2, iblockstate.withProperty(BlockEngineeringTable.HALF, BlockEngineeringTable.EnumEngineeringHalf.UPPER), 2);
	worldIn.notifyNeighborsOfStateChange(pos, door);
	worldIn.notifyNeighborsOfStateChange(blockpos2, door);
}
 
Example 8
Source File: BlockTofuBase.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
    BlockPos blockpos = pos.up();

    for (int i = 0; i < 128; ++i)
    {
        BlockPos blockpos1 = blockpos;
        int j = 0;

        while (true)
        {
            if (j >= i / 16)
            {
                if (worldIn.isAirBlock(blockpos1))
                {
                	if (rand.nextInt(8) == 0) 	plantFlower(worldIn, rand, blockpos1);
                }
                break;
            }

            blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);

            if (!(worldIn.getBlockState(blockpos1.down()).getBlock() instanceof BlockTofuBase) || worldIn.getBlockState(blockpos1).isNormalCube())
            {
                break;
            }

            ++j;
         }
     }
 }
 
Example 9
Source File: BlockPress.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
private boolean shouldBeExtended(World worldIn, BlockPos pos, EnumFacing facing)
{
	for (EnumFacing enumfacing : EnumFacing.values())
	{
		if (enumfacing != facing && worldIn.isSidePowered(pos.offset(enumfacing), enumfacing))
		{
			return true;
		}
	}

	if (worldIn.isSidePowered(pos, EnumFacing.DOWN))
	{
		return true;
	}
	else
	{
		BlockPos blockpos = pos.up();

		for (EnumFacing enumfacing1 : EnumFacing.values())
		{
			if (enumfacing1 != EnumFacing.DOWN && worldIn.isSidePowered(blockpos.offset(enumfacing1), enumfacing1))
			{
				return true;
			}
		}

		return false;
	}
}
 
Example 10
Source File: BlockValkyriumOre.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
private void tryFallingUp(World worldIn, BlockPos pos) {
    BlockPos downPos = pos.up();
    if ((worldIn.isAirBlock(downPos) || canFallThrough(worldIn.getBlockState(downPos)))
        && pos.getY() >= 0) {
        int i = 32;

        if (!BlockFalling.fallInstantly && worldIn
            .isAreaLoaded(pos.add(-32, -32, -32), pos.add(32, 32, 32))) {
            if (!worldIn.isRemote) {
                // Start falling up
                EntityFallingUpBlock entityfallingblock = new EntityFallingUpBlock(worldIn,
                    (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D,
                    worldIn.getBlockState(pos));
                worldIn.spawnEntity(entityfallingblock);
            }
        } else {
            IBlockState state = worldIn.getBlockState(pos);
            worldIn.setBlockToAir(pos);
            BlockPos blockpos;

            for (blockpos = pos.up(); (worldIn.isAirBlock(blockpos) || canFallThrough(
                worldIn.getBlockState(blockpos))) && blockpos.getY() < 255;
                blockpos = blockpos.up()) {
            }

            if (blockpos.getY() < 255) {
                worldIn.setBlockState(blockpos.down(), state, 3);
            }
        }
    }
}
 
Example 11
Source File: Job.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Alters the location's y-coordinate to be on the next air block touching a non-air block below it,
 * using the same x- and z-coordinates
 * searches up first, then down
 * ALTERS THE PASSED INTLOC. Also returns it.
 */
public static BlockPos groundify(World world, BlockPos loc)
{
	if (loc == null)
	{
		return null;
	}

	int ytemp = loc.getY();
	
	if (ytemp < 2)
	{
		ytemp = 2;
	}
	if (ytemp > 255)
	{
		ytemp = 255;
	}
	
	BlockPos tempLoc = new BlockPos(loc.getX(), ytemp, loc.getZ());
	
	//System.out.println("Groundifying " + tempLoc);

	// go down until found ground
	while (WorldHelper.isAirLikeBlock(world, tempLoc) && tempLoc.getY() > 2)
	{
		//System.out.println("Block at " + tempLoc + " is airblock, moving down");
		tempLoc = tempLoc.down();
	}
	// go up until found air
	while (!WorldHelper.isAirLikeBlock(world, tempLoc) && tempLoc.getY() < 255)
	{
		//System.out.println("Block at " + tempLoc + " is NOT airblock, moving up");
		tempLoc = tempLoc.up();
	}
	
	//System.out.println("Grounded to " + tempLoc);
	
	return tempLoc;
}
 
Example 12
Source File: ItemWaterHyacinth.java    From Production-Line with MIT License 4 votes vote down vote up
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

    if (raytraceresult == null) {
        return new ActionResult<>(EnumActionResult.PASS, itemStackIn);
    } else {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn)) {
                return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
            }

            BlockPos blockpos1 = blockpos.up();
            IBlockState iblockstate = worldIn.getBlockState(blockpos);

            if (iblockstate.getMaterial() == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL) == 0 && worldIn.isAirBlock(blockpos1)) {
                // special case for handling block placement with water lilies
                net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
                worldIn.setBlockState(blockpos1, PLBlocks.waterHyacinth.getDefaultState());
                if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP).isCanceled()) {
                    blocksnapshot.restore(true, false);
                    return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
                }

                worldIn.setBlockState(blockpos1, PLBlocks.waterHyacinth.getDefaultState(), 11);

                if (!playerIn.capabilities.isCreativeMode) {
                    --itemStackIn.stackSize;
                }

                playerIn.addStat(StatList.getObjectUseStats(this));
                worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
            }
        }

        return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
    }
}
 
Example 13
Source File: MapGenLander.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@SubscribeEvent
public void populateChunkPostEvent(PopulateChunkEvent.Post event) {
	World worldIn = event.getWorld();
	BlockPos position = new BlockPos(16*event.getChunkX() + 3,0, 16*event.getChunkZ() + 11);

	if(DimensionManager.getInstance().getDimensionProperties(worldIn.provider.getDimension()).getName().equals("Luna") && position.getX() == 67 && position.getZ() == 2347) {

		position = worldIn.getHeight(position).down();
		
		worldIn.setBlockState(position.add(0, 0, 3), Blocks.STONE_SLAB.getDefaultState().withProperty(BlockSlab.HALF, EnumBlockHalf.TOP));
		worldIn.setBlockState(position.add(0, 0, -3), Blocks.STONE_SLAB.getDefaultState().withProperty(BlockSlab.HALF, EnumBlockHalf.TOP));
		worldIn.setBlockState(position.add(3, 0, 0), Blocks.STONE_SLAB.getDefaultState().withProperty(BlockSlab.HALF, EnumBlockHalf.TOP));
		worldIn.setBlockState(position.add(-3, 0, 0), Blocks.STONE_SLAB.getDefaultState().withProperty(BlockSlab.HALF, EnumBlockHalf.TOP));
		
		position = position.up();

		worldIn.setBlockState(position, AdvancedRocketryBlocks.blockEngine.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, 3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, -3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(3, 0, 0), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(-3, 0, 0), Blocks.IRON_BARS.getDefaultState());

		position = position.up();
		worldIn.setBlockState(position.add(0, 0, 3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, -3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(3, 0, 0), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(-3, 0, 0), Blocks.IRON_BARS.getDefaultState());

		for(int x = -1; x <= 1; x++ ) {
			worldIn.setBlockState(position.add(-2, 0, x), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(2, 0, x), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(x, 0, -2), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(x, 0, 2), Blocks.GOLD_BLOCK.getDefaultState());
			for(int z = -1; z <= 1; z++) {
				worldIn.setBlockState(position.add(x, 0, z), Blocks.IRON_BLOCK.getDefaultState());
			}
		}

		position = position.up();
		worldIn.setBlockState(position.add(0, 0, 3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, -3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(3, 0, 0), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(-3, 0, 0), Blocks.IRON_BARS.getDefaultState());

		for(int x = -1; x <= 1; x++ ) {
			worldIn.setBlockState(position.add(-2, 0, x), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(2, 0, x), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(x, 0, -2), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(x, 0, 2), Blocks.GOLD_BLOCK.getDefaultState());
		}

		worldIn.setBlockState(position.add(0, 0, 1), Blocks.IRON_BLOCK.getDefaultState());
		worldIn.setBlockState(position.add(1, 0, 0), Blocks.IRON_BLOCK.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, -1), Blocks.IRON_BLOCK.getDefaultState());
		worldIn.setBlockState(position.add(-1, 0, 0), Blocks.IRON_BLOCK.getDefaultState());

		position = worldIn.getHeight(position.add(10,0,15));

		for(int x = 0; x <= 4; x++ ) 
			worldIn.setBlockState(position.add(0,x,0), Blocks.IRON_BARS.getDefaultState());

		worldIn.setBlockState(position.add(1,4,0), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(2,4,0), Blocks.IRON_BARS.getDefaultState());
	}
}
 
Example 14
Source File: ItemFuton.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand,
		EnumFacing facing, float hitX, float hitY, float hitZ) {
	if (worldIn.isRemote) {
		return EnumActionResult.SUCCESS;
	} else if (facing != EnumFacing.UP) {
		return EnumActionResult.FAIL;
	} else {
		IBlockState iblockstate = worldIn.getBlockState(pos);
		Block block = iblockstate.getBlock();
		boolean flag = block.isReplaceable(worldIn, pos);

		if (!flag) {
			pos = pos.up();
		}

		int i = MathHelper.floor(playerIn.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
		EnumFacing enumfacing = EnumFacing.getHorizontal(i);
		BlockPos blockpos = pos.offset(enumfacing);
		ItemStack itemstack = playerIn.getHeldItem(hand);

		if (playerIn.canPlayerEdit(pos, facing, itemstack) && playerIn.canPlayerEdit(blockpos, facing, itemstack)) {
			boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
			boolean flag2 = flag || worldIn.isAirBlock(pos);
			boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);

			if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isTopSolid()
					&& worldIn.getBlockState(blockpos.down()).isFullCube()) {
				IBlockState iblockstate1 = BlockLoader.FUTON.getDefaultState()
						.withProperty(BlockFuton.OCCUPIED, Boolean.valueOf(false))
						.withProperty(BlockHorizontal.FACING, enumfacing)
						.withProperty(BlockFuton.PART, BlockFuton.EnumPartType.FOOT);

				if (worldIn.setBlockState(pos, iblockstate1, 11)) {
					IBlockState iblockstate2 = iblockstate1.withProperty(BlockFuton.PART,
							BlockFuton.EnumPartType.HEAD);
					worldIn.setBlockState(blockpos, iblockstate2, 11);
				}

				SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, playerIn);
				worldIn.playSound(null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS,
						(soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
				itemstack.shrink(1);
				return EnumActionResult.SUCCESS;
			}
			return EnumActionResult.FAIL;
		}
		return EnumActionResult.FAIL;
	}
}
 
Example 15
Source File: WorldGenBigMaple.java    From Sakura_mod with MIT License 4 votes vote down vote up
/**
 * Generates a list of leaf nodes for the tree, to be populated by generateLeaves.
 */
void generateLeafNodeList()
{
    this.height = (int)(this.heightLimit * this.heightAttenuation);

    if (this.height >= this.heightLimit)
    {
        this.height = this.heightLimit - 1;
    }

    int i = (int)(1.382D + Math.pow(this.leafDensity * this.heightLimit / 13.0D, 2.0D));

    if (i < 1)
    {
        i = 1;
    }

    int j = this.basePos.getY() + this.height;
    int k = this.heightLimit - this.leafDistanceLimit;
    this.foliageCoords = Lists.<WorldGenBigMaple.FoliageCoordinates>newArrayList();
    this.foliageCoords.add(new WorldGenBigMaple.FoliageCoordinates(this.basePos.up(k), j));

    for (; k >= 0; --k)
    {
        float f = this.layerSize(k);

        if (f >= 0.0F)
        {
            for (int l = 0; l < i; ++l)
            {
                double d0 = this.scaleWidth * f * (this.rand.nextFloat() + 0.328D);
                double d1 = this.rand.nextFloat() * 2.0F * Math.PI;
                double d2 = d0 * Math.sin(d1) + 0.5D;
                double d3 = d0 * Math.cos(d1) + 0.5D;
                BlockPos blockpos = this.basePos.add(d2, k - 1, d3);
                BlockPos blockpos1 = blockpos.up(this.leafDistanceLimit);

                if (this.checkBlockLine(blockpos, blockpos1) == -1)
                {
                    int i1 = this.basePos.getX() - blockpos.getX();
                    int j1 = this.basePos.getZ() - blockpos.getZ();
                    double d4 = blockpos.getY() - Math.sqrt(i1 * i1 + j1 * j1) * this.branchSlope;
                    int k1 = d4 > j ? j : (int)d4;
                    BlockPos blockpos2 = new BlockPos(this.basePos.getX(), k1, this.basePos.getZ());

                    if (this.checkBlockLine(blockpos2, blockpos) == -1)
                    {
                        this.foliageCoords.add(new WorldGenBigMaple.FoliageCoordinates(blockpos, blockpos2.getY()));
                    }
                }
            }
        }
    }
}
 
Example 16
Source File: WorldGenMapleTree.java    From Sakura_mod with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
      int i = rand.nextInt(3) + this.minTreeHeight;
      boolean flag = true;

      if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
          for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
              int k = 1;

              if (j == position.getY()) {
                  k = 0;
              }

              if (j >= position.getY() + 1 + i - 2) {
                  k = 2;
              }

              BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

              for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
                  for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                      if (j >= 0 && j < worldIn.getHeight()) {
                          if (!this.isReplaceable(worldIn, blockpos$mutableblockpos.setPos(l, j, i1))) {
                              flag = false;
                          }
                      } else {
                          flag = false;
                      }
                  }
              }
          }

          if (!flag) {
              return false;
          }
	IBlockState state = worldIn.getBlockState(position.down());

	if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
	    state.getBlock().onPlantGrow(state, worldIn, position.down(), position);

	    for (int i3 = position.getY() - 3 + i; i3 <= position.getY() + i; ++i3) {
	        int i4 = i3 - (position.getY() + i);
	        int j1 = 1 - i4 / 2;

	        for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1) {
	            int l1 = k1 - position.getX();

	            for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2) {
	                int j2 = i2 - position.getZ();

	                if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0 && i4 != 0) {
	                    BlockPos blockpos = new BlockPos(k1, i3, i2);
	                    state = worldIn.getBlockState(blockpos);

	                    if (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getMaterial() == Material.VINE) {
	                        this.setBlockAndNotifyAdequately(worldIn, blockpos, this.metaLeaves);
	                    }
	                }
	            }
	        }
	    }

	    for (int j3 = 0; j3 < i; ++j3) {
	        BlockPos upN = position.up(j3);
	        state = worldIn.getBlockState(upN);

	        if (state.getBlock().isAir(state, worldIn, upN) || state.getBlock().isLeaves(state, worldIn, upN) || state.getMaterial() == Material.VINE) {
	            this.setBlockAndNotifyAdequately(worldIn, position.up(j3), this.metaWood);

	            if (this.generateSap && j3 == 1) {
	                if (worldIn.getBlockState(position.add(0, j3, 0))==this.metaWood) {
	                    this.addSapLog(worldIn, position.add(0, j3, 0));
	                }

	            }
	        }
	    }
	    fallenLeaves(worldIn, position,4,2,4, this.metaFallenLeaves);
	    
	    return true;
	}
	return false;
      }
return false;
  }
 
Example 17
Source File: WorldGenTreesHex.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
protected boolean canGrowHere(World world, BlockPos pos, TreeSchematic schem, int growthStage)
{
	IBlockState ground;
	IBlockState above;
	BlockPos gPos = pos;
	BlockPos aPos = pos.up();
	int radius = Math.max(1, growthStage);
	int count = 0;
	int failCount = 0;

	if(!world.isAirBlock(aPos))
		return false;

	//this should validate the ground
	for(int i = -radius; i <= radius; i++)
	{
		for(int k = -radius; k <= radius; k++)
		{
			count++;
			ground = world.getBlockState(gPos.add(i, 0, k));

			if(schem.getWoodType() != WoodType.Palm && !Core.isSoil(ground))
			{
				return false;
			}
			else if(schem.getWoodType() == WoodType.Palm && !Core.isSoil(ground) && !Core.isSand(ground))
			{
				return false;
			}

			for(int y = 1; y <= schem.getSizeY(); y++)
			{
				if(Core.isNaturalLog(world.getBlockState(gPos.add(0, y, 0))))
					return false;
			}
		}
	}

	/*if(failCount > count * 0.25 )
		return false;*/

	return true;
}
 
Example 18
Source File: TorikkiIceSpike.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
    while (worldIn.isAirBlock(position) && position.getY() > 2) {
        position = position.down();
    }

    if (worldIn.getBlockState(position).getBlock() != Blocks.SNOW) {
        return false;
    } else {
        position = position.up(rand.nextInt(4));
        int i = rand.nextInt(4) + 7;
        int j = i / 4 + rand.nextInt(2);

        if (j > 1 && rand.nextInt(60) == 0) {
            position = position.up(10 + rand.nextInt(30));
        }

        for (int k = 0; k < i; ++k) {
            float f = (1.0F - (float) k / (float) i) * (float) j;
            int l = MathHelper.ceil(f);

            for (int i1 = -l; i1 <= l; ++i1) {
                float f1 = (float) MathHelper.abs(i1) - 0.25F;

                for (int j1 = -l; j1 <= l; ++j1) {
                    float f2 = (float) MathHelper.abs(j1) - 0.25F;

                    if ((i1 == 0 && j1 == 0 || f1 * f1 + f2 * f2 <= f * f) && (i1 != -l && i1 != l && j1 != -l && j1 != l || rand.nextFloat() <= 0.75F)) {
                        IBlockState iblockstate = worldIn.getBlockState(position.add(i1, k, j1));
                        Block block = iblockstate.getBlock();

                        if (iblockstate.getBlock().isAir(iblockstate, worldIn, position.add(i1, k, j1)) || block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) {
                            this.setBlockAndNotifyAdequately(worldIn, position.add(i1, k, j1), Blocks.PACKED_ICE.getDefaultState());
                        }

                        if (k != 0 && l > 1) {
                            iblockstate = worldIn.getBlockState(position.add(i1, -k, j1));
                            block = iblockstate.getBlock();

                            if (iblockstate.getBlock().isAir(iblockstate, worldIn, position.add(i1, -k, j1)) || block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) {
                                this.setBlockAndNotifyAdequately(worldIn, position.add(i1, -k, j1), Blocks.PACKED_ICE.getDefaultState());
                            }
                        }
                    }
                }
            }
        }

        int k1 = j - 1;

        if (k1 < 0) {
            k1 = 0;
        } else if (k1 > 1) {
            k1 = 1;
        }

        for (int l1 = -k1; l1 <= k1; ++l1) {
            for (int i2 = -k1; i2 <= k1; ++i2) {
                BlockPos blockpos = position.add(l1, -1, i2);
                int j2 = 50;

                if (Math.abs(l1) == 1 && Math.abs(i2) == 1) {
                    j2 = rand.nextInt(5);
                }

                while (blockpos.getY() > 50) {
                    IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
                    Block block1 = iblockstate1.getBlock();

                    if (!iblockstate1.getBlock().isAir(iblockstate1, worldIn, blockpos) && block1 != Blocks.DIRT && block1 != Blocks.SNOW && block1 != Blocks.ICE && block1 != Blocks.PACKED_ICE) {
                        break;
                    }

                    this.setBlockAndNotifyAdequately(worldIn, blockpos, Blocks.PACKED_ICE.getDefaultState());
                    blockpos = blockpos.down();
                    --j2;

                    if (j2 <= 0) {
                        blockpos = blockpos.down(rand.nextInt(5) + 1);
                        j2 = rand.nextInt(5);
                    }
                }
            }
        }

        return true;
    }
}
 
Example 19
Source File: ChunkProviderSurface.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
protected void convertRiverBank(ChunkPrimer chunkprimer, BlockPos pos, boolean doAir)
{
	if(pos.getX() >= 0 && pos.getY() >= 0 && pos.getZ() >= 0 && pos.getX() < 16 && pos.getY() < 256 && pos.getZ() < 16)
	{
		IBlockState b = getState(chunkprimer, pos);
		if(Core.isTerrain(b))
		{
			Center closest = islandMap.getClosestCenter(pos.add(this.islandChunkX, 0, this.islandChunkZ));
			int elev = this.convertElevation(closest.getElevation());

			if(closest.hasAttribute(Attribute.River) && 
					(closest.biome == BiomeType.BEACH || closest.biome == BiomeType.MARSH || closest.biome == BiomeType.SWAMP)){return;}
			else
			{
				if(elevationMap[pos.getZ() << 4 | pos.getX()] != elev)
				{
					setState(chunkprimer, pos, TFCBlocks.Stone.getDefaultState().withProperty(BlockGravel.META_PROPERTY, islandMap.getParams().getSurfaceRock()));
					if(!Core.isStone(this.getState(chunkprimer, pos.down())))
					{
						setState(chunkprimer, pos.down(), TFCBlocks.Stone.getDefaultState().withProperty(BlockGravel.META_PROPERTY, islandMap.getParams().getSurfaceRock()));
						if(!Core.isStone(this.getState(chunkprimer, pos.down())))
						{
							setState(chunkprimer, pos.down(), TFCBlocks.Stone.getDefaultState().withProperty(BlockGravel.META_PROPERTY, islandMap.getParams().getSurfaceRock()));
						}
					}
				}
				else
				{
					setState(chunkprimer, pos, TFCBlocks.Gravel.getDefaultState().withProperty(BlockGravel.META_PROPERTY, islandMap.getParams().getSurfaceRock()));
				}
			}

			if(Core.isTerrain(getState(chunkprimer, pos.up(1))))
			{
				if(doAir && Core.isGravel(getState(chunkprimer, pos.up(1))))
				{
					convertRiverBank(chunkprimer, pos.up(1).north(), true);
					convertRiverBank(chunkprimer, pos.up(1).south(), true);
					convertRiverBank(chunkprimer, pos.up(1).east(), true);
					convertRiverBank(chunkprimer, pos.up(1).west(), true);
				}
				while(Core.isTerrain(getState(chunkprimer, pos.up())))
				{
					setState(chunkprimer, pos.up(), Blocks.AIR.getDefaultState());
					pos = pos.up();
				}
			}
		}
	}
}
 
Example 20
Source File: WorldGenTofuTrees.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    int i = rand.nextInt(3) + 4;
    boolean flag = true;

    if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight())
    {
        for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
        {
            int k = 1;

            if (j == position.getY())
            {
                k = 0;
            }

            if (j >= position.getY() + 1 + i - 2)
            {
                k = 2;
            }

            BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

            for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
            {
                for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
                {
                    if (j >= 0 && j < worldIn.getHeight())
                    {
                        if (!this.isReplaceable(worldIn,blockpos$mutableblockpos.setPos(l, j, i1)))
                        {
                            flag = false;
                        }
                    }
                    else
                    {
                        flag = false;
                    }
                }
            }
        }

        if (!flag)
        {
            return false;
        }
        else
        {
            IBlockState state = worldIn.getBlockState(position.down());
            int j1;
            if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, BlockLoader.TOFU_SAPLING) && position.getY() < worldIn.getHeight() - i - 1)
            {
                state.getBlock().onPlantGrow(state, worldIn, position.down(), position);

                for (int i3 = position.getY() - 3 + i; i3 <= position.getY() + i; ++i3)
                {
                    j1 = i / 3;

                    for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1)
                    {
                        for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2)
                        {
                            BlockPos blockpos = new BlockPos(k1, i3, i2);
                            state = worldIn.getBlockState(blockpos);

                            if (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getMaterial() == Material.VINE)
                            {
                                this.setBlockAndNotifyAdequately(worldIn, blockpos, BlockLoader.TOFU_LEAVE.getDefaultState());
                            }
                        }
                    }
                }
                
                for (int j3 = 0; j3 < i; ++j3)
                {
                    BlockPos upN = position.up(j3);
                    state = worldIn.getBlockState(upN);

                    if (state.getBlock().isAir(state, worldIn, upN) || state.getBlock().isLeaves(state, worldIn, upN) || state.getMaterial() == Material.VINE)
                    {
                        this.setBlockAndNotifyAdequately(worldIn, position.up(j3), BlockLoader.ISHITOFU.getDefaultState());

                    }
                }

                return true;
            }
            else
            {
                return false;
            }
        }
    }
    else
    {
        return false;
    }
}