Skip to content

Instantly share code, notes, and snippets.

@warmist
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warmist/ed4b1625ea9560bf4d90 to your computer and use it in GitHub Desktop.
Save warmist/ed4b1625ea9560bf4d90 to your computer and use it in GitHub Desktop.
A Catastrophes plugin for cuberite minecraft server
--[=====[
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to http://unlicense.org
--]=====]
allowed_distance=4*16*2 --4 chunks in both directions
block_count=50
block_depth=3
delay=100
next_process=80
elapsed=0
function make_set(t)
local ret={}
for i,v in ipairs(t) do
ret[v]=true
end
return ret
end
allowed_blocks=make_set{
E_BLOCK_LOG,
E_BLOCK_LEAVES,
E_BLOCK_NEW_LEAVES,
E_BLOCK_NEW_LOG,
E_BLOCK_GRASS,
E_BLOCK_TALL_GRASS,
E_BLOCK_DEAD_BUSH
}
function make_top( w,x,y,z,btype,bmeta )
for i=-1,1 do
for j=-1,1 do
w:SetBlock(x+i,y,z+j,btype,bmeta)
end
end
end
function make_shoot( w,x,y,z,btype,bmeta,steps_max ,angle_step_max)
local angle_step=0.15+math.random()*(angle_step_max or 0)
local dist=1
local steps=math.random(1,steps_max)
local theta=math.random()*math.pi
local phi=math.random()*math.pi*2
local cx=x
local cy=y
local cz=z
for i=1,steps do
w:SetBlock(cx,cy,cz,btype,bmeta)
theta=theta+math.random()*angle_step/2-angle_step/2
phi=phi+math.random()*angle_step/2-angle_step/2
cx=cx+math.sin(theta)*math.cos(phi)*dist
cz=cz+math.sin(theta)*math.sin(phi)*dist
cy=cy+math.cos(theta)*dist
end
end
function block_action(w,x,y,z,btype,bmeta)--todo: rewrite to use block area
local new_type=btype
if btype==E_BLOCK_LOG then
new_type=E_BLOCK_LEAVES
elseif btype==E_BLOCK_NEW_LOG then
new_type=E_BLOCK_NEW_LEAVES
elseif btype==E_BLOCK_LEAVES then
new_type=E_BLOCK_LOG
elseif btype==E_BLOCK_NEW_LEAVES then
new_type=E_BLOCK_NEW_LOG
else
new_type=E_BLOCK_NEW_LOG
end
local r=math.random()
if r>0.85 then
make_top(w,x,y+1,z,new_type,bmeta)
elseif r>0.75 then
make_shoot(w,x,y,z,new_type,bmeta,15,math.random()*0.75)
elseif r>0.5 then
make_shoot(w,x,y,z,new_type,bmeta,15,math.random()*0.15)
else
w:SetBlock(x,y+1,z,new_type,bmeta)
end
end
function real_process(world,center)
return function ()
local a2=allowed_distance/2
for i=1,block_count do
local x=center.x+math.random(-a2,a2)
local z=center.z+math.random(-a2,a2)
local ok,h=world:TryGetHeight(x,z)
if h>=253 then ok=false end
--local h=center.y+math.random(-block_depth*2,block_depth*2)
if ok then
for i=0,-block_depth,-1 do
local valid,btype,bmeta=world:GetBlockTypeMeta(x,h+i,z)
if valid and allowed_blocks[btype] then
block_action(world,x,h+i,z,btype,bmeta)
break
end
end
end
end
end
end
function do_process(player)
local w=player:GetWorld()
local center=player:GetPosition()
w:QueueTask(real_process(w,center))
end
function every_tick(time_delta)
elapsed=elapsed+time_delta
if elapsed>next_process then
next_process=math.random(delay/2,delay*2)
elapsed=0
cRoot:Get():ForEachPlayer(do_process)
--cRoot:Get():ForEachPlayer(hang)
end
end
function Initialize(a_Plugin)
a_Plugin:SetName("NaturesRevenge");
a_Plugin:SetVersion(1);
cPluginManager:AddHook(cPluginManager.HOOK_TICK, every_tick);
return true;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment