mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 14:31:50 +00:00
fix block.index() calls in grass_block.lua and export base:util.calc_loot()
This commit is contained in:
parent
1519febf6a
commit
2eae8f6f27
2 changed files with 8 additions and 6 deletions
|
|
@ -12,14 +12,14 @@ function util.drop(ppos, itemid, count, data, pickup_delay)
|
||||||
}})
|
}})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function calc_loot(loot_table)
|
function calc_loot(loot_table)
|
||||||
local results = {}
|
local results = {}
|
||||||
for _, loot in ipairs(loot_table) do
|
for _, loot in ipairs(loot_table) do
|
||||||
local chance = loot.chance or 1
|
local chance = loot.chance or 1
|
||||||
local count = loot.count or 1
|
local count = loot.count or 1
|
||||||
|
|
||||||
local roll = math.random()
|
local roll = math.random()
|
||||||
|
|
||||||
if roll < chance then
|
if roll < chance then
|
||||||
if loot.min and loot.max then
|
if loot.min and loot.max then
|
||||||
count = math.random(loot.min, loot.max)
|
count = math.random(loot.min, loot.max)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
local dirtid = block.index("base:dirt")
|
||||||
|
local grass_blockid = block.index("base:grass_block")
|
||||||
|
|
||||||
local offsets = {}
|
local offsets = {}
|
||||||
for lx=-1,1 do
|
for lx=-1,1 do
|
||||||
for ly=-1,1 do
|
for ly=-1,1 do
|
||||||
|
|
@ -8,18 +11,17 @@ for lx=-1,1 do
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_random_update(x, y, z)
|
function on_random_update(x, y, z)
|
||||||
local dirtid = block.index('base:dirt');
|
|
||||||
if block.is_solid_at(x, y+1, z) then
|
if block.is_solid_at(x, y+1, z) then
|
||||||
block.set(x, y, z, dirtid, 0)
|
block.set(x, y, z, dirtid, 0)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local grassblockid = block.index('base:grass_block')
|
|
||||||
for _, offset in ipairs(offsets) do
|
for _, offset in ipairs(offsets) do
|
||||||
local nx, ny, nz = x + offset[1], y + offset[2], z + offset[3]
|
local nx, ny, nz = x + offset[1], y + offset[2], z + offset[3]
|
||||||
|
|
||||||
if block.get(nx, ny, nz) == dirtid and
|
if block.get(nx, ny, nz) == dirtid and
|
||||||
not block.is_solid_at(nx, ny + 1, nz) then
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue