thomasfn

Revised

Jul 1st, 2011
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. local WindMill = {}
  2. local WindMillAng = 0
  3.  
  4. local bladeInfo = {
  5.     [1] = { 0, 1 }, -- Top blade
  6.     [2] = { 1, 0 }, -- Right blade
  7.     [3] = { 0, -1 }, -- Bottom blade
  8.     [4] = { -1, 0 } -- Left blade
  9. }
  10.  
  11.  
  12. FACING_FORWARD = 0
  13. FACING_RIGHT = math.pi / 2
  14. FACING_BACK = math.pi
  15. FACING_LEFT = (math.pi / 2) * 3
  16.  
  17. function DoWindmillArms(id, x, y, z, ang, facing )
  18.     local bladeLength = 1
  19.     local cMgr = core.ChunkManager
  20.    
  21.     for k=1, #WindMill do
  22.         cMgr:SetBlock(WindMill[k].x, WindMill[k].y, WindMill[k].z, 0, core.EntityManager:GetPlayers())
  23.     end
  24.    
  25.     WindMill = {}
  26.    
  27.     for i = 1, 4 do
  28.  
  29.         for j = 1, bladeLength do
  30.        
  31.             local bX = bladeInfo[i][1] * j
  32.             local bY = bladeInfo[i][2] * j
  33.            
  34.             bX =  math.floor(bX * math.cos( ang ) - bY * math.sin( ang ) + 0.5)
  35.             bY =  math.floor(bX * math.sin( ang ) + bY * math.cos( ang ) + 0.5)
  36.            
  37.             local blockX = math.floor(x + (bX * math.cos( facing )) + 0.5)
  38.             local blockY = math.floor(y + bY + 0.5)
  39.             local blockZ = math.floor(z + (-bX * math.sin( facing)) + 0.5)
  40.            
  41.             table.insert( WindMill, { x = blockX, y = blockY, z = blockZ } )
  42.            
  43.             cMgr:SetBlock( blockX, blockY, blockZ, ITEM_WOOD, core.EntityManager:GetPlayers() )
  44.            
  45.         end
  46.        
  47.     end
  48. end
  49.  
  50. function def.PlayerClickBlock( ply, x, y, z, blockid )
  51.     -- Called when the player left clicks a block
  52.     -- Return true to not handle the dig event
  53.    
  54.     local cMgr = core.ChunkManager
  55.    
  56.     if (blockid ~= ITEM_LOG) then
  57.         cMgr:SetBlock(x, y, z, 0, core.EntityManager:GetPlayers())
  58.     end
  59.    
  60.     if (blockid == ITEM_LOG) then
  61.         local WindMillID = #WindMill + 1
  62.         if (cMgr:GetBlockID(x, y, z + 1) == ITEM_LOG) then
  63.             DoWindmillArms(WindMillID, x, y, z, WindMillAng, FACING_BACK )
  64.            
  65.             WindMillAng = WindMillAng + (math.pi / 4)
  66.         end
  67.     end
  68.        
  69.     if (blockid == 78) then
  70.         local held = ply:GetHeldItemID()
  71.         if (held == ITEM_WOOD_SPADE
  72.             or held == ITEM_STONE_SPADE
  73.             or held == ITEM_IRON_SPADE
  74.             or held == ITEM_GOLD_SPADE
  75.             or held == ITEM_DIAMOND_SPADE) then
  76.            
  77.             cMgr:SetBlock(x, y, z, 0, core.EntityManager:GetPlayers())
  78.             cMgr:SpawnItem( 332, x, y, z )
  79.             return true
  80.         end
  81.     end
  82.    
  83.     if (blockid == 46) then
  84.         cMgr:DoExplosion( x, y, z, 4, core.EntityManager:GetPlayers())
  85.         return true
  86.     end
  87.     return false
  88. end
Advertisement
Add Comment
Please, Sign In to add comment