Lea9ue Posted October 1, 2019 Posted October 1, 2019 So I am having trouble sending chat under certain conditions. From my server handler I can do: @SubscribeEvent public static void sendMessage(LivingUpdateEvent event) { World world = event.getEntity().world; if(!world.isRemote) { if(event.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntity(); player.sendMessage(new TextComponentTranslation("diamondSacrifice" + diamondSacrifice, new Object[0]).setStyle(new Style().setColor(TextFormatting.BLACK))); ....Do Other things and with this everyone receives message as I intend. BUT if I add another if statement: @SubscribeEvent //Send message to player public static void sendMessage(LivingUpdateEvent event) { World world = event.getEntity().world; if(diamondSacrificeMessage == 1) { if(!world.isRemote) { if(event.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntity(); player.sendMessage(new TextComponentTranslation("diamondSacrifice" + diamondSacrifice, new Object[0]).setStyle(new Style().setColor(TextFormatting.BLACK))); Then the client no longer gets messages while testing thru LAN. Can someone explain to me why a check of a public static int would cause problems? Quote
Animefan8888 Posted October 1, 2019 Posted October 1, 2019 1 minute ago, Lea9ue said: Can someone explain to me why a check of a public static int would cause problems? How/where are you changing the value of diamondSacrificeMessage? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
Lea9ue Posted October 1, 2019 Author Posted October 1, 2019 9 minutes ago, Animefan8888 said: How/where are you changing the value of diamondSacrificeMessage? In the same class from multiple different ways. For example one reason I would have to do this would be for like this: @SubscribeEvent public static void mobDefeat(LivingDeathEvent event) { World world = event.getEntityLiving().world; if (event.getEntity() instanceof EntitySkeleton) { if(event.getSource().getTrueSource() instanceof EntityPlayerMP) { diamondSacrificeMessage = 1; } } } Obviously for this the true source would only be the player that killed mob so I change diamondSacrificeMessage to 1 and then check with if statement in my original post and then reset to 0 once chat message is sent. Quote
Animefan8888 Posted October 2, 2019 Posted October 2, 2019 1 hour ago, Lea9ue said: Obviously for this the true source would only be the player that killed mob so I change diamondSacrificeMessage to 1 and then check with if statement in my original post and then reset to 0 once chat message is sent. Try stepping through your code in a debugger. Also why not just send the message in the LivingDeathEvent...? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
Lea9ue Posted October 2, 2019 Author Posted October 2, 2019 3 hours ago, Animefan8888 said: Try stepping through your code in a debugger. Also why not just send the message in the LivingDeathEvent...? Yes I could, and that works for that scenario. But it doesnt work for other instances. For example take the onDeathEvent, I dont think it will send message to all players. Only player who is trueSource, and let's look at a hypothetical for using INT's. Let's say I want to count skeleton kills. Once 10 skeletons are killed by EntityPlayer, if I want to send a message to everyone playing, then I have a problem. So that's what I need a solution checking a if statement for a static int thats not going thru on client side. Quote
Recommended Posts
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.