help with coding

Started by Nico__09 on

Topic category: Help with modding (Java Edition)

Last seen on 09:07, 9. Sep 2024
Joined Jun 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
help with coding
Wed, 08/28/2024 - 08:35 (edited)

I'm trying to create a mod that puts the player in difficulty when he tries to break a block of wood and if he doesn't have an ax he gets nothing.
I wrote this code but it gives me error 

@Mod.EventBusSubscriber
public class Woodprocedure {

   @SubscribeEvent
   public static void harvestCheck(PlayerEvent.BreakSpeed ​​event) {
       BlockState block = event.getState();

       // Check if the block is a trunk (log)
       if (block.getBlock().getRegistryName().getPath().contains("log")) {
           PlayerEntity player = event.getPlayer();
           ItemStack item = player.getHeldItemMainhand();

           // Check if the object in your hand is not an axe
           if (!(item.getItem() instanceof AxeItem)) {
               event.setCanceled(true);
           }
       }
   }
}

Edited by Nico__09 on Wed, 08/28/2024 - 08:35
This can be achieved using…
Wed, 08/28/2024 - 15:28

This can be achieved using procedures so you may not need to have actual code for this

I suggest you check our tutorials collection playlist on our YouTube channel which contains many examples and tutorials that can help you get started with MCreator: https://www.youtube.com/playlist?list=PLAeL-oIFIEngE6jRgFYeFMfuj8WQsO3Ei