Club PA 2.0 has arrived! If you'd like to access some extra PA content and help support the forums, check it out at patreon.com/ClubPA
The image size limit has been raised to 1mb! Anything larger than that should be linked to. This is a HARD limit, please do not abuse it.
Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

# I need coding help (in Python?) - removing ores from a map in Minecraft

New Jersey, USARegistered User regular
edited July 2011
Okay, so - we have our map - roughly 5,500 x 5,500 - that we generated with Biome Terrain Mod. At the time, we were just kind've roughing out values for material deposits, but once we got the overall terrain the way we liked we started building. Unfortunately, we sort've neglected to ensure that the mineral deposits beneath the surface were present in anything approaching reasonable amounts. As a result, what we have now is an absolutely gorgeous, expansive, hand-tooled fantasy map with WAY TOO MUCH ORE.

I'm looking into solutions to fix this.

I was looking at maybe using MCEdit to remove the ores, and I was directed to a script called 'NearReplace' that basically shrinks the ore deposits down by doing some calculations based on what blocks are nearby.

I just changed the line
if level.blockAt(x,y,z)==fromb.ID:
to
if level.blockAt(x,y,z)==14 or 15 or 16 or 56 or 73 or 21:

... in order to thin out the frequency of Iron, Coal, Gold, Lapis, Diamond and Redstone ores. I set the percent chance to around 75%, but honestly anything over 50 usually knocks the blocks out due to how much stone is nearby anyway.

The problem is, though, that running that script in a 100 x 100 area takes about 5 minutes even on a reasonable computer when done inside MCEdit! Extrapolating this out, and assuming MCEdit wouldn't even crash first, I'm looking at something like 3 weeks of calculations to thin the resources on my map out properly, which is just not an option.

I was wondering if anyone might be able to help. I'm basically a moron when it comes to coding python - that one-line substitution was about the peak of my understanding - but I know it'll run notably faster if I do it via command line instead of within MCEdit. However, I don't know how to do stuff like that. Additionally, I have to imagine that the code I'm using from this NearReplace script is probably not as efficient as it could be.

Does anyone out there have experience with this kind of thing and can help out? I've found a couple other python scripts that do operations on minecraft maps but I have no idea how to run or modify these kinds of things.

Server info: mc.crafti.ca
Ein on

## Posts

• Registered User regular
edited June 2011
Try changing
``````if level.blockAt(x,y,z)==14 or 15 or 16 or 56 or 73 or 21:
``````

to
``````if level.blockAt(x,y,z)==14 or level.blockAt(x,y,z)==15 or level.blockAt(x,y,z)==16 orlevel.blockAt(x,y,z)== 56 or level.blockAt(x,y,z)==73 or level.blockAt(x,y,z)==21:
``````

Right now I believe, based on quick tests with python and more experience in other languages, that right now that if is basically just always evaluating to true and running for every block rather than just the ones you want.

Well, that's the "simplest" change. It is not the most "correct" way of writing the code in that it's kind of a pain in the balls to read/look at.

Jimmy King on
• TorontoRegistered User regular
edited June 2011
Yeah, what it looks like is happening is it's only checking if level.blockAt(x,y,z)==14

Basically it is checking like this:
``````if (level.blockAt(x,y,z)==14) or true or true  or true  or true or true:
``````

Try something like this:
``````
oreIDs = [14, 15, 16, 56, 73, 21]

if level.blockAt(x,y,z) in oreIDs:
``````

Disclaimer: It's been a while since I've worked with Python and I don't have a compiler handy. That syntax might be wrong.

Sharp101 on
• Registered User regular
edited June 2011
Good call, sharp. That syntax works. I checked the list and array api's for an array.contains/list.contains method and didn't find one so went with the stupid long if statement. Not sure why I didn't think of that.

Jimmy King on
• New Jersey, USARegistered User regular
edited July 2011
Awesome, thanks dudes.

Ein on

Server info: mc.crafti.ca
• TorontoRegistered User regular
edited July 2011
PS ein - we miss you in the 40k thread

Sharp101 on