Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Placing a vanilla block using my mod but making it unbreakable


Recommended Posts

What it sounds like you want to do is to place a regular 'dirt' block, but this dirt block is unbreakable.

 

If you want to do that for any vanilla block, you will have to keep a list of the BlockPos and check against it when BreakEvent happens.  That could get ugly fast depending how many of these you set.

 

 

If you only have a small list of blocks you want to do this with, you could create your own block that uses the same image and display name as the vanilla blocks and it would be cleaner.

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to post
Share on other sites

Well, I know I got it wrong, but.... Why something like this doesn't do the trick?

 

Block dirt = Blocks.dirt.setHardness(-1F);

 

And I use that dirt? I know that doesn't work but....

 

What if I do that, then I place the blocks, and after placing the blocks I back dirt to it's original hardness? Would that be a bad thing also?

Link to post
Share on other sites

I think you're missing an important point about how Minecraft handles blocks. There is only every one instance of each block. This is because in a Minecraft world there are millions of block positions and so instantiating the class for each position would cause memory and performance problems. So instead, the blocks in the world are actually not separate blocks, but instead are actually a map of positions of types of blocks.

 

This means that if you change anything in the block class it will affect all the blocks of the same type in the world.

 

However, there are certain things that happen based on the block position. For example, breaking a block obviously only happens to the position you're hitting. So what you need to do, as suggested above, is to somehow remember (probably with a list of block positions) all the positions of unbreakable blocks you want. Then you need to handle the block breaking event and check if the block the player is trying to break matches a position on your list of unbreakable blocks. If it is on the list, then cancel the event so the block doesn't actually break.

 

Anyway, the key point is that you can't change the block instance because that will affect all the blocks in the world.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to post
Share on other sites

I think you're missing an important point about how Minecraft handles blocks. There is only every one instance of each block. This is because in a Minecraft world there are millions of block positions and so instantiating the class for each position would cause memory and performance problems. So instead, the blocks in the world are actually not separate blocks, but instead are actually a map of positions of types of blocks.

 

This means that if you change anything in the block class it will affect all the blocks of the same type in the world.

 

However, there are certain things that happen based on the block position. For example, breaking a block obviously only happens to the position you're hitting. So what you need to do, as suggested above, is to somehow remember (probably with a list of block positions) all the positions of unbreakable blocks you want. Then you need to handle the block breaking event and check if the block the player is trying to break matches a position on your list of unbreakable blocks. If it is on the list, then cancel the event so the block doesn't actually break.

 

Anyway, the key point is that you can't change the block instance because that will affect all the blocks in the world.

 

Thanks a lot for the perfect explanation ;)

 

Link to post
Share on other sites

Block dirt = Blocks.dirt.setHardness(-1F);

 

And I use that dirt? I know that doesn't work but....

 

Your

Block dirt

there is the same object as

Blocks.dirt

, you didn't create anything new with that code.

Because setHardness looks like this:

 

public Block setHardness(float val) {
   this.hardness = val;
   return this;
}

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

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.