我想看看是否有人加入了一个世界,然后打印一些东西来安慰,但事件似乎没有触发。有人能帮我吗?这是我的代码:
package pl00py_TR.pl00pyspvpmod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class Pl00pysPVPMod {
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
}
@EventHandler
public void init(FMLInitializationEvent event) {
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
System.out.println("DIRT BLOCK >> " + Blocks.dirt.getUnlocalizedName());
}
public class EventTest {
@SubscribeEvent
public void OnEvent(LivingSpawnEvent event) {
System.out.println("Event Test");
if (event.entity instanceof EntityPlayer) {
System.out.println("Player Joined");
}
}
}
public void RegisterEvents() {
System.out.println("Registering Events...");
MinecraftForge.EVENT_BUS.register(EventTest.class);
}
}
代码适用于 1.8.9,我想知道是否有人加入服务器/世界。我正在尝试获取玩家坐标并将它们打印到控制台,但事件不会触发或初始化。有人可以解释为什么会这样,并告诉我如何解决这个问题吗?
可能是错的但尝试
MinecraftForge.EVENT_BUS.register(new EventTest());
而不是MinecraftForge.EVENT_BUS.register(EventTest.class);
在
EventBus
的文档中
void register(java.lang.Object target)
我知道我来晚了,但你可以使用
register(new EventClass())
这允许事件方法不是静态的或使方法静态并使用register(EventClass.class)