Jump to content

[1.7.X] Modifying Existing Blocks and Items


TheAurumGamer

Recommended Posts

Hi! I'm relatively new to Forge but have a year of Java under my belt, but I'm stumped by one thing: How do I modify existing blocks and items in the Minecraft game?

 

I already understand the concept of creating new blocks, entities, potions, items, and so forth, but how do i modify an existing block, such as a leaf dropping a slime ball?

 

Help would be appreciated as I have little time to work on this.

Link to comment
Share on other sites

There are multiple ways of doing this, depending on what exactly you want to do.

 

For example, setting the harvest level of a vanilla block (I've just got this working in my mod) is quite tricky, as Forge sets this after the mod loads. This means that you have to use an event listener, in my case, a player join even listener. This is done by creating a new class file to tell the mod what to run on that event, and using the EVENT_BUS on your main mod file to listen for the event:

 

Main file:

FMLCommonHandler.instance().bus().register(new PlayerJoinEvent());

 

PlayerJoinEvent.class:

 

public class PlayerJoinEvent{

@SubscribeEvent
public void playerJoin(PlayerEvent.PlayerLoggedInEvent event)
{
	//Modify iron ore to require a harvest level of 3 (diamond):
                Blocks.iron_ore.setHarvestLevel("pickaxe", 3);
}

}

 

Drops are done using the same method, but using a different event: HarvestDropsEvent. The following code would make iron ore drop 64 diamond pickaxes. Because why not?

 

public class BlockHarvestEvent {

@SubscribeEvent
public void onBlockHarvest(HarvestDropsEvent event)
{
	if(event.block == Blocks.iron_ore)
	{
		event.drops.clear();
		event.drops.add(new ItemStack(Items.diamond_pickaxe, 64));
	}
}

}

 

Again, this has to be called in your main file, but using a different event bus:

 

MinecraftForge.EVENT_BUS.register(new BlockHarvestEvent());

 

 

Most other things can be changed without needing to listen for an event, such as hardness (I know for a fact that this one works, I use it in my mods).

Link to comment
Share on other sites

Because I was writing it in a hurry and that was the only event I could think of on the spot. Any suggestions to improve it are welcome :P

 

I'm fairly new to Forge modding, so some of the stuff I do may not be the best solution.

Link to comment
Share on other sites

Because I was writing it in a hurry and that was the only event I could think of on the spot. Any suggestions to improve it are welcome :P

 

I'm fairly new to Forge modding, so some of the stuff I do may not be the best solution.

there is other events....I think better to use player tracker for client side , and for server side - i think server load will be ok , beacos its the latest what happyning on server startup...when commands are added.

Link to comment
Share on other sites

Guys... guys.

PlayerTracker is the same as PlayerLoggedInEvent, just for 1.6.

 

Stuff like this is done in preInit.

 

The issue with changing the harvest level in preInit is that Forge then goes and changes it back to default afterwards.

Link to comment
Share on other sites

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.