Giter VIP home page Giter VIP logo

minecraft's Introduction

pyCraftr

pyCraftr

Simple Minecraft-inspired demo written in Python and Pyglet.

http://www.youtube.com/watch?v=kC3lwK631X8

How to Run

pip install pyglet
git clone [email protected]:boskee/Minecraft
cd Minecraft
python main.py

You may also need to install AVBin library (http://avbin.github.com/AVbin/Download.html), especially if you are on Linux machine. If you have Windows or Linux operating system, you will also need to install OpenAL library (http://connect.creativelabs.com/openal/default.aspx).

Mac

On Mac OS X, you may have an issue with running Pyglet in 64-bit mode. Try running Python in 32-bit mode first:

arch -i386 python main.py

If that doesn't work, set Python to run in 32-bit mode by default:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

This assumes you are using the OS X default Python. Works on Lion 10.7 with the default Python 2.7, and may work on other versions too. Please raise an issue if not.

Or try Pyglet 1.2 alpha, which supports 64-bit mode:

pip install https://pyglet.googlecode.com/files/pyglet-1.2alpha1.tar.gz

If you don't have pip or git

Windows Pyglet builds

See this website, and download the correct version for the OS.
This is important to get this, as how it will have AVBin included with it.

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyglet
    For a 32 bit Windows Os, get the file named "pyglet-1.2alpha1.win32-py2.7.‌exe"
    For a 64 bit Windows Os, get the file named "pyglet-1.2alpha1.win-amd64-py2.7.‌exe"

For pip:

  • Mac or Linux: install with sudo easy_install pip (Mac or Linux) or (Linux) find a package called something like 'python-pip' in your package manager.
  • Ubuntu: install with sudo apt-get install python-pip
  • Windows: install Distribute then Pip using the linked .MSI installers.

For git:

  • Mac: install Homebrew first, then brew install git.
  • Windows or Linux: see Installing Git from the Pro Git book.

See the wiki for this project to install Python, and other tips.

How to Play

Moving

  • W: forward
  • S: back
  • A: strafe left
  • D: strafe right
  • Mouse: look around
  • Space: jump / (in flying mode) fly
  • Shift: (in flying mode) fly down
  • Tab: toggle flying mode

Building

  • 1 - 9: Selecting item in inventory
  • Mouse left-click: remove block
  • Mouse right-click: create block

GUI

  • B / F3: Toggle UI
  • E: Show inventory
  • V: Saving (save filename in command-line arguments)
  • ENTER: Move selected item to inventory / quick slots
  • Mouse left-click (in inventory): Pick up item and after second click put off last item
  • Mouse right-click when not focused on block: Eat item

Quitting

  • ESC / Q: release mouse, then close window

Better performance using Cython

For optimal performance, you can compile the code to C using Cython.

pip install cython
python setup.py build_ext --inplace

This will generate .pyd files, which Python will prefer to load instead of your .py files, so you will need to rebuild or delete the .pyd each time you make changes.

setup.py will also compile Pyglet using Cython, if you download the pyglet source code and put the pyglet folder inside the game repository.

Building Windows Executables

pip install cython cx_Freeze
python setup.py build

This builds Cython-optimized .pyd's, and bundles together all libraries including Python itself, into build/exe.win-amd64-3.7/

minecraft's People

Contributors

alexjmu avatar bertrandbordage avatar blainmaguire avatar boskee avatar embatbr avatar emportella avatar fogleman avatar geppettodivacin avatar ggaughan avatar jimx- avatar nebual avatar progval avatar richvel avatar ronmurphy avatar silent1mezzo avatar swiftcoder avatar tfaris avatar ubershmekel avatar zg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minecraft's Issues

Use a transactional memory and computing server

This is IMHO an extremely important feature, even though it can be postponed a bit.

The problems:

  1. Saves are huge (30 Mo for a 200² map!).
  2. Saving and restoring data is awfully long.
  3. The same process handles terrain generation, game logic and rendering
  4. The 3 previous points are ruining performance
  5. We will one day need to build a server

How the original Minecraft solved these problems:

  1. Only revelent data are saved; in our game we save nearly everything, including caches and textures (which leads to incompatibilities when the code is updated).
  2. Because of 1., they don't know this problem; if we do, it's because pickling (what we currently do when we save) is an extremely complex calculus.
  3. This was never really solved, that's why chunk updates are sometimes extremely slow (you know, when there are holes everywhere), even on the best computer of the world.
  4. Visual rendering has the priority, chunks are updated only when the CPU has the time to do it. Nowadays, rendering is smooth, but it wasn't a year ago because of this problem (if I remember well).
  5. I don't know how exactly they solved this. But the fact that it was impossible until recent days to play a network game without starting a standalone server tends to prove that they basically had to write the terrain generation and game logic twice: one time for the game, one time for the server.

The definitive solution to these problems is to separate this game in two parts: the pyglet part (rendering, handling key events, etc) and the rest.

So, we will have one process dedicaced to rendering, and one or several processes dedicaced to the complex world calculus (like terrain generation, physics, IA, etc). The rendering process will do requests to the memory and computing server to know, for example, which sectors to display considering the current player position, etc. All these processes starting automatically using python main.py.

Consequences:

  1. Excellent game stability.
  2. Possibility to make very complex systems, such as the basic physic engine that always lacked in the original Minecraft. Considering that most gaming machine now have at least 4 cores, 2-3 processes dedicaced to complex tasks sounds reasonable to me.
  3. Easy way to communicate with the game, which means that it will be easy to make a multiplayer game out of it.

How to achieve this? As a web developper, I immediately think that I should do a web server coupled with an asynchronous task queue. For example, using Flask and Celery. This may seem inappropriate, and it is maybe too heavy or slow to work. I don't know what data storage we should use, but even SQLite would be faster than pickling everything.

I also read on Wikipedia that Durus was done for such purposes.

What do you think? Totally nuts?

No Module named PIL

Running OS/X 10.8.5

Franks-MacBook-Pro:Minecraft frankkelly$ python --version
Python 2.7.2

The fogleman original branch works fine on my Mac so not sure what I am missing

Franks-MacBook-Pro:Minecraft frankkelly$ arch -i386 python main.py
Traceback (most recent call last):
  File "main.py", line 22, in <module>
    from controllers import MainMenuController
  File "/usr/local/coderdojo/python/pycraftr/Minecraft/controllers.py", line 21, in <module>
    from blocks import *
  File "/usr/local/coderdojo/python/pycraftr/Minecraft/blocks.py", line 24, in <module>
    from textures import TexturePackList
  File "/usr/local/coderdojo/python/pycraftr/Minecraft/textures.py", line 6, in <module>
    from PIL import Image
ImportError: No module named PIL

Also not sure what PIL is but I think I successfully installed it too (just in case)

Franks-MacBook-Pro:Minecraft frankkelly$ sudo easy_install PIL
Password:
Searching for PIL
Best match: PIL 1.1.7
Processing PIL-1.1.7-py2.7-macosx-10.8-intel.egg
PIL 1.1.7 is already the active version in easy-install.pth
Installing pilconvert.py script to /usr/local/bin
Installing pildriver.py script to /usr/local/bin
Installing pilfile.py script to /usr/local/bin
Installing pilfont.py script to /usr/local/bin
Installing pilprint.py script to /usr/local/bin

Using /Library/Python/2.7/site-packages/PIL-1.1.7-py2.7-macosx-10.8-intel.egg
Processing dependencies for PIL
Finished processing dependencies for PIL

Cannot install.

progval@Andromede:~/src/pyCraftr$ python setup.py install --user
running install
running build
running build_ext
cythoning world.py to world.c

Error compiling Cython file:
------------------------------------------------------------
...
    @cython.locals(block=object)
    cpdef object show_block(self, tuple position, bint immediate=?)

    @cython.locals(x=float, y=float, z=float,
                   index=int, count=int,
                   vertex_data=cython.list, texture_data=cython.list,
                                                              ^
------------------------------------------------------------

world.pxd:68:63: Not a type

Error compiling Cython file:
------------------------------------------------------------
...
    @cython.locals(block=object)
    cpdef object show_block(self, tuple position, bint immediate=?)

    @cython.locals(x=float, y=float, z=float,
                   index=int, count=int,
                   vertex_data=cython.list, texture_data=cython.list,
                                    ^
------------------------------------------------------------

world.pxd:68:37: Not a type
building 'world' extension
creating build
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c world.c -o build/temp.linux-x86_64-2.7/world.o
world.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.
error: command 'gcc' failed with exit status 1

World saves/reload

Even on newly generated worlds, I can't load in world saves:

File "ctypes/callbacks.c", line 314, in 'calling callback function'
File "build\bdist.win32\egg\pyglet\window\win32__init
_.py", line 849, in _wnd_proc

File "build\bdist.win32\egg\pyglet\window\win32__init__.py", line 1027, in _event_lbuttondown

File "build\bdist.win32\egg\pyglet\window\win32__init__.py", line 1021, in _event_mousebutton

File "build\bdist.win32\egg\pyglet\window__init__.py", line 1219, in dispatch_event

File "build\bdist.win32\egg\pyglet\event.py", line 343, in dispatch_event
File "build\bdist.win32\egg\pyglet\event.py", line 370, in raise_dispatch_exception
File "C:\Python27\lib\inspect.py", line 815, in getargspec
raise TypeError('{!r} is not a Python function'.format(func))
TypeError: <cyfunction MainMenuController.on_mouse_press at 0x055453F8> is not a Python function
Traceback (most recent call last):
File "F:\src\github\tfaris\Minecraft\main.py", line 220, in
main(options)
File "F:\src\github\tfaris\Minecraft\main.py", line 179, in main
pyglet.app.run()
File "build\bdist.win32\egg\pyglet\app__init
_.py", line 264, in run

File "build\bdist.win32\egg\pyglet\app\win32.py", line 74, in run
File "build\bdist.win32\egg\pyglet\app\win32.py", line 84, in timer_func
File "build\bdist.win32\egg\pyglet\app__init
_.py", line 187, in idle

File "build\bdist.win32\egg\pyglet\clock.py", line 700, in tick
File "build\bdist.win32\egg\pyglet\clock.py", line 303, in tick
File "F:\src\github\tfaris\Minecraft\main.py", line 80, in update
self.controller.update(dt)
File "controllers.py", line 122, in controllers.GameController.update (controllers.c:4085)
sector = sectorize(self.player.position)
AttributeError: 'GameController' object has no attribute 'player'

Anyone else? I'm on 3dd1b49

failure if PYGLET_SHADOW_WINDOW=0 in effect

Windows:

set PYGLET_SHADOW_WINDOW=0
python main.py

Linux:

export PYGLET_SHADOW_WINDOW=0
./main.py

Both fails with an unmodified PyGLet on Windows and Linux, but AFAICS it shouldn't, because pyCraft uses some feature without initializing it in that case.

Longer story:

When trying to run pyCraft under Windows/7 64 Bit I get following error:

pyglet.gl.ContextException: Unable to share contexts

Apparently my embedded ATI Radeon HD 4200 has some GL issues, as usual. For this there is a workaround in PyGLet: Set the environment variable PYGLET_SHADOW_WINDOW=0

So this error vanishes by using

set PYGLET_SHADOW_WINDOW=0
python main.py

It then fails with

  File "C:\python27.addon\Minecraft\blocks.py", line 62, in __init__
..
  File "C:\Python27\lib\site-packages\pyglet\image\__init__.py", line 930, in blit_to_texture
    if gl.current_context._workaround_unpack_row_length:
AttributeError: 'NoneType' object has no attribute '_workaround_unpack_row_length'

Apparently PyGLet is not prepared for this case if gl.current_context has not been initialized by the app. Changing the line into

 if gl.current_context and gl.current_context._workaround_unpack_row_length:

allows for a graceful workaround.

Then you get following warning:

C:\Python27\lib\site-packages\pyglet\gl\gl_info.py:125: UserWarning: No GL context created yet.

But pyCraft now starts up, somehow.

However all textures and buttons are missing (see screenshots below), so the world looks weird. Apparently Minecraft needs the shadow window somehow for textures, but I really have no idea how to fix that.

Any idea?

Note that I think it is a Minecraft bug, because it forgets to initialize gl.current_context if PygLet does not initialize it itself (as told by the environment variable which, according to googled results, usually should not have bad sideeffects). So the bug seems to be right before init of blocks.py. However I am not sure as I do not understand GL.

FYI: As PIL cannot be installed without some crude registry hacks under 64 bit Windows' Python, I tried it with Pillow. Same result.

Pillow can be installed into Windows Python2.7 64 bit easily (after easy_install has been added to Python) with something like:

\Python27\Scripts\easy_install.exe Pillow

pycraft1

pycraft2

Numpy?

Can I use numpy to improve performances and terrain generation posibilities?
This adds a dependency, but I'm sure we will have to do it one day or another.

I broke a flower and then tried to place it back

Exception happened during processing of request from ('192.168.0.226', 55775)
Traceback (most recent call last):
File "C:\Users\mayda\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\mayda\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\mayda\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 720, in init
self.handle()
File "server.py", line 55, in handle
self.loop()
File "server.py", line 100, in loop
world.remove_block(struct.unpack("iii", positionbytes), sync=False)
File "C:\Users\mayda\Desktop\Coding Class\Minecraft\world_server.py", line 96, in remove_block
del self[position]
File "C:\Users\mayda\Desktop\Coding Class\Minecraft\world_server.py", line 61, in delitem
super(WorldServer, self).delitem(position)
KeyError: (79, 62, 232)

Disconnected from server even before the first packet was sent

Starting internal server...
2019-06-10 12:51:09 [MainThread] [INFO] Mod loader has identified 1 mods to load
No seed set, generated random seed: 176701563921720149104828281598416444896
Server loop running in thread: Thread-1
Listening on 192.168.56.1 1486
Client PacketReceiver: We've been disconnected by the server
Game mode: creative
2019-06-10 12:51:17 [MainThread] [INFO] Average FPS: 593.075906

Process finished with exit code -1(manual stop in pycharm)

Started with singleplayer. I have changed the code to start the server on Singleplayer, similar to Nebual 's singleplayer server subprocess branch.
Here's the code:
utils.py:

cmd = None

def runserver():
    global cmd
    def run():
        global cmd
        with Popen([sys.executable, 'server.py']) as process:
            while True:
                if cmd == "stop":
                    process.stdin.write('stop')
                    process.stdin.flush()
                    return
                elif 'say' in cmd:
                    process.stdin.write(cmd)
                    process.stdin.flush()
                else:
                    continue
    threading.Thread(target=run).start()

controllers.py:

    def setup(self):
        if G.SINGLEPLAYER:
            try:
                print('Starting internal server...')
                # TODO: create world menu
                G.SAVE_FILENAME = "world"
                try:
                    utils.runserver()
                except:
                    print("Cannot run server with utils.runserver(), starting server with start_server(internal=True)")
                    start_server(internal=True)
                time.sleep(3)
                sock = socket.socket()
                sock.connect((socket.gethostbyname(socket.gethostname()), 1486))
            except socket.error as e:
                print("Socket Error:", e)
                # Otherwise back to the main menu we go
                return False
            except Exception as e:
                print('Unable to start internal server')
                import traceback
                traceback.print_exc()
                return False
        else:
            try:
                # Make sure the address they want to connect to works
                ipport = G.IP_ADDRESS.split(":")
                if len(ipport) == 1: ipport.append(1486)
                sock = socket.socket()
                sock.connect((tuple(ipport)))
            except socket.error as e:
                print("Socket Error:", e)
                # Otherwise back to the main menu we go
                return False

        self.init_gl()

        sky_rotation = -20.0  # -20.0

       # TERRAIN_CHOICE = self.biome_generator.get_biome_type(sector[0], sector[2])
        default_skybox = 'skydome.jpg'
        #if TERRAIN_CHOICE == G.NETHER:
        #    default_skybox = 'skydome_nether.jpg'
        #else:
        #    default_skybox = 'skybox.jpg'


        self.skydome = Skydome(
            G.RESOURCES + default_skybox,
            #'resources/skydome.jpg',
            0.7,
            100.0,
            sky_rotation,
        )

        self.player_ids = {}  # Dict of all players this session, indexes are their ID's [0: first Player on server,]

        self.focus_block = Block(width=1.05, height=1.05)
        self.earth = vec(0.8, 0.8, 0.8, 1.0)
        self.white = vec(1.0, 1.0, 1.0, 1.0)
        self.ambient = vec(1.0, 1.0, 1.0, 1.0)
        self.polished = GLfloat(100.0)
        self.crack_batch = pyglet.graphics.Batch()

        #if G.DISABLE_SAVE and world_exists(G.game_dir, G.SAVE_FILENAME):
        #    open_world(self, G.game_dir, G.SAVE_FILENAME)

        self.world = World()
        self.packetreceiver = PacketReceiver(self.world, self, sock)
        self.world.packetreceiver = self.packetreceiver
        G.CLIENT = self.packetreceiver
        self.packetreceiver.start()

        #Get our position from the server
        self.packetreceiver.request_spawnpos()
        #Since we don't know it yet, lets disable self.update, or we'll load the wrong chunks and fall
        self.update_disabled = self.update
        self.update = lambda dt: None
        #We'll re-enable it when the server tells us where we should be

        self.player = Player(game_mode=G.GAME_MODE)
        print(('Game mode: ' + self.player.game_mode))
        self.item_list = ItemSelector(self, self.player, self.world)
        self.inventory_list = InventorySelector(self, self.player, self.world)
        self.item_list.on_resize(self.window.width, self.window.height)
        self.inventory_list.on_resize(self.window.width, self.window.height)
        self.text_input = TextWidget(self.window, '',
                                     0, 0,
                                     self.window.width,
                                     visible=False,
                                     font_name=G.CHAT_FONT)
        self.text_input.push_handlers(on_toggled=self.on_text_input_toggled, key_released=self.text_input_callback)
        self.chat_box = TextWidget(self.window, '',
                                   0, self.text_input.y + self.text_input.height + 50,
                                   self.window.width // 2, height=min(300, self.window.height // 3),
                                   visible=False, multi_line=True, readonly=True,
                                   font_name=G.CHAT_FONT,
                                   text_color=(255, 255, 255, 255),
                                   background_color=(0, 0, 0, 100),
                                   enable_escape=True)
        self.camera = Camera3D(target=self.player)

        if G.HUD_ENABLED:
            self.label = pyglet.text.Label(
                '', font_name='Arial', font_size=8, x=10, y=self.window.height - 10,
                anchor_x='left', anchor_y='top', color=(255, 255, 255, 255))

        #if G.DEBUG_TEXT_ENABLED:
        #    self.debug_text = TextWidget(self.window, '',
        #                           0, self.window.height - 300,
        #                           500, 300,
        #                           visible=True, multi_line=True, readonly=True,
        #                           font_name='Arial', font_size=10,
        #                           text_color=(255, 255, 255, 255),
        #                           background_color=(0, 0, 0, 0))
        pyglet.clock.schedule_interval_soft(self.world.process_queue,
                                            1.0 / G.MAX_FPS)
        pyglet.clock.schedule_interval_soft(self.world.hide_sectors, 10.0, self.player)
        return True

G.RESOURCES was part of another change which allowed me to set the location of the resources folder. Currently that is set to pyglet.resource.get_settings_path("pyCraft") + "\\resources\\".
By the way, I didn't get any tracebacks.

Segmentation fault

An unknown error occurs each time I break and place dandelions several successive times.

This is not due to Cython, since it also occurs when .so files are removed.

Saving the World

Forking off the points in #40.
I want to write a better format for saving blocks.

Currently because no block really needs any form of memory (Doors, Chests, signs), we could get away with storing 3 int(16) for position, and then an uint(8) for id, with another uint(8) for the part after the decimal for wood. But how long will that be all the info that needs to be saved?
Mojang uses a uint(4) called "damage" across a great number of blocks, which is a pretty efficient (if somewhat confusing) approach. Using space after the decimal in .id makes sense in python for subtypes (like wood or sign rotation), but it makes saving a hassle if we have to worry about ensuring the decimal part remains precise (since floats can lose precision, but a separate int doesn't)

Design decisions:
Question 1: Do we store position for every block, or only for sectors?
Assuming sector size of 8x8x8 (512 blocks)
Option 1) Every block has a position.
a. Sector is full of dirt: (16+16+16 position) + (8 id + 4 damage) = 60 bits * 512 = 30720 bits = 3840 bytes
b. If only half the sector has blocks (say, on the surface, and the top half is air): 60 * 256 = 15360 bits = 1920 bytes.

Option 2) Every sector has a position, and then all 512 blocks in a sector are stored.
a. Full of dirt: (0 position) + (8 id + 4 damage) = 12 bits * 512 = 6144 bits = 768 bytes.
b. Half full of dirt: 12 * 512 = 6144 = 768 bytes. Theres no space advantage to emptyness here.

Assuming theres 12 bits of unique data for each block, 2 is the more efficient approach assuming at least 20% of a sector isn't air, (because 768/3840 = 0.2)
If theres more info for each block (say, also a dataid attribute that points to a second table containing varchars, so they can have data of any length, for say Books), the ratio gets worse, but 2) still sounds like the only option.

Question 2: Do we store in separate files like Mojang's regions?
Pros: Less chance of the whole world being corrupted if save is interrupted, Less memory
Cons: perf? I'm not sure how various OS's prefer accessing hundreds of small files or dozens of larger or 1 single.
Either way, we'll only load nearby sectors, but if theres only one file that we're seeking through it means we'll have a table of contents near the beginning saying the offset of where each sector is, as opposed to just looking at filenames for multifile.

Point 3: We need to store as little information as possible about every block, and have ways to store additional data about specific blocks where needed. Perhaps we could keep the main sector storage with just that 12bit approach (uint(8) for id, uint(4) for damage/subid), and have an additional storage file for overflow data organized with positions, like Question 1: Option 1.

Could discuss this in irc://irc.gamesurge.net/Pycrafter or whatever we're calling ourselves now.

MemoryError

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\graphics\vertexdomain.py", line 249, in _safe_alloc
return self.allocator.alloc(count)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\graphics\allocation.py", line 195, in alloc
raise AllocatorMemoryException(self.capacity + size - free_size)
pyglet.graphics.allocation.AllocatorMemoryException: 2097168

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/toshi/MicroHat/applications/games/factories/astrocraft-renovation/main.py", line 167, in
main(options)
File "C:/Users/toshi/MicroHat/applications/games/factories/astrocraft-renovation/main.py", line 139, in main
pyglet.app.run()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\app_init_.py", line 138, in run
event_loop.run()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\app\base.py", line 142, in run
self._run()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\app\base.py", line 154, in _run
timeout = self.idle()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\app\base.py", line 275, in idle
redraw_all = self.clock.call_scheduled_functions(dt)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\clock.py", line 346, in call_scheduled_functions
item.func(now - item.last_ts, *item.args, **item.kwargs)
File "C:\Users\toshi\MicroHat\applications\games\factories\astrocraft-renovation\world.py", line 310, in process_queue
self.packetreceiver.dequeue_packet()
File "C:\Users\toshi\MicroHat\applications\games\factories\astrocraft-renovation\client.py", line 104, in dequeue_packet
blocks.show_block(position)
File "C:\Users\toshi\MicroHat\applications\games\factories\astrocraft-renovation\world.py", line 201, in show_block
self._show_block(position, block)
File "C:\Users\toshi\MicroHat\applications\games\factories\astrocraft-renovation\world.py", line 234, in show_block
('c3f/static', color_data))
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\graphics_init
.py", line 370, in add
vlist = domain.create(count)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\graphics\vertexdomain.py", line 279, in create
start = self._safe_alloc(count)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\graphics\vertexdomain.py", line 254, in _safe_alloc
buffer.resize(capacity * buffer.element_size)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyglet\graphics\vertexbuffer.py", line 431, in resize
data = (ctypes.c_byte * size)()
MemoryError

cant download zip

hey bro I cant download the zip file of this please tell is there any other way of it it is not showing me the file I want or you have created it just show me the texture not the full code you have written or have made also not give any main.py

Restore rasterized textures

I don't understand how we lost rasterized textures.
I know this effect is obtained using:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

but I don't understand why it worked before and why it has no effect today. I guess this is due to a structure modification, but didn't found which.

Markdown or reStructuredText?

Today we have 3 markdown files in the repository.
Originally, there was only the README.md written by @fogleman.

Though Markdown is excellent, simple and widely used, I prefer using reStructuredText.
It has some defaults that Markdown has not (for example double ` for variables), but it is more complete, written for Python and it is the language of the Sphinx documentation generator.

What do you prefer?

Installation matters

Not a critical issue, but it's a tiny effort that stops the distribution of this project.

Currently, using pyCraftr is easy for geeks. Install pyglet, clone the repository and that's all.

For other people, it's not that easy. This requires to know how to:

  • install dependencies
  • use command-line
  • use git to update the game

Maybe 30 % of Linux users know how to use it. And something like 0.05 % of Mac and Windows users do.

People both need:

  • that dependencies and pyCraftr download/install in a single step
  • a launcher with an icon
  • an easy way to update the game

What goals we could achieve:

  • have Ubuntu (sorry for other distros), MacOS and Windows installers including dependencies and launcher(s)
  • add the game to the Ubuntu software center (when the project will be stable and less "alpha-like") ; that will be a good ad

What do we need:

  • a name. Now that anybody calls this "pyCraftr", why not choosing this? See #21.
  • version numbers. I suggest http://guide.python-distribute.org/specification.html#sequence-based-scheme
  • an icon
  • a module structure, so that the launcher can find the game installed somewhere in PYTHON_PATH
  • improve setup.py and distribute packages somewhere
  • MacOS and Windows scripts to update the game, probably based on git tags
  • Choose what tools to use to produce packages. Distutils contains a way to build Ubuntu and Windows packages, but this might not be enough.

Terrain generation

There is a "terrain.py" file in the repository. Why?

Besides, we need to discuss on how will terrain generation work. For the moment, the whole map is generated when starting the game. But how will we do to have this kind of two dimensional stream that generates coherent terrain?

ValueError: Can only assign sequence of same size

Output:

019-06-11 14:21:52 [MainThread] [INFO] Mod loader has identified 1 mods to load
Starting internal server...
2019-06-11 14:21:55 [MainThread] [INFO] Mod loader has identified 1 mods to load
No seed set, generated random seed: 308346342251917635352724370416101310883
Server loop running in thread: Thread-1
Listening on 192.168.56.1 1486
Client connecting... ('192.168.56.1', 50289)
Game mode: creative
('192.168.56.1', 50289)'s username is User 859
Traceback (most recent call last):
  File "C:/Users/toshi/MicroHat/applications/games/factories/astrocraft-python/main.py", line 177, in <module>
    start()
  File "C:/Users/toshi/MicroHat/applications/games/factories/astrocraft-python/main.py", line 173, in start
    main(options)
  File "C:/Users/toshi/MicroHat/applications/games/factories/astrocraft-python/main.py", line 142, in main
    pyglet.app.run()
  File "C:\Users\toshi\.virtualenvs\astrocraft-python\lib\site-packages\pyglet\app\__init__.py", line 138, in run
    event_loop.run()
  File "C:\Users\toshi\.virtualenvs\astrocraft-python\lib\site-packages\pyglet\app\base.py", line 142, in run
    self._run()
  File "C:\Users\toshi\.virtualenvs\astrocraft-python\lib\site-packages\pyglet\app\base.py", line 154, in _run
    timeout = self.idle()
  File "C:\Users\toshi\.virtualenvs\astrocraft-python\lib\site-packages\pyglet\app\base.py", line 275, in idle
    redraw_all = self.clock.call_scheduled_functions(dt)
  File "C:\Users\toshi\.virtualenvs\astrocraft-python\lib\site-packages\pyglet\clock.py", line 346, in call_scheduled_functions
    item.func(now - item.last_ts, *item.args, **item.kwargs)
  File "C:\Users\toshi\MicroHat\applications\games\factories\astrocraft-python\world.py", line 307, in process_queue
    self.packetreceiver.dequeue_packet()
  File "C:\Users\toshi\MicroHat\applications\games\factories\astrocraft-python\client.py", line 107, in dequeue_packet
    blocks.show_block(position)
  File "C:\Users\toshi\MicroHat\applications\games\factories\astrocraft-python\world.py", line 198, in show_block
    self._show_block(position, block)
  File "C:\Users\toshi\MicroHat\applications\games\factories\astrocraft-python\world.py", line 235, in _show_block
    ('t2f/static', texture_data))
  File "C:\Users\toshi\.virtualenvs\astrocraft-python\lib\site-packages\pyglet\graphics\__init__.py", line 372, in add
    vlist._set_attribute_data(i, array)
  File "C:\Users\toshi\.virtualenvs\astrocraft-python\lib\site-packages\pyglet\graphics\vertexdomain.py", line 443, in _set_attribute_data
    region.array[:] = data
ValueError: Can only assign sequence of same size
Client User 859 ('192.168.56.1', 50289) crashed.
Client disconnected, ('192.168.56.1', 50289) User 859

Broken collision system

It looks like the collision system is borked, at least in fly mode. I just flew facing down and clicked a block, which pushed me below the surface where I was completely stuck (can't remove blocks, can't move etc).

collision_bug

Improved performance by adding function which calcuates sine from cosine, but I'm not sure if it works good in every circumstances

I improved performance (this commit: https://github.com/avelanarius/Minecraft/commit/2dbee32c6c182d7e4a475378f88fb319b60a6dab) by adding function which calcuates sine from cosine, but I'm not sure if it works good in every circumstances.

It uses following trigonometric identity: sin^2 x + cos^2 x = 1 with condition for negative sine. It should work faster, because sqrt is faster than sin. If you can, please check if it doesn't return inaccurate value in some circumstances. When I'll be sure that my implementation is correct, I'll merge it to boskee / Minecraft.

Import globals as G

@Nebual suggested that we could import globals as G for readabilty purposes. I totally agree. Someone opposed?

Split stacks of blocks

Drag to split a stack of blocks(Such as 6 wood) into the squares the stack is dragged onto if the SPLIT_STACK key has been pressed while dragging.(Better shown than described)

Segmentation Fault on Ubuntu

After the main menu, I get a segmentation fault on Ubuntu. Other times when I do it, I get the following error:

Traceback (most recent call last):
File "main.py", line 159, in <module>
main(options)
File "main.py", line 133, in main
pyglet.app.run()
File "/usr/local/lib/python2.7/dist-packages/pyglet/app/__init__.py", line 264, in run
EventLoop().run()
File "/usr/local/lib/python2.7/dist-packages/pyglet/app/xlib.py", line 82, in run
window.dispatch_platform_event(e)
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/xlib/__init__.py", line 1169, in dispatch_platform_event
event_handler(e)
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/xlib/__init__.py", line 1438, in _event_button
x, y, button, modifiers)
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/__init__.py", line 1219, in dispatch_event
EventDispatcher.dispatch_event(self, *args)
File "/usr/local/lib/python2.7/dist-packages/pyglet/event.py", line 340, in dispatch_event
if handler(*args):
File "/home/travis/Minecraft/views.py", line 56, in on_mouse_press
self.dispatch_event('on_mouse_click', x, y, button, modifiers)
File "/usr/local/lib/python2.7/dist-packages/pyglet/event.py", line 340, in dispatch_event
if handler(*args):
File "/home/travis/Minecraft/gui.py", line 139, in on_mouse_click
self.dispatch_event('on_click')
File "/usr/local/lib/python2.7/dist-packages/pyglet/event.py", line 340, in dispatch_event
if handler(*args):
File "/home/travis/Minecraft/views.py", line 291, in launch_server
localip = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][0]
IndexError: list index out of range
AL lib: ReleaseALC: 1 device not closed

Documentation - Confusion on install

Hi there, I decided to try out this fork of the project, but found the docs on how to make it install somehow very confusing and incomplete.

If someone could help me out, I can try to make it more clear for others what has to be done "step-by-step" in order to help contribute to this project =).

Some questions, considering an Ubuntu machine:

  • what exectly are the system packages required
  • What is the required version of pyglet (from pip)?
  • after installing the SO packages what is the next step for running the client (Single Player mode)?
  • after installing the SO packages what is the next step for running the server (and the client in Multi Player Mode)?
  • is it strictly necessary to use Cython or is it optional?
  • What is the required version of Cython?

Thanks for the attention =)

Sector loading problem

@Nebual I notice that when I start game and connect to a server, the sector_packet stays 0 for about 20~30 seconds and after such a long time, it increases rapidly to 1000+ and the world is loaded in few seconds. I've tried it on several computers but the same problem happened. change_sectors is called as soon as the game connect to the server and begin to request sectors. So is this a server-side problem or something else?

Cython?

After doing some experiments using numpy (see #30), I managed to save some execution time.
Now I made some experiments using Cython. And some sensible functions are executed more than 10 times faster. I therefore wonder whether we should use Cython (that mixes beautifully with numpy).

If we make an advanced terrain generator like in the original game, I bet that we will quickly see the limits of Python. And unfortunately, pyglet is not thread-safe, so it may be impossible to do parallel computations.

And of course, the main problem with Cython is that we have to compile (beautiful) code.

'ImageData' object has no attribute 'texture'

Hi. I am currently running Windows 10 with Python 3.8.1 and I'm getting an error. Here's my logs:

2020-03-04 17:35:42 [MainThread] [INFO] Starting pyCraft...
2020-03-04 17:35:42 [MainThread] [INFO] Mod loader has identified 0 mods to load
Traceback (most recent call last):
File "main.py", line 165, in
main(options)
File "main.py", line 135, in main
pyglet.app.run()
File "C:\Users\mnqge\AppData\Local\Programs\Python\Python38\lib\site-packages\pyglet\app_init_.py", line 144, in run
event_loop.run()
File "C:\Users\mnqge\AppData\Local\Programs\Python\Python38\lib\site-packages\pyglet\app\base.py", line 175, in run
self._run()
File "C:\Users\mnqge\AppData\Local\Programs\Python\Python38\lib\site-packages\pyglet\app\base.py", line 187, in run
timeout = self.idle()
File "C:\Users\mnqge\AppData\Local\Programs\Python\Python38\lib\site-packages\pyglet\app\base.py", line 314, in idle
window.dispatch_event('on_draw')
File "C:\Users\mnqge\AppData\Local\Programs\Python\Python38\lib\site-packages\pyglet\window_init
.py", line 1330, in dispatch_event
if EventDispatcher.dispatch_event(self, *args) != False:
File "C:\Users\mnqge\AppData\Local\Programs\Python\Python38\lib\site-packages\pyglet\event.py", line 416, in dispatch_event
if handler(*args):
File "F:\views.py", line 437, in on_draw
self.draw_panorama()
File "F:\views.py", line 327, in draw_panorama
glBindTexture(self.panorama[i].texture.target, self.panorama[i].texture.id)
AttributeError: 'ImageData' object has no attribute 'texture'

I tried this on another computer and got the same error. Any ideas on what it could be?

I appreciate any help.

Edit: I do realize this is an older project, and may not work with the newest versions of Python.

problem running setup.py

Running setup.py to try to get into this wonderful project, I get:

Warning (from warnings module):
File "C:\Python\Python36\lib\site-packages\distutils\dist.py", line 261
warnings.warn(msg)
UserWarning: Unknown distribution option: 'executables'

Synchronise celestial bodies

In multiplayer the suns position can very wildly between clients. Preferably the day and night cycle should be the same for all players.

Sky artwork is stolen

The sly artwork is in resources/ is stolen from CGSkies, where it is proprietary and sold for USD $30.

It has illegaly been relicensed under the MIT license, at least according to the information stated in this repository.

Please remove it, maybe even asking GitHub to rewrite the history of the repository to get it removed from all commits.

Change GL_QUADS to GL_TRIANGLES

We should render blocks using GL_TRIANGLES instead of GL_QUADS, because:

  1. With GL_TRIANGLES we will be able to render flowers, potatoes, carrots etc. correctly (their textures should be drawn diagonally inside the block)
  2. GL_QUADS is deprecated in OpenGL 3

Communication: IRC?

I think it would help the direction of the project to have a faster, less formal discussion venue, in addition to formal Issues.

It was suggested in a few commit comments previously; how about IRC?
irc://irc.gamesurge.net/pyCraftr

Or if you lack a client, Mibbit or wsirc

Project name

I would like everyone involved to propose a name for this project. Obviously it can't be called Minecraft because of trademarks and stuff.

Right now it's "pyCraftr" (as defined with APP_NAME in main.py). I'm not sure where this name came from , but I think it's important, that things like this should be agreed among all of us.

So, what should we call this project?

Personally, I don't have a problem with "pyCraftr" (well, maybe apart from the extra r at the end.

I think it's a good idea to keep the "py" prefix so that it's obvious that it's a project written in Python. I don't think we should have "Minecraft" in project name, but Craft, Mine, Mining etc. is all good.

Anyway, what do you guys think?

Splitting into Client/Server

I am attempting to split what pyCraftr so far is into a networked game with a Client/Server relationship.

The vision is to have a dedicated Server process that handles terrain generation, loading, and saving the world.
The Client process handles rendering, UI's/controls, and nearly everything to do with the Player object itself (its own movement, view, etc)

If the client wants to modify the world, it tells the server (and probably does the modification immediately locally so it feels less laggy). If the client's player moves, it tells the server its new position (which then relays that info to everyone else).

To do this, I have split world.py into a client portion and serverworld.py. The client world.py's functions will mostly be like

def add_block(self, args...):
    self.packetreceiver.send("please add the following block to the world: "+args)
def remove_block(self, args...):
    self.packetreceiver.send("please remove the following block to the world: "+args)
def show_sector(self, sector):
    self.packetreceiver.send("\1"+struct.pack("iii",*sector))

While the serverworld.py's versions of those functions will be basically whats in world.py now.

I know Bertrand and Ronmurphy are fairly busy this coming week so this might not even affect anyone, but I request an edit lock on world.py and server.py until what I have is stable enough to push.

Player ins't a Player object in save_player method

This seems to be a bit of a problem, I'm running the server and the client, and right at the server start it crashes because it tries to save a player accessing it's position and momentum to the SQLite DB, but what you have as a player in this method is not a Player instance but the ThreadedTCPRequestHandler.

I don't know what is the best approach for a game development, but if it were to make it easier to work with the player in server side, then I believe it would be a nice idea to "convert" the ThrededTCPRequestHandler to a Player object then convert it back when the server finished doing whatever it needed. Or maybe just adding a Player instance as an attribute to the ThededTCPRequestHandler.

What do you guys think?

World generation speedup??

The game runs crazily slow using Python. Maybe use a different thread for world generation??(use threading module and start a thread)

Issue with removing blocks

The server throws a KeyError when I try to break a block.
Trace back:
Exception happened during processing of request from ('127.0.0.1', 50289)
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 596, in process_request_thread
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 331, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 652, in init
self.handle()
File "C:\Users\tript\Downloads\Minecraft-master\Minecraft-master\server.py", line 59, in handle
self.loop()
File "C:\Users\tript\Downloads\Minecraft-master\Minecraft-master\server.py", line 104, in loop
world.remove_block(struct.unpack("iii", positionbytes), sync=False)
File "C:\Users\tript\Downloads\Minecraft-master\Minecraft-master\world_server.py", line 96, in remove_block
del self[position]
File "C:\Users\tript\Downloads\Minecraft-master\Minecraft-master\world_server.py", line 61, in delitem
super(WorldServer, self).delitem(position)
KeyError: (-2, 39, 15)

User-settable parameters proposals

The goal of this proposal is to have more consistent settings. Settings that we change once and for all should be in game.cfg. Settings more likely to be changed should be changed in the menu, and for the moment using command-line parameters.

Proposals for game.cfg:

  • Use key names instead of key codes for keyboard bindings.
  • Use explicit booleans true|false instead of 1|0 (for flat & max_fog).
  • Remove type, hill_height, flat, & max_trees.
  • Add a system to automatically migrate this file.

Proposals for the command-line parameters:

  • Replace every -something with --something.
  • gamemode should be choices instead of integer.
  • gamemode -> game-mode, like save-mode.
  • Remove hide-fog, hillheight, worldsize, & maxtrees.
  • Move width, height, show-gui, draw-distance, fullscreen, save-mode & motion-blur to game.cfg.

Let's work on this project again!

This project has been left here alone for a long time...and obviously that there are more things that we can add to our game to make it fun...so let's start working on our game again!
Since we divided pyCraftr into two parts(server and client), it's more complicated to deal with the synchronization things, @Nebual can you write an article explaining how server and client communicate and synchronize with each other? I think that will help.
Anyway let's start working again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.