Jump to content

[1.7.10] Override a method


winnetrie

Recommended Posts

I want to override a method from a class from an other mod.

Or with better words: i want to replace that method with mine:

this:

@Override
public boolean isValidPosition(World world, int x, int y, int z, int metadata)
{
	Block block = world.getBlock(x, y - 1, z);

	switch (metadata)
	{
	case 2: // Burning Blossom
		return block == Blocks.netherrack || block == BOPCBlocks.overgrownNetherrack;

	case 6: // Miner's Delight
		return block == Blocks.stone

	case 8: // Rose
		return block == Blocks.grass || block == Blocks.dirt || block == Blocks.farmland || block == BOPCBlocks.longGrass || block == BOPCBlocks.overgrownNetherrack || block == BOPCBlocks.originGrass || block.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, this);

	default:
		return block == Blocks.grass || block == Blocks.dirt || block == Blocks.farmland || block == BOPCBlocks.longGrass || block == BOPCBlocks.overgrownNetherrack || block.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, this);
	}
}

the miners delight can only stay on stone blocks and i want to change that so it can also stay on my blocks.

The reason why is those plants do not stay on my blocks (they pop off) and eventually they will despawn

So maybe i can override that method with mine (same method only with more options)

I do not know where to start and if it's possble either.

Link to comment
Share on other sites

srry but i have no idea what that means. Can you explain it more please?

I have found something about reflection "ReflectionHelper.findMethod()".

If i understand it right i can use this to find a specific method and pass it to a variable.

But i have no idea how to use it or how to replace it with my own method.

 

It would be much better if everyone would start using "instanceof"

Link to comment
Share on other sites

Ok i guess , nothing i can do then. Too bad!

 

If it was "return block instanceof BlockStone"  instead of "return block= Blocks.stone" it would be compatible with my stone.

I don't think the mod owner is going to change this. Why would he/she?

So the only thing i can think now is to replace all miner's delight with airblocks, or just let them be for what it is now and maybe a player can still find them before they despawn.

 

Link to comment
Share on other sites

Ok thnx for the tip  :D

My native language is not English, but i guess you already know this.

 

About that API thing, the mod i use with my mod is Biomes O' Plenty and i see there is a package called API.

Is this what i need? If so how do i use it?

Link to comment
Share on other sites

Alright i have tried this now:

GameRegistry.registerBlock(BOPCBlocks.flowers2 = new BlockBOPFlower2Override().setBlockName("flowers2"),ItemBlockBOPFlower2Override.class, "flowers2");

This works all fine. It does what it needs to do, it's just a copy of the original and i can place the minersdelight on my stones!

But it adds it to the game and not replacing it.

So how do i replace it now?

Link to comment
Share on other sites

Ok, now i'm really confused...

When i say "nothing i can do then" you say "this is not true"

But when i ask how to change/replace it , you say "you can't"

 

Asking the modowner for more support is just the same as "nothing i can do" , because like you said, it's unlikely they do that for an outdated version!

 

Image you would do this for your mod. How would you solve this? There have to be something else !

Link to comment
Share on other sites

I have found a solution for this.

in the worldgeneration i replace all those blocks with my blocks.

I think this is the closest solution i can get.

Any recipe containing those blocks/items has to be changed too

 

EDIT: Or i can just simply not change the stone block under the minersdelight

Link to comment
Share on other sites

What would happen if you created your own extension of the miner's delight and coded two features:

 

1) It grows on your stone

 

2) When harvested, it drops the item that you really want.

 

If your stone spawns naturally in the world, then you might want your generator to add a few of your delights where your stone meets air.

 

You might then need to find an event where somebody tries to plant the other mod's item on one of your stones. At that moment, you'd want to substitute one of your delight blocks in the world in place of the other mod's block.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

I did indeed created my own miner's delight and during the world generation where my blocks generates i replace all bop miner's delight with my own miner's delight. They look like the real 1, they do the same thing, only difference is that i can now place them on all my blocks.

You can't find any original in the game anymore, except in chests, so i need to replace that too.

After that you would only be able to get them via creative mode (the original)

So using an event to intercept this all would be unnessecary.

Just removing them from the game (world) is also an option. They aren't that important anyway. They are only needed to make 1 potion(Ambrosia)

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.