Java Code Examples for net.minecraft.block.Blocks#CACTUS

The following examples show how to use net.minecraft.block.Blocks#CACTUS . 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: 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 2
Source File: IPlantable.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
default PlantType getPlantType(BlockView world, BlockPos pos) {
	if (this instanceof CropBlock) return PlantType.Crop;
	if (this instanceof SaplingBlock) return PlantType.Plains;
	if (this instanceof FlowerBlock) return PlantType.Plains;
	if (this == Blocks.CACTUS) return PlantType.Desert;
	if (this == Blocks.LILY_PAD) return PlantType.Water;
	if (this == Blocks.RED_MUSHROOM) return PlantType.Cave;
	if (this == Blocks.BROWN_MUSHROOM) return PlantType.Cave;
	if (this == Blocks.NETHER_WART) return PlantType.Nether;
	if (this == Blocks.TALL_GRASS) return PlantType.Plains;
	return net.minecraftforge.common.PlantType.Plains;
}
 
Example 3
Source File: MixinCactusBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "canPlaceAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getBlock()Lnet/minecraft/block/Block;"))
private Block redirectSoilCheck(BlockState blockState) {
	if (((IForgeBlockState) blockState).canSustainPlant(currentWorld.get(), currentBlockPos.get().down(), Direction.UP, this)) {
		return Blocks.CACTUS; // Forces condition to be true.
	}

	return blockState.getBlock(); // Pass this to let injects from fabric mods maybe work
}
 
Example 4
Source File: BlockRotator.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static boolean flippinEligibility(Entity entity)
{
    if (CarpetSettings.flippinCactus && (entity instanceof PlayerEntity))
    {
        PlayerEntity player = (PlayerEntity)entity;
        return (!player.getOffHandStack().isEmpty()
                && player.getOffHandStack().getItem() instanceof BlockItem &&
                ((BlockItem) (player.getOffHandStack().getItem())).getBlock() == Blocks.CACTUS);
    }
    return false;
}
 
Example 5
Source File: BlockRotator.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static boolean player_holds_cactus_mainhand(PlayerEntity playerIn)
{
    return (!playerIn.getMainHandStack().isEmpty()
            && playerIn.getMainHandStack().getItem() instanceof BlockItem &&
            ((BlockItem) (playerIn.getMainHandStack().getItem())).getBlock() == Blocks.CACTUS);
}