Jump to content

Recommended Posts

Posted
  On 10/6/2019 at 6:00 AM, Codemetry said:

Why is it fired multiple times when a player joins a server (and a world)? Are there any alternative events?

Expand  

The even is fired on both the client and the server. Make sure to only do your code on the logical server by checking if World#isRemote is false.

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 (edited)
  On 10/6/2019 at 6:04 AM, Animefan8888 said:

The even is fired on both the client and the server. Make sure to only do your code on the logical server by checking if World#isRemote is false.

Expand  

I am new to forge modding, so please forgive me for my basic questions.

 

I am trying to make the player send a chat message when joined a server world. Before ensuring World#isRemote is false, the chat message is sent 3 times every 3 seconds. When I added the check, no chat message is sent.

Edited by Codemetry
Posted
  On 10/6/2019 at 6:16 AM, Codemetry said:

I am new to forge modding, so please forgive me for my basic questions.

 

I am trying to make the player send a chat message when joined a server world. Before ensuring World#isRemote is false, the chat message is sent 3 times every 3 seconds. When I added the check, no chat message is sent.

Expand  

Post your code. And this includes how you registered your event handler.

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

What's the current state of the code?

 

  On 10/6/2019 at 6:16 AM, Codemetry said:

I am trying to make the player send a chat message when joined a server world.

Expand  

By this do you mean you want to send a message to the player, or send a message via the player?

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted (edited)
  On 10/6/2019 at 6:25 AM, SerpentDagger said:

What's the current state of the code?

 

By this do you mean you want to send a message to the player, or send a message via the player?

Expand  

via the player to the server

  On 10/6/2019 at 6:25 AM, Animefan8888 said:

Post your code. And this includes how you registered your event handler.

Expand  
	Minecraft mc;
	@EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		mc = Minecraft.getMinecraft();
		MinecraftForge.EVENT_BUS.register(this);
	}
	@SubscribeEvent
	public void onEntityJoinWorld(EntityJoinWorldEvent event) {
		if (!event.world.isRemote) {
			mc.thePlayer.sendChatMessage("hello");
		}
	}

 

Edited by Codemetry
Posted

It would be helpful if you could show the whole classes, as the event system is impacted by that.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted
  On 10/6/2019 at 6:38 AM, SerpentDagger said:

It would be helpful if you could show the whole classes, as the event system is impacted by that.

Expand  
package com.example.examplemod;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod {
	public static final String MODID = "examplemod";
	public static final String VERSION = "1.0";
	Minecraft mc;

	@EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		mc = Minecraft.getMinecraft();
		MinecraftForge.EVENT_BUS.register(this);
	}
	
	@SubscribeEvent
	public void onEntityJoinWorld(EntityJoinWorldEvent event) {
		if (!event.world.isRemote) {
			mc.thePlayer.sendChatMessage("hello");
		}
	}
}

 

Posted
  On 10/6/2019 at 6:30 AM, Codemetry said:

I am on recommended version of 1.8.9 of Forge.

Expand  

Sorry 1.8.9 is an extremely outdated version and we no longer support it on this forum. Please update to receive support. Once a forum moderator sees this they will lock it.

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.

  • 3 weeks later...
Posted

Bump.

I have updated to 1.14.4 - 28.1.0.

I did some testing and found that:

  • EntityJoinWorldEvent is fired once when joining a server (and a world) from the multiplayer menu
  • EntityJoinWorldEvent is fired multiple times (usually 6 - 10) when switching between worlds on a server or servers on a bungee network
  • The Worlds returned by EntityJoinWorldEvents are not the same instance
  • The EntityJoinWorldEvents are not the same instance (that means I did not register more than once)

I have already added the following check into EntityJoinWorldEvent handler

mc.thePlayer == event.entity

Here is my handler in case:

	@SubscribeEvent
	public void onEntityJoinWorld(EntityJoinWorldEvent event) {
		if (mc.thePlayer == event.entity) {
			mc.thePlayer.addChatMessage(
					new ChatComponentText("hello"));
		}
	}

Does anyone know why this is happening?

Posted
  On 10/22/2019 at 5:58 PM, Codemetry said:

Bump.

I have updated to 1.14.4 - 28.1.0.

I did some testing and found that:

  • EntityJoinWorldEvent is fired once when joining a server (and a world) from the multiplayer menu
  •  EntityJoinWorldEvent is fired multiple times (usually 6 - 10) when switching between worlds on a server or servers on a bungee network
  • The Worlds returned by EntityJoinWorldEvents are not the same instance
  • The EntityJoinWorldEvents are not the same instance (that means I did not register more than once)

I have already added the following check into EntityJoinWorldEvent handler

mc.thePlayer == event.entity

Here is my handler in case:

	@SubscribeEvent
	public void onEntityJoinWorld(EntityJoinWorldEvent event) {
		if (mc.thePlayer == event.entity) {
			mc.thePlayer.addChatMessage(
					new ChatComponentText("hello"));
		}
	}

Does anyone know why this is happening?

Expand  

if you updated to 1.14.4: Where did you get the method `addChatMessage` and `ChatComponentText` class?

Posted
  On 10/22/2019 at 5:58 PM, Codemetry said:

if (mc.thePlayer == event.entity) {

Expand  

mc here is almost certainly the result of calling Minecraft.getMinecraft(), which won't work on a server (it'll crash the server).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 10/23/2019 at 1:18 PM, Draco18s said:

mc here is almost certainly the result of calling Minecraft.getMinecraft(), which won't work on a server (it'll crash the server).

Expand  

I am working on a client side mod.

  On 10/22/2019 at 6:52 PM, MairwunNx said:

if you updated to 1.14.4: Where did you get the method `addChatMessage` and `ChatComponentText` class?

Expand  

Sorry I was in a rush and copied from my old java file.

Posted
  On 10/23/2019 at 1:55 PM, Codemetry said:

 Sorry I was in a rush and copied from my old java file.

Expand  

You should post your new updated code.

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Betafort Recovery has emerged as a prominent figure in the realm of cryptocurrency recovery, gaining a reputation for their exceptional ability to retrieve lost Bitcoin (BTC) and other cryptocurrencies. Their expertise and track record have made them a beacon of hope for individuals facing the distressing situation of lost or inaccessible crypto assets.  
    • When you name a method like that, with no return value, it is a constructor. The constructor must have the same name as the class it constructs, in this case, ModItems. I would strongly advise reading up on some basic Java tutorials, because you will definitely be running into a lot more issues as you go along without the basics. *I should also add that the Forge documentation is a reference, not a tutorial. Even following tutorials, you should know Java basics, otherwise the smallest of mistakes will trip you up as you copy someone elses code.
    • so, I'm starting modding and I'm following the official documantation for forge: https://docs.minecraftforge.net, but in the registries part it is not working as it is in the docs:   public class ModItems { private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, DarkStarvation.MOD_ID); public static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties())); public DarkStarvation(FMLJavaModLoadingContext context) { ITEMS.register(context.getModEventBus()); } } in 'public DarkStarvation(...' the DarkStarvation has this error: Invalid method declaration; return type required and the getModEventBus(): Cannot resolve method 'getModEventBus' in 'FMLJavaModLoadingContext' please help, I asked gpt but it is saying that I'm using an old method, but I'm following the latest version of Forge Docs???
    • I merged your second post with the original , there is no need to post a new thread asking for an answer. If someone sees your post and can help, they will reply. If you are seeking a quicker response, you could try asking in the Minecraft Forge diacord.
    • Create a new instance and start with cobblemon - if this works, add the rest of your mods in groups   Maybe another mod is conflicting - like Sodium/Iris or Radical Cobblemon Trainers
  • Topics

×
×
  • Create New...

Important Information

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