Jump to content

Recommended Posts

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?

Posted

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.

Posted

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

}

 

 

Posted

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?

Posted

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.

Posted

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.

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



×
×
  • Create New...

Important Information

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