urabaros Posted July 23, 2021 Posted July 23, 2021 Goal: when Entity attacks player, it dies. Code: public class EventHandler { @SubscribeEvent public static void onLivingAttackEvent(LivingAttackEvent event) { if (event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == ItemInit.LAVA_HELMET.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemInit.LAVA_CHEST.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.LEGS).getItem() == ItemInit.LAVA_LEGGINGS.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.FEET).getItem() == ItemInit.LAVA_BOOTS.get()) { if (event.getSource().getTrueSource().getEntity() instanceof MobEntity) { event.getSource().getTrueSource().getEntity().onKillCommand(); } } } } And: @Mod(LavaArmor.MODID) public class LavaArmor { public static final String MODID = "lavaarmor"; public LavaArmor() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ItemInit.ITEMS.register(bus); MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(EventHandler.class); } @SuppressWarnings("deprecation") private void setup(final FMLCommonSetupEvent event) { } } I think I've done everything I've needed. Moreover, the exact same code works fine in my another project. What's wrong? Quote
Luis_ST Posted July 23, 2021 Posted July 23, 2021 On 7/23/2021 at 3:14 PM, urabaros said: MinecraftForge.EVENT_BUS.register(EventHandler.class); Expand don't use this in separate classes, use the EventBusSubscriber annotation instead https://mcforge.readthedocs.io/en/latest/events/intro/#events 1 Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 I register it like in a tutorial you mentioned: public class MyStaticForgeEventHandler { @SubscribeEvent public static void arrowNocked(ArrowNockEvent event) { System.out.println("Arrow nocked!"); } } In the EventHandler And this in the main class: MinecraftForge.EVENT_BUS.register(MyStaticForgeEventHandler.class) When I delete this from the main class and add @Mod.EventBusSubscriber(modid = LavaArmor.MODID, bus = Bus.MOD, value = Dist.CLIENT) to the EventHandler class, my game doesn't work. Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 Exception message: java.lang.IllegalArgumentException: Method public static void lavaarmor.EventHandler.onLivingAttackEvent(net.minecraftforge.event.entity.living.LivingAttackEvent) has @SubscribeEvent annotation, but takes an argument that is not a subtype of the base type interface net.minecraftforge.fml.event.lifecycle.IModBusEvent: class net.minecraftforge.event.entity.living.LivingAttackEvent Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 Ye! I have been using this in my main class: MinecraftForge.EVENT_BUS.register(EventHandler.class); But it wasn't registering in the game. Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 My goal is to kill every enemy that attack player that wears armor. But it just wasn't working for some reason. It's really strange, because I copied every single line from my previous project, where everything works fine. So game was loading, but entities just don't die. Whole code: https://gist.github.com/daekgorsel/c903cff212bb5e8ecdad20bf2dd13c9a Quote
Draco18s Posted July 27, 2021 Posted July 27, 2021 Quote value = Dist.CLIENT Expand I don't know, maybe the client can't kill entities, because the server controls that? 1 Quote 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.
urabaros Posted July 27, 2021 Author Posted July 27, 2021 Yes, I've already delete it, my EventHandler looks like this: public class EventHandler { @SubscribeEvent public static void onLivingAttackEvent(LivingAttackEvent event) { if (event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == ItemInit.LAVA_HELMET.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemInit.LAVA_CHEST.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.LEGS).getItem() == ItemInit.LAVA_LEGGINGS.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.FEET).getItem() == ItemInit.LAVA_BOOTS.get()) { //event.getSource().getTrueSource().getEntity().onKillCommand(); if (event.getSource().getTrueSource().getEntity() instanceof MobEntity) { event.getSource().getTrueSource().getEntity().onKillCommand(); } } } } Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 I'm not sure about you question, but when Entity attacks my, nothing appears on Console. So I think it's not called... am I right? Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 Yes, Logger is silent. @SubscribeEvent public static void onLivingAttackEvent(LivingAttackEvent event) { LavaArmor.LOGGER.info("event is here"); . . . } It doesn't appear. Why? I'm so confused because the exact same thing works in another project Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 I register it in the main class: @Mod(LavaArmor.MODID) public class LavaArmor { public static final String MODID = "lavaarmor"; public LavaArmor() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ItemInit.ITEMS.register(bus); MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(EventHandler.class); } @SuppressWarnings("deprecation") private void setup(final FMLCommonSetupEvent event) { } } Whole code: https://gist.github.com/daekgorsel/c903cff212bb5e8ecdad20bf2dd13c9a Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 No, I'm not using them. My EventHandler and Main class sools exactly as I mentioned before. I've dropped gist to show other classes. Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 Sorry. I've deleted this stuff you mantioned: Quote Do not use @OnlyIn. Why are you using both @EventBusSubscriber as well as the manual registration for EventHandler? Expand But it still doesn't work. I'm registering it only once in main class and I don't have @OnlyIn thingy. I can't even imagine why it doesn't work Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 @SubscribeEvent public static void onLivingAttackEvent(LivingAttackEvent event) { LavaArmor.LOGGER.info("event is here"); . . . } Only this way! I've put Logger into this method and let a zombie hit me. Logger didn't show up. Quote
urabaros Posted July 27, 2021 Author Posted July 27, 2021 Sorry, I can't do that. My project is not loading to git repo. Can I just provide a screenshot or something? Quote
urabaros Posted July 28, 2021 Author Posted July 28, 2021 (edited) I was getting aan error, but now I've fixed it!!! My git repo: https://github.com/daekgorsel/ArmorPlusGit Edited July 28, 2021 by urabaros Quote
urabaros Posted July 28, 2021 Author Posted July 28, 2021 THANK YOU SO MUCH I WOULD NEVER NOTICED IT MYSELF!!! 😭😭😭 Thank you that you invested so much time to help me! It works perfectly! I hope you'll have a nice day! Thank you so much! 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.