|
| 1 | +import os |
| 2 | +from datetime import datetime |
| 3 | + |
| 4 | +import numpy |
| 5 | +from amulet import Block, SelectionBox |
| 6 | +from typing import TYPE_CHECKING, Tuple, Dict |
| 7 | +import wx |
| 8 | +from amulet.api.partial_3d_array.base_partial_3d_array import BasePartial3DArray |
| 9 | + |
| 10 | +from amulet_map_editor.api.wx.ui.base_select import EVT_PICK |
| 11 | +from amulet_map_editor.api.wx.ui.block_select import BlockDefine |
| 12 | +from amulet_map_editor.programs.edit.api.operations import DefaultOperationUI |
| 13 | + |
| 14 | +if TYPE_CHECKING: |
| 15 | + from amulet.api.level import BaseLevel |
| 16 | + from amulet_map_editor.programs.edit.api.canvas import EditCanvas |
| 17 | + |
| 18 | + |
| 19 | +def _check_block(block: Block, original_base_name: str, |
| 20 | + original_properties: Dict[str, "WildcardSNBTType"]) -> bool: |
| 21 | + if (block.base_name == original_base_name |
| 22 | + and all( |
| 23 | + original_properties.get(prop) in ["*", val.to_snbt()] |
| 24 | + for prop, val in block.properties.items() |
| 25 | + ) |
| 26 | + ): |
| 27 | + return True |
| 28 | + return False |
| 29 | + |
| 30 | + |
| 31 | +class CeilingFill(wx.Panel, DefaultOperationUI): |
| 32 | + def __init__( |
| 33 | + self, parent: wx.Window, canvas: "EditCanvas", world: "BaseLevel", options_path: str |
| 34 | + ): |
| 35 | + wx.Panel.__init__(self, parent) |
| 36 | + DefaultOperationUI.__init__(self, parent, canvas, world, options_path) |
| 37 | + |
| 38 | + self.Freeze() |
| 39 | + self._sizer = wx.BoxSizer(wx.VERTICAL) |
| 40 | + self.SetSizer(self._sizer) |
| 41 | + |
| 42 | + options = self._load_options({}) |
| 43 | + |
| 44 | + self._description = wx.TextCtrl( |
| 45 | + self, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_BESTWRAP, size=(200, 100) |
| 46 | + ) |
| 47 | + self._sizer.Add(self._description, 0, wx.ALL | wx.EXPAND, 5) |
| 48 | + self._description.SetLabel("ワールドの全ディメンションのY255に指定したブロックを敷き詰めます") |
| 49 | + self._description.Fit() |
| 50 | + |
| 51 | + self._block_define = BlockDefine( |
| 52 | + self, |
| 53 | + world.translation_manager, |
| 54 | + wx.VERTICAL, |
| 55 | + *(options.get("fill_block_options", []) or [world.level_wrapper.platform]), |
| 56 | + show_pick_block=True |
| 57 | + ) |
| 58 | + self._block_define.Bind(EVT_PICK, self._on_pick_block_button) |
| 59 | + self._sizer.Add(self._block_define, 1, wx.ALL | wx.ALIGN_CENTRE_HORIZONTAL, 5) |
| 60 | + |
| 61 | + self._run_button = wx.Button(self, label="検索開始") |
| 62 | + self._run_button.Bind(wx.EVT_BUTTON, self._run_operation) |
| 63 | + self._sizer.Add(self._run_button, 0, wx.ALL | wx.ALIGN_CENTRE_HORIZONTAL, 5) |
| 64 | + |
| 65 | + self.Layout() |
| 66 | + self.Thaw() |
| 67 | + |
| 68 | + @property |
| 69 | + def wx_add_options(self) -> Tuple[int, ...]: |
| 70 | + return (1,) |
| 71 | + |
| 72 | + def _on_pick_block_button(self, evt): |
| 73 | + self._show_pointer = True |
| 74 | + |
| 75 | + def disable(self): |
| 76 | + print("Unload CeilingFill") |
| 77 | + |
| 78 | + def _run_operation(self, _): |
| 79 | + self.canvas.run_operation( |
| 80 | + lambda: self._ceiling_fill() |
| 81 | + ) |
| 82 | + |
| 83 | + def _get_fill_block(self) -> Block: |
| 84 | + return self._block_define.universal_block[0] |
| 85 | + |
| 86 | + def _ceiling_fill(self): |
| 87 | + world = self.world |
| 88 | + chunk_count = 0 |
| 89 | + count = 0 |
| 90 | + ( |
| 91 | + fill_platform, |
| 92 | + fill_version, |
| 93 | + fill_blockstate, |
| 94 | + fill_namespace, |
| 95 | + fill_base_name, |
| 96 | + fill_properties, |
| 97 | + ) = ( |
| 98 | + self._block_define.platform, |
| 99 | + self._block_define.version_number, |
| 100 | + self._block_define.force_blockstate, |
| 101 | + self._block_define.namespace, |
| 102 | + self._block_define.block_name, |
| 103 | + self._block_define.str_properties, |
| 104 | + ) |
| 105 | + |
| 106 | + fill_block = self._get_fill_block() |
| 107 | + |
| 108 | + # 全てのディメンションのチャンク数を取得 |
| 109 | + for dimension in world.dimensions: |
| 110 | + chunk_count += len(list(world.all_chunk_coords(dimension))) |
| 111 | + |
| 112 | + for dimension in world.dimensions: |
| 113 | + for cx, cz in world.all_chunk_coords(dimension): |
| 114 | + chunk = world.get_chunk(cx, cz, dimension) |
| 115 | + |
| 116 | + for dx in range(16): |
| 117 | + for dz in range(16): |
| 118 | + chunk.set_block(dx, 255, dz, fill_block) |
| 119 | + |
| 120 | + chunk.changed = True |
| 121 | + |
| 122 | + count += 1 |
| 123 | + yield count / chunk_count |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +export = { |
| 129 | + "name": "天井敷き詰め", # the name of the plugin |
| 130 | + "operation": CeilingFill, # the actual function to call when running the plugin |
| 131 | +} |
0 commit comments