mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
Merge branch 'main' into animation
This commit is contained in:
commit
282c9b3de2
68 changed files with 1419 additions and 488 deletions
|
|
@ -1,3 +1,4 @@
|
|||
generator = "base:demo"
|
||||
player-entity = "base:player"
|
||||
hand-skeleton = "base:hand"
|
||||
block-material = "base:stone"
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ function util.drop(ppos, itemid, count, data, pickup_delay)
|
|||
}})
|
||||
end
|
||||
|
||||
local function calc_loot(loot_table)
|
||||
function util.calc_loot(loot_table)
|
||||
local results = {}
|
||||
for _, loot in ipairs(loot_table) do
|
||||
local chance = loot.chance or 1
|
||||
local count = loot.count or 1
|
||||
|
||||
|
||||
local roll = math.random()
|
||||
|
||||
|
||||
if roll < chance then
|
||||
if loot.min and loot.max then
|
||||
count = math.random(loot.min, loot.max)
|
||||
|
|
@ -37,7 +37,7 @@ end
|
|||
function util.block_loot(blockid)
|
||||
local lootscheme = block.properties[blockid]["base:loot"]
|
||||
if lootscheme then
|
||||
return calc_loot(lootscheme)
|
||||
return util.calc_loot(lootscheme)
|
||||
end
|
||||
return {{item=block.get_picking_item(blockid), count=1}}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
local dirtid = block.index("base:dirt")
|
||||
local grass_blockid = block.index("base:grass_block")
|
||||
|
||||
local offsets = {}
|
||||
for lx=-1,1 do
|
||||
for ly=-1,1 do
|
||||
|
|
@ -8,18 +11,17 @@ for lx=-1,1 do
|
|||
end
|
||||
|
||||
function on_random_update(x, y, z)
|
||||
local dirtid = block.index('base:dirt');
|
||||
if block.is_solid_at(x, y+1, z) then
|
||||
block.set(x, y, z, dirtid, 0)
|
||||
return
|
||||
end
|
||||
local grassblockid = block.index('base:grass_block')
|
||||
|
||||
for _, offset in ipairs(offsets) do
|
||||
local nx, ny, nz = x + offset[1], y + offset[2], z + offset[3]
|
||||
|
||||
if block.get(nx, ny, nz) == dirtid and
|
||||
not block.is_solid_at(nx, ny + 1, nz) then
|
||||
block.set(nx, ny, nz, grassblockid, 0)
|
||||
block.set(nx, ny, nz, grass_blockid, 0)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ function on_open(params)
|
|||
mode = params.mode
|
||||
end
|
||||
refresh()
|
||||
document.search_textbox.focused = true
|
||||
end
|
||||
|
||||
-- add - packs to be added to the world (after apply)
|
||||
|
|
@ -178,40 +179,40 @@ function place_pack(panel, packinfo, callback, position_func)
|
|||
end
|
||||
end
|
||||
|
||||
local Version = {};
|
||||
local Version = {}
|
||||
|
||||
function Version.matches_pattern(version)
|
||||
for _, letter in string.gmatch(version, "%.+") do
|
||||
if type(letter) ~= "number" or letter ~= "." then
|
||||
return false;
|
||||
end
|
||||
local t = string.split(version, ".")
|
||||
if #t ~= 2 and #t ~= 3 then return false end
|
||||
|
||||
local t = string.split(version, ".");
|
||||
|
||||
return #t == 2 or #t == 3;
|
||||
for i = 1, #t do
|
||||
local matched = string.match(t[i], "^%d+$")
|
||||
if not matched then return false end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function Version.__equal(ver1, ver2)
|
||||
return ver1[1] == ver2[1] and ver1[2] == ver2[2] and ver1[3] == ver2[3];
|
||||
return ver1[1] == ver2[1] and ver1[2] == ver2[2] and ver1[3] == ver2[3]
|
||||
end
|
||||
|
||||
function Version.__greater(ver1, ver2)
|
||||
if ver1[1] ~= ver2[1] then return ver1[1] > ver2[1] end;
|
||||
if ver1[2] ~= ver2[2] then return ver1[2] > ver2[2] end;
|
||||
return ver1[3] > ver2[3];
|
||||
if ver1[1] ~= ver2[1] then return ver1[1] > ver2[1] end
|
||||
if ver1[2] ~= ver2[2] then return ver1[2] > ver2[2] end
|
||||
return ver1[3] > ver2[3]
|
||||
end
|
||||
|
||||
function Version.__less(ver1, ver2)
|
||||
return Version.__greater(ver2, ver1);
|
||||
return Version.__greater(ver2, ver1)
|
||||
end
|
||||
|
||||
function Version.__greater_or_equal(ver1, ver2)
|
||||
return not Version.__less(ver1, ver2);
|
||||
return not Version.__less(ver2, ver1)
|
||||
end
|
||||
|
||||
function Version.__less_or_equal(ver1, ver2)
|
||||
return not Version.__greater(ver1, ver2);
|
||||
return not Version.__greater(ver1, ver2)
|
||||
end
|
||||
|
||||
Version.operators = {
|
||||
|
|
@ -223,40 +224,39 @@ Version.operators = {
|
|||
}
|
||||
|
||||
function Version.compare(op, ver1, ver2)
|
||||
ver1 = string.split(ver1, ".");
|
||||
ver2 = string.split(ver2, ".");
|
||||
ver1 = string.split(ver1, ".")
|
||||
ver2 = string.split(ver2, ".")
|
||||
|
||||
local comparison_func = Version.operators[op];
|
||||
|
||||
if comparison_func then
|
||||
return comparison_func(ver1, ver2);
|
||||
return comparison_func(ver1, ver2)
|
||||
else
|
||||
return false;
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function Version.parse(version)
|
||||
local op = string.sub(version, 1, 2);
|
||||
local op = string.sub(version, 1, 2)
|
||||
if op == ">=" or op == "<=" then
|
||||
return op, string.sub(version, #op + 1);
|
||||
return op, string.sub(version, #op + 1)
|
||||
end
|
||||
|
||||
op = string.sub(version, 1, 1);
|
||||
if op == ">" or op == "<" then
|
||||
return op, string.sub(version, #op + 1);
|
||||
return op, string.sub(version, #op + 1)
|
||||
end
|
||||
|
||||
return "=", version;
|
||||
return "=", version
|
||||
end
|
||||
|
||||
local function compare_version(dependent_version, actual_version)
|
||||
local function compare_version(op, dependent_version, actual_version)
|
||||
if Version.matches_pattern(dependent_version) and Version.matches_pattern(actual_version) then
|
||||
local op, dep_ver = Version.parse_version(dependent_version);
|
||||
Version.compare(op, dep_ver, actual_version);
|
||||
return Version.compare(op, dep_ver, actual_version)
|
||||
elseif dependent_version == "*" or dependent_version == actual_version then
|
||||
return true;
|
||||
return true
|
||||
else
|
||||
return false;
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -276,15 +276,15 @@ function check_dependencies(packinfo)
|
|||
)
|
||||
end
|
||||
|
||||
local dep_pack = pack.get_info(depid);
|
||||
|
||||
if not compare_version(depver, dep_pack.version) then
|
||||
local op, ver = Version.parse(depver)
|
||||
local dep_pack = pack.get_info(depid)
|
||||
local op, ver = Version.parse(depver)
|
||||
|
||||
if not compare_version(op, ver, dep_pack.version) then
|
||||
return string.format(
|
||||
"%s: %s != %s (%s)",
|
||||
gui.str("error.dependency-version-not-met"),
|
||||
dep_pack.version, ver, depid
|
||||
);
|
||||
)
|
||||
end
|
||||
|
||||
if table.has(packs_installed, packinfo.id) then
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ local FFI = ffi
|
|||
|
||||
FFI.cdef[[
|
||||
void* malloc(size_t);
|
||||
void* realloc(void*, size_t);
|
||||
void free(void*);
|
||||
typedef struct {
|
||||
unsigned char* bytes;
|
||||
int size;
|
||||
int capacity;
|
||||
} bytearray_t;
|
||||
void* memmove(void*, const void*, size_t);
|
||||
]]
|
||||
|
||||
local free = FFI.C.free
|
||||
|
|
@ -22,12 +24,33 @@ local GC_THRESHOLD = 50 * 1024 * 1024
|
|||
|
||||
local function malloc(size)
|
||||
local raw = FFI.C.malloc(size)
|
||||
if raw == nil then
|
||||
return nil
|
||||
if not raw then
|
||||
error("failed memory allocation of " .. size .. " bytes")
|
||||
end
|
||||
|
||||
allocated_bytes = allocated_bytes + size
|
||||
if allocated_bytes >= GC_THRESHOLD then
|
||||
collectgarbage("step", 200)
|
||||
allocated_bytes = 0
|
||||
end
|
||||
|
||||
return raw
|
||||
end
|
||||
|
||||
local function realloc(buff, size, throwerror)
|
||||
if throwerror == nil then throwerror = true end
|
||||
|
||||
if size <= 0 then
|
||||
free(buff)
|
||||
return
|
||||
end
|
||||
|
||||
local raw = FFI.C.realloc(buff, size)
|
||||
if not raw and throwerror then
|
||||
error("failed memory reallocation of block " .. buff .. " to new size " .. size)
|
||||
end
|
||||
|
||||
allocated_bytes = allocated_bytes + size
|
||||
if allocated_bytes >= GC_THRESHOLD then
|
||||
collectgarbage("step", 200)
|
||||
allocated_bytes = 0
|
||||
|
|
@ -38,23 +61,17 @@ end
|
|||
|
||||
local function grow_buffer(self, elems)
|
||||
local new_capacity = math.ceil(self.capacity / 0.75 + elems)
|
||||
local prev = self.bytes
|
||||
self.bytes = malloc(new_capacity)
|
||||
FFI.copy(self.bytes, prev, self.size)
|
||||
self.bytes = realloc(self.bytes, new_capacity)
|
||||
self.capacity = new_capacity
|
||||
free(prev)
|
||||
end
|
||||
|
||||
local function trim_buffer(self)
|
||||
if self.size == self.capacity then
|
||||
return
|
||||
if self.size == self.capacity then return end
|
||||
local new_bytes = realloc(self.bytes, self.size, false)
|
||||
if new_bytes then
|
||||
self.bytes = new_bytes
|
||||
self.capacity = self.size
|
||||
end
|
||||
local size = self.size
|
||||
local prev = self.bytes
|
||||
self.bytes = malloc(size)
|
||||
FFI.copy(self.bytes, prev, self.size)
|
||||
self.capacity = size
|
||||
free(prev)
|
||||
end
|
||||
|
||||
local function count_elements(b)
|
||||
|
|
@ -125,15 +142,21 @@ local function clear(self)
|
|||
self.size = 0
|
||||
end
|
||||
|
||||
local function reserve(self, new_capacity)
|
||||
if new_capacity <= self.capacity then
|
||||
return
|
||||
local function fill(self, index, size, byte)
|
||||
if index ~= nil and size ~= nil and size > 0 then
|
||||
if index < 1 or index + size - 1 > self.size then
|
||||
error("selected fill range is out of array bounds")
|
||||
end
|
||||
FFI.fill(self.bytes + index - 1, size, byte)
|
||||
else
|
||||
FFI.fill(self.bytes, self.size, byte)
|
||||
end
|
||||
local prev = self.bytes
|
||||
self.bytes = malloc(new_capacity)
|
||||
FFI.copy(self.bytes, prev, self.size)
|
||||
end
|
||||
|
||||
local function reserve(self, new_capacity)
|
||||
if new_capacity <= self.capacity then return end
|
||||
self.bytes = realloc(self.bytes, new_capacity)
|
||||
self.capacity = new_capacity
|
||||
free(prev)
|
||||
end
|
||||
|
||||
local function get_capacity(self)
|
||||
|
|
@ -150,22 +173,46 @@ local function slice(self, offset, length)
|
|||
length = self.size - offset + 1
|
||||
end
|
||||
local buffer = malloc(length)
|
||||
if not buffer then
|
||||
error("malloc(" .. length .. ") returned NULL")
|
||||
end
|
||||
FFI.copy(buffer, self.bytes + (offset - 1), length)
|
||||
return bytearray_type(buffer, length, length)
|
||||
end
|
||||
|
||||
local function copy(self, srcindex, dst, dstindex, size)
|
||||
if size <= 0 then error("size of byte range must be positive non-zero integer") end
|
||||
if srcindex < 1 or srcindex + size - 1 > self.size then
|
||||
error("specified source byte range is out of source array bounds")
|
||||
end
|
||||
if dstindex < 1 or dstindex + size - 1 > dst.size then
|
||||
error("specified destination byte range is out of destination array bounds")
|
||||
end
|
||||
|
||||
FFI.copy(dst.bytes + dstindex - 1, self.bytes + srcindex - 1, size)
|
||||
end
|
||||
|
||||
local function move(self, fromindex, toindex, size)
|
||||
if size <= 0 then error("size of byte range must be positive non-zero integer") end
|
||||
if fromindex < 1 or fromindex + size - 1 > self.size then
|
||||
error("specified source byte range is out of array bounds")
|
||||
end
|
||||
if toindex < 1 or toindex + size - 1 > self.size then
|
||||
error("specified destination byte range is out of array bounds")
|
||||
end
|
||||
|
||||
FFI.C.memmove(self.bytes + toindex - 1, self.bytes + fromindex - 1, size)
|
||||
end
|
||||
|
||||
local bytearray_methods = {
|
||||
append=append,
|
||||
insert=insert,
|
||||
remove=remove,
|
||||
trim=trim_buffer,
|
||||
clear=clear,
|
||||
reserve=reserve,
|
||||
get_capacity=get_capacity,
|
||||
slice=slice,
|
||||
append = append,
|
||||
insert = insert,
|
||||
remove = remove,
|
||||
trim = trim_buffer,
|
||||
clear = clear,
|
||||
reserve = reserve,
|
||||
get_capacity = get_capacity,
|
||||
slice = slice,
|
||||
fill = fill,
|
||||
copy = copy,
|
||||
move = move
|
||||
}
|
||||
|
||||
local bytearray_mt = {
|
||||
|
|
@ -256,7 +303,8 @@ local function FFIBytearray_as_string(bytes)
|
|||
end
|
||||
end
|
||||
|
||||
local function create_FFIview_class(name, typename, typesize)
|
||||
local function create_FFIview_class(name, typename)
|
||||
local typesize = FFI.sizeof(typename)
|
||||
local ptrtype = typename .. "*"
|
||||
local FFIview_mt = {
|
||||
__index = function(self, key)
|
||||
|
|
@ -291,27 +339,44 @@ local function create_FFIview_class(name, typename, typesize)
|
|||
return i, ptr[i - 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
||||
return function (bytes)
|
||||
local x = setmetatable({
|
||||
bytes=bytes,
|
||||
}, FFIview_mt)
|
||||
return x
|
||||
end
|
||||
return setmetatable({}, {
|
||||
__call = function (self, bytes)
|
||||
local x = setmetatable({
|
||||
bytes=bytes,
|
||||
}, FFIview_mt)
|
||||
return x
|
||||
end,
|
||||
__index = {
|
||||
typesize = function()
|
||||
return typesize
|
||||
end
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
local FFII16view = create_FFIview_class("FFII16view", "int16_t", 2)
|
||||
local FFIU16view = create_FFIview_class("FFIU16view", "uint16_t", 2)
|
||||
local FFII32view = create_FFIview_class("FFII32view", "int32_t", 4)
|
||||
local FFIU32view = create_FFIview_class("FFIU32view", "uint32_t", 4)
|
||||
local FFII8view = create_FFIview_class("FFII8view", "int8_t")
|
||||
local FFII16view = create_FFIview_class("FFII16view", "int16_t")
|
||||
local FFIU16view = create_FFIview_class("FFIU16view", "uint16_t")
|
||||
local FFII32view = create_FFIview_class("FFII32view", "int32_t")
|
||||
local FFIU32view = create_FFIview_class("FFIU32view", "uint32_t")
|
||||
local FFII64view = create_FFIview_class("FFII64view", "int64_t")
|
||||
local FFIU64view = create_FFIview_class("FFIU64view", "uint64_t")
|
||||
local FFIFLTview = create_FFIview_class("FFIFLTview", "float")
|
||||
local FFIDBLview = create_FFIview_class("FFIDBLview", "double")
|
||||
|
||||
return {
|
||||
FFIBytearray = setmetatable(FFIBytearray, FFIBytearray),
|
||||
FFIBytearray_as_string = FFIBytearray_as_string,
|
||||
FFIBytearray_as_ptr = FFIBytearray_as_ptr,
|
||||
FFII8view = FFII8view,
|
||||
FFIU16view = FFIU16view,
|
||||
FFII16view = FFII16view,
|
||||
FFIU32view = FFIU32view,
|
||||
FFII32view = FFII32view,
|
||||
FFIU64view = FFIU64view,
|
||||
FFII64view = FFII64view,
|
||||
FFIFLTview = FFIFLTview,
|
||||
FFIDBLview = FFIDBLview,
|
||||
}
|
||||
|
|
|
|||
38
res/modules/internal/ctypes.lua
Normal file
38
res/modules/internal/ctypes.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
local FFI = ffi
|
||||
|
||||
FFI.cdef[[
|
||||
unsigned long long strtoull(const char* nptr, char** endptr, int base);
|
||||
long long strtoll(const char* nptr, char** endptr, int base);
|
||||
]]
|
||||
|
||||
local this = {}
|
||||
|
||||
local function create_integral_type(ctype_name, signed)
|
||||
local parse_func = signed and FFI.C.strtoll or FFI.C.strtoull
|
||||
return function(value, base)
|
||||
value = value or 0
|
||||
local typename = type(value)
|
||||
if typename == "number" then
|
||||
return FFI.cast(ctype_name, value)
|
||||
elseif typename == "string" then
|
||||
if type(base) ~= "number" then
|
||||
base = 10
|
||||
end
|
||||
return parse_func(value, nil, base)
|
||||
end
|
||||
error(string.format("invalid value type: %s", typename))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
this.uint8 = create_integral_type("uint8_t", false)
|
||||
this.uint16 = create_integral_type("uint16_t", false)
|
||||
this.uint32 = create_integral_type("uint32_t", false)
|
||||
this.uint64 = create_integral_type("uint64_t", false)
|
||||
|
||||
this.int8 = create_integral_type("int8_t", true)
|
||||
this.int16 = create_integral_type("int16_t", true)
|
||||
this.int32 = create_integral_type("int32_t", true)
|
||||
this.int64 = create_integral_type("int64_t", true)
|
||||
|
||||
return this
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
local rules = {nexid = 1, rules = {}}
|
||||
local rules = {nextid = 1, rules = {}}
|
||||
|
||||
function rules.get_rule(name)
|
||||
local rule = rules.rules[name]
|
||||
|
|
@ -27,13 +27,13 @@ end
|
|||
|
||||
function rules.reset(name)
|
||||
local rule = rules.get_rule(name)
|
||||
rules.set(rule.default)
|
||||
rules.set(name, rule.default)
|
||||
end
|
||||
|
||||
function rules.listen(name, handler)
|
||||
local rule = rules.get_rule(name)
|
||||
local id = rules.nexid
|
||||
rules.nextid = rules.nexid + 1
|
||||
local id = rules.nextid
|
||||
rules.nextid = rules.nextid + 1
|
||||
rule.listeners[utf8.encode(id)] = handler
|
||||
return id
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@ name = "default"
|
|||
base_packs = ["base"]
|
||||
permissions = [
|
||||
"network",
|
||||
"record-audio"
|
||||
"record-audio",
|
||||
"sub-instances",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ console.add_command(
|
|||
for y=y1,y2 do
|
||||
for z=z1,z2 do
|
||||
for x=x1,x2 do
|
||||
block.set(x, y, z, id)
|
||||
block.set(x, y, z, id, 0, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -140,7 +140,20 @@ local __vc_named_coroutines = {}
|
|||
local __vc_next_coroutine = 1
|
||||
|
||||
function __vc_start_coroutine(chunk)
|
||||
local co = coroutine.create(chunk)
|
||||
local co = coroutine.create(function()
|
||||
local _, err = xpcall(chunk, function(msg)
|
||||
local traceback = debug.get_traceback(0)
|
||||
local s = string.format("%s:", msg)
|
||||
for i=1,#traceback - 2 do
|
||||
local frame = traceback[i]
|
||||
s = s .. "\n\t"..tb_frame_tostring(frame)
|
||||
end
|
||||
return s
|
||||
end)
|
||||
if err then
|
||||
error(err)
|
||||
end
|
||||
end)
|
||||
local id = __vc_next_coroutine
|
||||
__vc_next_coroutine = __vc_next_coroutine + 1
|
||||
__vc_coroutines[id] = co
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@ vc = {
|
|||
is_client = function()
|
||||
return not _vc_headless
|
||||
end,
|
||||
get_version = __vc_app.get_version,
|
||||
get_setting = __vc_app.get_setting,
|
||||
get_setting_str = __vc_app.get_setting_str,
|
||||
str_setting = __vc_app.str_setting,
|
||||
get_setting_info = __vc_app.get_setting_info,
|
||||
}
|
||||
|
||||
|
|
@ -310,12 +311,19 @@ local bytearray = require "core:internal/bytearray"
|
|||
Bytearray = bytearray.FFIBytearray
|
||||
Bytearray_as_string = bytearray.FFIBytearray_as_string
|
||||
Bytearray_as_ptr = bytearray.FFIBytearray_as_ptr
|
||||
I8view = bytearray.FFII8view
|
||||
U16view = bytearray.FFIU16view
|
||||
I16view = bytearray.FFII16view
|
||||
U32view = bytearray.FFIU32view
|
||||
I32view = bytearray.FFII32view
|
||||
U64view = bytearray.FFIU64view
|
||||
I64view = bytearray.FFII64view
|
||||
FLTview = bytearray.FFIFLTview
|
||||
DBLview = bytearray.FFIDBLview
|
||||
Bytearray_construct = function(...) return Bytearray(...) end
|
||||
|
||||
ctypes = require "core:internal/ctypes"
|
||||
|
||||
bit.compile = require "core:bitwise/compiler"
|
||||
bit.execute = require "core:bitwise/executor"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue