diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-10-19 14:26:38 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-10-19 14:26:38 +0200 |
commit | b81e1b0e806f0e594cef5011ae1869d0dbe62bf0 (patch) | |
tree | fcf148ce67456254a8d30f74b87130a32f259867 | |
parent | 9d3f2aec02fb7c8436bd44661320874f4580325f (diff) | |
download | BerryClient-b81e1b0e806f0e594cef5011ae1869d0dbe62bf0.tar.gz BerryClient-b81e1b0e806f0e594cef5011ae1869d0dbe62bf0.zip |
implement models and compat BlockWorld class
-rw-r--r-- | BerryClient/addons/blockworld.py | 41 | ||||
-rw-r--r-- | BerryClient/addons/core.py (renamed from BerryClient/addons/reload.py) | 0 | ||||
-rw-r--r-- | BerryClient/addons/msg.py | 9 | ||||
-rw-r--r-- | BerryClient/core.py | 5 | ||||
-rw-r--r-- | BerryClient/models/House.py | 52 | ||||
-rw-r--r-- | BerryClient/models/Roof.py | 22 | ||||
-rw-r--r-- | BerryClient/models/Wall.py | 28 | ||||
-rw-r--r-- | BerryClient/models/WallWithDoor.py | 19 | ||||
-rw-r--r-- | BerryClient/models/WallWithWindow.py | 17 |
9 files changed, 182 insertions, 11 deletions
diff --git a/BerryClient/addons/blockworld.py b/BerryClient/addons/blockworld.py new file mode 100644 index 0000000..958e61a --- /dev/null +++ b/BerryClient/addons/blockworld.py @@ -0,0 +1,41 @@ +import mcpi.block + +from BerryClient.commands import command +from BerryClient.models.House import House + +MATERIAL_MAPPING = { + "air": mcpi.block.AIR, + "stone": mcpi.block.STONE, + "brick": mcpi.block.STONE_BRICK, +} + +class BlockWorld: + + def __init__(self, core): + self.core = core + + def set_block(self, x, y, z, block): + pos = (x, y, z) + block_obj = MATERIAL_MAPPING[block] + + self.core.setBlock(*pos, block_obj.id) + + def set_blocks(self, x1, y1, z1, x2, y2, z2, block): + pos1 = (x1, y1, z1) + pos2 = (x2, y2, z2) + block_obj = MATERIAL_MAPPING[block] + + self.core.setBlocks(*pos1, *pos2, block_obj.id) + + def player_position(self) -> tuple: + return self.core.player.getPos() + + def __getattr__(self, attr): + return getattr(self.core, attr) + +@command() +def b(core): + bw = BlockWorld(core) + + h = House(bw.player_position(), bw) + h.build() diff --git a/BerryClient/addons/reload.py b/BerryClient/addons/core.py index 958bb2b..958bb2b 100644 --- a/BerryClient/addons/reload.py +++ b/BerryClient/addons/core.py diff --git a/BerryClient/addons/msg.py b/BerryClient/addons/msg.py deleted file mode 100644 index 61edabd..0000000 --- a/BerryClient/addons/msg.py +++ /dev/null @@ -1,9 +0,0 @@ -import logging - -from BerryClient.commands import command - -log = logging.getLogger(__name__) - -@command() -def msg(core, *content): - log.info(" ".join(content)) diff --git a/BerryClient/core.py b/BerryClient/core.py index 5f59e1b..1b4e5b5 100644 --- a/BerryClient/core.py +++ b/BerryClient/core.py @@ -11,8 +11,9 @@ log = logging.getLogger() class BerryCore: ADDONS = [ - "BerryClient.addons.msg", - "BerryClient.addons.reload" + "BerryClient.addons.core", + + "BerryClient.addons.blockworld", ] ADDON_MODULES = {} diff --git a/BerryClient/models/House.py b/BerryClient/models/House.py new file mode 100644 index 0000000..72ae549 --- /dev/null +++ b/BerryClient/models/House.py @@ -0,0 +1,52 @@ +from BerryClient.models.Roof import Roof +from BerryClient.models.Wall import Wall +from BerryClient.models.WallWithDoor import WallWithDoor +from BerryClient.models.WallWithWindow import WallWithWindow + +class House: + wallFront: Wall + wallLeft: Wall + wallRight: Wall + wallBack: Wall + pos: tuple + roof: Roof + __bw: "BlockWorld" + + def __init__(self, pos, bw): + self.pos = pos + self.__bw = bw + + x, y, z = self.pos + + x -= (Wall.width/2) + z -= (Wall.width/2) + + corner_bottom_left = (x, y, z) + corner_bottom_right = (x + Wall.width-1, y, z) + corner_top_left = (x, y, z + Wall.width-1) + + self.wallFront = WallWithDoor(corner_bottom_left, bw) + + self.wallLeft = WallWithWindow(corner_bottom_left, bw) + self.wallLeft.rotated = True + + self.wallRight = WallWithWindow(corner_bottom_right, bw) + self.wallRight.rotated = True + + self.wallBack = Wall(corner_top_left, bw) + + roof_corner = (x, y + Wall.height, z) + self.roof = Roof(roof_corner, bw) + + def build(self): + self.wallFront.build() + self.wallLeft.build() + self.wallRight.build() + self.wallBack.build() + self.roof.build() + + def change_wall_material(self, new_material_id: str): + wallFront.material_id = new_material_id + wallLeft.material_id = new_material_id + wallRight.material_id = new_material_id + wallBack.material_id = new_material_id diff --git a/BerryClient/models/Roof.py b/BerryClient/models/Roof.py new file mode 100644 index 0000000..5bef395 --- /dev/null +++ b/BerryClient/models/Roof.py @@ -0,0 +1,22 @@ + +class Roof: + width: int = 6 + depth: int = 6 + roof_material_id: str = "brick" + pos: tuple + __bw: "BlockWorld" + + def __init__(self, pos, bw): + self.pos = pos + self.__bw = bw + + def build(self): + + for d in range(self.depth): + x, y, z = self.pos + z += d + + from_pos = (x, y, z) + to_pos = (x + self.width-1, y, z) + + self.__bw.set_blocks(*from_pos, *to_pos, self.roof_material_id) diff --git a/BerryClient/models/Wall.py b/BerryClient/models/Wall.py new file mode 100644 index 0000000..cbd761a --- /dev/null +++ b/BerryClient/models/Wall.py @@ -0,0 +1,28 @@ + +class Wall: + width: int = 6 + height: int = 5 + pos: tuple + rotated: bool = False + material_id: str = "stone" + _bw: "BlockWorld" + + def __init__(self, pos, bw): + self.pos = pos + self._bw = bw + + def build(self): + for h in range(self.height): + x, y, z = self.pos + y += h + + from_pos = (x,y,z) + + if self.rotated: + z += self.width - 1 + else: + x += self.width - 1 + + to_pos = (x,y,z) + + self._bw.set_blocks(*from_pos, *to_pos, self.material_id) diff --git a/BerryClient/models/WallWithDoor.py b/BerryClient/models/WallWithDoor.py new file mode 100644 index 0000000..0d9da8a --- /dev/null +++ b/BerryClient/models/WallWithDoor.py @@ -0,0 +1,19 @@ +from BerryClient.models.Wall import Wall + +class WallWithDoor(Wall): + door_material_id: str = "air" + + def build(self): + super().build() + + x, y, z = self.pos + + if self.rotated: + z += (self.width / 2) + else: + x += (self.width / 2) + + from_pos = (x, y, z) + to_pos = (x, y+1, z) + + self._bw.set_blocks(*from_pos, *to_pos, self.door_material_id) diff --git a/BerryClient/models/WallWithWindow.py b/BerryClient/models/WallWithWindow.py new file mode 100644 index 0000000..36ea92f --- /dev/null +++ b/BerryClient/models/WallWithWindow.py @@ -0,0 +1,17 @@ +from BerryClient.models.Wall import Wall + +class WallWithWindow(Wall): + window_material_id: str = "air" + + def build(self): + super().build() + + x, y, z = self.pos + if self.rotated: + z += (self.width / 2) + else: + x += (self.width / 2) + + window_pos = (x, y+1, z) + + self._bw.set_block(*window_pos, self.window_material_id)
\ No newline at end of file |