Ejemplo n.º 1
0
    def exposed(self, position):
        """Returns False is given `position` is surrounded on all 6 sides by solid
        blocks, True otherwise.

        """
        bcx, _, bcz = mathhelper.sectorize(position)
        basechunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
            (bcx, bcz))
        flag1 = basechunkprovider.generated
        x, y, z = position
        for dx in range(-1, 2):
            for dy in range(-1, 2):
                for dz in range(-1, 2):
                    if [dx, dy, dz].count(0) > 1 and not dx == dy == dz == 0:
                        nx, ny, nz = x + dx, y + dy, z + dz
                        cx, _, cz = mathhelper.sectorize((nx, ny, nz))
                        chunkprovider = (G.player.dimension.worldprovider.
                                         getChunkProviderFor((cx, cz)))
                        if (((nx, ny, nz) not in chunkprovider.world
                             or G.GAMESTAGE != 3 or not chunkprovider.world[
                                 (nx, ny, nz)].isFullBlock()) and
                            (nx, ny, nz) not in G.BlockGenerateTasks
                            ) and not (flag1 and not chunkprovider.generated):
                            return True
                        else:
                            pass
                            # log.printMSG((nx, ny, nz) not in chunkprovider.world,
                            # mathhelper.sectorize((nx, ny, nz)) in G.player.dimension.worldprovider.chunks,
                            # (nx, ny, nz) not in G.BlockGenerateTasks)
        return False
    def update(self, dt):
        """This method is scheduled to be called repeatedly by the pyglet
        clock.

        Parameters
        ----------
        dt : float
            The change in time since the last call.

        """
        G.model.process_queue()
        sector = mathhelper.sectorize(self.position)
        if (sector != self.sector
                and G.statehandler.active_state.getName() == "minecraft:game"):
            G.model.change_sectors(self.sector, sector)
            if self.sector is None:
                G.model.process_entire_queue()
            self.sector = sector
        m = 8
        dt = min(dt, 0.2)
        for _ in range(m):
            self._update(dt / m)
        for entity in G.entityhandler.entitys:
            entity.update(dt)
        G.eventhandler.call("core:update")
        if G.statehandler.active_state.getName() == "minecraft:game":
            self.time += dt * 20
            self.day += round(self.time // 24000)
            self.time = round(self.time % 24000)
        if G.GAMESTAGE != 3:
            return
        i = 0
        max = len(G.BlockGenerateTasks)
        l = list(G.BlockGenerateTasks.keys())
        t = time.time()
        for position in l:
            G.model.add_block(position,
                              G.BlockGenerateTasks[position][0],
                              immediate=True)
            task = G.BlockGenerateTasks[position]
            if len(task) > 1:
                task = task[1:]
                while len(task) > 0:
                    st = task.pop(0)
                    cx, _, cz = mathhelper.sectorize(position)
                    chunkprovider = (
                        G.player.dimension.worldprovider.getChunkProviderFor(
                            (cx, cz)))
                    if st == "sdata":
                        chunkprovider.world[position].setStorageData(
                            task.pop(0))
                    else:
                        log.printMSG("[TASKS][ERROR] unknown subtask " +
                                     str(st))
            del G.BlockGenerateTasks[position]
            if time.time() - t > 0.1:
                return
    def draw_label(self):
        """Draw the label in the top left of the screen."""
        x, y, z = G.window.position
        self.label1.text = "%02d (%.2f, %.2f, %.2f) %d" % (
            pyglet.clock.get_fps(),
            x,
            y,
            z,
            len(G.player.dimension.worldprovider.chunkproviders),
        )

        vector = G.window.get_sight_vector()
        block, _ = G.model.hit_test(G.window.position, vector)
        if block:
            cx, _, cz = mathhelper.sectorize(block)
            chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
                (cx, cz))
        else:
            chunkprovider = None
        self.label1.text += (
            "; looking at: " + str(block) +
            ("" if not block or block not in chunkprovider.world else " - " +
             str(chunkprovider.world[block].getName())))

        nx, ny, nz = mathhelper.normalize(G.window.position)
        self.label1.y = G.window.height - 10
        self.label1.draw()
        self.label2.y = G.window.height - 25
        self.label2.text = ("daytime: " + str(round(G.window.time)) +
                            "; day: " + str(G.window.day))
        self.label2.draw()
Ejemplo n.º 4
0
    def hit_test(self, position, vector, max_distance=8):
        """Line of sight search from current position. If a block is
        intersected it is returned, along with the block previously in the line
        of sight. If no block is found, return None, None.

        Parameters
        ----------
        position : tuple of len 3
            The (x, y, z) position to check visibility from.
        vector : tuple of len 3
            The line of sight vector.
        max_distance : int
            How many blocks away to search for a hit.

        """
        m = 8
        x, y, z = position
        dx, dy, dz = vector
        previous = None
        for _ in range(max_distance * m):
            key = mathhelper.normalize((x, y, z))
            cx, _, cz = mathhelper.sectorize(key)
            if (key != previous and key
                    in G.player.dimension.worldprovider.getChunkProviderFor(
                        (cx, cz)).world):
                return key, previous
            previous = key
            x, y, z = x + dx / m, y + dy / m, z + dz / m
        return None, None
Ejemplo n.º 5
0
    def change_sectors(self, before, after):
        """Move from sector `before` to sector `after`. A sector is a
        contiguous x, y sub-region of world. Sectors are used to speed up
        world rendering.

        """
        before_set = set()
        after_set = set()
        pad = 4
        for dx in range(-pad, pad + 1):
            for dy in [0]:  # range(-pad, pad + 1):
                for dz in range(-pad, pad + 1):
                    if dx**2 + dy**2 + dz**2 > (pad + 1)**2:
                        continue
                    if before:
                        x, y, z = before
                        before_set.add((x + dx, y + dy, z + dz))
                    if after:
                        x, y, z = after
                        after_set.add((x + dx, y + dy, z + dz))
        show = after_set - before_set
        hide = before_set - after_set
        for sector in show:
            self.show_sector(sector)
        for sector in hide:
            self.hide_sector(sector)
        if not after:
            after = mathhelper.sectorize(G.window.position)
        sector = after
 def past(self, chunkprovider, r, x, y, z):
     xrot = r.generateValueForPosition((x, y - 1000, z), -90, 90)
     yrot = r.generateValueForPosition((x, y - 1001, z), -90, 90)
     zrot = r.generateValueForPosition((x, y - 1002, z), -90, 90)
     xlenght = r.generateValueForPosition(
         (x, y - 1003, z), self.getMinSize(self) / 2, self.getMaxSize(self) / 2
     )
     ylenght = r.generateValueForPosition(
         (x, y - 1004, z), self.getMinSize(self) / 2, self.getMaxSize(self) / 2
     )
     zlenght = r.generateValueForPosition(
         (x, y - 1005, z), self.getMinSize(self) / 2, self.getMaxSize(self) / 2
     )
     if xlenght == 0 or ylenght == 0 or zlenght == 0:
         return  # this orevein is empty
     for dx in range(-xlenght, xlenght + 1):
         for dy in range(-ylenght, ylenght + 1):
             for dz in range(-zlenght, zlenght + 1):
                 mx, my, mz = _rotatepoint(x, y, z, xrot, yrot, zrot)
                 if (mx * mx) / (xlenght * xlenght) + (my * my) / (
                     ylenght * ylenght
                 ) + (mz * mz) / (
                     zlenght * zlenght
                 ) <= 1:  # valid position
                     # if (x+dx, y+dy, z+dz) in chunkprovider.generationcache["blocks"] and \
                     #        chunkprovider.generationcache["blocks"][(x + dx, y + dy, z + dz)] in \
                     #        self.getReplaceAbleBlocks(self):
                     cx, _, cz = mathhelper.sectorize((x + dx, 0, z + dz))
                     chunkprovider = chunkprovider.worldprovider.getChunkProviderFor(
                         (cx, cz)
                     )
                     if chunkprovider.generated:
                         chunkprovider.generationcache["blocks"][
                             (x + dx, y + dy, z + dz)
                         ] = self.getOreName(self)
 def on_tick_update(self, inst):
     (x, y, z) = inst.position
     cx, _, cz = mathhelper.sectorize(inst.position)
     chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor((cx, cz))
     if not (x, y - 1, z) in chunkprovider.world and y > 0:
         G.model.add_block((x, y - 1, z), inst)
         G.model.remove_block((x, y, z))
     inst.blocked = False
Ejemplo n.º 8
0
 def on_block_update(self, inst):
     (x, y, z) = inst.position
     cx, _, cz = mathhelper.sectorize(inst.position)
     chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
         (cx, cz))
     if (not (x, y - 1, z) in chunkprovider.world and y > 0
             and not (hasattr(inst, "blocked") and not inst.blocked)):
         inst.blocked = True
         G.tickhandler.tick(self.on_tick_update, args=[inst], tick=4)
 def getStorageData(self, inst):
     """returns the data that should be stored. should be storeable by pickle"""
     cx, _, cz = mathhelper.sectorize(inst.position)
     chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
         (cx, cz))
     return {
         "name": self.getName(),
         "data": inst.data,
         "shown": inst.position in chunkprovider.shown,
     }
Ejemplo n.º 10
0
 def block_update(self, position):
     cx, _, cz = mathhelper.sectorize(position)
     chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
         (cx, cz))
     x, y, z = position
     for dx, dy, dz in config.FACES:
         key = (x + dx, y + dy, z + dz)
         if key in chunkprovider.world:
             chunkprovider.world[key].on_block_update()
     if position in chunkprovider.world:
         chunkprovider.world[position].on_block_update()
 def generate(self):
     if not self.chunkprovider.generated:
         raise RuntimeError()
     biomes = []
     biomeamount = {}
     for x, z in self.chunkprovider.generationcache["biomemap"].keys():
         biome = G.biomehandler.biomes[
             self.chunkprovider.generationcache["biomemap"][(x, z)]
         ]
         if not biome in biomes:
             biomes.append(biome)
             biomeamount[biome] = 1
         else:
             biomeamount[biome] += 1
     veintable = {}  # vein -> percent of chunk
     for biome in biomes:
         oreveins = biome.getOreVeins()
         for vein in oreveins:
             if not vein in self.generationtable:
                 self.generationtable[vein] = 0
                 veintable[vein] = (
                     biomeamount[biome] * vein.getChunkAmount(vein) / 256
                 )
             else:
                 veintable[vein] += (
                     biomeamount[biome] * vein.getChunkAmount(vein) / 256
                 )
     for orevein in self.generationtable.keys():
         while self.generationtable[orevein] < veintable[orevein]:
             x = self.random.generateValueForPosition(
                 (self.chunk[0] * 16, -12, self.chunk[1] * 16), 0, 15
             )
             x += self.chunkprovider.chunk[0] * 16
             z = self.random.generateValueForPosition(
                 (self.chunk[0] * 16, -14, self.chunk[1] * 16), 0, 15
             )
             z += self.chunkprovider.chunk[1] * 16
             cx, _, cz = mathhelper.sectorize((x, 0, z))
             chunkprovider = self.chunkprovider.worldprovider.getChunkProviderFor(
                 (cx, cz)
             )
             if chunkprovider.generated:
                 y = self.random.generateValueForPosition(
                     (x, -13, z),
                     0,
                     chunkprovider.generationcache["highmap"][(x, z)] - 5,
                 )
                 biome = G.biomehandler.biomes[
                     chunkprovider.generationcache["biomemap"][(x, z)]
                 ]
                 if orevein in biome.getOreVeins():
                     self.generationtable[orevein] += 1
                     orevein.past(orevein, self.chunkprovider, self.random, x, y, z)
 def on_redstone_update(self, inst):
     x, y, z = inst.position
     flag = False
     for dx, dy, dz, face in SURROUNDING:
         px, py, pz = x + dx, y + dy, z + dz
         cx, _, cz = mathhelper.sectorize((px, py, pz))
         chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
             (cx, cz)
         )
         if (px, py, pz) in chunkprovider.world and chunkprovider.world[
             (px, py, pz)
         ].getErmittedRedstoneSignal(face) > 0:
             flag = True
     if flag:
         self.light(inst)
 def generateHighMapToChunkProvider(self, chunk):
     """
     this function should renamed to something like debugblockselector
     """
     if len(BLOCKTABLE) != 0:
         return
     blocks = list(G.blockhandler.blocks.keys())
     blocks.sort()
     blocks.remove("minecraft:none")
     xr = math.ceil(math.sqrt(len(blocks)) / 2) * 2 + 1
     for x in range(-round(xr / 2), round(xr / 2)):
         for y in range(-round(xr / 2), round(xr / 2)):
             index = (xr + x) * xr + xr + y
             if len(blocks) > index:
                 block = blocks[index]
                 cx, _, cz = mathhelper.sectorize((x, 0, y))
                 if (cx, cz) not in BLOCKTABLE:
                     BLOCKTABLE[(cx, cz)] = {}
                 BLOCKTABLE[(cx, cz)][(x * 4, 5, y * 4)] = block
Ejemplo n.º 14
0
    def hide_block(self, position, block, immediate=True):
        """Hide the block at the given `position`. Hiding does not remove the
        block from the world.

        Parameters
        ----------
        position : tuple of len 3
            The (x, y, z) position of the block to hide.
        immediate : bool
            Whether or not to immediately remove the block from the canvas.

        """
        cx, _, cz = mathhelper.sectorize(position)
        chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
            (cx, cz))
        if not position in chunkprovider.shown:
            return
        chunkprovider.shown.pop(position)
        if immediate:
            self._hide_block(position, block)
        else:
            self._enqueue(self._hide_block, position, block)
Ejemplo n.º 15
0
    def add_block(self, position, texture, immediate=True, blocksettedto=None):
        """Add a block with the given `texture` and `position` to the world.

        Parameters
        ----------
        position : tuple of len 3
            The (x, y, z) position of the block to add.
        texture : list of len 3
            The coordinates of the texture squares. Use `tex_coords()` to
            generate.
        immediate : bool
            Whether or not to draw the block immediately.

        """
        if position[1] < 0 or position[1] > 255:
            return
        cx, _, cz = mathhelper.sectorize(position)
        chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
            (cx, cz))
        if position in chunkprovider.world:
            self.remove_block(position, immediate)
        if texture in ["air", "minecraft:air"]:
            return
        if not type(texture) == G.blockinst:
            # todo: re-add blocksettedto
            block = G.blockhandler.getInst(
                texture, position)  # , blocksettedto=blocksettedto)
        else:
            block = texture
            block.position = position
        if not block:
            return
        chunkprovider.world[position] = block
        if immediate:
            if self.exposed(position):
                self.show_block(position)
            self.check_neighbors(position)
        if G.GAMESTAGE == 3:
            self.block_update(position)
Ejemplo n.º 16
0
    def check_neighbors(self, position):
        """Check all blocks surrounding `position` and ensure their visual
        state is current. This means hiding blocks that are not exposed and
        ensuring that all exposed blocks are shown. Usually used after a block
        is added or removed.

        """
        x, y, z = position
        for dx in range(-1, 2):
            for dy in range(-1, 2):
                for dz in range(-1, 2):
                    if [dx, dy, dz].count(0) == 1:
                        key = (x + dx, y + dy, z + dz)
                        cx, _, cz = mathhelper.sectorize(key)
                        chunkprovider = (G.player.dimension.worldprovider.
                                         getChunkProviderFor((cx, cz)))
                        if key not in chunkprovider.world:
                            continue
                        if not self.exposed(key):
                            self.show_block(position)
                        else:
                            self.hide_block(key, chunkprovider.world[key])
Ejemplo n.º 17
0
    def show_block(self, position, immediate=True, test=True):
        """Show the block at the given `position`. This method assumes the
        block has already been added with add_block()

        Parameters
        ----------
        position : tuple of len 3
            The (x, y, z) position of the block to show.
        immediate : bool
            Whether or not to show the block immediately.

        """
        cx, _, cz = mathhelper.sectorize(position)
        chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
            (cx, cz))
        if not position in chunkprovider.world:
            return
        block = chunkprovider.world[position]
        chunkprovider.shown[position] = block
        if immediate and not (test and not self.exposed(position)):
            self._show_block(position, block)
        elif not immediate and not (test and not self.exposed(position)):
            self._enqueue(self._show_block, position, block)
Ejemplo n.º 18
0
    def remove_block(self, position, immediate=True):
        """Remove the block at the given `position`.

        Parameters
        ----------
        position : tuple of len 3
            The (x, y, z) position of the block to remove.
        immediate : bool
            Whether or not to immediately remove block from canvas.

        """
        cx, _, cz = mathhelper.sectorize(position)
        chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
            (cx, cz))
        if position not in chunkprovider.world:
            return
        chunkprovider.world[position].delete()
        if immediate:
            if position in chunkprovider.shown:
                self.hide_block(position, chunkprovider.world[position])
            self.check_neighbors(position)
        self.block_update(position)
        del chunkprovider.world[position]
 def show(self, batch, blockinst):
     position = blockinst.position
     cx, _, cz = mathhelper.sectorize(position)
     chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
         (cx, cz))
     if len(blockinst.showndata) > 0:
         self.hide(batch, blockinst)
     if not G.model.exposed(blockinst.position):
         return
     if not blockinst.position in chunkprovider.world:
         return
     x, y, z = blockinst.position
     vertex_data = chunkprovider.world[blockinst.position].getCubeVerticens(
         *list(chunkprovider.world[blockinst.position].
               convertPositionToRenderable(blockinst.position)) + [0.5])
     textureatlas = G.textureatlashandler.atlases[
         self.model.indexes[0][0] if hasattr(self.model.
                                             indexes[0], "__getitem__"
                                             ) else G.textureatlashandler.
         indexarray[self.model.indexes[0]][0]]
     texture_data = text_coords_complex(*[
         self.model.indexes[i][1][1]
         if hasattr(self.model.indexes[i][1][1], "__getitem__") else
         self.model.indexes[i][1] for i in self.entry["sides"]
     ],
                                        n1=16,
                                        n2=16)
     # create vertex list
     # FIXME Maybe `add_indexed()` should be used insteads
     blockinst.showndata.append(
         batch.add(
             24,
             pyglet.gl.GL_QUADS,
             textureatlas.pyglet_atlas,
             ("v3f/static", vertex_data),
             ("t2f/static", texture_data),
         ))
    def on_event(self, name, *args):
        if name == "opengl:draw3d":
            t = G.window.time + 12000 if G.window.time < 12000 else G.window.time
            w = (24000 - G.window.time) / 24000
            pyglet.gl.glClearColor(0.5 * w, 0.69 * w, 1.0 * w, 1 * w)
            pyglet.gl.glColor3d(w, w, w)
            # draw with alpha - alpha setup
            pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
            pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA,
                                  pyglet.gl.GL_ONE_MINUS_SRC_ALPHA)
            # end alpha setup
            G.player.dimension.worldprovider.batch.draw()
            self.draw_focused_block()
        elif name == "opengl:draw2d":
            self.draw_label()
            self.draw_reticle()
            G.inventoryhandler.draw()
            G.player.on_draw()
        elif name == "core:window:on_resize":
            # label
            self.label1.y = G.window.height - 10
            self.label2.y = G.window.height - 25
            # reticle
            if self.reticle:
                self.reticle.delete()
            x, y = G.window.width // 2, G.window.height // 2
            n = 10
            self.reticle = pyglet.graphics.vertex_list(
                4, ("v2i", (x - n, y, x + n, y, x, y - n, x, y + n)))
        elif name == "core:window:on_key_release":
            symbol, modifiers = args

            if G.chat.active:
                G.window.strafe = [0, 0]
                return

            if symbol == config.Keyboard.WALK_FORWARD:
                G.window.strafe[0] += 1
            elif symbol == config.Keyboard.WALK_BACKWARD:
                G.window.strafe[0] -= 1
            elif symbol == config.Keyboard.WALK_LEFT:
                G.window.strafe[1] += 1
            elif symbol == config.Keyboard.WALK_RIGHT:
                G.window.strafe[1] -= 1
        elif name == "core:window:on_key_press":
            symbol, modifiers = args

            if G.chat.active:
                G.chat.on_key_press(symbol, modifiers)
                return

            if any([
                    G.inventoryhandler.inventorys[inventory].isDisablyingGame(
                    ) for inventory in G.inventoryhandler.activeinventorys
            ]):
                log.printMSG([(
                    G.inventoryhandler.inventorys[inventory],
                    G.inventoryhandler.inventorys[inventory].isDisablyingGame(
                    ),
                ) for inventory in G.inventoryhandler.activeinventorys])
                if symbol == key.ESCAPE:
                    for e in G.inventoryhandler.activeated:
                        inv = G.inventoryhandler.inventorys[e]
                        log.printMSG(inv)
                        if "system:nothideable" not in inv.tag:
                            G.inventoryhandler.hide_inventory(e)
                        else:
                            inv.on_try_close()
                else:
                    for e in G.inventoryhandler.activeated:
                        inv = G.inventoryhandler.inventorys[e]
                        inv.on_key_press(*args)
                return

            if symbol == config.Keyboard.WALK_FORWARD:
                G.window.strafe[0] -= 1
            elif symbol == config.Keyboard.WALK_BACKWARD:
                G.window.strafe[0] += 1
            elif symbol == config.Keyboard.WALK_LEFT:
                G.window.strafe[1] -= 1
            elif symbol == config.Keyboard.WALK_RIGHT:
                G.window.strafe[1] += 1
            elif symbol == config.Keyboard.JUMP:
                if G.window.dy == 0:
                    G.window.dy = config.Physiks.JUMP_SPEED
            elif symbol == config.Keyboard.CLOSE:
                if G.window.player.inventory.guitype == 1:
                    G.window.player.inventory.guitype = 0
                    G.window.set_exclusive_mouse(True)
                    G.inventoryhandler.hide_inventory(G.player.inventory.id)
                    G.inventoryhandler.show_inventory(G.player.inventory.id)
                elif G.chat.active:
                    G.inventoryhandler.hide_inventory(G.chat.id)
                    G.window.set_exclusive_mouse(True)
                    G.chat.active = False
                elif len(G.inventoryhandler.activeinventorys) > 3:
                    for e in G.inventoryhandler.activeinventorys:
                        e = G.inventoryhandler.inventorys[e]
                        if not "player:inventory" in e.tag:
                            G.inventoryhandler.hide_inventory(e.id)
                else:
                    if G.window.worldname:
                        G.commandhandler.executeCommand("/save", None, None)
                    G.statehandler.setState("minecraft:escape_menu")
            elif symbol == config.Keyboard.TOGGLE_FLYING and G.player.gamemode == 1:
                G.window.flying = not G.window.flying
            elif symbol in G.window.num_keys:
                index = (symbol - G.window.num_keys[0]) % 9
                G.player.selectedinventoryslot = index
            elif symbol == config.Keyboard.OPEN_INVENTORY:
                if G.window.player.inventory.guitype == 1:
                    G.window.player.inventory.guitype = 0
                    G.window.set_exclusive_mouse(True)
                    G.inventoryhandler.hide_inventory(
                        G.window.player.inventory.id)
                    G.inventoryhandler.show_inventory(
                        G.window.player.inventory.id)
                    for e in G.player.inventory.inventorys[1:]:
                        return G.player.checkinventorysforslots.remove(e)
                else:
                    G.window.player.inventory.guitype = 1
                    G.window.set_exclusive_mouse(False)
                    G.inventoryhandler.hide_inventory(
                        G.window.player.inventory.id)
                    G.inventoryhandler.show_inventory(
                        G.window.player.inventory.id)
                    G.player.checkinventorysforslots += G.player.inventory.inventorys[
                        1:]

            elif symbol == config.Keyboard.OPEN_CHAT:
                G.inventoryhandler.show_inventory(G.chat.id)
        elif name == "core:window:on_mouse_motion":
            x, y, dx, dy = args
            if G.player.inventory.inventorys[0].type == 1:
                G.player.on_mouse_motion(x, y, dx, dy)
                return
            if any([
                    G.inventoryhandler.inventorys[inventory].isDisablyingGame(
                    ) for inventory in G.inventoryhandler.activeinventorys
            ]):
                G.player.on_mouse_motion(*args)
                return
            if G.window.exclusive:
                m = config.Physiks.MOUSE_REAKTION
                x, y = G.window.rotation
                x, y = x + dx * m, y + dy * m
                y = max(-90, min(90, y))
                G.window.rotation = (x, y)
        elif name == "core:window:on_mouse_press":
            x, y, button, modifiers = args
            if G.player.inventory.inventorys[0].type == 1:
                G.player.on_mouse_press(x, y, button, modifiers)
                return
            if any([
                    G.inventoryhandler.inventorys[inventory].
                    shouldInteractWithPlayerInventoryMoving()
                    for inventory in G.inventoryhandler.activeinventorys
            ]):
                G.player.on_mouse_press(*args)
                return
            if G.window.exclusive:
                vector = G.window.get_sight_vector()
                block, previous = G.model.hit_test(G.window.position, vector)
                if (button == mouse.RIGHT) or ((button == mouse.LEFT) and
                                               (modifiers & key.MOD_CTRL)):
                    chunkprovider = chunkprovider2 = None
                    if previous:
                        cx, _, cz = mathhelper.sectorize(previous)
                        chunkprovider = (G.player.dimension.worldprovider.
                                         getChunkProviderFor((cx, cz)))
                    if block:
                        cx, _, cz = mathhelper.sectorize(block)
                        chunkprovider2 = (G.player.dimension.worldprovider.
                                          getChunkProviderFor((cx, cz)))
                    # ON OSX, control + left click = right click.
                    if (previous and G.player.inventory.inventorys[0].slots[
                            G.player.selectedinventoryslot].stack
                            and G.player.inventory.inventorys[0].slots[
                                G.player.selectedinventoryslot].stack.item
                            and G.player.inventory.inventorys[0].slots[
                                G.player.selectedinventoryslot].stack.item.
                            hasBlock() and
                            not chunkprovider2.world[block].isOpeningInventory(
                                G.player.inventory.inventorys[0].slots[
                                    G.player.selectedinventoryslot].stack)):
                        G.model.add_block(
                            previous,
                            G.player.inventory.inventorys[0].slots[
                                G.player.selectedinventoryslot].stack.item.
                            getBlockName(),
                            blocksettedto=block,
                        )
                        G.model.check_neighbors(previous)
                        if not G.model.exposed(previous):
                            G.model.show_block(previous)
                        G.eventhandler.call(
                            "game:on_block_add_by_player",
                            vector,
                            block,
                            previous,
                            G.player.inventory.inventorys[0].slots[
                                G.player.selectedinventoryslot].stack.item.
                            getBlockName(),
                        )
                        chunkprovider.world[previous].blocksettedto = block
                        if G.player.gamemode != 1:
                            G.player.inventory.inventorys[0].slots[
                                G.player.
                                selectedinventoryslot].stack.amount -= 1
                        block = chunkprovider.world[previous]
                        G.soundhandler.playSound(previous,
                                                 block.getBrakeSoundFile())
                    elif (block and chunkprovider
                          and chunkprovider.world[block].isOpeningInventory(
                              G.player.inventory.inventorys[0].slots[
                                  G.player.selectedinventoryslot].stack)):
                        # log.printMSG(chunkprovider.world[block], chunkprovider.world[block].blockclass, chunkprovider.world[block].getInventorys())
                        for e in chunkprovider.world[block].getInventorys():
                            G.inventoryhandler.show_inventory(e if type(e) ==
                                                              int else e.id)
                            # log.printMSG(e if type(e) == int else e.id)
                elif button == pyglet.window.mouse.LEFT and block:
                    cx, _, cz = mathhelper.sectorize(block)
                    chunkprovider = (
                        G.player.dimension.worldprovider.getChunkProviderFor(
                            (cx, cz)))
                    block = chunkprovider.world[block]
                    if block.isBrakeAbleInGamemode0(
                    ) or G.player.gamemode == 1:
                        G.soundhandler.playSound(block.position,
                                                 block.getBrakeSoundFile())
                        if G.player.gamemode != 1:
                            drops = block.getDrop()
                            for e in drops.keys():
                                G.player.addToInventory(e, drops[e])
                        else:
                            drops = {}
                        G.model.remove_block(block.position)
                        G.model.hide_block(block.position, block)
                        # G.model.check_neighbors(block.position)
                        G.eventhandler.call(
                            "game:on_block_remove_by_player",
                            vector,
                            block,
                            previous,
                            drops,
                        )
                elif button == pyglet.window.mouse.MIDDLE and G.player.gamemode == 1:
                    vector = G.window.get_sight_vector()
                    block, previous = G.model.hit_test(G.window.position,
                                                       vector)
                    cx, _, cz = mathhelper.sectorize(block)
                    chunkprovider = (
                        G.player.dimension.worldprovider.getChunkProviderFor(
                            (cx, cz)))
                    binst = chunkprovider.world[block]
                    G.player.inventory.inventorys[0].slots[
                        G.player.
                        selectedinventoryslot].stack = IItemStack.IItemStack(
                            binst.getName())
                    if (G.player.inventory.inventorys[0].slots[
                            G.player.selectedinventoryslot].stack.item):
                        G.player.inventory.inventorys[0].slots[
                            G.player.selectedinventoryslot].stack.amount = (
                                G.player.inventory.inventorys[0].slots[
                                    G.player.selectedinventoryslot].stack.item.
                                getMaxStackSize())
            else:
                G.window.set_exclusive_mouse(True)
    def generateChunk(self, chunk):
        bios = []
        for x in range(chunk[0] * 16, chunk[0] * 16 + 16):
            for z in range(chunk[1] * 16, chunk[1] * 16 + 16):
                if not (x, z) in self.biome_data:
                    raise ValueError("getted an unprepared area-biome-data", x,
                                     z)
                self.biome_instances[self.biome_data[(x, z)]].poslist.append(
                    (x, z))
                if not self.biome_instances[self.biome_data[(x, z)]] in bios:
                    bios.append(self.biome_instances[self.biome_data[(x, z)]])
        for biome in bios:
            biome.GenerateBiome(G.model)
        if random.randint(1, 5) == 1 and config.CONFIGS["GENERATE_PERLIN"]:
            bpos = chunk[0] * 16, chunk[1] * 16
            pos = []
            for _ in range(random.randint(1, 5)):
                x, z = random.randint(bpos[0], bpos[0] + 15), random.randint(
                    bpos[1], bpos[1] + 15)
                y = G.model.high_data[(x, z)]
                pos.append((x, y, z))

            print("adding perlin...")
            data = pyfastnoisesimd.generate([255, 255, 255],
                                            start=pos,
                                            seed=G.seed)

            print("sorting them for generation...")
            dt = time.time()
            i = -1
            ch = []
            for xl in data:
                for zl in xl:
                    pos = zl[0]
                    cx, _, cz = mathhelper.sectorize((pos[0], pos[1], pos[2]))
                    self.perlin_positions[(zl[0][0], zl[0][2])] = zl
                    if not (cx, cz) in ch:
                        ch.append((cx, cz))
                    i += 1
                    if time.time() - dt > 1:
                        dt = time.time()
                        print(str(round(i / (255 * 255 * 255) * 100)) + "%")

            for e in ch:
                if e in G.model.generated:
                    print("applying perlins to chunk", e)
                    print(self.perlin_positions[chunk])
                    dt = time.time()
                    for x in range(chunk[0] * 16, chunk[0] * 16 + 16):
                        for z in range(chunk[1] * 16, chunk[1] * 16 + 16):
                            if (x, z) in self.perlin_positions:
                                for y, v in enumerate(
                                        self.perlin_positions[(x, z)]):
                                    if v >= 0 and (x, y, z) in G.model.world:
                                        G.model.remove_block((x, y, z),
                                                             immediate=False,
                                                             save=False)
                                    if time.time() - dt > 1:
                                        dt = time.time()
                                        print(
                                            str(
                                                round(i / len(
                                                    self.
                                                    perlin_positions[chunk]) *
                                                      100)) + "%")

            print("looking for perlin-positions for asked chunk", chunk)
            if not chunk in self.perlin_positions:
                print("[ERROR] generated perlin and found NONE in chunk")
            else:
                pass
 def executeCommand(command, entity, position):
     chunk = mathhelper.sectorize(G.window.position)
     cx, cz = chunk[0], chunk[2]
     chunkprovider = G.player.dimension.worldprovider.getChunkProviderFor(
         (cx, cz))
     chunkprovider.generate()