Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

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.

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

  • Author

I think I understand how the method should work, however I can't get the EntityJoinWorldEvent to be called at proper places

  • 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);

}

 

 

@SubscribeEvent

 

Not @EventHandler

1.7.10 is no longer supported by forge, you are on your own.

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

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 :D

1.7.10 is no longer supported by forge, you are on your own.

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.

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.