Jump to content

[SOLVED] [1.12] Checking if a region is empty


Recommended Posts

I'm pretty new to modding but have a pretty good understanding of Java.


The big question I have is if there is a relatively easy way to check if an area in world is either empty.


I have an item that builds a structure. At the moment anywhere a block is placed it replaces whatever was there. I would like it to only run the block placement code if the region for the final structure is either completely empty or only contains blocks that are replaceable (I.e grass, snow, etc.).


Is this possible or do I need to check before every block placement?

Edited by GenghisKahn1992
Question Answered
Link to comment
Share on other sites

You have to check for every block placement. You can check for == Blocks.AIR (and other blocks you consider replaceable. (Note that in 1.13 upcoming I think they are adding some different types of air like "cave air" to help with generation and spawning.).


The alternative is to take over the chunk generator and replace it with one where, if you're going to build the structure, doesn't put anything else in the way in the first place. 

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

Link to comment
Share on other sites

40 minutes ago, GenghisKahn1992 said:

Ok. I was afraid of that. I'll needed to find a better way of storing the block locations of the structure then. 


Why? are you seeing a performance problem? Almost everything related to handling the blocks in the world is already pretty optimized so not sure how you would optimize it further. What is different about what you're trying to do versus something like a stronghold?

Edited by jabelar

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

Link to comment
Share on other sites

Oh, sorry for the confusion. It's not a world gen structure. It's an item that builds structures on use using items in the players inventory.

So instead of listing every block location and then testing block.isReplaceable(world, pos) I'll need to find a good way to store relative positioning of the structure so that I can loop through the positions with only a single isReplaceable test that gets called each loop.


(And hopefully have the looping generic enough so that I can have the single item usable for multiple structures)

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.

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.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.