Scrafitipty/README.md
2025-07-29 14:04:21 +08:00

107 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Scrafitipty暂定名称 - 脚本执行器
![Minecraft Fabric](https://img.shields.io/badge/Minecraft-1.21.4-green) ![Mod Loader](https://img.shields.io/badge/Mod%20Loader-Fabric-blue)
Scrafitipty(暂定名称) 是一个 Minecraft Fabric Mod允许玩家在游戏中运行自定义脚本来自动化任务、扩展游戏功能。它提供了一个类似 Python 的脚本语言解释器,让玩家可以编写简单的脚本来控制游戏行为。
> **重要提示**
> 此 Mod 仍处于**半成品阶段**,功能有限且可能存在不稳定性。脚本语法只是**表面上类似 Python**,但**并未使用真正的 Python 解释器**。
### 基本命令
| 命令 | 描述 | 示例 |
|------|------|------|
| `/scrafitipty run <脚本名>` | 运行指定脚本 | `/scrafitipty run example_script` |
| `/scrafitipty open <脚本名>` | 打开脚本文件 | `/scrafitipty open example_script` |
| `/scrafitipty open_folder` | 打开脚本文件夹 | `/scrafitipty open_folder` |
| `/scrafitipty list` | 列出所有可用脚本 | `/scrafitipty list` |
| `/scrafitipty delete <脚本名>` | 删除脚本 | `/scrafitipty delete old_script` |
首次使用时,系统会自动在游戏目录下创建 `Scrafitipty_scripts` 文件夹,并生成一个示例脚本 `example_script.py`
### 脚本位置
所有脚本都存储在 Minecraft 根目录下的 `Scrafitipty_scripts` 文件夹中:
```
.minecraft/
└── Scrafitipty_scripts/
├── example_script.py
└── your_scripts_here.py
```
### 基本语法
Scrafitipty 使用类似 Python 的语法,但请注意:
- **不是真正的 Python** - 这是一个简化版的自定义脚本语言
- 支持变量、条件语句(`if`/`else`)、循环(`while`)
- 使用缩进4个空格表示代码块
- 支持单行注释(以 `#` 开头)
### 内置函数
#### 游戏交互
| 函数 | 参数 | 描述 | 示例 |
|------|------|------|------|
| `send_chat(message)` | `message`: 字符串 | 发送聊天消息 | `send_chat("Hello Minecraft!")` |
| `send_command(command)` | `command`: 字符串 | 执行游戏命令 | `send_command("time set day")` |
| `print_output(message)` | `message`: 字符串 | 显示仅自己可见的消息 | `print_output("脚本运行中...")` |
| `get_player_x()` | 无 | 获取玩家 X 坐标 | `x = get_player_x()` |
| `get_player_y()` | 无 | 获取玩家 Y 坐标 | `y = get_player_y()` |
| `get_player_z()` | 无 | 获取玩家 Z 坐标 | `z = get_player_z()` |
| `get_player_dimension()` | 无 | 获取玩家当前维度 | `dim = get_player_dimension()` |
| `get_time()` | 无 | 获取游戏时间 | `time = get_time()` |
| `get_block_id(x, y, z)` | `x, y, z`: 数字 | 获取指定位置的方块ID | `block = get_block_id(0, 64, 0)` |
| `crash_game()` | 无 | 崩溃游戏(测试用) | `crash_game()` |
| `sleep(milliseconds)` | `milliseconds`: 数字 | 延迟执行 | `sleep(2000) # 等待2秒` |
#### 实用功能
| 函数 | 参数 | 描述 | 示例 |
|------|------|------|------|
| `get_random_number(min, max)` | `min, max`: 数字 | 生成随机整数 | `rand = get_random_number(1, 100)` |
| `execute_system_command(command)` | `command`: 字符串 | 执行系统命令(**危险!** | `execute_system_command("notepad.exe")` |
### 数据类型
- **数字**:整数和浮点数(`123`, `3.14`
- **字符串**:用双引号包围(`"Hello"`
- **布尔值**`true``false`
- **变量**:动态类型,无需声明类型
### 控制结构
#### 条件语句
```python
if condition:
# 条件为真时执行
else:
# 条件为假时执行
```
#### 循环
```python
count = 0
while count < 5:
print_output("计数: " + str(count))
count = count + 1
sleep(500)
```
### 运算符
| 类型 | 运算符 | 示例 |
|------|--------|------|
| 算术 | `+`, `-`, `*`, `/` | `result = 10 + 5` |
| 比较 | `==`, `!=`, `<`, `>`, `<=`, `>=` | `if x > 10: ...` |
| 逻辑 | `and`, `or`, `not` | `if a and b: ...` |
### 类型转换
```python
# 转换为字符串
str_value = str(123) # "123"
# 字符串转数字(需要手动实现)
# 当前版本暂不支持自动转换
```