Posted October 10, 20205 yr I'm trying to write a test mod, I can't solve the problem. When I right-click with a stick in my hands, I expect to send one chat message to the player, but I get two How to solve this problem? Test.java package com.alexstank.test; import com.alexstank.test.events.ModClientEvents; import net.minecraft.block.Blocks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @Mod("test") public class Test { public static final Logger LOGGER = LogManager.getLogger(); public Test() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); MinecraftForge.EVENT_BUS.register(ModClientEvents.class); } private void setup(final FMLCommonSetupEvent event) { LOGGER.info("HELLO FROM PREINIT"); LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); } private void doClientStuff(final FMLClientSetupEvent event) { LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings); } } ModClientEvents.java package com.alexstank.test.events; import com.alexstank.test.Test; import net.minecraft.entity.LivingEntity; import net.minecraft.item.Items; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.client.event.ColorHandlerEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; public class ModClientEvents { @SubscribeEvent public static void OnRightMouseClick(PlayerInteractEvent.RightClickItem event) { LivingEntity player = event.getEntityLiving(); if(player.getHeldItemMainhand().getItem() == Items.STICK) { System.out.println("help me please"); player.sendMessage(ITextComponent.func_244388_a("help me please!"), player.getUniqueID()); Test.LOGGER.info("double execution"); } } } Log [19:00:10] [Render thread/INFO] [STDOUT/]: [com.alexstank.test.events.ModClientEvents:OnRightMouseClick:18]: help me please [19:00:10] [Server thread/INFO] [STDOUT/]: [com.alexstank.test.events.ModClientEvents:OnRightMouseClick:18]: help me please [19:00:10] [Server thread/INFO] [co.al.te.Test/]: double execution [19:00:10] [Render thread/INFO] [minecraft/NewChatGui]: [CHAT] help me please! [19:00:10] [Render thread/INFO] [co.al.te.Test/]: double execution [19:00:10] [Render thread/INFO] [minecraft/NewChatGui]: [CHAT] help me please! Edited October 10, 20205 yr by Lex023
October 10, 20205 yr 2 minutes ago, Lex023 said: [Render thread/INFO] [STDOUT/]: [com.alexstank.test.events.ModClientEvents:OnRightMouseClick:18]: help me please [19:00:10] [Server thread/INFO] [STDOUT/]: [com.alexstank.test.events.ModClientEvents:OnRightMouseClick:18]: help me please It's called on both threads. You should make the code execute on a specific side.
October 11, 20205 yr Author 17 hours ago, ChampionAsh5357 said: It's called on both threads. You should make the code execute on a specific side. Thanks, all worked well.
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.