Posted June 4, 201510 yr Is there a way to override a vanilla item method without editing the base classes or do I have to create my own item with the same properties and replace the vanilla one with my own?
June 4, 201510 yr Unless you know ASM, which is overkill, there is not. What is your goal - you might be able to use Events to do something. 1.7.10 is no longer supported by forge, you are on your own.
June 4, 201510 yr Author I want a vanilla item to change into an item from my mod when dropped in water. For that I need to override onEntityItemUpdate(EntityItem) method.
June 4, 201510 yr Author I think I understand how the method should work, however I can't get the EntityJoinWorldEvent to be called at proper places
June 4, 201510 yr Author In a class called ChangeDefaults I've got this: public static void entityJoinEvent(EntityJoinWorldEvent event) { if (event.entity instanceof EntityItem) { EntityItem entityItem = (EntityItem) event.entity; if (entityItem.getEntityItem().getItem() == Items.coal) if (entityItem.worldObj.getBlockState(new BlockPos((int) Math.floor(entityItem.posX), (int) Math.floor(entityItem.posY), (int) Math.floor(entityItem.posZ))).getBlock() == Blocks.water) { entityItem.setEntityItemStack(new ItemStack(entityItem.getEntityItem().getMetadata() == 0 ? ModItems.wetCoal : ModItems.wetCharcoal, 1, 0)); } } } In the main mod class is where I get stuck. I tried this: @Mod.EventHandler public void entityJoinWorld(EntityJoinWorldEvent event) { ChangeDefaults.entityJoinEvent(event); }
June 4, 201510 yr @SubscribeEvent Not @EventHandler 1.7.10 is no longer supported by forge, you are on your own.
June 4, 201510 yr Author Still doesn't work. That method is not being called. And also, as far as I understand, Entity join happens once for every new dropped item. And that is not what I want to do. Basically, I'm just asking whether my code will work or not to turn any coal/charcoal into wet one?
June 4, 201510 yr Forge has only access to LivingUpdates (LivingUpdateEvent), BUT there is also event that would allow you to get access to non-living entities. EntityEvent.CanUpdate Would allow you to run code when ANY Entity is being updated. Note that I have NO IDEA what will actually happen - never used it, but seems like it would work. @SubscribeEvent should work. You also need to register MyEvent.class FMLCommonHandler.instance().bus().register(new FMLEvents()); MinecraftForge.EVENT_BUS.register(new ForgeEvents()); Use one of those in preInit of common proxy. ("one of" - depending what events are you using, events can be recognized by package). EDIT If my wild idea (EntityEvent.CanUpdate) won't work - then you need to extend EntityItem as mentioned before. Only way 1.7.10 is no longer supported by forge, you are on your own.
June 4, 201510 yr You need to make it. You create class with methods in it that have @SubscribeEvent on them. EDIT There are tons of tuts on how to use events. Look them up please. 1.7.10 is no longer supported by forge, you are on your own.
June 4, 201510 yr Author Well, seems like a lot to be understood and rethought. I will probably look deeper into it tomorrow.
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.