Java Code Examples for net.minecraft.world.World#isAirBlock()

The following examples show how to use net.minecraft.world.World#isAirBlock() . 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: SpawnUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
public static boolean seachYForClearGround(Point3i target, World world, int searchRange, boolean checkForLivingEntities) {
  boolean foundY = false;
  for (int i = 0; i < searchRange && !foundY; i++) {
    if(world.isAirBlock(VecUtil.bpos(target.x, target.y, target.z))) {
      foundY = true;
    } else {
      target.y++;
    }
  }
  boolean onGround = false;
  if(foundY) {
    for (int i = 0; i < searchRange && !onGround; i++) {
      onGround = !world.isAirBlock(VecUtil.bpos(target.x, target.y - 1, target.z)) && !isLiquid(world, target.x, target.y - 1, target.z);
      if(!onGround) {
        target.y--;
      } else if(checkForLivingEntities && containsLiving(world, target)) {
        return false;
      }
    }
  }
  return foundY && onGround;
}
 
Example 2
Source File: WorldGenPlant.java    From Traverse-Legacy-1-12-2 with MIT License 6 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
    for (IBlockState iblockstate = worldIn.getBlockState(position); (iblockstate.getBlock().isAir(iblockstate, worldIn, position) || iblockstate.getBlock().isLeaves(iblockstate, worldIn, position)) && position.getY() > 0; iblockstate = worldIn.getBlockState(position)) {
        position = position.down();
    }

    for (int i = 0; i < 128; ++i) {
        BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

        boolean canStay = true;

        if (state.getBlock() instanceof BlockBush && !(((BlockBush) state.getBlock()).canBlockStay(worldIn, blockpos, this.state))) {
            canStay = false;
        }

        if (worldIn.isAirBlock(blockpos) && canStay) {
            worldIn.setBlockState(blockpos, this.state, 2);
        }
    }

    return true;
}
 
Example 3
Source File: BlockDecorativePot.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
protected boolean applyItemToGarden (World world, int x, int y, int z, EntityPlayer player, ItemStack itemStack, float hitX, float hitY, float hitZ, boolean hitValid) {
    ItemStack item = (itemStack == null) ? player.inventory.getCurrentItem() : itemStack;

    if (item != null && item.getItem() == Items.flint_and_steel) {
        ItemStack substrate = getGardenSubstrate(world, x, y, z, Slot2Profile.SLOT_CENTER);
        if (substrate != null && substrate.getItem() == Item.getItemFromBlock(Blocks.netherrack)) {
            if (world.isAirBlock(x, y + 1, z)) {
                world.playSoundEffect(x + .5, y + .5, z + .5, "fire.ignite", 1, world.rand.nextFloat() * .4f + .8f);
                world.setBlock(x, y + 1, z, ModBlocks.smallFire);

                world.notifyBlocksOfNeighborChange(x, y, z, this);
                world.notifyBlocksOfNeighborChange(x, y - 1, z, this);
            }

            item.damageItem(1, player);
            return true;
        }
    }

    return super.applyItemToGarden(world, x, y, z, player, itemStack, hitX, hitY, hitZ, hitValid);
}
 
Example 4
Source File: BlockQuickSand.java    From Artifacts with MIT License 6 votes vote down vote up
private boolean flowSideways(World world, int x, int y, int z, int xOffset, int zOffset) {
	if(world.getBlock(x, y, z) == BlockQuickSand.instance) {
		//A bit viscous; won't flow into an adjacent quicksand block unless its quicksand level is at least 2 less. 
 	if(world.getBlockMetadata(x, y, z) < 15 && 
 			(world.isAirBlock(x + xOffset, y, z + zOffset) || (world.getBlock(x + xOffset, y, z + zOffset) == BlockQuickSand.instance && 
 			getQuicksandLevel(world, x, y, z) > getQuicksandLevel(world, x + xOffset, y, z + zOffset) + 2))) {
 		//Only flow one piece of the block sideways, in the given direction.
 		int sandAmount = getQuicksandLevel(world, x, y, z);
 		int amountFlowed = flowIntoBlock(world, x+xOffset, y, z+zOffset, 1);
 		
 		if(amountFlowed > 0) {
 			if(sandAmount <= amountFlowed) {
 				world.setBlockToAir(x, y, z);
		return true; //This should never happen! But it's here just in case.
 			}
 			else {
		world.setBlockMetadataWithNotify(x, y, z, 16 - (sandAmount - amountFlowed), 3);
		return true;
	}
 		}
 	}
	}
	return false;
}
 
Example 5
Source File: BlockTofuYuba.java    From TofuCraftReload with MIT License 6 votes vote down vote up
private void growByBonemeal(World worldIn, Random rand, BlockPos blockpos) {
    if (worldIn.isAirBlock(blockpos.down()) && rand.nextFloat() < 0.8F) {
        worldIn.setBlockState(blockpos.down(), this.getDefaultState(), 2);
        if (worldIn.isAirBlock(blockpos.down(2)) && rand.nextFloat() < 0.6F) {
            worldIn.setBlockState(blockpos.down(2), this.getDefaultState(), 2);
            if (worldIn.isAirBlock(blockpos.down(3)) && rand.nextFloat() < 0.45F) {
                worldIn.setBlockState(blockpos.down(3), this.getDefaultState(), 2);
                if (worldIn.isAirBlock(blockpos.down(4)) && rand.nextFloat() < 0.25F) {
                    worldIn.setBlockState(blockpos.down(4), this.getDefaultState(), 2);
                    worldIn.neighborChanged(blockpos.down(4), this, blockpos);
                }
                worldIn.neighborChanged(blockpos.down(3), this, blockpos);
            }
            worldIn.neighborChanged(blockpos.down(2), this, blockpos);
        }
        worldIn.neighborChanged(blockpos.down(), this, blockpos);
    }
    worldIn.neighborChanged(blockpos, this, blockpos);
}
 
Example 6
Source File: BlockPresenceSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getRedstoneValue(World world, int x, int y, int z, int sensorRange, String textBoxText, Set<ChunkPosition> positions){
    for(ChunkPosition pos : positions) {
        if(!world.isAirBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) return 15;
    }
    return 0;
}
 
Example 7
Source File: BlockGrass.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 1. Content
 *******************************************************************************/
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
{
	if(world.isRemote)
		return;

	if(world.getBlockState(pos.north()).getBlock() == TFCBlocks.Dirt && world.isAirBlock(pos.north().up()) && rand.nextInt(10) == 0)
	{
		world.setBlockState(pos.north(), this.getDefaultState().withProperty(META_PROPERTY, world.getBlockState(pos.north()).getValue(BlockDirt.META_PROPERTY)));
	}

	if(world.getBlockState(pos.south()).getBlock() == TFCBlocks.Dirt && world.isAirBlock(pos.south().up()) && rand.nextInt(10) == 0)
	{
		world.setBlockState(pos.south(), this.getDefaultState().withProperty(META_PROPERTY, world.getBlockState(pos.south()).getValue(BlockDirt.META_PROPERTY)));
	}

	if(world.getBlockState(pos.east()).getBlock() == TFCBlocks.Dirt && world.isAirBlock(pos.east().up()) && rand.nextInt(10) == 0)
	{
		world.setBlockState(pos.east(), this.getDefaultState().withProperty(META_PROPERTY, world.getBlockState(pos.east()).getValue(BlockDirt.META_PROPERTY)));
	}

	if(world.getBlockState(pos.west()).getBlock() == TFCBlocks.Dirt && world.isAirBlock(pos.west().up()) && rand.nextInt(10) == 0)
	{
		world.setBlockState(pos.west(), this.getDefaultState().withProperty(META_PROPERTY, world.getBlockState(pos.west()).getValue(BlockDirt.META_PROPERTY)));
	}
}
 
Example 8
Source File: TileStationBuilder.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void scanRocket(World world, BlockPos pos2, AxisAlignedBB bb) {

	int actualMinX = (int)bb.maxX,
			actualMinY = (int)bb.maxY,
			actualMinZ = (int)bb.maxZ,
			actualMaxX = (int)bb.minX,
			actualMaxY = (int)bb.minY,
			actualMaxZ = (int)bb.minZ;


	for(int xCurr = (int)bb.minX; xCurr <= bb.maxX; xCurr++) {
		for(int zCurr = (int)bb.minZ; zCurr <= bb.maxZ; zCurr++) {
			for(int yCurr = (int)bb.minY; yCurr<= bb.maxY; yCurr++) {

				BlockPos posCurr = new BlockPos(xCurr, yCurr, zCurr);

				if(!world.isAirBlock(posCurr)) {
					if(xCurr < actualMinX)
						actualMinX = xCurr;
					if(yCurr < actualMinY)
						actualMinY = yCurr;
					if(zCurr < actualMinZ)
						actualMinZ = zCurr;
					if(xCurr > actualMaxX)
						actualMaxX = xCurr;
					if(yCurr > actualMaxY)
						actualMaxY = yCurr;
					if(zCurr > actualMaxZ)
						actualMaxZ = zCurr;
				}
			}
		}
	}

	status = ErrorCodes.SUCCESS_STATION;
}
 
Example 9
Source File: WrenchBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (!world.isRemote && !world.isAirBlock(pos)) {
        ItemStack stack = player.getHeldItem(hand);
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof MetaTileEntityHolder)
            //machines handle wrench click manually
            return EnumActionResult.PASS;
        if (world.getBlockState(pos).getBlock().rotateBlock(world, pos, side)) {
            GTUtility.doDamageItem(stack, this.cost, false);
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
 
Example 10
Source File: Core.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static Block getGroundAboveSeaLevel(World world, BlockPos pos)
{
	BlockPos blockpos1;

	for (blockpos1 = new BlockPos(pos.getX(), Global.SEALEVEL, pos.getZ()); !world.isAirBlock(blockpos1.up()); blockpos1 = blockpos1.up())
	{
		;
	}

	return world.getBlockState(blockpos1).getBlock();
}
 
Example 11
Source File: DiamondTofuToolHandler.java    From TofuCraftReload with MIT License 5 votes vote down vote up
private boolean canBreakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos, BlockPos refPos) {
    if (world.isAirBlock(pos)) {
        return false;
    }
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (tool.getDestroySpeed(stack, state) <= 1.0F)
        return false;

    IBlockState refState = world.getBlockState(refPos);
    float refStrength = ForgeHooks.blockStrength(refState, player, world, refPos);
    float strength = ForgeHooks.blockStrength(state, player, world, pos);

    if (!ForgeHooks.canHarvestBlock(block, player, world, pos) || refStrength / strength > 10f) {
        return false;
    }

    if (player.capabilities.isCreativeMode) {
        block.onBlockHarvested(world, pos, state, player);
        if (block.removedByPlayer(state, world, pos, player, false)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
        }
        // send update to client
        if (!world.isRemote) {
            if (player instanceof EntityPlayerMP && ((EntityPlayerMP) player).connection != null) {
                ((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
            }
        }
        return false;
    }
    return true;
}
 
Example 12
Source File: BlockKnowledgeBook.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
    if(world.isRemote) return;
    Block lower = world.getBlock(x, y - 1, z);
    int metaLower = world.getBlockMetadata(x, y - 1, z);
    if(!lower.equals(ConfigBlocks.blockStoneDevice) || metaLower != 1) {
        breakThisBlock(world, x, y, z);
    }
    if(!world.isAirBlock(x, y + 1, z)) {
        breakThisBlock(world, x, y, z);
    }
}
 
Example 13
Source File: WorldGenWyvernGrass.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
{
    int var11;

    Block block = null;
    do 
    {
        block = Block.blocksList[par1World.getBlockId(par3,  par4, par5)];
        if (block != null && !block.isLeaves(par1World, par3, par4, par5))
        {
            break;
        }
        par4--;
    } while (par4 > 0);

    for (int var7 = 0; var7 < 128; ++var7)
    {
        int var8 = par3 + par2Random.nextInt(8) - par2Random.nextInt(8);
        int var9 = par4 + par2Random.nextInt(4) - par2Random.nextInt(4);
        int var10 = par5 + par2Random.nextInt(8) - par2Random.nextInt(8);

        if (par1World.isAirBlock(var8, var9, var10) && Block.blocksList[this.tallGrassID].canBlockStay(par1World, var8, var9, var10))
        {
            par1World.setBlock(var8, var9, var10, this.tallGrassID, this.tallGrassMetadata, 3);
        }
    }

    return true;
}
 
Example 14
Source File: ItemAstroBed.java    From AdvancedRocketry 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
	{
		ItemStack stack = playerIn.getHeldItem(hand);
		IBlockState iblockstate = worldIn.getBlockState(pos);
		Block block = iblockstate.getBlock();
		boolean flag = block.isReplaceable(worldIn, pos);

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

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

		if (playerIn.canPlayerEdit(pos, facing, stack) && playerIn.canPlayerEdit(blockpos, facing, stack))
		{
			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()).isSideSolid(worldIn, pos.down(), EnumFacing.UP) && worldIn.getBlockState(blockpos.down()).isSideSolid(worldIn, blockpos.down(), EnumFacing.UP))
			{
				IBlockState iblockstate1 = AdvancedRocketryBlocks.blockAstroBed.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);

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

				SoundType soundtype = iblockstate1.getBlock().getSoundType();
				worldIn.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
				stack.setCount(stack.getCount() - 1);
				return EnumActionResult.SUCCESS;
			}
			else
			{
				return EnumActionResult.FAIL;
			}
		}
		else
		{
			return EnumActionResult.FAIL;
		}
	}
}
 
Example 15
Source File: MovingTargetDecoratorImplementation.java    From malmo with MIT License 4 votes vote down vote up
private boolean isValid(World world, BlockPos pos)
{
    // In bounds?
    if (!blockInBounds(pos, this.arenaBounds))
        return false;
    // Already in path?
    if (this.path.contains(pos))
        return false;
    // Does there need to be air above the target?
    if (this.targetParams.isRequiresAirAbove() && !world.isAirBlock(pos.up()))
        return false;
    // Check the current block is "permeable"...
    IBlockState block = world.getBlockState(pos);
    List<IProperty> extraProperties = new ArrayList<IProperty>();
    DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(block, extraProperties);

    boolean typesMatch = this.targetParams.getPermeableBlocks().getType().isEmpty();
    for (BlockType bt : this.targetParams.getPermeableBlocks().getType())
    {
        if (db.getType() == bt)
        {
            typesMatch = true;
            break;
        }
    }
    if (!typesMatch)
        return false;

    if (db.getColour() != null)
    {
        boolean coloursMatch = this.targetParams.getPermeableBlocks().getColour().isEmpty();
        for (Colour col : this.targetParams.getPermeableBlocks().getColour())
        {
            if (db.getColour() == col)
            {
                coloursMatch = true;
                break;
            }
        }
        if (!coloursMatch)
            return false;
    }

    if (db.getVariant() != null)
    {
        boolean variantsMatch = this.targetParams.getPermeableBlocks().getVariant().isEmpty();
        for (Variation var : this.targetParams.getPermeableBlocks().getVariant())
        {
            if (db.getVariant() == var)
            {
                variantsMatch = true;
                break;
            }
        }
        if (!variantsMatch)
            return false;
    }
    return true;
}
 
Example 16
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 17
Source File: BuildBattleDecoratorImplementation.java    From malmo with MIT License 4 votes vote down vote up
private void updateAndScorePlayerVolume(World w, boolean updateReward)
{
    int wrongBlocks = 0;
    int rightBlocks = 0;
    int totalMatchingBlocks = 0;
    BlockDrawingHelper drawContext = new BlockDrawingHelper();
    drawContext.beginDrawing(w);

    for (int x = this.sourceBounds.getMin().getX(); x <= this.sourceBounds.getMax().getX(); x++)
    {
        for (int y = this.sourceBounds.getMin().getY(); y <= this.sourceBounds.getMax().getY(); y++)
        {
            for (int z = this.sourceBounds.getMin().getZ(); z <= this.sourceBounds.getMax().getZ(); z++)
            {
                BlockPos goalStructurePos = new BlockPos(x, y, z);
                BlockPos playerStructurePos = goalStructurePos.add(this.delta);
                // We don't compare the world's block states, since we re-colour them to give
                // feedback on right / wrong blocks.
                // Instead, query our internal representations:
                IBlockState srcState = getSourceBlockState(w, goalStructurePos);
                IBlockState dstState = getDestBlockState(w, playerStructurePos);
                if (srcState == null || dstState == null)
                    continue;   // Shouldn't happen unless we've had an out-of-bounds error somehow.
                boolean destAir = w.isAirBlock(playerStructurePos);
                if (srcState.equals(dstState))
                {
                    // They match. We count this if the dest block is not air.
                    if (!destAir)
                        rightBlocks++;
                    if (blockTypeOnCorrectPlacement != null && !w.isAirBlock(goalStructurePos))
                    {
                        // Mark both source and destination blocks for correct placement:
                        drawContext.setBlockState(w, playerStructurePos, blockTypeOnCorrectPlacement);
                        drawContext.setBlockState(w, goalStructurePos, blockTypeOnCorrectPlacement);
                    }
                    totalMatchingBlocks++;
                }
                else
                {
                    // Non-match. We call this wrong if the dest block is not air.
                    if (!destAir)
                    {
                        wrongBlocks++;
                        if (blockTypeOnIncorrectPlacement != null)
                        {
                            // Recolour the destination block only:
                            drawContext.setBlockState(w, playerStructurePos, blockTypeOnIncorrectPlacement);
                        }
                    }
                    // Check the source block - if it was previously correct, and has become incorrect,
                    // then we will need to reset the world's blockstate:
                    IBlockState actualState = w.getBlockState(goalStructurePos);
                    if (!actualState.equals(srcState))
                        drawContext.setBlockState(w, goalStructurePos, new XMLBlockState(srcState));
                }
            }
        }
    }
    drawContext.endDrawing(w);
    int score = rightBlocks - wrongBlocks;
    boolean sendData = false;
    boolean sendCompletionBonus = false;
    int reward = 0;

    if (updateReward && score != this.currentScore)
    {
        reward = score - this.currentScore;
        sendData = true;
    }
    this.currentScore = score;

    if (totalMatchingBlocks == this.structureVolume)
    {
        if (!this.structureHasBeenCompleted)
        {
            // The structure has been completed - send the reward bonus.
            // We check structureHasBeenCompleted here because we only want to do this once.
            // (Otherwise the agent can game the rewards by repeatedly breaking and re-adding the
            // final block.)
            if (updateReward)
                sendCompletionBonus = true;
        }
        this.structureHasBeenCompleted = true;
    }
    this.valid = true;

    if (sendData)
    {
        HashMap<String,String> data = new HashMap<String, String>();
        data.put("reward", Integer.toString(reward));
        data.put("completed", Boolean.toString(sendCompletionBonus));
        MalmoMod.safeSendToAll(MalmoMessageType.SERVER_BUILDBATTLEREWARD, data);
    }
}
 
Example 18
Source File: WorldGenHotSpring.java    From Sakura_mod with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
      for (position = position.add(-8, 0, -8); position.getY() > 5 && worldIn.isAirBlock(position); position = position.down()) {
          ;
      }
position = position.down(4);
boolean[] aboolean = new boolean[2048];
int i = rand.nextInt(4) + 4;

for (int j = 0; j < i; ++j) {
    double d0 = rand.nextDouble() * 6.0D + 3.0D;
    double d1 = rand.nextDouble() * 4.0D + 2.0D;
    double d2 = rand.nextDouble() * 6.0D + 3.0D;
    double d3 = rand.nextDouble() * (16.0D - d0 - 2.0D) + 1.0D + d0 / 2.0D;
    double d4 = rand.nextDouble() * (8.0D - d1 - 4.0D) + 2.0D + d1 / 2.0D;
    double d5 = rand.nextDouble() * (16.0D - d2 - 2.0D) + 1.0D + d2 / 2.0D;

    for (int l = 1; l < 15; ++l) {
        for (int i1 = 1; i1 < 15; ++i1) {
            for (int j1 = 1; j1 < 7; ++j1) {
                double d6 = (l - d3) / (d0 / 2.0D);
                double d7 = (j1 - d4) / (d1 / 2.0D);
                double d8 = (i1 - d5) / (d2 / 2.0D);
                double d9 = d6 * d6 + d7 * d7 + d8 * d8;

                if (d9 < 1.0D)
                    aboolean[(l * 16 + i1) * 8 + j1] = true;
            }
        }
    }
}

for (int k1 = 0; k1 < 16; ++k1){
    for (int l2 = 0; l2 < 16; ++l2) {
        for (int k = 0; k < 8; ++k) {
            boolean flag = !aboolean[(k1 * 16 + l2) * 8 + k] && (k1 < 15 && aboolean[((k1 + 1) * 16 + l2) * 8 + k] || k1 > 0 && aboolean[((k1 - 1) * 16 + l2) * 8 + k] || l2 < 15 && aboolean[(k1 * 16 + l2 + 1) * 8 + k] || l2 > 0 && aboolean[(k1 * 16 + (l2 - 1)) * 8 + k] || k < 7 && aboolean[(k1 * 16 + l2) * 8 + k + 1] || k > 0 && aboolean[(k1 * 16 + l2) * 8 + (k - 1)]);

            if (flag) {
                Material material = worldIn.getBlockState(position.add(k1, k, l2)).getMaterial();

                if (k >= 4 && material.isLiquid())  {
                    return false;
                }

                if (k < 4 && !material.isSolid() && worldIn.getBlockState(position.add(k1, k, l2)).getBlock() != BlockLoader.HOT_SPRING_WATER)  {
                    return false;
                }
            }
        }
    }
}

for (int l1 = 0; l1 < 16; ++l1) {
    for (int i3 = 0; i3 < 16; ++i3) {
        for (int i4 = 0; i4 < 8; ++i4) {
            if (aboolean[(l1 * 16 + i3) * 8 + i4]) {
                worldIn.setBlockState(position.add(l1, i4, i3), i4 >= 4 ? Blocks.AIR.getDefaultState() : BlockLoader.HOT_SPRING_WATER.getDefaultState(), 2);
            }
        }
    }
}

for (int i2 = 0; i2 < 16; ++i2){
    for (int j3 = 0; j3 < 16; ++j3) {
        for (int j4 = 4; j4 < 8; ++j4) {
            if (aboolean[(i2 * 16 + j3) * 8 + j4]) {
                BlockPos blockpos = position.add(i2, j4 - 1, j3);

                if (worldIn.getBlockState(blockpos).getBlock() == Blocks.DIRT && worldIn.getLightFor(EnumSkyBlock.SKY, position.add(i2, j4, j3)) > 0) {
                    Biome biome = worldIn.getBiome(blockpos);

                    if (biome.topBlock.getBlock() == Blocks.MYCELIUM) {
                        worldIn.setBlockState(blockpos, Blocks.MYCELIUM.getDefaultState(), 2);
                    }
                    else {
                        worldIn.setBlockState(blockpos, Blocks.GRASS.getDefaultState(), 2);
                    }
                }
            }
        }
    }
}
   for (int j2 = 0; j2 < 16; ++j2) {
       for (int k3 = 0; k3 < 16; ++k3) {
           for (int k4 = 0; k4 < 8; ++k4) {
               boolean flag1 = !aboolean[(j2 * 16 + k3) * 8 + k4] && (j2 < 15 && aboolean[((j2 + 1) * 16 + k3) * 8 + k4] || j2 > 0 && aboolean[((j2 - 1) * 16 + k3) * 8 + k4] || k3 < 15 && aboolean[(j2 * 16 + k3 + 1) * 8 + k4] || k3 > 0 && aboolean[(j2 * 16 + (k3 - 1)) * 8 + k4] || k4 < 7 && aboolean[(j2 * 16 + k3) * 8 + k4 + 1] || k4 > 0 && aboolean[(j2 * 16 + k3) * 8 + (k4 - 1)]);
               if (flag1 && (k4 < 4 || rand.nextInt(2) != 0) && worldIn.getBlockState(position.add(j2, k4, k3)).getMaterial().isSolid()){
                   worldIn.setBlockState(position.add(j2, k4, k3), Blocks.STONE.getDefaultState(), 2);
               }
           }
       }
   }

return true;
  }
 
Example 19
Source File: WorldGenMapleTreeGreen.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);
	                      BlockPos fruitBlockPos = new BlockPos(k1, i3 - 1, i2);
	                      BlockPos blockBelowFruitPos = new BlockPos(k1, i3 - 2, i2);
	                      if (worldIn.isAirBlock(fruitBlockPos)) 
	                          if (worldIn.isAirBlock(blockBelowFruitPos) && i3 > 2) 
	                              if (rand.nextInt(4) == 0) 
	                                  this.setBlockAndNotifyAdequately(worldIn,fruitBlockPos, BlockLoader.CHESTNUTBURR.getDefaultState());
	                    }
	                }
	            }
	        }
	    }

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

	        if (state.getBlock().isAir(state, worldIn, upN) || this.isBurr(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 20
Source File: BlockMiningDrill.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public float getMiningSpeed(World world, BlockPos pos) {
	return world.isAirBlock(pos.add(0,1,0)) && world.isAirBlock(pos.add(0,2,0)) ? 0.02f : 0.01f;
}