Jump to content

Recommended Posts

Posted (edited)

Hi,

 

I'm using the following code to prevent the player breaking carrots which aren't fully-grown, but it's not preventing the block breaking even though all of the conditions have been met. Why could this be?

 

@SubscribeEvent
	public void onBlockBreak(PlayerInteractEvent.LeftClickBlock event)
	{
		if (!event.getWorld().isRemote) return;
		IBlockState state = event.getWorld().getBlockState(event.getPos());
		
		for (Object o : state.getProperties().entrySet())
		{
			Map.Entry e = (Map.Entry)o;
			
			if (e.getKey() instanceof PropertyInteger)
			{
				PropertyInteger prop = (PropertyInteger)e.getKey();

				if (prop.getName().equals("age"))
				{
					int age = state.getValue(prop);
					
					if (age < 7)
					{
						event.setUseBlock(Result.DENY);
						event.setUseItem(Result.DENY);
						event.setCanceled(true);
					}
					
					return;
				}
			}
		}
	}

 

Edited by AntiRix
Posted (edited)

I didn't lie. It's going to be the same process for both 1.12.2 and 1.9, but my mod is 1.9. Even if you don't support 1.9 code, you by default support the concept by saying you support 1.12.2, even if you won't provide 1.9-compatible code.

To put it more simply, you are able to help me without the need for code whatsoever, by just telling me what I'm doing wrong. For example, "You could set both results to DENY for PlayerInteractEvent.LeftClickBlock and cancel the event on the client to prevent the left-click interaction.". This tells me what to do, without any code. This essentially means the help you provide is version-agnostic. It is not reasonable to refuse people help unless they rewrite thousands of lines of code.

Edited by AntiRix
  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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