脚本展示
local Script = {}
Script.openFnArgs = {
-- 1. 通用:修改指定坐标的方块ID和数据值
修改方块数据 = {
returnType = Mini.Bool,
displayName = "修改指定坐标的方块数据",
params = {
("坐标"), Mini.Vec3,
("新方块ID"), Mini.Number,
("新方块数据值"), Mini.Number
},
sort = 1,
},
-- 2. 批量:在指定范围内修改所有方块为同一ID和数据值
范围批量修改方块 = {
returnType = Mini.Bool,
displayName = "范围批量修改方块",
params = {
("起始坐标"), Mini.Vec3,
("结束坐标"), Mini.Vec3,
("目标方块ID"), Mini.Number,
("目标方块数据值"), Mini.Number
},
sort = 2,
},
-- 3. 条件:在指定范围内,将匹配ID的方块修改为新ID和数据值
范围条件修改方块 = {
returnType = Mini.Bool,
displayName = "范围条件修改方块",
params = {
("起始坐标"), Mini.Vec3,
("结束坐标"), Mini.Vec3,
("原方块ID"), Mini.Number,
("新方块ID"), Mini.Number,
("新方块数据值"), Mini.Number
},
sort = 3,
},
}
-- 工具函数:检查坐标是否为有效 Mini.Vec3
local function IsValidVec3(pos)
return type(pos) == "table" and type(pos.x) == "number" and type(pos.y) == "number" and type(pos.z) == "number"
end
-- 1. 通用:修改指定坐标的方块ID和数据值
function Script:修改方块数据(pos, newBlockID, newBlockData)
if not IsValidVec3(pos) or type(newBlockID) ~= "number" or type(newBlockData) ~= "number" then
print("[Error] 修改方块数据:参数无效")
return false
end
local x, y, z = pos.x, pos.y, pos.z
local success = Block:SetBlockAll(x, y, z, newBlockID, newBlockData)
if success then
print(string.format("[方块修改] 成功:坐标(%.0f, %.0f, %.0f) → ID:%d, 数据:%d", x, y, z, newBlockID, newBlockData))
else
print(string.format("[方块修改] 失败:坐标(%.0f, %.0f, %.0f)", x, y, z))
end
return success
end
-- 2. 批量:在指定范围内修改所有方块为同一ID和数据值
function Script:范围批量修改方块(startPos, endPos, targetBlockID, targetBlockData)
if not IsValidVec3(startPos) or not IsValidVec3(endPos)
or type(targetBlockID) ~= "number" or type(targetBlockData) ~= "number" then
print("[Error] 范围批量修改方块:参数无效")
return false
end
local startX, startY, startZ = startPos.x, startPos.y, startPos.z
local endX, endY, endZ = endPos.x, endPos.y, endPos.z
local count = 0
for i = startX, endX do
for j = startY, endY do
for k = startZ, endZ do
if Block:SetBlockAll(i, j, k, targetBlockID, targetBlockData) then
count = count + 1
end
end
end
end
print(string.format("[范围批量修改] 成功修改 %d 个方块 → ID:%d, 数据:%d", count, targetBlockID, targetBlockData))
return count > 0
end
-- 3. 条件:在指定范围内,将匹配ID的方块修改为新ID和数据值
function Script:范围条件修改方块(startPos, endPos, oldBlockID, newBlockID, newBlockData)
if not IsValidVec3(startPos) or not IsValidVec3(endPos)
or type(oldBlockID) ~= "number" or type(newBlockID) ~= "number" or type(newBlockData) ~= "number" then
print("[Error] 范围条件修改方块:参数无效")
return false
end
local startX, startY, startZ = startPos.x, startPos.y, startPos.z
local endX, endY, endZ = endPos.x, endPos.y, endPos.z
local count = 0
for i = startX, endX do
for j = startY, endY do
for k = startZ, endZ do
local currentID = Block:GetBlockID(i, j, k)
if currentID == oldBlockID then
if Block:SetBlockAll(i, j, k, newBlockID, newBlockData) then
count = count + 1
end
end
end
end
end
print(string.format("[范围条件修改] 成功修改 %d 个方块:ID:%d → ID:%d, 数据:%d", count, oldBlockID, newBlockID, newBlockData))
return count > 0
end
return Script脚本介绍
此脚本共包含3个函数:1,单次修改指定位置的方块(含ID为0的空气方块)为指定ID方块类型和数据值(方块数据值:数值类型,用于存储方块的颜色,朝向,状态);2,批量修改位置到位置的所有方块的ID和数据值;3,条件批量修改位置到位置的指定方块类型的ID和数据值
脚本用处
适合做生存辅助,可用于催熟作务,随时召唤飞艇和神庙等,更多玩法等你发现
创作灵感及感谢
灵感来源于站长的“催熟作务”脚本,感谢站长的支持发布!