Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi,

 

I'm using the following code to prevent the player breaking carrots which aren't fully-grown. It works fine on singleplayer, but not at all on multiplayer, in fact on multiplayer the event isn't being fired at all. Why could this be?

 

@SubscribeEvent
    public void onBlockBreak(BreakEvent event)
    {
        IBlockState state = event.getState();
        net.minecraft.block.Block block = state.getBlock();
        
        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.setCanceled(true);
                }
            }
        }
}

Edited by AntiRix

  • Author

I had 1.12.2 already set up so might as well go with that.

 

The mod isn't for the server itself, it's a client-side mod, but one which isn't working on multiplayer for some reason.

  • Author

Does that include the internal server? It works fine on singleplayer.

  • Author

Ok, so how should I approach cancelling block break events with a client-side mod only, on multiplayer?

Edited by AntiRix

  • Author

I've adjusted the code, but now it seems the block doesn't even have any properties. 

 

@SubscribeEvent
	public void onBlockBreak(PlayerInteractEvent.LeftClickBlock event)
	{
		IBlockState state = mc.theWorld.getBlockState(event.getPos());
		
		mc.thePlayer.addChatMessage(new TextComponentString("onBlockBreak"));
		for (Object o : state.getProperties().entrySet())
		{
			Map.Entry e = (Map.Entry)o;
			
			if (e.getKey() instanceof PropertyInteger)
			{
				PropertyInteger prop = (PropertyInteger)e.getKey();
				mc.thePlayer.addChatMessage(new TextComponentString(prop.getName() + ": " + state.getValue(prop)));
				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

  • Author

If I have the following at the beginning of the method, nothing happens.

 

if (!mc.theWorld.isRemote) return;

 

If I have the following, properties are retrieved but it still doesn't cancel the breaking, even though age < 7 is true:

 

if (mc.theWorld.isRemote) return;

 

This makes no sense considering what you just said

Edited by AntiRix

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.