#Minecraft Forge 1.19: BreakEvent, get the blocks Tag as a String?

1 messages · Page 1 of 1 (latest)

lavish falcon
#

Howdy! 🤠
I have been at this for a few days now and feel like I am at an impasse. I am happy to say blocks of the LOG tag are detected on BreakEvents.

public class ModEvents {
    @Mod.EventBusSubscriber(modid = TreeFS.MODID)
    public static class ForgeEvents {
        @SubscribeEvent
        public static void onBlockBreak(BlockEvent.BreakEvent event) {
            ServerPlayer player = (ServerPlayer) event.getPlayer();
            BlockState blockState = (BlockState) event.getState();

            if (blockState.is(LOGS)) {
                String blockStateString = blockState.toString();
                player.sendSystemMessage(Component.nullToEmpty("Block broken with tag: " + blockStateString));
            }
        }
    }
}

However, while I am able to get the blocks tag from event.getState() as a value for the blockState variable (at least I think that is what's happening), I cannot seem to implement it for .toString() .

I am sure I got some concept backwards or mixed up terminology, but, to clarify:

  • I want to listen for BreakEvent.
  • Get the tag of the broken block.
  • if it is of tag LOGS, send the tag as a string in chat.

The chat message should read "Block broken with tag: LOGS" but instead, reads, "Block broken with tag: minecraft:tags | minecraft:logs, axis (the axis)"

I hope this explains things and you can help me.

wheat robinBOT
# lavish falcon Howdy! 🤠 I have been at this for a few days now and feel like I am at an impas...

Detected code, here are some useful tools:

Formatted code
public class ModEvents {
  @Mod
  .EventBusSubscriber(modid = TreeFS.MODID) public static class ForgeEvents {
    @SubscribeEvent
    public static void onBlockBreak(BlockEvent.BreakEvent event) {
      ServerPlayer player = (ServerPlayer) event.getPlayer();
      BlockState blockState = (BlockState) event.getState();
      if (blockState.is(LOGS)) {
        String blockStateString = blockState.toString();
        player.sendSystemMessage(Component.nullToEmpty("Block broken with tag: " + blockStateString));
      }
    }
  }
}
#

<@&987246883653156906> please have a look, thanks.

lavish falcon
lavish falcon
#

Sorry, but, shouldnt @wheat robin have mentioned <@&987246652869971988> ?

#

sorry for mention sorry

cinder stone
#

well I think it pings the role with the least members, to hit the most niche topic of the related ones

wheat robinBOT
#

Changed the category to Minecraft.

#

<@&987246652869971988> please have a look, thanks.

lavish falcon
#

ah

cinder stone
#

now it added minecraft helper

lavish falcon
#

resolved by mr coder man ethan himself tyty

#

implemented blockutil class with .toList()