Java Code Examples for net.minecraft.block.Material#WATER

The following examples show how to use net.minecraft.block.Material#WATER . 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: JesusHack.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
public boolean isOverLiquid()
{
	boolean foundLiquid = false;
	boolean foundSolid = false;
	
	// check collision boxes below player
	ArrayList<Box> blockCollisions = MC.world
		.getBlockCollisions(MC.player,
			MC.player.getBoundingBox().offset(0, -0.5, 0))
		.map(VoxelShape::getBoundingBox)
		.collect(Collectors.toCollection(() -> new ArrayList<>()));
	
	for(Box bb : blockCollisions)
	{
		BlockPos pos = new BlockPos(bb.getCenter());
		Material material = BlockUtils.getState(pos).getMaterial();
		
		if(material == Material.WATER || material == Material.LAVA)
			foundLiquid = true;
		else if(material != Material.AIR)
			foundSolid = true;
	}
	
	return foundLiquid && !foundSolid;
}
 
Example 2
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Use this to change the fog color used when the entity is "inside" a material.
 * {@link Vec3d} is used here as "r/g/b" 0 - 1 values.
 *
 * @param state         The state at the entity viewport.
 * @param world         The world.
 * @param pos           The position at the entity viewport.
 * @param entity        the entity
 * @param originalColor The current fog color, You are not expected to use this, Return as the default if applicable.
 * @return The new fog color.
 */
@Environment(EnvType.CLIENT)
default Vec3d getFogColor(BlockState state, CollisionView world, BlockPos pos, Entity entity, Vec3d originalColor, float partialTicks) {
	if (state.getMaterial() == Material.WATER) {
		float visibility = 0.0F;

		if (entity instanceof LivingEntity) {
			LivingEntity ent = (LivingEntity) entity;
			visibility = (float) EnchantmentHelper.getRespiration(ent) * 0.2F;

			if (ent.hasStatusEffect(StatusEffects.WATER_BREATHING)) {
				visibility = visibility * 0.3F + 0.6F;
			}
		}

		return new Vec3d(0.02F + visibility, 0.02F + visibility, 0.2F + visibility);
	} else if (state.getMaterial() == Material.LAVA) {
		return new Vec3d(0.6F, 0.1F, 0.0F);
	}

	return originalColor;
}
 
Example 3
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determines if this block can support the passed in plant, allowing it to be planted and grow.
 * Some examples:
 * Reeds check if its a reed, or if its sand/dirt/grass and adjacent to water
 * Cacti checks if its a cacti, or if its sand
 * Nether types check for soul sand
 * Crops check for tilled soil
 * Caves check if it's a solid surface
 * Plains check if its grass or dirt
 * Water check if its still water
 *
 * @param state     The Current state
 * @param world     The current world
 * @param facing    The direction relative to the given position the plant wants to be, typically its UP
 * @param plantable The plant that wants to check
 * @return True to allow the plant to be planted/stay.
 */
default boolean canSustainPlant(BlockState state, BlockView world, BlockPos pos, Direction facing, IPlantable plantable) {
	BlockState plant = plantable.getPlant(world, pos.offset(facing));

	if (plant.getBlock() == Blocks.CACTUS) {
		return this.getBlock() == Blocks.CACTUS || this.getBlock() == Blocks.SAND || this.getBlock() == Blocks.RED_SAND;
	}

	if (plant.getBlock() == Blocks.SUGAR_CANE && this.getBlock() == Blocks.SUGAR_CANE) {
		return true;
	}

	if (plantable instanceof PlantBlock && ((PlantBlockAccessor) plantable).invokeCanPlantOnTop(state, world, pos)) {
		return true;
	}

	switch (plantable.getPlantType(world, pos)) {
	case Desert:
		return this.getBlock() == Blocks.SAND || this.getBlock() == Blocks.TERRACOTTA || this.getBlock() instanceof GlazedTerracottaBlock;
	case Nether:
		return this.getBlock() == Blocks.SOUL_SAND;
	case Crop:
		return this.getBlock() == Blocks.FARMLAND;
	case Cave:
		return Block.isSideSolidFullSquare(state, world, pos, Direction.UP);
	case Plains:
		return this.getBlock() == Blocks.GRASS_BLOCK || Block.isNaturalDirt(this.getBlock()) || this.getBlock() == Blocks.FARMLAND;
	case Water:
		return state.getMaterial() == Material.WATER;
	case Beach:
		boolean isBeach = this.getBlock() == Blocks.GRASS_BLOCK || Block.isNaturalDirt(this.getBlock()) || this.getBlock() == Blocks.SAND;
		boolean hasWater = (world.getBlockState(pos.east()).getMaterial() == Material.WATER
				|| world.getBlockState(pos.west()).getMaterial() == Material.WATER
				|| world.getBlockState(pos.north()).getMaterial() == Material.WATER
				|| world.getBlockState(pos.south()).getMaterial() == Material.WATER);
		return isBeach && hasWater;
	}

	return false;
}
 
Example 4
Source File: BlockSaplingHelper.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static boolean hasWater(IWorld worldIn, BlockPos pos)
{
    for (BlockPos blockpos$mutableblockpos : BlockPos.iterate(pos.add(-4, -4, -4), pos.add(4, 1, 4)))
    {
        if (worldIn.getBlockState(blockpos$mutableblockpos).getMaterial() == Material.WATER)
        {
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: Pony.java    From MineLittlePony with MIT License 4 votes vote down vote up
@Override
public boolean isPartiallySubmerged(LivingEntity entity) {
    return entity.isSubmergedInWater()
            || entity.getEntityWorld().getBlockState(entity.getBlockPos()).getMaterial() == Material.WATER;
}
 
Example 6
Source File: Pony.java    From MineLittlePony with MIT License 4 votes vote down vote up
@Override
public boolean isFullySubmerged(LivingEntity entity) {
    return entity.isSubmergedInWater()
            && entity.getEntityWorld().getBlockState(new BlockPos(getVisualEyePosition(entity))).getMaterial() == Material.WATER;
}