Java Code Examples for net.minecraft.block.material.Material#isSolid()

The following examples show how to use net.minecraft.block.material.Material#isSolid() . 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: 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 2
Source File: WorldGenManaLake.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void generate(World world, Random rand, BlockPos position) {
	int chance = rand.nextInt(ConfigValues.manaPoolRarity);
	if (chance == 0) {
		if (position.getY() > 4) {
			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 = ((double) l - d3) / (d0 / 2.0D);
							double d7 = ((double) j1 - d4) / (d1 / 2.0D);
							double d8 = ((double) 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 = world.getBlockState(position.add(k1, k, l2)).getMaterial();

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

							if (k < 4 && !material.isSolid() && world.getBlockState(position.add(k1, k, l2)).getBlock() != this.block) {
								return;
							}
						}
					}
				}
			}

			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]) {
							world.setBlockState(position.add(l1, i4, i3), i4 >= 4 ? Blocks.AIR.getDefaultState() : this.block.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 (world.getBlockState(blockpos).getBlock() == Blocks.DIRT && world.getLightFor(EnumSkyBlock.SKY, position.add(i2, j4, j3)) > 0) {
								Biome biome = world.getBiome(blockpos);

								if (biome.topBlock.getBlock() == Blocks.MYCELIUM) {
									world.setBlockState(blockpos, Blocks.MYCELIUM.getDefaultState(), 2);
								} else {
									world.setBlockState(blockpos, Blocks.GRASS.getDefaultState(), 2);

									if (rand.nextInt(3) == 0) {
										WorldGeneratorWisdomTree tree = new WorldGeneratorWisdomTree(false);
										tree.generate(world, rand, blockpos);
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
 
Example 3
Source File: SealableBlockHandler.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
/**
 * Checks to see if the block at the location can be sealed
 * @param world
 * @param pos
 * @return
 */
@Override
public boolean isBlockSealed(World world, BlockPos pos)
{
	//Ensure we are not checking outside of the map
	if(pos.getY() >= 0 && pos.getY() <= 256)
	{
		//Prevents orphan chunk loading - DarkGuardsman
		//ChunkExists
		if(world instanceof WorldServer && !((WorldServer) world).getChunkProvider().chunkExists(pos.getX() >> 4, pos.getZ() >> 4))
		{
			return false;
		}

		IBlockState state = world.getBlockState(pos);
		Block block = state.getBlock();
		Material material = state.getMaterial();

		//Always allow list
		if (blockAllowList.contains(block) || materialAllowList.contains(material))
		{
			return true;
		}
		//Always block list
		else if (blockBanList.contains(block) || materialBanList.contains(material))
		{
			return false;
		}
		else if (material.isLiquid() || !material.isSolid())
		{
			return false;
		}
		else if (world.isAirBlock(pos) || block instanceof IFluidBlock)
		{
			return false;
		}
		//TODO replace with seal logic handler
		else if (block == AdvancedRocketryBlocks.blockAirLock)
		{
			HashedBlockPosition myPos = new HashedBlockPosition(pos);
			if(doorPositions.contains(myPos))
				return true;
			doorPositions.add(myPos);
			
			boolean doorIsSealed = checkDoorIsSealed(world, pos, state);
			doorPositions.remove(myPos);
			return doorIsSealed;
		}
		//TODO add is side solid check, which will require forge direction or side check. Eg more complex logic...
		return isFulBlock(world, pos);
	}
	return false;
}
 
Example 4
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *  Attempts to place one fluid block in the world, identified by the given FluidStack
 */
public boolean tryPlaceFluidBlock(World world, BlockPos pos, FluidStack fluidStack)
{
    if (fluidStack == null || fluidStack.getFluid() == null || fluidStack.getFluid().canBePlacedInWorld() == false)
    {
        return false;
    }

    Block block = fluidStack.getFluid().getBlock();

    // We need to convert water and lava to the flowing variant, otherwise we get non-flowing source blocks
    if (block == Blocks.WATER)
    {
        block = Blocks.FLOWING_WATER;
    }
    else if (block == Blocks.LAVA)
    {
        block = Blocks.FLOWING_LAVA;
    }

    IBlockState state = world.getBlockState(pos);
    Material material = state.getMaterial();

    if (world.isAirBlock(pos) == false && material.isSolid())
    {
        return false;
    }

    if (world.provider.doesWaterVaporize() && block == Blocks.FLOWING_WATER)
    {
        float x = pos.getX();
        float y = pos.getY();
        float z = pos.getZ();

        world.playSound(null, x + 0.5F, y + 0.5F, z + 0.5F, SoundEvents.BLOCK_FIRE_EXTINGUISH,
                SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);

        for (int l = 0; l < 8; ++l)
        {
            world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, x + Math.random(), y + Math.random(), z + Math.random(), 0.0D, 0.0D, 0.0D);
        }
    }
    else
    {
        if (world.isRemote == false && material.isSolid() == false && material.isLiquid() == false)
        {
            // Set a replaceable block to air, and drop the items
            world.destroyBlock(pos, true);
        }

        world.setBlockState(pos, block.getDefaultState(), 3);
        SoundEvent soundevent = block == Blocks.FLOWING_LAVA ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;
        world.playSound(null, pos, soundevent, SoundCategory.BLOCKS, 1.0f, 1.0f);
    }

    return true;
}