diff --git a/community/block_type.py b/community/block_type.py new file mode 100644 index 00000000..e39015b2 --- /dev/null +++ b/community/block_type.py @@ -0,0 +1,59 @@ +import models.cube # default model + +class Block_type: + # new optional model argument (cube model by default) + def __init__(self, texture_manager, name = "unknown", block_face_textures = {"all": "cobblestone"}, model = models.cube): + self.name = name + self.block_face_textures = block_face_textures + self.model = model + + # create members based on model attributes + + self.transparent = model.transparent + self.is_cube = model.is_cube + self.glass = model.glass + self.translucent = model.translucent + + # replace data contained in numbers.py with model specific data + + self.vertex_positions = model.vertex_positions + self.tex_coords = model.tex_coords # to deprecate + self.tex_indices = [0] * len(self.tex_coords) + self.shading_values = model.shading_values + + def set_block_face(face, texture): + # make sure we don't add inexistent face + if face > len(self.tex_coords) - 1: + return + self.tex_indices[face] = texture + + for face in block_face_textures: + texture = block_face_textures[face] + texture_manager.add_texture(texture) + + texture_index = texture_manager.textures.index(texture) + + if face == "all": + for i in range(len(self.tex_coords)): + set_block_face(i, texture_index) + + elif face == "sides": + set_block_face(0, texture_index) + set_block_face(1, texture_index) + set_block_face(4, texture_index) + set_block_face(5, texture_index) + + elif face == "x": + set_block_face(0, texture_index) + set_block_face(1, texture_index) + + elif face == "y": + set_block_face(2, texture_index) + set_block_face(3, texture_index) + + elif face == "z": + set_block_face(4, texture_index) + set_block_face(5, texture_index) + + else: + set_block_face(["right", "left", "top", "bottom", "front", "back"].index(face), texture_index) \ No newline at end of file diff --git a/community/camera.py b/community/camera.py new file mode 100644 index 00000000..2dfb5d56 --- /dev/null +++ b/community/camera.py @@ -0,0 +1,63 @@ +import math +import matrix + +WALKING_SPEED = 7 +SPRINTING_SPEED = 21 + +class Camera: + def __init__(self, shader, width, height): + self.width = width + self.height = height + + # create matrices + + self.mv_matrix = matrix.Matrix() + self.p_matrix = matrix.Matrix() + self.mvp_matrix = matrix.Matrix() + + # shaders + + self.shader = shader + self.shader_matrix_location = self.shader.find_uniform(b"u_ModelViewProjMatrix") + + # camera variables + + self.input = [0, 0, 0] + + self.position = [0, 80, 0] + self.rotation = [-math.tau / 4, 0] + + self.target_speed = WALKING_SPEED + self.speed = self.target_speed + + def update_camera(self, delta_time): + self.speed += (self.target_speed - self.speed) * delta_time * 20 + multiplier = self.speed * delta_time + + self.position[1] += self.input[1] * multiplier + + if self.input[0] or self.input[2]: + angle = self.rotation[0] - math.atan2(self.input[2], self.input[0]) + math.tau / 4 + + self.position[0] += math.cos(angle) * multiplier + self.position[2] += math.sin(angle) * multiplier + + def update_matrices(self): + # create projection matrix + + self.p_matrix.load_identity() + + self.p_matrix.perspective( + 90 + 20 * (self.speed - WALKING_SPEED) / (SPRINTING_SPEED - WALKING_SPEED), + float(self.width) / self.height, 0.1, 500) + + # create modelview matrix + + self.mv_matrix.load_identity() + self.mv_matrix.rotate_2d(self.rotation[0] + math.tau / 4, self.rotation[1]) + self.mv_matrix.translate(-self.position[0], -self.position[1], -self.position[2]) + + # modelviewprojection matrix + + self.mvp_matrix = self.p_matrix * self.mv_matrix + self.shader.uniform_matrix(self.shader_matrix_location, self.mvp_matrix) \ No newline at end of file diff --git a/community/chunk.py b/community/chunk.py new file mode 100644 index 00000000..eedd8ede --- /dev/null +++ b/community/chunk.py @@ -0,0 +1,164 @@ +import ctypes + +import pyglet.gl as gl + +import subchunk + +CHUNK_WIDTH = 16 +CHUNK_HEIGHT = 128 +CHUNK_LENGTH = 16 + +class Chunk: + def __init__(self, world, chunk_position): + self.world = world + + self.modified = False + self.chunk_position = chunk_position + + self.position = ( + self.chunk_position[0] * CHUNK_WIDTH, + self.chunk_position[1] * CHUNK_HEIGHT, + self.chunk_position[2] * CHUNK_LENGTH) + + self.blocks = [[[0 + for z in range(CHUNK_LENGTH)] + for y in range(CHUNK_HEIGHT)] + for x in range(CHUNK_WIDTH )] + + self.subchunks = {} + + for x in range(int(CHUNK_WIDTH / subchunk.SUBCHUNK_WIDTH)): + for y in range(int(CHUNK_HEIGHT / subchunk.SUBCHUNK_HEIGHT)): + for z in range(int(CHUNK_LENGTH / subchunk.SUBCHUNK_LENGTH)): + self.subchunks[(x, y, z)] = subchunk.Subchunk(self, (x, y, z)) + + # mesh variables + + self.mesh = [] + self.translucent_mesh = [] + + self.mesh_quad_count = 0 + self.translucent_quad_count = 0 + + # create VAO and VBO's + + self.vao = gl.GLuint(0) + gl.glGenVertexArrays(1, ctypes.byref(self.vao)) + gl.glBindVertexArray(self.vao) + + self.vbo = gl.GLuint(0) + gl.glGenBuffers(1, ctypes.byref(self.vbo)) + gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vbo) + gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(gl.GLfloat * CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_LENGTH * 8), None, gl.GL_DYNAMIC_DRAW) + + gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, + gl.GL_FALSE, 6 * ctypes.sizeof(gl.GLfloat), 0) + gl.glEnableVertexAttribArray(0) + gl.glVertexAttribPointer(1, 2, gl.GL_FLOAT, + gl.GL_FALSE, 6 * ctypes.sizeof(gl.GLfloat), 3 * ctypes.sizeof(gl.GLfloat)) + gl.glEnableVertexAttribArray(1) + gl.glVertexAttribPointer(2, 1, gl.GL_FLOAT, + gl.GL_FALSE, 6 * ctypes.sizeof(gl.GLfloat), 5 * ctypes.sizeof(gl.GLfloat)) + gl.glEnableVertexAttribArray(2) + + gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, world.ibo) + + def __del__(self): + gl.glDeleteBuffers(1, ctypes.byref(self.vbo)) + gl.glDeleteVertexArrays(1, ctypes.byref(self.vao)) + + def update_subchunk_meshes(self): + for subchunk_position in self.subchunks: + subchunk = self.subchunks[subchunk_position] + subchunk.update_mesh() + + def update_at_position(self, position): + x, y, z = position + + lx = int(x % subchunk.SUBCHUNK_WIDTH ) + ly = int(y % subchunk.SUBCHUNK_HEIGHT) + lz = int(z % subchunk.SUBCHUNK_LENGTH) + + clx, cly, clz = self.world.get_local_position(position) + + sx = clx // subchunk.SUBCHUNK_WIDTH + sy = cly // subchunk.SUBCHUNK_HEIGHT + sz = clz // subchunk.SUBCHUNK_LENGTH + + self.subchunks[(sx, sy, sz)].update_mesh() + + def try_update_subchunk_mesh(subchunk_position): + if subchunk_position in self.subchunks: + self.subchunks[subchunk_position].update_mesh() + + if lx == subchunk.SUBCHUNK_WIDTH - 1: try_update_subchunk_mesh((sx + 1, sy, sz)) + if lx == 0: try_update_subchunk_mesh((sx - 1, sy, sz)) + + if ly == subchunk.SUBCHUNK_HEIGHT - 1: try_update_subchunk_mesh((sx, sy + 1, sz)) + if ly == 0: try_update_subchunk_mesh((sx, sy - 1, sz)) + + if lz == subchunk.SUBCHUNK_LENGTH - 1: try_update_subchunk_mesh((sx, sy, sz + 1)) + if lz == 0: try_update_subchunk_mesh((sx, sy, sz - 1)) + + def update_mesh(self): + # combine all the small subchunk meshes into one big chunk mesh + + for subchunk_position in self.subchunks: + subchunk = self.subchunks[subchunk_position] + + self.mesh.extend(subchunk.mesh) + self.translucent_mesh.extend(subchunk.translucent_mesh) + + # send the full mesh data to the GPU and free the memory used client-side (we don't need it anymore) + # don't forget to save the length of 'self.mesh_indices' before freeing + + self.mesh_quad_count = len(self.mesh) // 24 + self.translucent_quad_count = len(self.translucent_mesh) // 24 + + self.send_mesh_data_to_gpu() + + self.mesh = [] + self.translucent_mesh = [] + + def send_mesh_data_to_gpu(self): # pass mesh data to gpu + if not self.mesh_quad_count: + return + + self.mesh.extend(self.translucent_mesh) + + gl.glBindVertexArray(self.vao) + + gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vbo) + gl.glBufferSubData( + gl.GL_ARRAY_BUFFER, + 0, + ctypes.sizeof(gl.GLfloat * len(self.mesh)), + (gl.GLfloat * len(self.mesh)) (*self.mesh)) + + + def draw(self): + if not self.mesh_quad_count: + return + + gl.glBindVertexArray(self.vao) + + gl.glDrawElementsBaseVertex( + gl.GL_TRIANGLES, + self.mesh_quad_count * 6, + gl.GL_UNSIGNED_INT, + None, + 0) + + def draw_translucent(self): + if not self.translucent_quad_count: + return + + gl.glBindVertexArray(self.vao) + + gl.glDrawElementsBaseVertex( + gl.GL_TRIANGLES, + self.translucent_quad_count * 6, + gl.GL_UNSIGNED_INT, + None, + self.mesh_quad_count * 4 + ) \ No newline at end of file diff --git a/community/data/blocks.mcpy b/community/data/blocks.mcpy new file mode 100644 index 00000000..2c069379 --- /dev/null +++ b/community/data/blocks.mcpy @@ -0,0 +1,91 @@ +# block ID's from: +# https://www.minecraftforum.net/forums/minecraft-java-edition/discussion/114963-all-item-block-ids-in-one-place +# (with some slight modifications) + +1: name "Stone", texture.all stone +2: name "Grass", texture.top grass, texture.bottom dirt, texture.sides grass_side +3: name "Dirt", texture.all dirt +4: name "Cobblestone", texture.all cobblestone +5: name "Planks", texture.all planks +6: name "Sapling", model models.plant, texture.all sapling +7: name "Bedrock", texture.all bedrock +8: name "Water", model models.liquid, texture.all water +9: sameas 8, name "Stationary Water" +10: name "Lava", model models.liquid, texture.all lava +11: sameas 10, name "Stationary Lava" +12: name "Sand", texture.all sand +13: name "Gravel", texture.all gravel +14: name "Gold Ore", texture.all gold_ore +15: name "Iron Ore", texture.all iron_ore +16: name "Coal Ore", texture.all coal_ore +17: name "Log", texture.y log_y, texture.sides log_side +18: name "Leaves", model models.leaves, texture.all leaves +19: name "Sponge", texture.all sponge +20: name "Glass", model models.glass, texture.all glass +21: name "Red Cloth", texture.all red_cloth +22: name "Orange Cloth", texture.all orange_cloth +23: name "Yellow Cloth", texture.all yellow_cloth +24: name "Lime Cloth", texture.all lime_cloth +25: name "Green Cloth", texture.all green_cloth +26: name "Aqua Cloth", texture.all aqua_cloth +27: name "Cyan Cloth", texture.all cyan_cloth +28: name "Blue Cloth", texture.all blue_cloth +29: name "Purple Cloth", texture.all purple_cloth +30: name "Indigo Cloth", texture.all indigo_cloth +31: name "Violet Cloth", texture.all violet_cloth +32: name "Magenta Cloth", texture.all magenta_cloth +33: name "Pink Cloth", texture.all pink_cloth +34: name "Black Cloth", texture.all black_cloth +35: name "Grey Cloth", texture.all grey_cloth +36: name "White Cloth", texture.all white_cloth +37: name "Yellow Flower", model models.plant, texture.all yellow_flower +38: name "Red Rose", model models.plant, texture.all red_rose +39: name "Brown Mushroom", model models.plant, texture.all brown_mushroom +40: name "Red Mushroom", model models.plant, texture.all red_mushroom +41: name "Gold Block", texture.all gold_block +42: name "Iron Block", texture.all iron_block +43: name "Double Slab", texture.sides slab_side, texture.y slab_y +44: name "Slab", model models.slab, texture.sides slab_side, texture.y slab_y +45: name "Bricks", texture.all bricks +46: name "TNT", texture.top tnt_top, texture.bottom tnt_bottom, texture.sides tnt_side +47: name "Bookshelf", texture.y planks, texture.sides bookshelf +48: name "Mossy Cobblestone", texture.all mossy_cobblestone +49: name "Obsidian", texture.all obsidian +50: name "Torch", model models.torch, texture.top torch_top, texture.bottom torch, texture.sides torch +51: name "Fire", model models.fire, texture.all fire +# I know, the model name isn't great, but it's got the same graphical properties +52: name "Mob Spawner", model models.leaves, texture.all mob_spawner +53: name "Wooden Stairs", model models.stairs, texture.all planks +54: name "Chest", texture.y chest_top, texture.sides chest_side, texture.front chest_front +55: name "Redstone Wire", model models.flat, texture.all redstone_wire +56: name "Diamond Ore", texture.all diamond_ore +57: name "Diamond Block", texture.all diamond_block +58: name "Crafting Table", texture.top crafting_table_top, texture.bottom planks, texture.x crafting_table_x, texture.z crafting_table_z +59: name "Crops", model models.crop, texture.all crops +60: name "Soil", model models.soil, texture.all dirt, texture.top soil +61: name "Furnace", texture.y furnace_y, texture.sides furnace_side, texture.front furnace_front +62: name "Lit Furnace", texture.y furnace_y, texture.sides furnace_side, texture.front lit_furnace_front +63: name "Sign Post", model models.sign_post, texture.all planks +64: name "Wooden Door", model models.door, texture.all wooden_door +65: name "Ladder", model models.ladder, texture.all ladder +66: name "Rails", model models.flat, texture.all rails +67: name "Cobblestone Stairs", model models.stairs, texture.all cobblestone +68: name "Sign", model models.sign, texture.all planks +69: name "Lever", model models.lever, texture.all lever +70: name "Stone Pressure Plate", model models.pressure_plate, texture.all stone +71: name "Iron Door", model models.door, texture.all iron_door_bottom_half +72: name "Wooden Pressure Plate", model models.pressure_plate, texture.all planks +73: name "Redstone Ore", texture.all redstone_ore +# when we implement a lighting system, this will have some kind of "emissive" property +74: name "Lit Redstone Ore", texture.all redstone_ore +75: name "Redstone Torch", model models.torch, texture.top redstone_torch_top, texture.bottom redstone_torch, texture.sides redstone_torch +76: name "Redstone Torch (Off)", model models.torch, texture.top off_redstone_torch_top, texture.bottom off_redstone_torch, texture.sides off_redstone_torch +77: name "Stone Button", model models.button, texture.all stone +78: name "Snow", model models.snow, texture.all snow +# ditto as for mob spawners (52) +79: name "Ice", model models.glass, texture.all ice +80: name "Snow Block", texture.all snow +81: name "Cactus", model models.cactus, texture.top cactus_top, texture.bottom cactus_bottom, texture.sides cactus_side +82: name "Clay", texture.all clay +83: name "Sugar Cane", model models.plant, texture.all sugar_cane +84: name "Jukebox", texture.all jukebox, texture.top jukebox_top diff --git a/community/frag.glsl b/community/frag.glsl new file mode 100644 index 00000000..25c93cce --- /dev/null +++ b/community/frag.glsl @@ -0,0 +1,17 @@ +#version 330 + +out vec4 fragColor; + +uniform sampler2DArray u_TextureArraySampler; + +in vec3 v_Position; +in vec3 v_TexCoords; +in float v_LightMultiplier; + +void main(void) { + vec4 textureColor = texture(u_TextureArraySampler, v_TexCoords); + if (textureColor.a < 0.5) { // discard if texel's alpha component is 0 (texel is transparent) + discard; + } + fragColor = textureColor * v_LightMultiplier; +} \ No newline at end of file diff --git a/community/hit.py b/community/hit.py new file mode 100644 index 00000000..88389510 --- /dev/null +++ b/community/hit.py @@ -0,0 +1,105 @@ +import math + +HIT_RANGE = 3 + +class Hit_ray: + def __init__(self, world, rotation, starting_position): + self.world = world + + # get the ray unit vector based on rotation angles + # sqrt(ux ^ 2 + uy ^ 2 + uz ^ 2) must always equal 1 + + self.vector = ( + math.cos(rotation[0]) * math.cos(rotation[1]), + math.sin(rotation[1]), + math.sin(rotation[0]) * math.cos(rotation[1])) + + # point position + self.position = list(starting_position) + + # block position in which point currently is + self.block = tuple(map(lambda x: int(round(x)), self.position)) + + # current distance the point has travelled + self.distance = 0 + + # 'check' and 'step' both return 'True' if something is hit, and 'False' if not + + def check(self, hit_callback, distance, current_block, next_block): + if self.world.get_block_number(next_block): + hit_callback(current_block, next_block) + return True + + else: + self.position = list(map(lambda x: self.position[x] + self.vector[x] * distance, range(3))) + + self.block = next_block + self.distance += distance + + return False + + def step(self, hit_callback): + bx, by, bz = self.block + + # point position relative to block centre + local_position = list(map(lambda x: self.position[x] - self.block[x], range(3))) + + # we don't want to deal with negatives, so remove the sign + # this is also cool because it means we don't need to take into account the sign of our ray vector + # we do need to remember which components were negative for later on, however + + sign = [1, 1, 1] # '1' for positive, '-1' for negative + absolute_vector = list(self.vector) + + for component in range(3): + if self.vector[component] < 0: + sign[component] = -1 + + absolute_vector[component] = -absolute_vector[component] + local_position[component] = -local_position[component] + + lx, ly, lz = local_position + vx, vy, vz = absolute_vector + + # calculate intersections + # I only detail the math for the first component (X) because the rest is pretty self-explanatory + + # ray line (passing through the point) r ≡ (x - lx) / vx = (y - ly) / lz = (z - lz) / vz (parametric equation) + + # +x face fx ≡ x = 0.5 (y & z can be any real number) + # r ∩ fx ≡ (0.5 - lx) / vx = (y - ly) / vy = (z - lz) / vz + + # x: x = 0.5 + # y: (y - ly) / vy = (0.5 - lx) / vx IFF y = (0.5 - lx) / vx * vy + ly + # z: (z - lz) / vz = (0.5 - lx) / vx IFF z = (0.5 - lx) / vx * vz + lz + + if vx: + x = 0.5 + y = (0.5 - lx) / vx * vy + ly + z = (0.5 - lx) / vx * vz + lz + + if y >= -0.5 and y <= 0.5 and z >= -0.5 and z <= 0.5: + distance = math.sqrt((x - lx) ** 2 + (y - ly) ** 2 + (z - lz) ** 2) + + # we can return straight away here + # if we intersect with one face, we know for a fact we're not intersecting with any of the others + + return self.check(hit_callback, distance, (bx, by, bz), (bx + sign[0], by, bz)) + + if vy: + x = (0.5 - ly) / vy * vx + lx + y = 0.5 + z = (0.5 - ly) / vy * vz + lz + + if x >= -0.5 and x <= 0.5 and z >= -0.5 and z <= 0.5: + distance = math.sqrt((x - lx) ** 2 + (y - ly) ** 2 + (z - lz) ** 2) + return self.check(hit_callback, distance, (bx, by, bz), (bx, by + sign[1], bz)) + + if vz: + x = (0.5 - lz) / vz * vx + lx + y = (0.5 - lz) / vz * vy + ly + z = 0.5 + + if x >= -0.5 and x <= 0.5 and y >= -0.5 and y <= 0.5: + distance = math.sqrt((x - lx) ** 2 + (y - ly) ** 2 + (z - lz) ** 2) + return self.check(hit_callback, distance, (bx, by, bz), (bx, by, bz + sign[2])) \ No newline at end of file diff --git a/community/main.py b/community/main.py new file mode 100644 index 00000000..07b1419f --- /dev/null +++ b/community/main.py @@ -0,0 +1,173 @@ +import math +import random +import pyglet + +pyglet.options["shadow_window"] = False +pyglet.options["debug_gl"] = False + +import pyglet.gl as gl + +import shader +import camera + + +import world + +import hit + +class Window(pyglet.window.Window): + def __init__(self, **args): + super().__init__(**args) + + # create shader + + self.shader = shader.Shader("vert.glsl", "frag.glsl") + self.shader_sampler_location = self.shader.find_uniform(b"u_TextureArraySampler") + self.shader.use() + + # pyglet stuff + + pyglet.clock.schedule(self.update) + self.mouse_captured = False + + # camera stuff + + self.camera = camera.Camera(self.shader, self.width, self.height) + + # create world + + self.world = world.World(self.camera) + + # misc stuff + + self.holding = 5 + + # bind textures + + gl.glActiveTexture(gl.GL_TEXTURE0) + gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.world.texture_manager.texture_array) + gl.glUniform1i(self.shader_sampler_location, 0) + + # enable cool stuff + + gl.glEnable(gl.GL_DEPTH_TEST) + gl.glEnable(gl.GL_CULL_FACE) + gl.glBlendFunc(gl.GL_SRC_COLOR, gl.GL_ONE_MINUS_SRC_COLOR) + + # Sync status: + self.status = gl.GL_CONDITION_SATISFIED + self.fence = gl.glFenceSync(gl.GL_SYNC_GPU_COMMANDS_COMPLETE, 0) + + def update(self, delta_time): + # print(pyglet.clock.get_fps()) + + if not self.mouse_captured: + self.camera.input = [0, 0, 0] + + self.camera.update_camera(delta_time) + + def on_draw(self): + self.camera.update_matrices() + + self.status = gl.glClientWaitSync(self.fence, gl.GL_SYNC_FLUSH_COMMANDS_BIT, 2985984) + gl.glDeleteSync(self.fence) + + gl.glClearColor(0.4, 0.7, 1.0, 1.0) + self.clear() + + self.world.draw() + + self.fence = gl.glFenceSync(gl.GL_SYNC_GPU_COMMANDS_COMPLETE, 0) + + + + # input functions + + def on_resize(self, width, height): + print(f"Resize {width} * {height}") + gl.glViewport(0, 0, width, height) + + self.camera.width = width + self.camera.height = height + + def on_mouse_press(self, x, y, button, modifiers): + if not self.mouse_captured: + self.mouse_captured = True + self.set_exclusive_mouse(True) + + return + + # handle breaking/placing blocks + + def hit_callback(current_block, next_block): + if button == pyglet.window.mouse.RIGHT: self.world.set_block(current_block, self.holding) + elif button == pyglet.window.mouse.LEFT: self.world.set_block(next_block, 0) + elif button == pyglet.window.mouse.MIDDLE: self.holding = self.world.get_block_number(next_block) + + hit_ray = hit.Hit_ray(self.world, self.camera.rotation, self.camera.position) + + while hit_ray.distance < hit.HIT_RANGE: + if hit_ray.step(hit_callback): + break + + def on_mouse_motion(self, x, y, delta_x, delta_y): + if self.mouse_captured: + sensitivity = 0.004 + + self.camera.rotation[0] += delta_x * sensitivity + self.camera.rotation[1] += delta_y * sensitivity + + self.camera.rotation[1] = max(-math.tau / 4, min(math.tau / 4, self.camera.rotation[1])) + + def on_mouse_drag(self, x, y, delta_x, delta_y, buttons, modifiers): + self.on_mouse_motion(x, y, delta_x, delta_y) + + def on_key_press(self, key, modifiers): + if not self.mouse_captured: + return + + if key == pyglet.window.key.D: self.camera.input[0] += 1 + elif key == pyglet.window.key.A: self.camera.input[0] -= 1 + elif key == pyglet.window.key.W: self.camera.input[2] += 1 + elif key == pyglet.window.key.S: self.camera.input[2] -= 1 + + elif key == pyglet.window.key.SPACE : self.camera.input[1] += 1 + elif key == pyglet.window.key.LSHIFT: self.camera.input[1] -= 1 + elif key == pyglet.window.key.LCTRL : self.camera.target_speed = camera.SPRINTING_SPEED + + elif key == pyglet.window.key.G: + self.holding = random.randint(1, len(self.world.block_types) - 1) + + elif key == pyglet.window.key.O: + self.world.save.save() + + elif key == pyglet.window.key.ESCAPE: + self.mouse_captured = False + self.set_exclusive_mouse(False) + + def on_key_release(self, key, modifiers): + if not self.mouse_captured: + return + + if key == pyglet.window.key.D: self.camera.input[0] -= 1 + elif key == pyglet.window.key.A: self.camera.input[0] += 1 + elif key == pyglet.window.key.W: self.camera.input[2] -= 1 + elif key == pyglet.window.key.S: self.camera.input[2] += 1 + + elif key == pyglet.window.key.SPACE : self.camera.input[1] -= 1 + elif key == pyglet.window.key.LSHIFT: self.camera.input[1] += 1 + elif key == pyglet.window.key.LCTRL : self.camera.target_speed = camera.WALKING_SPEED + +class Game: + def __init__(self): + self.config = gl.Config(double_buffer = True, + major_version = 3, minor_version = 3, + depth_size = 16) + self.window = Window(config = self.config, width = 854, height = 480, caption = "Minecraft clone", resizable = True, vsync = False) + + def run(self): + pyglet.app.run() + +if __name__ == "__main__": + game = Game() + game.run() diff --git a/community/matrix.py b/community/matrix.py new file mode 100644 index 00000000..7210217a --- /dev/null +++ b/community/matrix.py @@ -0,0 +1,138 @@ + +import copy +import math + +def copy_matrix(matrix): + return copy.deepcopy(matrix) # we need to use deepcopy since we're dealing with 2D arrays + +clean_matrix = [[0.0 for x in range(4)] for x in range(4)] +identity_matrix = copy_matrix(clean_matrix) + +identity_matrix[0][0] = 1.0 +identity_matrix[1][1] = 1.0 +identity_matrix[2][2] = 1.0 +identity_matrix[3][3] = 1.0 + +def multiply_matrices(x_matrix, y_matrix): + result_matrix = copy_matrix(clean_matrix) + + for i in range(4): + for j in range(4): + result_matrix[i][j] = \ + (x_matrix[0][j] * y_matrix[i][0]) + \ + (x_matrix[1][j] * y_matrix[i][1]) + \ + (x_matrix[2][j] * y_matrix[i][2]) + \ + (x_matrix[3][j] * y_matrix[i][3]) + + return result_matrix + +class Matrix: + def __init__(self, base = None): + if type(base) == Matrix: self.data = copy_matrix(base.data) + elif type(base) == list: self.data = copy_matrix(base) + else: self.data = copy_matrix(clean_matrix) + + def load_identity(self): + self.data = copy_matrix(identity_matrix) + + def __mul__(self, matrix): + return Matrix(multiply_matrices(self.data, matrix.data)) + + def __imul__(self, matrix): + self.data = multiply_matrices(self.data, matrix.data) + + def scale(self, x, y, z): + for i in range(4): self.data[0][i] *= x + for i in range(4): self.data[1][i] *= y + for i in range(4): self.data[2][i] *= z + + def translate(self, x, y, z): + for i in range(4): + self.data[3][i] = self.data[3][i] + (self.data[0][i] * x + self.data[1][i] * y + self.data[2][i] * z) + + def rotate(self, angle, x, y, z): + magnitude = math.sqrt(x * x + y * y + z * z) + + x /= -magnitude + y /= -magnitude + z /= -magnitude + + sin_angle = math.sin(angle) + cos_angle = math.cos(angle) + one_minus_cos = 1.0 - cos_angle + + xx = x * x + yy = y * y + zz = z * z + + xy = x * y + yz = y * z + zx = z * x + + xs = x * sin_angle + ys = y * sin_angle + zs = z * sin_angle + + rotation_matrix = copy_matrix(clean_matrix) + + rotation_matrix[0][0] = (one_minus_cos * xx) + cos_angle + rotation_matrix[0][1] = (one_minus_cos * xy) - zs + rotation_matrix[0][2] = (one_minus_cos * zx) + ys + + rotation_matrix[1][0] = (one_minus_cos * xy) + zs + rotation_matrix[1][1] = (one_minus_cos * yy) + cos_angle + rotation_matrix[1][2] = (one_minus_cos * yz) - xs + + rotation_matrix[2][0] = (one_minus_cos * zx) - ys + rotation_matrix[2][1] = (one_minus_cos * yz) + xs + rotation_matrix[2][2] = (one_minus_cos * zz) + cos_angle + + rotation_matrix[3][3] = 1.0 + self.data = multiply_matrices(self.data, rotation_matrix) + + def rotate_2d(self, x, y): + self.rotate(x, 0, 1.0, 0) + self.rotate(-y, math.cos(x), 0, math.sin(x)) + + def frustum(self, left, right, bottom, top, near, far): + deltax = right - left + deltay = top - bottom + deltaz = far - near + + frustum_matrix = copy_matrix(clean_matrix) + + frustum_matrix[0][0] = 2 * near / deltax + frustum_matrix[1][1] = 2 * near / deltay + + frustum_matrix[2][0] = (right + left) / deltax + frustum_matrix[2][1] = (top + bottom) / deltay + frustum_matrix[2][2] = -(near + far) / deltaz + + frustum_matrix[2][3] = -1.0 + frustum_matrix[3][2] = -2 * near * far / deltaz + + self.data = multiply_matrices(self.data, frustum_matrix) + + def perspective(self, fovy, aspect, near, far): + frustum_y = math.tan(math.radians(fovy) / 2) + frustum_x = frustum_y * aspect + + self.frustum(-frustum_x * near, frustum_x * near, -frustum_y * near, frustum_y * near, near, far) + + def orthographic(self, left, right, bottom, top, near, far): + deltax = right - left + deltay = top - bottom + deltaz = far - near + + orthographic_matrix = copy_matrix(identity_matrix) + + orthographic_matrix[0][0] = 2.0 / deltax + orthographic_matrix[3][0] = -(right + left) / deltax + + orthographic_matrix[1][1] = 2.0 / deltay + orthographic_matrix[3][1] = -(top + bottom) / deltay + + orthographic_matrix[2][2] = 2.0 / deltax + orthographic_matrix[3][2] = -(near + far) / deltaz + + self.data = multiply_matrices(self.data, orthographic_matrix) diff --git a/community/models/__init__.py b/community/models/__init__.py new file mode 100644 index 00000000..2de92c17 --- /dev/null +++ b/community/models/__init__.py @@ -0,0 +1,27 @@ +# all possible models + +__all__ = [ + "cube", + "plant", + "liquid", + "leaves", + "glass", + "slab", + "torch", + "fire", + "stairs", + "flat", + "crop", + "soil", + "sign_post", + "door", + "ladder", + "sign", + "lever", + "pressure_plate", + "button", + "snow", + "cactus", +] + +from . import * \ No newline at end of file diff --git a/community/models/button.py b/community/models/button.py new file mode 100644 index 00000000..cec02833 --- /dev/null +++ b/community/models/button.py @@ -0,0 +1,31 @@ +translucent = False +transparent = True +is_cube = False +glass = False + +vertex_positions = [ + [ 0.5, 0.0, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.0, -0.5], # right + [-0.5, 0.0, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.0, 0.5], # left + [ 0.5, 0.0, 0.5, 0.5, 0.0, -0.5, -0.5, 0.0, -0.5, -0.5, 0.0, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.0, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.0, 0.5], # front + [ 0.5, 0.0, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.0, -0.5], # back +] + +tex_coords = [ + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/cactus.py b/community/models/cactus.py new file mode 100644 index 00000000..b049b4fb --- /dev/null +++ b/community/models/cactus.py @@ -0,0 +1,31 @@ +translucent = False +transparent = True +is_cube = False +glass = False + +vertex_positions = [ + [ 0.4375, 0.5000, 0.5000, 0.4375, -0.5000, 0.5000, 0.4375, -0.5000, -0.5000, 0.4375, 0.5000, -0.5000], # right + [-0.4375, 0.5000, -0.5000, -0.4375, -0.5000, -0.5000, -0.4375, -0.5000, 0.5000, -0.4375, 0.5000, 0.5000], # left + [ 0.5000, 0.5000, 0.5000, 0.5000, 0.5000, -0.5000, -0.5000, 0.5000, -0.5000, -0.5000, 0.5000, 0.5000], # top + [-0.5000, -0.5000, 0.5000, -0.5000, -0.5000, -0.5000, 0.5000, -0.5000, -0.5000, 0.5000, -0.5000, 0.5000], # bottom + [-0.5000, 0.5000, 0.4375, -0.5000, -0.5000, 0.4375, 0.5000, -0.5000, 0.4375, 0.5000, 0.5000, 0.4375], # front + [ 0.5000, 0.5000, -0.4375, 0.5000, -0.5000, -0.4375, -0.5000, -0.5000, -0.4375, -0.5000, 0.5000, -0.4375], # back +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/crop.py b/community/models/crop.py new file mode 100644 index 00000000..fd377819 --- /dev/null +++ b/community/models/crop.py @@ -0,0 +1,37 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.25, 0.4375, 0.50, 0.25, -0.5625, 0.50, 0.25, -0.5625, -0.50, 0.25, 0.4375, -0.50], # right + [ 0.25, 0.4375, -0.50, 0.25, -0.5625, -0.50, 0.25, -0.5625, 0.50, 0.25, 0.4375, 0.50], # right + [-0.25, 0.4375, -0.50, -0.25, -0.5625, -0.50, -0.25, -0.5625, 0.50, -0.25, 0.4375, 0.50], # left + [-0.25, 0.4375, 0.50, -0.25, -0.5625, 0.50, -0.25, -0.5625, -0.50, -0.25, 0.4375, -0.50], # left + [-0.50, 0.4375, 0.25, -0.50, -0.5625, 0.25, 0.50, -0.5625, 0.25, 0.50, 0.4375, 0.25], # front + [ 0.50, 0.4375, 0.25, 0.50, -0.5625, 0.25, -0.50, -0.5625, 0.25, -0.50, 0.4375, 0.25], # front + [ 0.50, 0.4375, -0.25, 0.50, -0.5625, -0.25, -0.50, -0.5625, -0.25, -0.50, 0.4375, -0.25], # back + [-0.50, 0.4375, -0.25, -0.50, -0.5625, -0.25, 0.50, -0.5625, -0.25, 0.50, 0.4375, -0.25], # back +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/cube.py b/community/models/cube.py new file mode 100644 index 00000000..e80d6a75 --- /dev/null +++ b/community/models/cube.py @@ -0,0 +1,32 @@ +transparent = False +is_cube = True +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5], # right + [-0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5], # left + [ 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5], # front + [ 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5], # back +] + +# Deprecating +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/door.py b/community/models/door.py new file mode 100644 index 00000000..184033fc --- /dev/null +++ b/community/models/door.py @@ -0,0 +1,31 @@ +transparent = False +is_cube = True +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5], # right + [-0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5], # left + [ 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5], # front + [ 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5], # back +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/fire.py b/community/models/fire.py new file mode 100644 index 00000000..a80d50c2 --- /dev/null +++ b/community/models/fire.py @@ -0,0 +1,25 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [-0.3536, 0.5000, 0.3536, -0.3536, -0.5000, 0.3536, 0.3536, -0.5000, -0.3536, 0.3536, 0.5000, -0.3536], + [-0.3536, 0.5000, -0.3536, -0.3536, -0.5000, -0.3536, 0.3536, -0.5000, 0.3536, 0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, -0.3536, 0.3536, -0.5000, -0.3536, -0.3536, -0.5000, 0.3536, -0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, 0.3536, 0.3536, -0.5000, 0.3536, -0.3536, -0.5000, -0.3536, -0.3536, 0.5000, -0.3536], +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], +] \ No newline at end of file diff --git a/community/models/flat.py b/community/models/flat.py new file mode 100644 index 00000000..d25ecd9f --- /dev/null +++ b/community/models/flat.py @@ -0,0 +1,19 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, -0.4375, 0.5, 0.5, -0.4375, -0.5, -0.5, -0.4375, -0.5, -0.5, -0.4375, 0.5], # top + [-0.5, -0.4375, 0.5, -0.5, -0.4375, -0.5, 0.5, -0.4375, -0.5, 0.5, -0.4375, 0.5], # bottom +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], +] \ No newline at end of file diff --git a/community/models/glass.py b/community/models/glass.py new file mode 100644 index 00000000..9c0f6df6 --- /dev/null +++ b/community/models/glass.py @@ -0,0 +1,31 @@ +transparent = True +is_cube = True +glass = True +translucent = False + +vertex_positions = [ + [ 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5], # right + [-0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5], # left + [ 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5], # front + [ 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5], # back +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/ladder.py b/community/models/ladder.py new file mode 100644 index 00000000..a80d50c2 --- /dev/null +++ b/community/models/ladder.py @@ -0,0 +1,25 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [-0.3536, 0.5000, 0.3536, -0.3536, -0.5000, 0.3536, 0.3536, -0.5000, -0.3536, 0.3536, 0.5000, -0.3536], + [-0.3536, 0.5000, -0.3536, -0.3536, -0.5000, -0.3536, 0.3536, -0.5000, 0.3536, 0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, -0.3536, 0.3536, -0.5000, -0.3536, -0.3536, -0.5000, 0.3536, -0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, 0.3536, 0.3536, -0.5000, 0.3536, -0.3536, -0.5000, -0.3536, -0.3536, 0.5000, -0.3536], +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], +] \ No newline at end of file diff --git a/community/models/leaves.py b/community/models/leaves.py new file mode 100644 index 00000000..dfc86c88 --- /dev/null +++ b/community/models/leaves.py @@ -0,0 +1,31 @@ +transparent = True +is_cube = True +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5], # right + [-0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5], # left + [ 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5], # front + [ 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5], # back +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/lever.py b/community/models/lever.py new file mode 100644 index 00000000..66257452 --- /dev/null +++ b/community/models/lever.py @@ -0,0 +1,31 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, 0.0, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.0, -0.5], # right + [-0.5, 0.0, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.0, 0.5], # left + [ 0.5, 0.0, 0.5, 0.5, 0.0, -0.5, -0.5, 0.0, -0.5, -0.5, 0.0, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.0, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.0, 0.5], # front + [ 0.5, 0.0, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.0, -0.5], # back +] + +tex_coords = [ + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/liquid.py b/community/models/liquid.py new file mode 100644 index 00000000..1af2b4d6 --- /dev/null +++ b/community/models/liquid.py @@ -0,0 +1,43 @@ +# in the end, it'd be nice to have it so that liquids fill up the whole block when they have a block above them +# this would avoid the problems this solution has + +translucent = True +transparent = True +is_cube = True +glass = True + +vertex_positions = [ + [ 0.500, 0.375, 0.500, 0.500, -0.625, 0.500, 0.500, -0.625, -0.500, 0.500, 0.375, -0.500], # right + [-0.500, 0.375, -0.500, -0.500, -0.625, -0.500, -0.500, -0.625, 0.500, -0.500, 0.375, 0.500], # left + [ 0.500, 0.375, 0.500, 0.500, 0.375, -0.500, -0.500, 0.375, -0.500, -0.500, 0.375, 0.500], # top + [-0.500, -0.625, 0.500, -0.500, -0.625, -0.500, 0.500, -0.625, -0.500, 0.500, -0.625, 0.500], # bottom + [-0.500, 0.375, 0.500, -0.500, -0.625, 0.500, 0.500, -0.625, 0.500, 0.500, 0.375, 0.500], # front + [ 0.500, 0.375, -0.500, 0.500, -0.625, -0.500, -0.500, -0.625, -0.500, -0.500, 0.375, -0.500], # back +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] + +_shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0] +] \ No newline at end of file diff --git a/community/models/plant.py b/community/models/plant.py new file mode 100644 index 00000000..a80d50c2 --- /dev/null +++ b/community/models/plant.py @@ -0,0 +1,25 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [-0.3536, 0.5000, 0.3536, -0.3536, -0.5000, 0.3536, 0.3536, -0.5000, -0.3536, 0.3536, 0.5000, -0.3536], + [-0.3536, 0.5000, -0.3536, -0.3536, -0.5000, -0.3536, 0.3536, -0.5000, 0.3536, 0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, -0.3536, 0.3536, -0.5000, -0.3536, -0.3536, -0.5000, 0.3536, -0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, 0.3536, 0.3536, -0.5000, 0.3536, -0.3536, -0.5000, -0.3536, -0.3536, 0.5000, -0.3536], +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], +] \ No newline at end of file diff --git a/community/models/pressure_plate.py b/community/models/pressure_plate.py new file mode 100644 index 00000000..d25ecd9f --- /dev/null +++ b/community/models/pressure_plate.py @@ -0,0 +1,19 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, -0.4375, 0.5, 0.5, -0.4375, -0.5, -0.5, -0.4375, -0.5, -0.5, -0.4375, 0.5], # top + [-0.5, -0.4375, 0.5, -0.5, -0.4375, -0.5, 0.5, -0.4375, -0.5, 0.5, -0.4375, 0.5], # bottom +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], +] \ No newline at end of file diff --git a/community/models/sign.py b/community/models/sign.py new file mode 100644 index 00000000..a80d50c2 --- /dev/null +++ b/community/models/sign.py @@ -0,0 +1,25 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [-0.3536, 0.5000, 0.3536, -0.3536, -0.5000, 0.3536, 0.3536, -0.5000, -0.3536, 0.3536, 0.5000, -0.3536], + [-0.3536, 0.5000, -0.3536, -0.3536, -0.5000, -0.3536, 0.3536, -0.5000, 0.3536, 0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, -0.3536, 0.3536, -0.5000, -0.3536, -0.3536, -0.5000, 0.3536, -0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, 0.3536, 0.3536, -0.5000, 0.3536, -0.3536, -0.5000, -0.3536, -0.3536, 0.5000, -0.3536], +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], +] \ No newline at end of file diff --git a/community/models/sign_post.py b/community/models/sign_post.py new file mode 100644 index 00000000..a80d50c2 --- /dev/null +++ b/community/models/sign_post.py @@ -0,0 +1,25 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [-0.3536, 0.5000, 0.3536, -0.3536, -0.5000, 0.3536, 0.3536, -0.5000, -0.3536, 0.3536, 0.5000, -0.3536], + [-0.3536, 0.5000, -0.3536, -0.3536, -0.5000, -0.3536, 0.3536, -0.5000, 0.3536, 0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, -0.3536, 0.3536, -0.5000, -0.3536, -0.3536, -0.5000, 0.3536, -0.3536, 0.5000, 0.3536], + [ 0.3536, 0.5000, 0.3536, 0.3536, -0.5000, 0.3536, -0.3536, -0.5000, -0.3536, -0.3536, 0.5000, -0.3536], +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], + [1.0, 1.0, 1.0, 1.0], +] \ No newline at end of file diff --git a/community/models/slab.py b/community/models/slab.py new file mode 100644 index 00000000..66257452 --- /dev/null +++ b/community/models/slab.py @@ -0,0 +1,31 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, 0.0, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.0, -0.5], # right + [-0.5, 0.0, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.0, 0.5], # left + [ 0.5, 0.0, 0.5, 0.5, 0.0, -0.5, -0.5, 0.0, -0.5, -0.5, 0.0, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.0, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.0, 0.5], # front + [ 0.5, 0.0, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.0, -0.5], # back +] + +tex_coords = [ + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/snow.py b/community/models/snow.py new file mode 100644 index 00000000..d25ecd9f --- /dev/null +++ b/community/models/snow.py @@ -0,0 +1,19 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, -0.4375, 0.5, 0.5, -0.4375, -0.5, -0.5, -0.4375, -0.5, -0.5, -0.4375, 0.5], # top + [-0.5, -0.4375, 0.5, -0.5, -0.4375, -0.5, 0.5, -0.4375, -0.5, 0.5, -0.4375, 0.5], # bottom +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], +] \ No newline at end of file diff --git a/community/models/soil.py b/community/models/soil.py new file mode 100644 index 00000000..af5bb98a --- /dev/null +++ b/community/models/soil.py @@ -0,0 +1,31 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, 0.4375, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.4375, -0.5], # right + [-0.5, 0.4375, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.4375, 0.5], # left + [ 0.5, 0.4375, 0.5, 0.5, 0.4375, -0.5, -0.5, 0.4375, -0.5, -0.5, 0.4375, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.4375, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.4375, 0.5], # front + [ 0.5, 0.4375, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.4375, -0.5], # back +] + +tex_coords = [ + [0.0, 0.9375, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.9375, 0.0], + [0.0, 0.9375, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.9375, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 0.9375, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.9375, 0.0], + [0.0, 0.9375, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.9375, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/stairs.py b/community/models/stairs.py new file mode 100644 index 00000000..66257452 --- /dev/null +++ b/community/models/stairs.py @@ -0,0 +1,31 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.5, 0.0, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.0, -0.5], # right + [-0.5, 0.0, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.0, 0.5], # left + [ 0.5, 0.0, 0.5, 0.5, 0.0, -0.5, -0.5, 0.0, -0.5, -0.5, 0.0, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.0, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.0, 0.5], # front + [ 0.5, 0.0, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.0, -0.5], # back +] + +tex_coords = [ + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], + [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] \ No newline at end of file diff --git a/community/models/torch.py b/community/models/torch.py new file mode 100644 index 00000000..75239771 --- /dev/null +++ b/community/models/torch.py @@ -0,0 +1,31 @@ +transparent = True +is_cube = False +glass = False +translucent = False + +vertex_positions = [ + [ 0.0625, 0.5, 0.5, 0.0625, -0.5, 0.5, 0.0625, -0.5, -0.5, 0.0625, 0.5, -0.5], # right + [-0.0625, 0.5, -0.5, -0.0625, -0.5, -0.5, -0.0625, -0.5, 0.5, -0.0625, 0.5, 0.5], # left + [ 0.5, 0.125, 0.5, 0.5, 0.125, -0.5, -0.5, 0.125, -0.5, -0.5, 0.125, 0.5], # top + [-0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5], # bottom + [-0.5, 0.5, 0.0625, -0.5, -0.5, 0.0625, 0.5, -0.5, 0.0625, 0.5, 0.5, 0.0625], # front + [ 0.5, 0.5, -0.0625, 0.5, -0.5, -0.0625, -0.5, -0.5, -0.0625, -0.5, 0.5, -0.0625], # back +] + +tex_coords = [ + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0], +] + +shading_values = [ + [0.6, 0.6, 0.6, 0.6], + [0.6, 0.6, 0.6, 0.6], + [1.0, 1.0, 1.0, 1.0], + [0.4, 0.4, 0.4, 0.4], + [0.8, 0.8, 0.8, 0.8], + [0.8, 0.8, 0.8, 0.8], +] diff --git a/community/options.py b/community/options.py new file mode 100644 index 00000000..2f12f1f5 --- /dev/null +++ b/community/options.py @@ -0,0 +1,7 @@ +# FAST = 0; FANCY = 1 +import pyglet.gl as gl + + +TRANSLUCENT_BLENDING = 1 +ALTERNATE_BLOCKS = False # True is in WIP +MIPMAP_TYPE = gl.GL_LINEAR_MIPMAP_LINEAR \ No newline at end of file diff --git a/community/render_region.py b/community/render_region.py new file mode 100644 index 00000000..fb068ecb --- /dev/null +++ b/community/render_region.py @@ -0,0 +1,13 @@ +import chunk + +# Work in Progress # + +import pyglet.gl as gl + +class RenderRegion: + def __init__(self, chunks): + self.chunks = chunks + def build_draw_batch(): + pass + def draw(): + gl.glMultiDrawElementsBaseVertex() \ No newline at end of file diff --git a/community/save.py b/community/save.py new file mode 100644 index 00000000..6fe61755 --- /dev/null +++ b/community/save.py @@ -0,0 +1,95 @@ +import nbtlib as nbt +import base36 + +import chunk + +class Save: + def __init__(self, world, path = "save"): + self.world = world + self.path = path + + def chunk_position_to_path(self, chunk_position): + x, y, z = chunk_position + + chunk_path = '/'.join((self.path, + base36.dumps(x % 64), base36.dumps(z % 64), + f"c.{base36.dumps(x)}.{base36.dumps(z)}.dat")) + + return chunk_path + + def load_chunk(self, chunk_position): + # load the chunk file + + chunk_path = self.chunk_position_to_path(chunk_position) + + try: + chunk_blocks = nbt.load(chunk_path)["Level"]["Blocks"] + + except FileNotFoundError: + return + + # create chunk and fill it with the blocks from our chunk file + + self.world.chunks[chunk_position] = chunk.Chunk(self.world, chunk_position) + + for x in range(chunk.CHUNK_WIDTH): + for y in range(chunk.CHUNK_HEIGHT): + for z in range(chunk.CHUNK_LENGTH): + self.world.chunks[chunk_position].blocks[x][y][z] = chunk_blocks[ + x * chunk.CHUNK_LENGTH * chunk.CHUNK_HEIGHT + + z * chunk.CHUNK_HEIGHT + + y] + + def save_chunk(self, chunk_position): + x, y, z = chunk_position + + # try to load the chunk file + # if it doesn't exist, create a new one + + chunk_path = self.chunk_position_to_path(chunk_position) + + try: + chunk_data = nbt.load(chunk_path) + + except FileNotFoundError: + chunk_data = nbt.File({"": nbt.Compound({"Level": nbt.Compound()})}) + + chunk_data["Level"]["xPos"] = x + chunk_data["Level"]["zPos"] = z + + # fill the chunk file with the blocks from our chunk + + chunk_blocks = nbt.ByteArray([0] * (chunk.CHUNK_WIDTH * chunk.CHUNK_HEIGHT * chunk.CHUNK_LENGTH)) + + for x in range(chunk.CHUNK_WIDTH): + for y in range(chunk.CHUNK_HEIGHT): + for z in range(chunk.CHUNK_LENGTH): + chunk_blocks[ + x * chunk.CHUNK_LENGTH * chunk.CHUNK_HEIGHT + + z * chunk.CHUNK_HEIGHT + + y] = self.world.chunks[chunk_position].blocks[x][y][z] + + # save the chunk file + + chunk_data["Level"]["Blocks"] = chunk_blocks + chunk_data.save(chunk_path, gzipped = True) + + def load(self): + # for x in range(-1, 15): + # for y in range(-15, 1): + # self.load_chunk((x, y)) + + for x in range(-4, 4): + for y in range(-4, 4): + self.load_chunk((x, 0, y)) + + def save(self): + for chunk_position in self.world.chunks: + if chunk_position[1] != 0: # reject all chunks above and below the world limit + continue + + chunk = self.world.chunks[chunk_position] + + if chunk.modified: + self.save_chunk(chunk_position) + chunk.modified = False diff --git a/community/save/0/0/c.0.0.dat b/community/save/0/0/c.0.0.dat new file mode 100644 index 00000000..bc537027 Binary files /dev/null and b/community/save/0/0/c.0.0.dat differ diff --git a/community/save/0/1/c.0.1.dat b/community/save/0/1/c.0.1.dat new file mode 100644 index 00000000..3c7f8acc Binary files /dev/null and b/community/save/0/1/c.0.1.dat differ diff --git a/community/save/0/1o/c.0.-4.dat b/community/save/0/1o/c.0.-4.dat new file mode 100644 index 00000000..d840026b Binary files /dev/null and b/community/save/0/1o/c.0.-4.dat differ diff --git a/community/save/0/1p/c.0.-3.dat b/community/save/0/1p/c.0.-3.dat new file mode 100644 index 00000000..f1210d2e Binary files /dev/null and b/community/save/0/1p/c.0.-3.dat differ diff --git a/community/save/0/1q/c.0.-2.dat b/community/save/0/1q/c.0.-2.dat new file mode 100644 index 00000000..1d0f5490 Binary files /dev/null and b/community/save/0/1q/c.0.-2.dat differ diff --git a/community/save/0/1r/c.0.-1.dat b/community/save/0/1r/c.0.-1.dat new file mode 100644 index 00000000..c894eeed Binary files /dev/null and b/community/save/0/1r/c.0.-1.dat differ diff --git a/community/save/0/2/c.0.2.dat b/community/save/0/2/c.0.2.dat new file mode 100644 index 00000000..29d57ca6 Binary files /dev/null and b/community/save/0/2/c.0.2.dat differ diff --git a/community/save/0/3/c.0.3.dat b/community/save/0/3/c.0.3.dat new file mode 100644 index 00000000..69d837c0 Binary files /dev/null and b/community/save/0/3/c.0.3.dat differ diff --git a/community/save/1/0/c.1.0.dat b/community/save/1/0/c.1.0.dat new file mode 100644 index 00000000..cbd8002e Binary files /dev/null and b/community/save/1/0/c.1.0.dat differ diff --git a/community/save/1/1/c.1.1.dat b/community/save/1/1/c.1.1.dat new file mode 100644 index 00000000..ab84ceb0 Binary files /dev/null and b/community/save/1/1/c.1.1.dat differ diff --git a/community/save/1/1o/c.1.-4.dat b/community/save/1/1o/c.1.-4.dat new file mode 100644 index 00000000..bf48008f Binary files /dev/null and b/community/save/1/1o/c.1.-4.dat differ diff --git a/community/save/1/1p/c.1.-3.dat b/community/save/1/1p/c.1.-3.dat new file mode 100644 index 00000000..f4a072cd Binary files /dev/null and b/community/save/1/1p/c.1.-3.dat differ diff --git a/community/save/1/1q/c.1.-2.dat b/community/save/1/1q/c.1.-2.dat new file mode 100644 index 00000000..962b0c3c Binary files /dev/null and b/community/save/1/1q/c.1.-2.dat differ diff --git a/community/save/1/1r/c.1.-1.dat b/community/save/1/1r/c.1.-1.dat new file mode 100644 index 00000000..d83ae71f Binary files /dev/null and b/community/save/1/1r/c.1.-1.dat differ diff --git a/community/save/1/2/c.1.2.dat b/community/save/1/2/c.1.2.dat new file mode 100644 index 00000000..9132f761 Binary files /dev/null and b/community/save/1/2/c.1.2.dat differ diff --git a/community/save/1/3/c.1.3.dat b/community/save/1/3/c.1.3.dat new file mode 100644 index 00000000..e15c80bc Binary files /dev/null and b/community/save/1/3/c.1.3.dat differ diff --git a/community/save/1o/0/c.-4.0.dat b/community/save/1o/0/c.-4.0.dat new file mode 100644 index 00000000..5e4c9645 Binary files /dev/null and b/community/save/1o/0/c.-4.0.dat differ diff --git a/community/save/1o/1/c.-4.1.dat b/community/save/1o/1/c.-4.1.dat new file mode 100644 index 00000000..cb228884 Binary files /dev/null and b/community/save/1o/1/c.-4.1.dat differ diff --git a/community/save/1o/1o/c.-4.-4.dat b/community/save/1o/1o/c.-4.-4.dat new file mode 100644 index 00000000..63c9b6d1 Binary files /dev/null and b/community/save/1o/1o/c.-4.-4.dat differ diff --git a/community/save/1o/1p/c.-4.-3.dat b/community/save/1o/1p/c.-4.-3.dat new file mode 100644 index 00000000..e83bd868 Binary files /dev/null and b/community/save/1o/1p/c.-4.-3.dat differ diff --git a/community/save/1o/1q/c.-4.-2.dat b/community/save/1o/1q/c.-4.-2.dat new file mode 100644 index 00000000..2e6901dc Binary files /dev/null and b/community/save/1o/1q/c.-4.-2.dat differ diff --git a/community/save/1o/1r/c.-4.-1.dat b/community/save/1o/1r/c.-4.-1.dat new file mode 100644 index 00000000..4fa7a7bc Binary files /dev/null and b/community/save/1o/1r/c.-4.-1.dat differ diff --git a/community/save/1o/2/c.-4.2.dat b/community/save/1o/2/c.-4.2.dat new file mode 100644 index 00000000..533d78f1 Binary files /dev/null and b/community/save/1o/2/c.-4.2.dat differ diff --git a/community/save/1o/3/c.-4.3.dat b/community/save/1o/3/c.-4.3.dat new file mode 100644 index 00000000..bde272ba Binary files /dev/null and b/community/save/1o/3/c.-4.3.dat differ diff --git a/community/save/1p/0/c.-3.0.dat b/community/save/1p/0/c.-3.0.dat new file mode 100644 index 00000000..549461da Binary files /dev/null and b/community/save/1p/0/c.-3.0.dat differ diff --git a/community/save/1p/1/c.-3.1.dat b/community/save/1p/1/c.-3.1.dat new file mode 100644 index 00000000..074d25b7 Binary files /dev/null and b/community/save/1p/1/c.-3.1.dat differ diff --git a/community/save/1p/1o/c.-3.-4.dat b/community/save/1p/1o/c.-3.-4.dat new file mode 100644 index 00000000..c9a6d415 Binary files /dev/null and b/community/save/1p/1o/c.-3.-4.dat differ diff --git a/community/save/1p/1p/c.-3.-3.dat b/community/save/1p/1p/c.-3.-3.dat new file mode 100644 index 00000000..b57847d6 Binary files /dev/null and b/community/save/1p/1p/c.-3.-3.dat differ diff --git a/community/save/1p/1q/c.-3.-2.dat b/community/save/1p/1q/c.-3.-2.dat new file mode 100644 index 00000000..c298dcb1 Binary files /dev/null and b/community/save/1p/1q/c.-3.-2.dat differ diff --git a/community/save/1p/1r/c.-3.-1.dat b/community/save/1p/1r/c.-3.-1.dat new file mode 100644 index 00000000..738fcacf Binary files /dev/null and b/community/save/1p/1r/c.-3.-1.dat differ diff --git a/community/save/1p/2/c.-3.2.dat b/community/save/1p/2/c.-3.2.dat new file mode 100644 index 00000000..d27fe8c0 Binary files /dev/null and b/community/save/1p/2/c.-3.2.dat differ diff --git a/community/save/1p/3/c.-3.3.dat b/community/save/1p/3/c.-3.3.dat new file mode 100644 index 00000000..bec68c2c Binary files /dev/null and b/community/save/1p/3/c.-3.3.dat differ diff --git a/community/save/1q/0/c.-2.0.dat b/community/save/1q/0/c.-2.0.dat new file mode 100644 index 00000000..2a0f9d68 Binary files /dev/null and b/community/save/1q/0/c.-2.0.dat differ diff --git a/community/save/1q/1/c.-2.1.dat b/community/save/1q/1/c.-2.1.dat new file mode 100644 index 00000000..1045f76a Binary files /dev/null and b/community/save/1q/1/c.-2.1.dat differ diff --git a/community/save/1q/1o/c.-2.-4.dat b/community/save/1q/1o/c.-2.-4.dat new file mode 100644 index 00000000..ef51a50a Binary files /dev/null and b/community/save/1q/1o/c.-2.-4.dat differ diff --git a/community/save/1q/1p/c.-2.-3.dat b/community/save/1q/1p/c.-2.-3.dat new file mode 100644 index 00000000..ec6aa86f Binary files /dev/null and b/community/save/1q/1p/c.-2.-3.dat differ diff --git a/community/save/1q/1q/c.-2.-2.dat b/community/save/1q/1q/c.-2.-2.dat new file mode 100644 index 00000000..61d07f6d Binary files /dev/null and b/community/save/1q/1q/c.-2.-2.dat differ diff --git a/community/save/1q/1r/c.-2.-1.dat b/community/save/1q/1r/c.-2.-1.dat new file mode 100644 index 00000000..5516a354 Binary files /dev/null and b/community/save/1q/1r/c.-2.-1.dat differ diff --git a/community/save/1q/2/c.-2.2.dat b/community/save/1q/2/c.-2.2.dat new file mode 100644 index 00000000..db26b75a Binary files /dev/null and b/community/save/1q/2/c.-2.2.dat differ diff --git a/community/save/1q/3/c.-2.3.dat b/community/save/1q/3/c.-2.3.dat new file mode 100644 index 00000000..9a2d3fb1 Binary files /dev/null and b/community/save/1q/3/c.-2.3.dat differ diff --git a/community/save/1r/0/c.-1.0.dat b/community/save/1r/0/c.-1.0.dat new file mode 100644 index 00000000..3c1d0631 Binary files /dev/null and b/community/save/1r/0/c.-1.0.dat differ diff --git a/community/save/1r/1/c.-1.1.dat b/community/save/1r/1/c.-1.1.dat new file mode 100644 index 00000000..9254e9ad Binary files /dev/null and b/community/save/1r/1/c.-1.1.dat differ diff --git a/community/save/1r/1o/c.-1.-4.dat b/community/save/1r/1o/c.-1.-4.dat new file mode 100644 index 00000000..e113e918 Binary files /dev/null and b/community/save/1r/1o/c.-1.-4.dat differ diff --git a/community/save/1r/1p/c.-1.-3.dat b/community/save/1r/1p/c.-1.-3.dat new file mode 100644 index 00000000..2ab9f0c0 Binary files /dev/null and b/community/save/1r/1p/c.-1.-3.dat differ diff --git a/community/save/1r/1q/c.-1.-2.dat b/community/save/1r/1q/c.-1.-2.dat new file mode 100644 index 00000000..2a597b55 Binary files /dev/null and b/community/save/1r/1q/c.-1.-2.dat differ diff --git a/community/save/1r/1r/c.-1.-1.dat b/community/save/1r/1r/c.-1.-1.dat new file mode 100644 index 00000000..83d36a09 Binary files /dev/null and b/community/save/1r/1r/c.-1.-1.dat differ diff --git a/community/save/1r/2/c.-1.2.dat b/community/save/1r/2/c.-1.2.dat new file mode 100644 index 00000000..7db9d2f1 Binary files /dev/null and b/community/save/1r/2/c.-1.2.dat differ diff --git a/community/save/1r/3/c.-1.3.dat b/community/save/1r/3/c.-1.3.dat new file mode 100644 index 00000000..51ac8873 Binary files /dev/null and b/community/save/1r/3/c.-1.3.dat differ diff --git a/community/save/2/0/c.2.0.dat b/community/save/2/0/c.2.0.dat new file mode 100644 index 00000000..35ca0883 Binary files /dev/null and b/community/save/2/0/c.2.0.dat differ diff --git a/community/save/2/1/c.2.1.dat b/community/save/2/1/c.2.1.dat new file mode 100644 index 00000000..38098181 Binary files /dev/null and b/community/save/2/1/c.2.1.dat differ diff --git a/community/save/2/1o/c.2.-4.dat b/community/save/2/1o/c.2.-4.dat new file mode 100644 index 00000000..ec2b75f5 Binary files /dev/null and b/community/save/2/1o/c.2.-4.dat differ diff --git a/community/save/2/1p/c.2.-3.dat b/community/save/2/1p/c.2.-3.dat new file mode 100644 index 00000000..e2543c4b Binary files /dev/null and b/community/save/2/1p/c.2.-3.dat differ diff --git a/community/save/2/1q/c.2.-2.dat b/community/save/2/1q/c.2.-2.dat new file mode 100644 index 00000000..d78bded0 Binary files /dev/null and b/community/save/2/1q/c.2.-2.dat differ diff --git a/community/save/2/1r/c.2.-1.dat b/community/save/2/1r/c.2.-1.dat new file mode 100644 index 00000000..77f7311c Binary files /dev/null and b/community/save/2/1r/c.2.-1.dat differ diff --git a/community/save/2/2/c.2.2.dat b/community/save/2/2/c.2.2.dat new file mode 100644 index 00000000..8bc0fc85 Binary files /dev/null and b/community/save/2/2/c.2.2.dat differ diff --git a/community/save/2/3/c.2.3.dat b/community/save/2/3/c.2.3.dat new file mode 100644 index 00000000..fd08a54f Binary files /dev/null and b/community/save/2/3/c.2.3.dat differ diff --git a/community/save/3/0/c.3.0.dat b/community/save/3/0/c.3.0.dat new file mode 100644 index 00000000..5d50c087 Binary files /dev/null and b/community/save/3/0/c.3.0.dat differ diff --git a/community/save/3/1/c.3.1.dat b/community/save/3/1/c.3.1.dat new file mode 100644 index 00000000..bc472fc3 Binary files /dev/null and b/community/save/3/1/c.3.1.dat differ diff --git a/community/save/3/1o/c.3.-4.dat b/community/save/3/1o/c.3.-4.dat new file mode 100644 index 00000000..0b093de8 Binary files /dev/null and b/community/save/3/1o/c.3.-4.dat differ diff --git a/community/save/3/1p/c.3.-3.dat b/community/save/3/1p/c.3.-3.dat new file mode 100644 index 00000000..954513fe Binary files /dev/null and b/community/save/3/1p/c.3.-3.dat differ diff --git a/community/save/3/1q/c.3.-2.dat b/community/save/3/1q/c.3.-2.dat new file mode 100644 index 00000000..26d8a64f Binary files /dev/null and b/community/save/3/1q/c.3.-2.dat differ diff --git a/community/save/3/1r/c.3.-1.dat b/community/save/3/1r/c.3.-1.dat new file mode 100644 index 00000000..6f69f1d8 Binary files /dev/null and b/community/save/3/1r/c.3.-1.dat differ diff --git a/community/save/3/2/c.3.2.dat b/community/save/3/2/c.3.2.dat new file mode 100644 index 00000000..02f4acb6 Binary files /dev/null and b/community/save/3/2/c.3.2.dat differ diff --git a/community/save/3/3/c.3.3.dat b/community/save/3/3/c.3.3.dat new file mode 100644 index 00000000..159e18cd Binary files /dev/null and b/community/save/3/3/c.3.3.dat differ diff --git a/community/shader.py b/community/shader.py new file mode 100644 index 00000000..5414a0e2 --- /dev/null +++ b/community/shader.py @@ -0,0 +1,71 @@ +import ctypes +import pyglet.gl as gl + +class Shader_error(Exception): + def __init__(self, message): + self.message = message + +def create_shader(target, source_path): + # read shader source + + source_file = open(source_path, "rb") + source = source_file.read() + source_file.close() + + source_length = ctypes.c_int(len(source) + 1) + source_buffer = ctypes.create_string_buffer(source) + + buffer_pointer = ctypes.cast( + ctypes.pointer(ctypes.pointer(source_buffer)), + ctypes.POINTER(ctypes.POINTER(ctypes.c_char))) + + # compile shader + + gl.glShaderSource(target, 1, buffer_pointer, ctypes.byref(source_length)) + gl.glCompileShader(target) + + # handle potential errors + + log_length = gl.GLint(0) + gl.glGetShaderiv(target, gl.GL_INFO_LOG_LENGTH, ctypes.byref(log_length)) + + log_buffer = ctypes.create_string_buffer(log_length.value) + gl.glGetShaderInfoLog(target, log_length, None, log_buffer) + + if log_length.value > 1: + raise Shader_error(str(log_buffer.value)) + +class Shader: + def __init__(self, vert_path, frag_path): + self.program = gl.glCreateProgram() + + # create vertex shader + + self.vert_shader = gl.glCreateShader(gl.GL_VERTEX_SHADER) + create_shader(self.vert_shader, vert_path) + gl.glAttachShader(self.program, self.vert_shader) + + # create fragment shader + + self.frag_shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) + create_shader(self.frag_shader, frag_path) + gl.glAttachShader(self.program, self.frag_shader) + + # link program and clean up + + gl.glLinkProgram(self.program) + + gl.glDeleteShader(self.vert_shader) + gl.glDeleteShader(self.frag_shader) + + def __del__(self): + gl.glDeleteProgram(self.program) + + def find_uniform(self, name): + return gl.glGetUniformLocation(self.program, ctypes.create_string_buffer(name)) + + def uniform_matrix(self, location, matrix): + gl.glUniformMatrix4fv(location, 1, gl.GL_FALSE, (gl.GLfloat * 16) (*sum(matrix.data, []))) + + def use(self): + gl.glUseProgram(self.program) diff --git a/community/subchunk.py b/community/subchunk.py new file mode 100644 index 00000000..eb2e903f --- /dev/null +++ b/community/subchunk.py @@ -0,0 +1,96 @@ +import options +import random + +SUBCHUNK_WIDTH = 4 +SUBCHUNK_HEIGHT = 4 +SUBCHUNK_LENGTH = 4 + +class Subchunk: + def __init__(self, parent, subchunk_position): + self.parent = parent + self.world = self.parent.world + + self.subchunk_position = subchunk_position + + self.local_position = ( + self.subchunk_position[0] * SUBCHUNK_WIDTH, + self.subchunk_position[1] * SUBCHUNK_HEIGHT, + self.subchunk_position[2] * SUBCHUNK_LENGTH) + + self.position = ( + self.parent.position[0] + self.local_position[0], + self.parent.position[1] + self.local_position[1], + self.parent.position[2] + self.local_position[2]) + + # mesh variables + + self.mesh = [] + self.translucent_mesh = [] + + def add_face(self, face, pos, block_type): + rotation = 0 + if options.ALTERNATE_BLOCKS and block_type.is_cube and not block_type.transparent: + rotation = random.randint(0, 3) + x, y, z = pos + vertex_positions = block_type.vertex_positions[face] + tex_index = block_type.tex_indices[face] + shading_values = block_type.shading_values[face] + + if block_type.model.translucent: + mesh = self.translucent_mesh + else: + mesh = self.mesh + + for i in range(4): + mesh.append(vertex_positions[i * 3 + 0] + x) + mesh.append(vertex_positions[i * 3 + 1] + y) + mesh.append(vertex_positions[i * 3 + 2] + z) + + mesh.append((i + rotation) % 4) + mesh.append(tex_index) + + mesh.append(shading_values[i]) + + def can_render_face(self, block_type, block_number, position): + return not (self.world.is_opaque_block(position) + or (block_type.glass and self.world.get_block_number(position) == block_number)) \ + or (block_type.translucent and self.world.get_block_number(position) != block_number) + + + def update_mesh(self): + self.mesh = [] + self.translucent_mesh = [] + + for local_x in range(SUBCHUNK_WIDTH): + for local_y in range(SUBCHUNK_HEIGHT): + for local_z in range(SUBCHUNK_LENGTH): + parent_lx = self.local_position[0] + local_x + parent_ly = self.local_position[1] + local_y + parent_lz = self.local_position[2] + local_z + + block_number = self.parent.blocks[parent_lx][parent_ly][parent_lz] + + if block_number: + block_type = self.world.block_types[block_number] + + x, y, z = pos = ( + self.position[0] + local_x, + self.position[1] + local_y, + self.position[2] + local_z) + + + # if block is cube, we want it to check neighbouring blocks so that we don't uselessly render faces + # if block isn't a cube, we just want to render all faces, regardless of neighbouring blocks + # since the vast majority of blocks are probably anyway going to be cubes, this won't impact performance all that much; the amount of useless faces drawn is going to be minimal + + if block_type.is_cube: + if self.can_render_face(block_type, block_number, (x + 1, y, z)): self.add_face(0, pos, block_type) + if self.can_render_face(block_type, block_number, (x - 1, y, z)): self.add_face(1, pos, block_type) + if self.can_render_face(block_type, block_number, (x, y + 1, z)): self.add_face(2, pos, block_type) + if self.can_render_face(block_type, block_number, (x, y - 1, z)): self.add_face(3, pos, block_type) + if self.can_render_face(block_type, block_number, (x, y, z + 1)): self.add_face(4, pos, block_type) + if self.can_render_face(block_type, block_number, (x, y, z - 1)): self.add_face(5, pos, block_type) + + else: + for i in range(len(block_type.vertex_positions)): + self.add_face(i, pos, block_type) \ No newline at end of file diff --git a/community/texture_manager.py b/community/texture_manager.py new file mode 100644 index 00000000..7d326dec --- /dev/null +++ b/community/texture_manager.py @@ -0,0 +1,42 @@ +import options +import pyglet + +import pyglet.gl as gl + +class Texture_manager: + def __init__(self, texture_width, texture_height, max_textures): + self.texture_width = texture_width + self.texture_height = texture_height + + self.max_textures = max_textures + + self.textures = [] + + self.texture_array = gl.GLuint(0) + gl.glGenTextures(1, self.texture_array) + gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.texture_array) + + gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, options.MIPMAP_TYPE) + gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) + + gl.glTexImage3D( + gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA, + self.texture_width, self.texture_height, self.max_textures, + 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, None) + + def generate_mipmaps(self): + gl.glGenerateMipmap(gl.GL_TEXTURE_2D_ARRAY) + + def add_texture(self, texture): + if not texture in self.textures: + self.textures.append(texture) + + texture_image = pyglet.image.load(f"textures/{texture}.png").get_image_data() + gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.texture_array) + + gl.glTexSubImage3D( + gl.GL_TEXTURE_2D_ARRAY, 0, + 0, 0, self.textures.index(texture), + self.texture_width, self.texture_height, 1, + gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, + texture_image.get_data("RGBA", texture_image.width * 4)) \ No newline at end of file diff --git a/community/textures/aqua_cloth.png b/community/textures/aqua_cloth.png new file mode 100644 index 00000000..d24b7d5b Binary files /dev/null and b/community/textures/aqua_cloth.png differ diff --git a/community/textures/bedrock.png b/community/textures/bedrock.png new file mode 100644 index 00000000..8922e20f Binary files /dev/null and b/community/textures/bedrock.png differ diff --git a/community/textures/black_cloth.png b/community/textures/black_cloth.png new file mode 100644 index 00000000..b9a0c8fd Binary files /dev/null and b/community/textures/black_cloth.png differ diff --git a/community/textures/blue_cloth.png b/community/textures/blue_cloth.png new file mode 100644 index 00000000..8a58871f Binary files /dev/null and b/community/textures/blue_cloth.png differ diff --git a/community/textures/bookshelf.png b/community/textures/bookshelf.png new file mode 100644 index 00000000..1fd85b5e Binary files /dev/null and b/community/textures/bookshelf.png differ diff --git a/community/textures/bricks.png b/community/textures/bricks.png new file mode 100644 index 00000000..30f8548a Binary files /dev/null and b/community/textures/bricks.png differ diff --git a/community/textures/brown_mushroom.png b/community/textures/brown_mushroom.png new file mode 100644 index 00000000..fc2245cc Binary files /dev/null and b/community/textures/brown_mushroom.png differ diff --git a/community/textures/cactus_bottom.png b/community/textures/cactus_bottom.png new file mode 100644 index 00000000..ca2984b4 Binary files /dev/null and b/community/textures/cactus_bottom.png differ diff --git a/community/textures/cactus_side.png b/community/textures/cactus_side.png new file mode 100644 index 00000000..b59d492f Binary files /dev/null and b/community/textures/cactus_side.png differ diff --git a/community/textures/cactus_top.png b/community/textures/cactus_top.png new file mode 100644 index 00000000..f03df7f0 Binary files /dev/null and b/community/textures/cactus_top.png differ diff --git a/community/textures/chest_front.png b/community/textures/chest_front.png new file mode 100644 index 00000000..5bb4289d Binary files /dev/null and b/community/textures/chest_front.png differ diff --git a/community/textures/chest_side.png b/community/textures/chest_side.png new file mode 100644 index 00000000..d4dd91c6 Binary files /dev/null and b/community/textures/chest_side.png differ diff --git a/community/textures/chest_top.png b/community/textures/chest_top.png new file mode 100644 index 00000000..b05685cc Binary files /dev/null and b/community/textures/chest_top.png differ diff --git a/community/textures/clay.png b/community/textures/clay.png new file mode 100644 index 00000000..3670a867 Binary files /dev/null and b/community/textures/clay.png differ diff --git a/community/textures/coal_ore.png b/community/textures/coal_ore.png new file mode 100644 index 00000000..c60f980d Binary files /dev/null and b/community/textures/coal_ore.png differ diff --git a/community/textures/cobblestone.png b/community/textures/cobblestone.png new file mode 100644 index 00000000..b43d14dd Binary files /dev/null and b/community/textures/cobblestone.png differ diff --git a/community/textures/crafting_table_top.png b/community/textures/crafting_table_top.png new file mode 100644 index 00000000..cc3000ad Binary files /dev/null and b/community/textures/crafting_table_top.png differ diff --git a/community/textures/crafting_table_x.png b/community/textures/crafting_table_x.png new file mode 100644 index 00000000..49c8803c Binary files /dev/null and b/community/textures/crafting_table_x.png differ diff --git a/community/textures/crafting_table_z.png b/community/textures/crafting_table_z.png new file mode 100644 index 00000000..31de683d Binary files /dev/null and b/community/textures/crafting_table_z.png differ diff --git a/community/textures/crops.png b/community/textures/crops.png new file mode 100644 index 00000000..9a530f08 Binary files /dev/null and b/community/textures/crops.png differ diff --git a/community/textures/cyan_cloth.png b/community/textures/cyan_cloth.png new file mode 100644 index 00000000..79ecc348 Binary files /dev/null and b/community/textures/cyan_cloth.png differ diff --git a/community/textures/dead_bush.png b/community/textures/dead_bush.png new file mode 100644 index 00000000..ca793d4b Binary files /dev/null and b/community/textures/dead_bush.png differ diff --git a/community/textures/diamond_block.png b/community/textures/diamond_block.png new file mode 100644 index 00000000..c6d07a6f Binary files /dev/null and b/community/textures/diamond_block.png differ diff --git a/community/textures/diamond_ore.png b/community/textures/diamond_ore.png new file mode 100644 index 00000000..18877726 Binary files /dev/null and b/community/textures/diamond_ore.png differ diff --git a/community/textures/dirt.png b/community/textures/dirt.png new file mode 100644 index 00000000..58d3fac4 Binary files /dev/null and b/community/textures/dirt.png differ diff --git a/community/textures/fire.png b/community/textures/fire.png new file mode 100644 index 00000000..ae4a5b91 Binary files /dev/null and b/community/textures/fire.png differ diff --git a/community/textures/furnace_front.png b/community/textures/furnace_front.png new file mode 100644 index 00000000..8059c5af Binary files /dev/null and b/community/textures/furnace_front.png differ diff --git a/community/textures/furnace_side.png b/community/textures/furnace_side.png new file mode 100644 index 00000000..18aaba26 Binary files /dev/null and b/community/textures/furnace_side.png differ diff --git a/community/textures/furnace_y.png b/community/textures/furnace_y.png new file mode 100644 index 00000000..d4a429f1 Binary files /dev/null and b/community/textures/furnace_y.png differ diff --git a/community/textures/glass.png b/community/textures/glass.png new file mode 100644 index 00000000..64cb447f Binary files /dev/null and b/community/textures/glass.png differ diff --git a/community/textures/gold_block.png b/community/textures/gold_block.png new file mode 100644 index 00000000..c6c25774 Binary files /dev/null and b/community/textures/gold_block.png differ diff --git a/community/textures/gold_ore.png b/community/textures/gold_ore.png new file mode 100644 index 00000000..d5221fe3 Binary files /dev/null and b/community/textures/gold_ore.png differ diff --git a/community/textures/grass.png b/community/textures/grass.png new file mode 100644 index 00000000..89ffa14d Binary files /dev/null and b/community/textures/grass.png differ diff --git a/community/textures/grass_side.png b/community/textures/grass_side.png new file mode 100644 index 00000000..a2e27891 Binary files /dev/null and b/community/textures/grass_side.png differ diff --git a/community/textures/gravel.png b/community/textures/gravel.png new file mode 100644 index 00000000..5e56f715 Binary files /dev/null and b/community/textures/gravel.png differ diff --git a/community/textures/green_cloth.png b/community/textures/green_cloth.png new file mode 100644 index 00000000..7455d725 Binary files /dev/null and b/community/textures/green_cloth.png differ diff --git a/community/textures/grey_cloth.png b/community/textures/grey_cloth.png new file mode 100644 index 00000000..4dc15772 Binary files /dev/null and b/community/textures/grey_cloth.png differ diff --git a/community/textures/ice.png b/community/textures/ice.png new file mode 100644 index 00000000..d17fe06e Binary files /dev/null and b/community/textures/ice.png differ diff --git a/community/textures/indigo_cloth.png b/community/textures/indigo_cloth.png new file mode 100644 index 00000000..59c1ae01 Binary files /dev/null and b/community/textures/indigo_cloth.png differ diff --git a/community/textures/iron_block.png b/community/textures/iron_block.png new file mode 100644 index 00000000..f782394f Binary files /dev/null and b/community/textures/iron_block.png differ diff --git a/community/textures/iron_door.png b/community/textures/iron_door.png new file mode 100644 index 00000000..e00dc8df Binary files /dev/null and b/community/textures/iron_door.png differ diff --git a/community/textures/iron_door_bottom_half.png b/community/textures/iron_door_bottom_half.png new file mode 100644 index 00000000..283d8965 Binary files /dev/null and b/community/textures/iron_door_bottom_half.png differ diff --git a/community/textures/iron_ore.png b/community/textures/iron_ore.png new file mode 100644 index 00000000..001beee9 Binary files /dev/null and b/community/textures/iron_ore.png differ diff --git a/community/textures/jukebox.png b/community/textures/jukebox.png new file mode 100644 index 00000000..4f9dfca9 Binary files /dev/null and b/community/textures/jukebox.png differ diff --git a/community/textures/jukebox_top.png b/community/textures/jukebox_top.png new file mode 100644 index 00000000..ceb81f2c Binary files /dev/null and b/community/textures/jukebox_top.png differ diff --git a/community/textures/ladder.png b/community/textures/ladder.png new file mode 100644 index 00000000..3f0a7877 Binary files /dev/null and b/community/textures/ladder.png differ diff --git a/community/textures/lava.png b/community/textures/lava.png new file mode 100644 index 00000000..52f13999 Binary files /dev/null and b/community/textures/lava.png differ diff --git a/community/textures/leaves.png b/community/textures/leaves.png new file mode 100644 index 00000000..858664e1 Binary files /dev/null and b/community/textures/leaves.png differ diff --git a/community/textures/lever.png b/community/textures/lever.png new file mode 100644 index 00000000..b43d14dd Binary files /dev/null and b/community/textures/lever.png differ diff --git a/community/textures/lime_cloth.png b/community/textures/lime_cloth.png new file mode 100644 index 00000000..99bf0b18 Binary files /dev/null and b/community/textures/lime_cloth.png differ diff --git a/community/textures/lit_furnace_front.png b/community/textures/lit_furnace_front.png new file mode 100644 index 00000000..83abc9f7 Binary files /dev/null and b/community/textures/lit_furnace_front.png differ diff --git a/community/textures/log_side.png b/community/textures/log_side.png new file mode 100644 index 00000000..e33b02fe Binary files /dev/null and b/community/textures/log_side.png differ diff --git a/community/textures/log_y.png b/community/textures/log_y.png new file mode 100644 index 00000000..186b8582 Binary files /dev/null and b/community/textures/log_y.png differ diff --git a/community/textures/magenta_cloth.png b/community/textures/magenta_cloth.png new file mode 100644 index 00000000..ac80e9e2 Binary files /dev/null and b/community/textures/magenta_cloth.png differ diff --git a/community/textures/mob_spawner.png b/community/textures/mob_spawner.png new file mode 100644 index 00000000..3ba90802 Binary files /dev/null and b/community/textures/mob_spawner.png differ diff --git a/community/textures/mossy_cobblestone.png b/community/textures/mossy_cobblestone.png new file mode 100644 index 00000000..d76bac86 Binary files /dev/null and b/community/textures/mossy_cobblestone.png differ diff --git a/community/textures/obsidian.png b/community/textures/obsidian.png new file mode 100644 index 00000000..b4869a91 Binary files /dev/null and b/community/textures/obsidian.png differ diff --git a/community/textures/off_redstone_torch.png b/community/textures/off_redstone_torch.png new file mode 100644 index 00000000..e0909434 Binary files /dev/null and b/community/textures/off_redstone_torch.png differ diff --git a/community/textures/off_redstone_torch_top.png b/community/textures/off_redstone_torch_top.png new file mode 100644 index 00000000..c2d50249 Binary files /dev/null and b/community/textures/off_redstone_torch_top.png differ diff --git a/community/textures/orange_cloth.png b/community/textures/orange_cloth.png new file mode 100644 index 00000000..c05421c6 Binary files /dev/null and b/community/textures/orange_cloth.png differ diff --git a/community/textures/pink_cloth.png b/community/textures/pink_cloth.png new file mode 100644 index 00000000..d83b6162 Binary files /dev/null and b/community/textures/pink_cloth.png differ diff --git a/community/textures/planks.png b/community/textures/planks.png new file mode 100644 index 00000000..346f77dc Binary files /dev/null and b/community/textures/planks.png differ diff --git a/community/textures/purple_cloth.png b/community/textures/purple_cloth.png new file mode 100644 index 00000000..8b245d92 Binary files /dev/null and b/community/textures/purple_cloth.png differ diff --git a/community/textures/rails.png b/community/textures/rails.png new file mode 100644 index 00000000..802d13ce Binary files /dev/null and b/community/textures/rails.png differ diff --git a/community/textures/red_cloth.png b/community/textures/red_cloth.png new file mode 100644 index 00000000..7990f69f Binary files /dev/null and b/community/textures/red_cloth.png differ diff --git a/community/textures/red_mushroom.png b/community/textures/red_mushroom.png new file mode 100644 index 00000000..1ea2f78d Binary files /dev/null and b/community/textures/red_mushroom.png differ diff --git a/community/textures/red_rose.png b/community/textures/red_rose.png new file mode 100644 index 00000000..4a202b59 Binary files /dev/null and b/community/textures/red_rose.png differ diff --git a/community/textures/redstone_ore.png b/community/textures/redstone_ore.png new file mode 100644 index 00000000..ef0bcfe4 Binary files /dev/null and b/community/textures/redstone_ore.png differ diff --git a/community/textures/redstone_torch.png b/community/textures/redstone_torch.png new file mode 100644 index 00000000..b9aec5eb Binary files /dev/null and b/community/textures/redstone_torch.png differ diff --git a/community/textures/redstone_torch_top.png b/community/textures/redstone_torch_top.png new file mode 100644 index 00000000..ecd10c45 Binary files /dev/null and b/community/textures/redstone_torch_top.png differ diff --git a/community/textures/redstone_wire.png b/community/textures/redstone_wire.png new file mode 100644 index 00000000..c4427878 Binary files /dev/null and b/community/textures/redstone_wire.png differ diff --git a/community/textures/sand.png b/community/textures/sand.png new file mode 100644 index 00000000..257020ed Binary files /dev/null and b/community/textures/sand.png differ diff --git a/community/textures/sapling.png b/community/textures/sapling.png new file mode 100644 index 00000000..df8784b3 Binary files /dev/null and b/community/textures/sapling.png differ diff --git a/community/textures/slab_side.png b/community/textures/slab_side.png new file mode 100644 index 00000000..0c9bc23a Binary files /dev/null and b/community/textures/slab_side.png differ diff --git a/community/textures/slab_y.png b/community/textures/slab_y.png new file mode 100644 index 00000000..4ccf6c61 Binary files /dev/null and b/community/textures/slab_y.png differ diff --git a/community/textures/snow.png b/community/textures/snow.png new file mode 100644 index 00000000..be324c1d Binary files /dev/null and b/community/textures/snow.png differ diff --git a/community/textures/snowy_grass_side.png b/community/textures/snowy_grass_side.png new file mode 100644 index 00000000..da174175 Binary files /dev/null and b/community/textures/snowy_grass_side.png differ diff --git a/community/textures/soil.png b/community/textures/soil.png new file mode 100644 index 00000000..8cde713b Binary files /dev/null and b/community/textures/soil.png differ diff --git a/community/textures/sponge.png b/community/textures/sponge.png new file mode 100644 index 00000000..dcb11e79 Binary files /dev/null and b/community/textures/sponge.png differ diff --git a/community/textures/stone.png b/community/textures/stone.png new file mode 100644 index 00000000..49b7f024 Binary files /dev/null and b/community/textures/stone.png differ diff --git a/community/textures/sugar_cane.png b/community/textures/sugar_cane.png new file mode 100644 index 00000000..10e918d0 Binary files /dev/null and b/community/textures/sugar_cane.png differ diff --git a/community/textures/tnt_bottom.png b/community/textures/tnt_bottom.png new file mode 100644 index 00000000..55c2f8fd Binary files /dev/null and b/community/textures/tnt_bottom.png differ diff --git a/community/textures/tnt_side.png b/community/textures/tnt_side.png new file mode 100644 index 00000000..7aaa0d75 Binary files /dev/null and b/community/textures/tnt_side.png differ diff --git a/community/textures/tnt_top.png b/community/textures/tnt_top.png new file mode 100644 index 00000000..9985223d Binary files /dev/null and b/community/textures/tnt_top.png differ diff --git a/community/textures/torch.png b/community/textures/torch.png new file mode 100644 index 00000000..e7d24f31 Binary files /dev/null and b/community/textures/torch.png differ diff --git a/community/textures/torch_top.png b/community/textures/torch_top.png new file mode 100644 index 00000000..8d66d02f Binary files /dev/null and b/community/textures/torch_top.png differ diff --git a/community/textures/unknown.png b/community/textures/unknown.png new file mode 100644 index 00000000..1ba274d9 Binary files /dev/null and b/community/textures/unknown.png differ diff --git a/community/textures/violet_cloth.png b/community/textures/violet_cloth.png new file mode 100644 index 00000000..30374ae3 Binary files /dev/null and b/community/textures/violet_cloth.png differ diff --git a/community/textures/water.png b/community/textures/water.png new file mode 100644 index 00000000..a081420c Binary files /dev/null and b/community/textures/water.png differ diff --git a/community/textures/white_cloth.png b/community/textures/white_cloth.png new file mode 100644 index 00000000..6d24926e Binary files /dev/null and b/community/textures/white_cloth.png differ diff --git a/community/textures/wooden_door.png b/community/textures/wooden_door.png new file mode 100644 index 00000000..9d21e890 Binary files /dev/null and b/community/textures/wooden_door.png differ diff --git a/community/textures/yellow_cloth.png b/community/textures/yellow_cloth.png new file mode 100644 index 00000000..f939f410 Binary files /dev/null and b/community/textures/yellow_cloth.png differ diff --git a/community/textures/yellow_flower.png b/community/textures/yellow_flower.png new file mode 100644 index 00000000..6f35174d Binary files /dev/null and b/community/textures/yellow_flower.png differ diff --git a/community/vert.glsl b/community/vert.glsl new file mode 100644 index 00000000..4aa417bb --- /dev/null +++ b/community/vert.glsl @@ -0,0 +1,26 @@ +#version 330 + +layout(location = 0) in vec3 a_Position; +layout(location = 1) in vec2 a_TextureFetcher; +layout(location = 2) in float a_LightMultiplier; + + +out vec3 v_Position; +out vec3 v_TexCoords; +out float v_LightMultiplier; + +uniform mat4 u_ModelViewProjMatrix; + +const vec2 texture_UV[4] = const vec2[4]( + vec2(0.0, 1.0), + vec2(0.0, 0.0), + vec2(1.0, 0.0), + vec2(1.0, 1.0) +); + +void main(void) { + v_Position = a_Position; + v_TexCoords = vec3(texture_UV[int(a_TextureFetcher[0])], a_TextureFetcher[1]); + v_LightMultiplier = a_LightMultiplier; + gl_Position = u_ModelViewProjMatrix * vec4(a_Position, 1.0); +} \ No newline at end of file diff --git a/community/vscode_mcpy_extension/language-configuration.json b/community/vscode_mcpy_extension/language-configuration.json new file mode 100644 index 00000000..6bd45cbc --- /dev/null +++ b/community/vscode_mcpy_extension/language-configuration.json @@ -0,0 +1,33 @@ +{ + "comments": { + "lineComment": "#" + }, + "brackets": [ + [ + "[", + "]" + ], + ], + "autoClosingPairs": [ + { + "open": "\"", + "close": "\"", + "notIn": ["string"] + }, + { + "open": "[", + "close": "]", + "notIn": ["comment"] + }, + ], + "surroundingPairs": [ + [ + "\"", + "\"" + ], + [ + "[", + "]" + ], + ] +} \ No newline at end of file diff --git a/community/vscode_mcpy_extension/package.json b/community/vscode_mcpy_extension/package.json new file mode 100644 index 00000000..443213de --- /dev/null +++ b/community/vscode_mcpy_extension/package.json @@ -0,0 +1,36 @@ +{ + "name": "mcpy", + "displayName": "MCPY", + "description": "Syntax highlighting for MCPY data files", + "categories": [ + "Programming Languages" + ], + "publisher": "obiwac", + "author": { + "name": "obiwac" + }, + "homepage": "https://github.com/obiwac/python-minecraft-clone", + "version": "0.0.1", + "engines": { + "vscode": "^1.22.0" + }, + "contributes": { + "languages": [{ + "id": "mcpy_blocks", + "aliases": [ + "MCPY Blocks" + ], + "filenames": [ + "blocks.mcpy" + ], + "configuration": "./language-configuration.json" + }], + "grammars": [ + { + "language": "mcpy_blocks", + "scopeName": "source.mcpy_blocks", + "path": "./syntaxes/mcpy_blocks.tmLanguage.json" + } + ] + } +} \ No newline at end of file diff --git a/community/vscode_mcpy_extension/syntaxes/mcpy_blocks.tmLanguage.json b/community/vscode_mcpy_extension/syntaxes/mcpy_blocks.tmLanguage.json new file mode 100644 index 00000000..0e382d2d --- /dev/null +++ b/community/vscode_mcpy_extension/syntaxes/mcpy_blocks.tmLanguage.json @@ -0,0 +1,36 @@ +{ + "name": "mcpy_blocks", + "scopeName": "source.mcpy_blocks", + "patterns": [ + { + "name": "keyword.control.mcpy_blocks", + "match": "\\b(name|texture|model)\\b" + }, + { + "name": "keyword.operator.mcpy_blocks", + "match": "\\b(sameas)\\b" + }, + { + "name": "constant.language.mcpy_blocks", + "match": "\\b(all|sides|x|y|z|top|bottom|front|back|left|right)\\b" + }, + { + "name": "constant.numeric.mcpy_blocks", + "match": "\\b[0-9]+\\b" + }, + { + "name": "comment.line.mcpy_blocks", + "begin": "#", + "end": "$" + }, + { + "name": "string.quoted.double.mcpy_blocks", + "begin": "\"", + "end": "\"", + "patterns": [{ + "name": "constant.character.escape.mcpy_blocks", + "match": "\\\\." + }] + } + ] +} \ No newline at end of file diff --git a/community/world.py b/community/world.py new file mode 100644 index 00000000..4e59316b --- /dev/null +++ b/community/world.py @@ -0,0 +1,248 @@ +import chunk +import ctypes +import math + + +import pyglet.gl as gl + +import block_type +import models +import save +import texture_manager +import options +# import custom block models + + +class World: + def __init__(self, camera): + self.camera = camera + self.texture_manager = texture_manager.Texture_manager(16, 16, 256) + self.block_types = [None] + + # parse block type data file + + blocks_data_file = open("data/blocks.mcpy") + blocks_data = blocks_data_file.readlines() + blocks_data_file.close() + + for block in blocks_data: + if block[0] in ['\n', '#']: # skip if empty line or comment + continue + + number, props = block.split(':', 1) + number = int(number) + + # default block + + name = "Unknown" + model = models.cube + texture = {"all": "unknown"} + + # read properties + + for prop in props.split(','): + prop = prop.strip() + prop = list(filter(None, prop.split(' ', 1))) + + if prop[0] == "sameas": + sameas_number = int(prop[1]) + + name = self.block_types[sameas_number].name + texture = self.block_types[sameas_number].block_face_textures + model = self.block_types[sameas_number].model + + elif prop[0] == "name": + name = eval(prop[1]) + + elif prop[0][:7] == "texture": + _, side = prop[0].split('.') + texture[side] = prop[1].strip() + + elif prop[0] == "model": + model = eval(prop[1]) + + # add block type + + _block_type = block_type.Block_type(self.texture_manager, name, texture, model) + + if number < len(self.block_types): + self.block_types[number] = _block_type + + else: + self.block_types.append(_block_type) + + self.texture_manager.generate_mipmaps() + + chunk_indices = [] + + for nquad in range(chunk.CHUNK_WIDTH * chunk.CHUNK_HEIGHT * chunk.CHUNK_LENGTH * 8): + chunk_indices.append(4 * nquad + 0) + chunk_indices.append(4 * nquad + 1) + chunk_indices.append(4 * nquad + 2) + chunk_indices.append(4 * nquad + 0) + chunk_indices.append(4 * nquad + 2) + chunk_indices.append(4 * nquad + 3) + + print(len(chunk_indices)) + + self.ibo = gl.GLuint(0) + gl.glGenBuffers(1, ctypes.byref(self.ibo)) + gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, self.ibo) + gl.glBufferData( + gl.GL_ELEMENT_ARRAY_BUFFER, + ctypes.sizeof(gl.GLuint * len(chunk_indices)), + (gl.GLuint * len(chunk_indices))(*chunk_indices), + gl.GL_STATIC_DRAW) + gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, 0) + + + + # load the world + + self.save = save.Save(self) + + self.chunks = {} + self.save.load() + + for chunk_position in self.chunks: + self.chunks[chunk_position].update_subchunk_meshes() + self.chunks[chunk_position].update_mesh() + + del chunk_indices + + def __del__(self): + gl.glDeleteBuffers(1, ctypes.byref(self.ibo)) + + def get_chunk_position(self, position): + x, y, z = position + + return ( + (x // chunk.CHUNK_WIDTH), + (y // chunk.CHUNK_HEIGHT), + (z // chunk.CHUNK_LENGTH)) + + def get_local_position(self, position): + x, y, z = position + + return ( + int(x % chunk.CHUNK_WIDTH), + int(y % chunk.CHUNK_HEIGHT), + int(z % chunk.CHUNK_LENGTH)) + + def get_block_number(self, position): + x, y, z = position + chunk_position = self.get_chunk_position(position) + + if not chunk_position in self.chunks: + return 0 + + lx, ly, lz = self.get_local_position(position) + + block_number = self.chunks[chunk_position].blocks[lx][ly][lz] + return block_number + + def is_opaque_block(self, position): + # get block type and check if it's opaque or not + # air counts as a transparent block, so test for that too + + block_type = self.block_types[self.get_block_number(position)] + + if not block_type: + return False + + return not block_type.transparent + + def set_block(self, position, number): # set number to 0 (air) to remove block + x, y, z = position + chunk_position = self.get_chunk_position(position) + + if not chunk_position in self.chunks: # if no chunks exist at this position, create a new one + if number == 0: + return # no point in creating a whole new chunk if we're not gonna be adding anything + + self.chunks[chunk_position] = chunk.Chunk(self, chunk_position) + + if self.get_block_number(position) == number: # no point updating mesh if the block is the same + return + + lx, ly, lz = self.get_local_position(position) + + self.chunks[chunk_position].blocks[lx][ly][lz] = number + self.chunks[chunk_position].modified = True + + self.chunks[chunk_position].update_at_position((x, y, z)) + self.chunks[chunk_position].update_mesh() + + cx, cy, cz = chunk_position + + def try_update_chunk_at_position(chunk_position, position): + if chunk_position in self.chunks: + self.chunks[chunk_position].update_at_position(position) + self.chunks[chunk_position].update_mesh() + + if lx == chunk.CHUNK_WIDTH - 1: try_update_chunk_at_position((cx + 1, cy, cz), (x + 1, y, z)) + if lx == 0: try_update_chunk_at_position((cx - 1, cy, cz), (x - 1, y, z)) + + if ly == chunk.CHUNK_HEIGHT - 1: try_update_chunk_at_position((cx, cy + 1, cz), (x, y + 1, z)) + if ly == 0: try_update_chunk_at_position((cx, cy - 1, cz), (x, y - 1, z)) + + if lz == chunk.CHUNK_LENGTH - 1: try_update_chunk_at_position((cx, cy, cz + 1), (x, y, z + 1)) + if lz == 0: try_update_chunk_at_position((cx, cy, cz - 1), (x, y, z - 1)) + + def can_render_chunk(self, chunk_position, pl_c_pos): + rx, ry, rz = (chunk_position[0] - pl_c_pos[0]) \ + * math.cos(self.camera.rotation[0]) \ + * math.cos(self.camera.rotation[1]) , \ + (chunk_position[1] - pl_c_pos[1]) \ + * math.sin(self.camera.rotation[1]) , \ + (chunk_position[2] - pl_c_pos[2]) \ + * math.sin(self.camera.rotation[0]) \ + * math.cos(self.camera.rotation[1]) + return rx >= -1 and ry >= -1 and rz >= -1 + + def draw_translucent_fast(self, player_chunk_pos): + gl.glDisable(gl.GL_CULL_FACE) + gl.glEnable(gl.GL_BLEND) + gl.glDepthMask(gl.GL_FALSE) + + for chunk_position in self.chunks: + if self.can_render_chunk(chunk_position, player_chunk_pos): + self.chunks[chunk_position].draw_translucent() + + gl.glDepthMask(gl.GL_TRUE) + gl.glDisable(gl.GL_BLEND) + gl.glEnable(gl.GL_CULL_FACE) + + def draw_translucent_fancy(self, player_chunk_pos): + gl.glDepthMask(gl.GL_FALSE) + gl.glFrontFace(gl.GL_CW) + gl.glEnable(gl.GL_BLEND) + + for chunk_position in self.chunks: + if self.can_render_chunk(chunk_position, player_chunk_pos): + self.chunks[chunk_position].draw_translucent() + + gl.glFrontFace(gl.GL_CCW) + gl.glEnable(gl.GL_BLEND) + + for chunk_position in self.chunks: + if self.can_render_chunk(chunk_position, player_chunk_pos): + self.chunks[chunk_position].draw_translucent() + + gl.glDisable(gl.GL_BLEND) + gl.glDepthMask(gl.GL_TRUE) + + draw_translucent = draw_translucent_fancy if options.TRANSLUCENT_BLENDING else draw_translucent_fast + + def draw(self): + player_floored_pos = tuple(self.camera.position) + player_chunk_pos = self.get_chunk_position(player_floored_pos) + + for chunk_position in self.chunks: + if self.can_render_chunk(chunk_position, player_chunk_pos): + self.chunks[chunk_position].draw() + + self.draw_translucent(player_chunk_pos) + + + \ No newline at end of file