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

So I started modding Minecraft just out of fun and to learn something new, but quickly I started structuring it into a coherent idea and before I consider making this official I still want to experiment a little. This is just to explain why I haven't requested mod status yet, if that's needed. Apologies, if that's the case.

 

To the point: I've created a tool(an ItemSpade) and an item, and I'd like this item to be dropped if the player breaks dirt using this item. I had a real hard time trying to figure out how to manage that.

 

At first I tried changing the BlockDirt class directly, but that would only work when testing from Eclipse. After recompiling and reobfuscating the code and packing it up any changes to Dirt would be ignored.

 

I finally found a solution that involves creating a new class that will behave like BlockDirt, unregister the dirt block at initialization and register mine on top. It works, but sounds to me as incredibly shifty(not to mention possibly non-compatible with other mods). Is there another proper and better way to tamper with existing blocks with Forge?

  • Author

That sounds interesting... any quick reference you recommend about that? I'm googling it already, but a good recommendation is sometimes a lot more helpful than wading through Google results.

Well, this ASM I'm talking about is actually something built into forge. However, I have no clue how this works, all I know is that you can change base classes w/o losing compatibility with other mods this way.

ASM might not be your best option if you're just starting out. Also, it greatly decreases performance. I believe it is similar to java reflection. An alternate solution is to take your fake dirt block and replace all real dirt in the world. then give it all the real dirt functions. then have it drop real dirt and your item when broken. not the best idea in my opinion I would recommend every other alternative, but if you absolutely have to get something to drop from dirt, then feel free to use ASM/java reflection, just note that the game will be laggier.

I like collars. XP

  • Author

Okay, midway through this thread I just decided to create a new block to do this instead, so it's a new block crafted from dirt that can only be crafted with a special tool now. A lot easier, I guess.

 

Still, thanks very much, maybe later on I'll look into ASM if I really need that.

I do this (sort of) with Plugins for Forestry's Butcher Knife. I just cause the player to 'drop' the item when the conditions are met.

 

It looks a bit silly but its far more simple than any other way I've come across.

Aye, I think this should all be able to be handled in the blockbreak/blockharvest event, or even in the itemtool itself (overriding one of the methods).

 

You should basically be able to tell the game to spit out your item whenever a dirt block is broken with your tool.  I'll try and take a closer look and see if I can find the specific methods/etc.

 

Ahh, yes..in Item.java:

 

  public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving)
    {
        return false;
    }

 

implement an override here, and make either the player drop the item, or merely spawn it in the world.  You might even be able to call the block-drop method to have the block spit it out.  You will have to check that the block destroyed==Block.dirt or ==Block.grass (by calling world.getblockID(x,y,z) and comparing that to dirt/grass blockIDs).

 

Either way..no base-edits.  No block overrides.  No compatibility issues.

 

Please let me know if it helps.

 

 

 

  • Author

Hey shadowmage! Thanks much, I actually found that out before I was coming back here to comment that, while I managed to use that to do what I want(now an ax/shear hybrid), it's not working because I can't get the blocks dropped.

 

I'll post the code later when I'm back home, but for now any idea of what might be going on? I basically used a code with an if for block == Block.leaves and spawning a new entity, and the leaves blocks just stand there on the ground. =/

 

Here's the code:

 

@Override
public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player)
{	
	//System.out.println("Cutting "+player.worldObj.getBlockId(x,y,z));
	if (player.worldObj.getBlockId(x,y,z) == Block.leaves.blockID)
	{
		EntityItem sheared = new EntityItem(player.worldObj, x, y, z, new ItemStack(Block.leaves, 1, player.worldObj.getBlockMetadata(x, y, z)));
		//sheared.delayBeforeCanPickup = 10;
		player.worldObj.spawnEntityInWorld(sheared);
		return true;
	}

	return false;
}

  • Author

ERP DERP, found it! Here's code for EntityItem.collideWithPlayer:

 

public void onCollideWithPlayer(EntityPlayer par1EntityPlayer)
    {
        if (!this.worldObj.isRemote)
        {

 

Apparently in Minecraft 1.3 isRemote is always true. This means any entityItem will never collide with the player.

 

With that in mind, how do I even create items in Minecraft 1.3? I'm confused.

 


But the leaves block does disappear, the block stack pops out and fall to the floor and... stays there. I can't take it.

 

 

Not sure if it helps, but here's a screenshot:

 

 

4dfrL.png

 

 

The leaves blocks are the ones I can't get. Yes, the beetle is the tool.

  • Author

Okay, this was completely crazy, but worked. Here's what I figured out:

 

When testing from Eclipse, the "isRemote" flag is always true. Since the usual "onBlockStartBreak" code is only executed on the Client side, this leads to the code never working. Except it will work normally when the mod is compiled.

 

And then I had to return a false value to make sure the leaves block was destroyed. I actually did try it returning true, and the block was never destroying, generating an infinite source of leaves! Woot!

 

Anyway, the code is working now. Awesome! :D

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.