curlyc
Posts: 15
Joined: Wed Feb 01, 2017 4:30 am

20,000 lines of wasted time

Wed Feb 01, 2017 4:41 am

so im verry new to python, day one,
im using minecraft pi to help me learn,

right now i am building a small castle, at this point it is only a shell, 4 walls 20 blocks long each, with circle towers at the corners 9 blocks across the wall itself is 5 blocks high aboce ground, 65 (dow to the void) underground, the towers are 10 blocks high above ground, and again 65 blocks below

now being a total noob, each block has its own line of code, prety much the same as the rest but the x y and z is different, also i am using a variable for the block type so i can change them all without wasting a ton of time

that being said, it would be nice if i could just set the dimensions as variables and some how have the rest filled in? im shure this is quite obvious, but like i said im a noob


at this point i have about 20k lines of code devided over 3 files as i could only go up to around 13,000 in one file (and since i was seperting them any way iy made sense for me to make a third.

so my questions are 1. can i use some sort of loop to do most of the coding for me and 2. if i can not (or either way as im shure ill need it anyway) can i save an entire script and have it run with one line of code?

[MOD EDIT - PROFANITY REMOVED - PLEASE DO NOT SWEAR ON THESE FORUMS]

User avatar
RST8
Posts: 64
Joined: Tue Nov 25, 2014 1:57 pm

Re: 20,000 lines of wasted time

Wed Feb 01, 2017 10:15 am

There are many ways to do this, but what you really need to do is separate your code that does the drawing in minecraft and the data that represents the objects being drawn.

If you head over to :
https://github.com/joedeller/pymine

take a look at the drawcsv2.py code and also download some of the.csv files, (Comma Separated Values).
I'm showing my age by using that particular format, but it's long established way of storing data.

You'll need to make the python file executable , by running chmod +x drawcsv2.py in a terminal window.

If you start minecraft and a terminal window, then run ./drawcsv2.py newcastle2.csv, this should draw you a castle near where your player is standing.
The csv file is just a list of blocks, mostly a single number, but some have a second number to indicate extra information, wool colour for example. There is a separate entry when a new layer (it builds upwards) is starting.

To draw a different building, you give drawcsv2.py a different filename, so to draw a village ./drawcsv2.py village3.csv
There's basically a loop that reads from the CSV file from start to finish and sets the block type at an X,Y coordinate.

There is some extra code to handle special blocks, you don't want to put water or lava in place until you've drawn the container, so it keeps a note of these and draws them once the main building has finished

This is just one approach, other data formats are available and the code is not particularly fast.

If you're wondering how the CSV files are created, have a look at the readblocks.py code. You should be able to create a file that contains your current castle and save that to a CSV file that drawcsv2 can use.
On the older Pi models you can see more easily how the code works as it is relatively slow, Pi2 and 3 will build much quicker.

I'd recommend looking at :http://www.stuffaboutcode.com/p/minecraft.html for some great Pi, Python and Minecraft examples and ideas.

Joe

curlyc
Posts: 15
Joined: Wed Feb 01, 2017 4:30 am

Re: 20,000 lines of wasted time

Wed Feb 01, 2017 6:28 pm

that is exactly the responce i was hoping for, rather than just a few lines ofcode, a way for me to figure that out on myown



and to the mods, i didnt use any profanity so what the $%^&$#@ did you remove?

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: 20,000 lines of wasted time

Wed Feb 01, 2017 6:48 pm

Good luck! Do come back with any more questions if you get stuck again.

As for the edit by the mods, I've sent you a private message.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
RST8
Posts: 64
Joined: Tue Nov 25, 2014 1:57 pm

Re: 20,000 lines of wasted time

Thu Feb 02, 2017 11:03 am

Unfortunately my code was written back in the days when Minecraft Pi only supported Python 2.7 and it's not happy under 3.0, so I'll update at some point. Thanks to CurlyC for finding that.

Joe

Return to “Python”