mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-23 02:49:46 +00:00
Merge branch 'main' into release-0.33
This commit is contained in:
commit
ecf8f83a61
18 changed files with 187 additions and 46 deletions
|
|
@ -372,11 +372,17 @@ To generate loot, the function `block_loot(block_id: int)` in the `base:util` mo
|
||||||
|
|
||||||
## Other properties
|
## Other properties
|
||||||
|
|
||||||
|
### *abstract*
|
||||||
|
|
||||||
|
An abstract block is used as a basis for defining blocks of the same type through inheritance (the `parent` property) (example: stairs).
|
||||||
|
As in the case of `hidden=true`, the item for the block is not generated.
|
||||||
|
Unlike `hidden`, the property is not inherited.
|
||||||
|
|
||||||
### *script-name*
|
### *script-name*
|
||||||
|
|
||||||
Used to specify block script name (to reuse one script to multiple blocks). Name must not contain `packid:scripts/` and extension. Just name.
|
Used to specify block script name (to reuse one script to multiple blocks). Name must not contain `packid:scripts/` and extension. Just name.
|
||||||
|
|
||||||
### Tick Interval - *tick-interval*
|
### *tick-interval*
|
||||||
|
|
||||||
The interval in ticks (1/20th of a second). A value of 20 results in an on_block_tick call interval of one second.
|
The interval in ticks (1/20th of a second). A value of 20 results in an on_block_tick call interval of one second.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -372,6 +372,11 @@
|
||||||
|
|
||||||
## Другое
|
## Другое
|
||||||
|
|
||||||
|
### Абстрактный блок - *abstract*
|
||||||
|
|
||||||
|
Абстрактный блок используется исключительно как основа для определений однотипных блоков через наследование (свойство `parent`) (пример: ступеньки). Как в случае `hidden=true` предмет для блока не генерируется.
|
||||||
|
В отличие от `hidden` свойство не наследуется.
|
||||||
|
|
||||||
### Имя скрипта - *script-name*
|
### Имя скрипта - *script-name*
|
||||||
|
|
||||||
Позволяет указать название скрипта блока. Свойство обеспечивает возможность использования одного скрипта для нескольких блоков.
|
Позволяет указать название скрипта блока. Свойство обеспечивает возможность использования одного скрипта для нескольких блоков.
|
||||||
|
|
|
||||||
48
res/content/base/blocks/abstract_stairs.json
Normal file
48
res/content/base/blocks/abstract_stairs.json
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
{
|
||||||
|
"abstract": true,
|
||||||
|
"model": "custom",
|
||||||
|
"model-name": "stairs",
|
||||||
|
"rotation": "stairs",
|
||||||
|
"uv-lock": true,
|
||||||
|
"hitboxes": [
|
||||||
|
[0, 0.0, 0, 1, 0.5, 1.0],
|
||||||
|
[0, 0.5, 0, 1, 0.5, 0.5]
|
||||||
|
],
|
||||||
|
"light-passing": true,
|
||||||
|
"state-based": {
|
||||||
|
"offset": 0,
|
||||||
|
"bits": 3,
|
||||||
|
"variants": [
|
||||||
|
{
|
||||||
|
"model-name": "stairs_inner_left",
|
||||||
|
"hitboxes": [
|
||||||
|
[0.0, 0.0, 0.0, 1.0, 0.5, 1.0],
|
||||||
|
[0.0, 0.5, 0.0, 1.0, 0.5, 0.5],
|
||||||
|
[0.0, 0.5, 0.5, 0.5, 0.5, 0.5]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model-name": "stairs_inner_right",
|
||||||
|
"hitboxes": [
|
||||||
|
[0.0, 0.0, 0.0, 1.0, 0.5, 1.0],
|
||||||
|
[0.0, 0.5, 0.0, 1.0, 0.5, 0.5],
|
||||||
|
[0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model-name": "stairs_outer_left",
|
||||||
|
"hitboxes": [
|
||||||
|
[0.0, 0.0, 0.0, 1.0, 0.5, 1.0],
|
||||||
|
[0.0, 0.5, 0.0, 0.5, 0.5, 0.5]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model-name": "stairs_outer_right",
|
||||||
|
"hitboxes": [
|
||||||
|
[0.0, 0.0, 0.0, 1.0, 0.5, 1.0],
|
||||||
|
[0.5, 0.5, 0.0, 0.5, 0.5, 0.5]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
5
res/content/base/blocks/brick_stairs.json
Normal file
5
res/content/base/blocks/brick_stairs.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"parent": "base:abstract_stairs",
|
||||||
|
"texture": "brick",
|
||||||
|
"base:durability": 10.5
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
{
|
{
|
||||||
"entities": [
|
"items": [
|
||||||
"drop",
|
"bazalt_breaker"
|
||||||
"player",
|
|
||||||
"falling_block"
|
|
||||||
],
|
],
|
||||||
"blocks": [
|
"blocks": [
|
||||||
"dirt",
|
"dirt",
|
||||||
|
|
@ -30,9 +28,13 @@
|
||||||
"torch",
|
"torch",
|
||||||
"wooden_door",
|
"wooden_door",
|
||||||
"coal_ore",
|
"coal_ore",
|
||||||
"ice"
|
"ice",
|
||||||
|
"brick_stairs",
|
||||||
|
"abstract_stairs"
|
||||||
],
|
],
|
||||||
"items": [
|
"entities": [
|
||||||
"bazalt_breaker"
|
"drop",
|
||||||
|
"player",
|
||||||
|
"falling_block"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -14,5 +14,6 @@
|
||||||
["radius", 0.3],
|
["radius", 0.3],
|
||||||
["radius", 1.6]
|
["radius", 1.6]
|
||||||
],
|
],
|
||||||
"blocking": false
|
"blocking": false,
|
||||||
|
"translucent": true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,6 @@
|
||||||
],
|
],
|
||||||
"skeleton-name": "base:block",
|
"skeleton-name": "base:block",
|
||||||
"hitbox": [0.98, 0.98, 0.98],
|
"hitbox": [0.98, 0.98, 0.98],
|
||||||
"solid": true
|
"solid": true,
|
||||||
|
"translucent": true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
65
res/content/base/scripts/abstract_stairs.lua
Normal file
65
res/content/base/scripts/abstract_stairs.lua
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
-- variants
|
||||||
|
local DEFAULT = 0
|
||||||
|
local INNER_LEFT = 1
|
||||||
|
local INNER_RIGHT = 2
|
||||||
|
local OUTER_LEFT = 3
|
||||||
|
local OUTER_RIGHT = 4
|
||||||
|
|
||||||
|
local function get_stairs_info(id, x, y, z)
|
||||||
|
if block.get(x, y, z) ~= id then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local zx, _, zz = block.get_Z(x, y, z)
|
||||||
|
local _, half = block.get_Y(x, y, z)
|
||||||
|
return -zx, -zz, half
|
||||||
|
end
|
||||||
|
|
||||||
|
local function detect_variant(id, x, y, z)
|
||||||
|
local bx, bz, half = get_stairs_info(id, x, y, z)
|
||||||
|
local lx, _, lz = block.get_X(x, y, z)
|
||||||
|
lx, lz = -lx, -lz
|
||||||
|
|
||||||
|
local function is_oriented_same(ox, oz)
|
||||||
|
local nbx, nbz, nhalf = get_stairs_info(id, x + ox, y, z + oz)
|
||||||
|
return nbx == bx and nbz == bz and nhalf == half
|
||||||
|
end
|
||||||
|
|
||||||
|
local function corner_side(ox, oz, sign)
|
||||||
|
local nbx, nbz, nhalf = get_stairs_info(id, x + ox, y, z + oz)
|
||||||
|
if nbx == nil or nhalf ~= half or nbx * bx + nbz * bz ~= 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if is_oriented_same(nbx * sign, nbz * sign) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return nbx == lx and nbz == lz
|
||||||
|
end
|
||||||
|
|
||||||
|
local left = corner_side(bx, bz, -1)
|
||||||
|
if left ~= nil then
|
||||||
|
return left and OUTER_LEFT or OUTER_RIGHT
|
||||||
|
end
|
||||||
|
left = corner_side(-bx, -bz, 1)
|
||||||
|
if left ~= nil then
|
||||||
|
return left and INNER_LEFT or INNER_RIGHT
|
||||||
|
end
|
||||||
|
return DEFAULT
|
||||||
|
end
|
||||||
|
|
||||||
|
local function refresh(x, y, z, keep_variant)
|
||||||
|
local variant = detect_variant(block.get(x, y, z), x, y, z)
|
||||||
|
if keep_variant and variant == DEFAULT then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if block.get_variant(x, y, z) ~= variant then
|
||||||
|
block.set_variant(x, y, z, variant)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_placed(x, y, z)
|
||||||
|
refresh(x, y, z, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_update(x, y, z)
|
||||||
|
refresh(x, y, z, true)
|
||||||
|
end
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@box from (0,0,0) to (1,0.5,1) delete (top,north)
|
@box from (0,0,0) to (1,0.5,1) delete (top,north)
|
||||||
@box from (0,0.5,0) to (1,1,0.5) delete (bottom,north)
|
@box from (0,0.5,0) to (1,1,0.5) delete (bottom,north)
|
||||||
@rect from (0,0.5,0.5) right (1,0,0) up (0,0,0.5) texture "$2"
|
@rect from (1.0,0.5,1.0) right (-1,0,0) up (0,0,-0.5) texture "$2"
|
||||||
@rect from (0,0,0) right (1,0,0) up (0,1,0) texture "$1"
|
@rect from (0,0,0) right (1,0,0) up (0,1,0) texture "$1"
|
||||||
|
|
|
||||||
3
res/models/stairs_inner_left.vcm
Normal file
3
res/models/stairs_inner_left.vcm
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
@box from (0,0,0) to (1,0.5,1)
|
||||||
|
@box from (0,0.5,0) to (1,1,0.5) delete (bottom)
|
||||||
|
@box from (0,0.5,0.5) to (0.5,1,1) delete (bottom,north)
|
||||||
3
res/models/stairs_inner_right.vcm
Normal file
3
res/models/stairs_inner_right.vcm
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
@box from (0,0,0) to (1,0.5,1)
|
||||||
|
@box from (0,0.5,0) to (1,1,0.5) delete (bottom)
|
||||||
|
@box from (0.5,0.5,0.5) to (1,1,1) delete (bottom,north)
|
||||||
2
res/models/stairs_outer_left.vcm
Normal file
2
res/models/stairs_outer_left.vcm
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
@box from (0,0,0) to (1,0.5,1)
|
||||||
|
@box from (0,0.5,0) to (0.5,1,0.5) delete (bottom)
|
||||||
2
res/models/stairs_outer_right.vcm
Normal file
2
res/models/stairs_outer_right.vcm
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
@box from (0,0,0) to (1,0.5,1)
|
||||||
|
@box from (0.5,0.5,0) to (1,1,0.5) delete (bottom)
|
||||||
|
|
@ -193,45 +193,36 @@ static void perform_rect(const xmlelement& root, ModelBuilder& builder) {
|
||||||
std::string texture = root.attr("texture", "$0").getText();
|
std::string texture = root.attr("texture", "$0").getText();
|
||||||
|
|
||||||
glm::vec3 normal;
|
glm::vec3 normal;
|
||||||
|
glm::vec3 backNormal;
|
||||||
if (root.has("normal")) {
|
if (root.has("normal")) {
|
||||||
normal = root.attr("normal").asVec3();
|
normal = root.attr("normal").asVec3();
|
||||||
|
backNormal = normal;
|
||||||
} else {
|
} else {
|
||||||
normal = glm::cross(glm::normalize(right), glm::normalize(up));
|
normal = glm::cross(glm::normalize(right), glm::normalize(up));
|
||||||
|
backNormal = -normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 center = from + right * 0.5f + up * 0.5f;
|
||||||
|
UVRegion backRegion = region;
|
||||||
|
std::swap(backRegion.u1, backRegion.u2);
|
||||||
|
|
||||||
auto cullFace = root.attr("cull-face", "back").getText();
|
auto cullFace = root.attr("cull-face", "back").getText();
|
||||||
if (cullFace == "front") {
|
if (cullFace != "front") {
|
||||||
normal *= -1.0f;
|
|
||||||
} else if (cullFace == "off") {
|
|
||||||
builder.addRect(
|
builder.addRect(
|
||||||
texture,
|
texture, shading, center, right * 0.5f, up * 0.5f, normal, region
|
||||||
shading,
|
|
||||||
from + right * 0.5f + up * 0.5f,
|
|
||||||
right * 0.5f,
|
|
||||||
up * 0.5f,
|
|
||||||
normal,
|
|
||||||
region
|
|
||||||
);
|
);
|
||||||
builder.addRect(
|
|
||||||
texture,
|
|
||||||
shading,
|
|
||||||
from + right * 0.5f + up * 0.5f,
|
|
||||||
right * -0.5f,
|
|
||||||
up * -0.5f,
|
|
||||||
-normal,
|
|
||||||
region
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (cullFace == "front" || cullFace == "off") {
|
||||||
builder.addRect(
|
builder.addRect(
|
||||||
texture,
|
texture,
|
||||||
shading,
|
shading,
|
||||||
from + right * 0.5f + up * 0.5f,
|
center,
|
||||||
right * 0.5f,
|
right * -0.5f,
|
||||||
up * 0.5f,
|
up * 0.5f,
|
||||||
normal,
|
backNormal,
|
||||||
region
|
backRegion
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perform_triangle(const xmlelement& root, ModelBuilder& builder) {
|
static void perform_triangle(const xmlelement& root, ModelBuilder& builder) {
|
||||||
|
|
@ -249,10 +240,13 @@ static void perform_triangle(const xmlelement& root, ModelBuilder& builder) {
|
||||||
glm::vec3 ba = pointB - pointA;
|
glm::vec3 ba = pointB - pointA;
|
||||||
glm::vec3 ca = pointC - pointA;
|
glm::vec3 ca = pointC - pointA;
|
||||||
glm::vec3 normal;
|
glm::vec3 normal;
|
||||||
|
glm::vec3 backNormal;
|
||||||
if (root.has("normal")) {
|
if (root.has("normal")) {
|
||||||
normal = root.attr("normal").asVec3();
|
normal = root.attr("normal").asVec3();
|
||||||
|
backNormal = normal;
|
||||||
} else {
|
} else {
|
||||||
normal = glm::normalize(glm::cross(ba, ca));
|
normal = glm::normalize(glm::cross(ba, ca));
|
||||||
|
backNormal = -normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root.has("uv")) {
|
if (root.has("uv")) {
|
||||||
|
|
@ -276,10 +270,10 @@ static void perform_triangle(const xmlelement& root, ModelBuilder& builder) {
|
||||||
if (cullFace == "front") {
|
if (cullFace == "front") {
|
||||||
std::swap(pointB, pointC);
|
std::swap(pointB, pointC);
|
||||||
std::swap(uvs[1], uvs[2]);
|
std::swap(uvs[1], uvs[2]);
|
||||||
normal *= -1.0f;
|
normal = backNormal;
|
||||||
} else if (cullFace == "off") {
|
} else if (cullFace == "off") {
|
||||||
builder.addTriangle(texture, shading, pointA, pointB, pointC, normal, uvs[0], uvs[1], uvs[2]);
|
builder.addTriangle(texture, shading, pointA, pointB, pointC, normal, uvs[0], uvs[1], uvs[2]);
|
||||||
builder.addTriangle(texture, shading, pointA, pointC, pointB, -normal, uvs[0], uvs[2], uvs[1]);
|
builder.addTriangle(texture, shading, pointA, pointC, pointB, backNormal, uvs[0], uvs[2], uvs[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
builder.addTriangle(texture, shading, pointA, pointB, pointC, normal, uvs[0], uvs[1], uvs[2]);
|
builder.addTriangle(texture, shading, pointA, pointB, pointC, normal, uvs[0], uvs[1], uvs[2]);
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
||||||
content->items
|
content->items
|
||||||
.require(
|
.require(
|
||||||
def->pickingItem.empty()
|
def->pickingItem.empty()
|
||||||
? (def->hidden ? CORE_EMPTY
|
? ((def->abstract || def->hidden) ? CORE_EMPTY
|
||||||
: def->name + BLOCK_ITEM_SUFFIX)
|
: def->name + BLOCK_ITEM_SUFFIX)
|
||||||
: def->pickingItem
|
: def->pickingItem
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ void ContentLoader::loadContent(const dv::value& root) {
|
||||||
|
|
||||||
ContentUnitLoader<Block>(*pack, builder.blocks, "blocks",
|
ContentUnitLoader<Block>(*pack, builder.blocks, "blocks",
|
||||||
[this](const Block& def) {
|
[this](const Block& def) {
|
||||||
if (!def.hidden) {
|
if (!def.abstract && !def.hidden) {
|
||||||
bool created;
|
bool created;
|
||||||
auto& item = builder.items.create(
|
auto& item = builder.items.create(
|
||||||
def.name + BLOCK_ITEM_SUFFIX, &created
|
def.name + BLOCK_ITEM_SUFFIX, &created
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,7 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
||||||
root.at("selectable").get(def.selectable);
|
root.at("selectable").get(def.selectable);
|
||||||
root.at("grounded").get(def.grounded);
|
root.at("grounded").get(def.grounded);
|
||||||
root.at("hidden").get(def.hidden);
|
root.at("hidden").get(def.hidden);
|
||||||
|
root.at("abstract").get(def.abstract);
|
||||||
root.at("picking-item").get(def.pickingItem);
|
root.at("picking-item").get(def.pickingItem);
|
||||||
root.at("surface-replacement").get(def.surfaceReplacement);
|
root.at("surface-replacement").get(def.surfaceReplacement);
|
||||||
root.at("script-name").get(def.scriptName);
|
root.at("script-name").get(def.scriptName);
|
||||||
|
|
@ -286,7 +287,7 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
||||||
def.tickInterval = 1;
|
def.tickInterval = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def.hidden && def.pickingItem == def.name + BLOCK_ITEM_SUFFIX) {
|
if ((def.abstract || def.hidden) && def.pickingItem == def.name + BLOCK_ITEM_SUFFIX) {
|
||||||
def.pickingItem = CORE_EMPTY;
|
def.pickingItem = CORE_EMPTY;
|
||||||
}
|
}
|
||||||
if (root.has("script-name") || def.scriptFile.empty()) {
|
if (root.has("script-name") || def.scriptFile.empty()) {
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,9 @@ public:
|
||||||
/// below
|
/// below
|
||||||
bool grounded = false;
|
bool grounded = false;
|
||||||
|
|
||||||
|
/// @brief Makes block abstract
|
||||||
|
bool abstract = false;
|
||||||
|
|
||||||
/// @brief Turns off block item generation
|
/// @brief Turns off block item generation
|
||||||
bool hidden = false;
|
bool hidden = false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue