Jump to content

[1.8.9] Overriding Vanilla Block Properties


drok0920

Recommended Posts

I'm trying to make a mod that changes the properties of vanilla blocks.  I would like to replace them with my own class if possible or at least change thier harvest level.  I have read the solution here: http://www.minecraftforge.net/forum/index.php?topic=7866.0 but it doesnt seem to work any more and the only other solution i have found use reflection or some similar method to achieve it.

 

Thanks

Link to comment
Share on other sites

I am not sure it will work in 1.8.9 but it works in 1.7.10

If you know, there is list of blocks.

Like Blocks.sand

If you pick up your block for modifying, then use some basic methods from Block class.

 

Example

Block b = Blocks.sand;
b.setHardness(6.0F) //Sets a hardness for given block
b.setTextureName(.......) //Sets texture for block.
b.setHarvestLevel("pickaxe", 3) //Sets harvest level for block.

And so on...

If I am wrong with this, simply write a reply or PM me.

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

I'm not sure if it works with blocks, but I did smth like this

public static final void init() {
    	
        Items.diamond_sword.setMaxDamage(500);
        Items.diamond_sword.setTextureName(Main.MODID + ":itemSwordSuperIron");
        Items.diamond_sword.setUnlocalizedName("itemSwordSuperIron");

Link to comment
Share on other sites

Do note that a harvest level of 0 (wood tools) is not sufficient to prevent blocks from being dropped when mined by hand.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I am not sure it will work in 1.8.9 but it works in 1.7.10

If you know, there is list of blocks.

Like Blocks.sand

If you pick up your block for modifying, then use some basic methods from Block class.

 

Example

Block b = Blocks.sand;
b.setHardness(6.0F) //Sets a hardness for given block
b.setTextureName(.......) //Sets texture for block.
b.setHarvestLevel("pickaxe", 3) //Sets harvest level for block.

And so on...

If I am wrong with this, simply write a reply or PM me.

 

I can't believe i didnt think of doing that thank you!  However i would still like to know if there is a way to override it with my own class/add a tile entity to the block.

Link to comment
Share on other sites

Try something like this

 

Main class

Blocks.sand = new BlockCustomizedSand()

 

Customized block class

public class BlockCustomizedSand extends BlockSand
{
     @Override
     Override methods you want
}

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

I can't believe i didnt think of doing that thank you!  However i would still like to know if there is a way to override it with my own class/add a tile entity to the block.

 

The substitution alias system (

GameRegistry.addSubstitutionAlias

) is supposed to allow this, but I haven't had much luck with it myself.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Sorry if this is stupid question.

But Hand = harvest level -1?

 

Hand doesn't have a harvest level.  There's simply a check to see if the player is allowed to harvest a material without needing a tool.  If so, the block is always harvested, regardless of how the player broke it (hand, wrong tool, correct tool, or with a random item), and is harvested with a x5 speed bonus (this is why it takes so long to break stone by hand, even though Stone and Wood have the same hardness).

 

Setting the harvest level to 0 (or higher) is for the tool-speed-multiplier lookup.  This is why digging with a wooden shovel is faster than by hand but not by much: dirt can already be harvested by hand and already benefits from the "can harvest: x5 speed" bonus, whereas using a wooden shovel adds another x2 (taking it from 0.9 seconds to 0.45 per block).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ok so i tried just using

Items.wooden_pickaxe = flint_pickaxe;

to override the class it uses with no success.  It gives an error: "The final field Items.wooden_pickaxe cannot be assigned". I know this means it cannot be assigned to so is there a better way to do this?

Link to comment
Share on other sites

The field cannot be assigned because these fields are final but I will try to find anither way to do this.

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

The field cannot be assigned because these fields are final but I will try to find another way to do this.

Reflection? Can a final field be brute-forced?

(Probably bad style for anything shared beyond your own server and friends, somewhat like a core mod)

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

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.