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

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.

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

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.

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.

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.

Sadly forge uses some static initialization here, so you'd have to do

Reflection.initialize(ForgeHooks.class);

before changing the HarvestLevel.

 

You, my good sir, are awesome. Thanks for that, works perfectly :P

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.