Jump to content

Recommended Posts

Posted

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?  

Posted
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?

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.

Posted
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.

Posted
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...?

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.

Posted
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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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