boskee / Minecraft

Simple Minecraft-inspired program using Python and Pyglet
MIT License
207 stars 33 forks source link

I broke a flower and then tried to place it back #104

Open BenMaydan opened 5 years ago

BenMaydan commented 5 years ago

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)

r58Playz commented 5 years ago

Just change the code near line 100 to this:

                    try:
                        world.remove_block(struct.unpack("iii", positionbytes), sync=False)
                    except KeyError:
                        warn("Cannot remove block!")

And change the imports to this:

from _socket import SHUT_RDWR
import socket
import struct
import time
import timer
import socketserver
import threading

import globals as G
from custom_types import fVector, iVector
from savingsystem import save_sector_to_bytes, save_blocks, save_world, load_player, save_player
from world_server import WorldServer
import blocks
from text_commands import CommandParser, COMMAND_HANDLED, CommandException, COMMAND_ERROR_COLOR
from utils import sectorize, make_string_packet
from mod import load_modules
from warnings import warn

This will just show an warning. The error is most likely because the game was laggy( probably you played on Singleplayer) and you tried to remove the flower twice. This results in an KeyError, because the block was removed from the index and you are trying to remove it again.

EDIT: Specify where the change is.