-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Top down development of high-level API #30
Comments
I'm not convinced about the indexing syntax yet. This just covers a small part of the API. What happens if you call How do you get the height of a specific place? Furthermore, Last but not least, this will lead to a lot of hacks in the codebase. I'm more for a function or method based approach. |
I'd really like to avoid an explicit connection to the world. I believe this should be handled by the instantiation of a |
I disagree about that. That's global connection state. It makes testing harder, creates side effects and makes it hard or impossible to control multiple minecraft instances at once. A lot of projects (e.g. Django or Celery) moved from implicit initialization to explicit initialization (with a very simple default) in the last 1-2 years. |
Surely that's nothing global, that's a connection per |
Aaah, sorry, I didn't get that :) In that case it would be:
Right? |
@dbrgn – Yes that's the API I was going for, sorry I should have added an example to be specific. |
You wrote
Did you follow the link I gave to
The answer is YES. |
Sorry, I overlooked that :) In that case: How would you get the height of a specific x-z coordinate in the world? You can't attach any methods to the indexed world call, as it returns an enum type (which is an integer). |
from minecraft import Minecraft
world = Minecraft()
# you're connected! 👍 |
@dbrgn asked
A really good API is one where the answer to this question is obvious, from the basic examples given in my sample file smoke.py. A good API is one where the answer is obviously the only correct one, once you have seen it. I'm leaving your question as an exercise. I'll tell you what my answer is this evening. You'll appreciate my answer better if you try to answer the question yourself. (There, I sound like a teacher.) |
It is definitely not obvious. You could go with You could go with something like The return value is also non-obvious. It could return either the height as an integer, or - if you consider the syntax a slice - a sequence of blocks that matches the coordinates (in the case of |
@dbrgn |
You do sound like a teacher. And it makes it hard to provide good feedback. |
We have You were trying to use the One last thing - h = world.height[pos] |
While I like the concept that the world is indexable (treating it as a 3D array), i'm not too fond of having A few thoughts (not all of them well thought-out):
from minecraft import Minecraft
mc = Minecraft()
some_position = mc.world[1, 2, 3]
print(some_position.height)
print(some_position.type)
print(some_position.hits) That would be the OOP style approach. I'm not completely sure yet whether it's better than a functional approach though.
from minecraft import BlockGroup, BlockType
# Positions could be indicated by tuples
group = BlockGroup((1, 2, 3), (4, 5, 6), (7, 8, 9))
group.type = BlockType.WOOD
# Or maybe by a separate type? We had a discussion about this in a separate issue.
group = BlockGroup(Position(1, 2, 3), Position(4, 5, 6), Position(7, 8, 9))
# A group could act like a set. That would allow things like intersections or differences.
group.add((1, 3, 5))
# We could define different operations
group.destroy() # Remove blocks (replace with air)
group.translate(0, 3, 0) # Move up by three blocks |
We could treat BlockGroups as iterators:
Does the low-level API allow us to issue commands affecting more than one |
There is a |
OK, then it definitely makes sense to allow some whole-group operations in the high-level API (though I think we could usefully make them iterable, too). |
That would be trivial by implementing |
Absolutely! I'm just saying that we should do so :-) On Thu, Oct 2, 2014 at 9:25 PM, Danilo Bargen [email protected]
|
I've started exploring the design of the high-level API. My basic idea it to write user code that feels right, and then to provide a stub implementation.
For example, here's how to get going
You can see the whole user sample user file at smoke.py
To reduce distractions while I work I'm doing this in a fork of the main repository, but in my own github account.
I welcome comments, and if it helps to do this you can create a pull request.
The text was updated successfully, but these errors were encountered: