Jump to content

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


Recommended Posts

Posted

How would it be the way to place a Minecraft Vanilla block in my world, using my mod, but making that block unbreakable?

 

I tried something, but I end up with all the blocks of that type on my world been unbreakable, so I guess I overwrote the original block somehow.

Posted

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

Posted

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?

Posted

So you want to make it so that all blocks with the block type are unbreakable?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

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/

Posted

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

 

Posted

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.

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.