Jump to content

[1.12.2] Checking if block is water


GammaS_

Recommended Posts

I am currently using onItemUse() 

@Override
	public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand,
			EnumFacing facing, float hitX, float hitY, float hitZ) {

		if (!worldIn.isRemote) {
			IBlockState block = worldIn.getBlockState(pos);

			// CHECK AND SEE IF THE PLAYER IS HOLDING A DUST IN THEIR OFF HAND
			System.out.println("Pan right clicked!");
			if (block == Blocks.WATER.getDefaultState() || block == Blocks.FLOWING_WATER.getDefaultState()
					|| block == Blocks.GRASS.getDefaultState()) {
				System.out.println("Used on water");
				if (RecipeHolder.getPanningRecipe(player.getHeldItemOffhand()).get(0) != ItemStack.EMPTY) {
					System.out.println("Recipe found!");
					ItemStack offHand = player.getHeldItemOffhand();
					List<ItemStack> recipe = RecipeHolder.getPanningRecipe(offHand);

					// The player has enough of the dust in their hand
					if (offHand.getCount() >= recipe.get(0).getCount()) {
						System.out.println("Recipe input confirmed!");
						offHand.shrink(recipe.get(0).getCount());

						for (int i = 1; i < recipe.size(); i++) {
							worldIn.spawnEntity(
									new EntityItem(worldIn, pos.getX(), pos.getY() + 1, pos.getZ(), recipe.get(i)));
						}

						return EnumActionResult.SUCCESS;
					}
				}
			}
		}

		return EnumActionResult.FAIL;

	}

 

Grass is in there so I could test the other functionality, and it works, but water does not work. I am assuming this is because you interact through water so it never detects the water block but what is behind it. So how would I check for water?

 

Thanks, James

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.