Skip to content

Instantly share code, notes, and snippets.

@Adrodoc
Created March 17, 2018 21:23
Show Gist options
  • Save Adrodoc/92ab47411d9a7d9090ee9ac6336cb88b to your computer and use it in GitHub Desktop.
Save Adrodoc/92ab47411d9a7d9090ee9ac6336cb88b to your computer and use it in GitHub Desktop.
Tinkers Construct Hammer
local pkg = {}
function pkg.give()
if spell.owner then
spell:execute('give %s golden_pickaxe 1 0 {hammer:true}')
end
end
function pkg.stop()
spell:execute('kill @e[type=wol:spell,tag=adrodoc.hammer]')
end
local function isRock(block)
-- return block.material == Materials.ROCK
local name = block.name
return not block.material.requiresNoTool and
-- Materials.ANVIL
name ~= 'anvil' and
-- Materials.BARRIER
name ~= 'barrier' and
-- Materials.CRAFTED_SNOW
name ~= 'snow' and
-- Materials.IRON
name ~= 'brewing_stand' and
name ~= 'cauldron' and
name ~= 'command_block' and
name ~= 'hopper' and
name ~= 'structure_block' and
name ~= 'lapis_block' and
name ~= 'gold_block' and
name ~= 'iron_block' and
name ~= 'diamond_block' and
name ~= 'iron_door' and
name ~= 'iron_bars' and
name ~= 'emerald_block' and
name ~= 'light_weighted_pressure_plate' and
name ~= 'heavy_weighted_pressure_plate' and
name ~= 'redstone_block' and
name ~= 'iron_trapdoor' and
-- Materials.SNOW
name ~= 'snow_layer' and
-- Materials.WEB
name ~= 'web'
end
local function destroyNeighbours(origPos, createVec3)
for a=-1,1 do
for b =-1,1 do
spell.pos = origPos + createVec3(a,b)
if isRock(spell.block) then
spell:execute('setblock ~ ~ ~ air 0 destroy')
end
end
end
end
local playerFaces = {}
local function eventListener(event)
if event.name == 'LeftClickBlockEvent' then
playerFaces[event.player] = event.face
else
local tag = event.player.mainhand.nbt.tag
if tag and tag.hammer and isRock(event.block) then
local face = playerFaces[event.player]
if face == 'up' or face == 'down' then
destroyNeighbours(event.pos, function(x,z)
return Vec3(x,0,z)
end)
elseif face == 'north' or face == 'south' then
destroyNeighbours(event.pos, function(x,y)
return Vec3(x,y,0)
end)
else
destroyNeighbours(event.pos, function(y,z)
return Vec3(0,y,z)
end)
end
end
end
end
function pkg.start()
pkg.stop()
spell:addTag('adrodoc.hammer')
--[[
local queue = Events.connect('LeftClickBlockEvent','BlockBreakEvent')
while true do
local event = queue:next()
eventListener(event)
end
]]
Events.on('LeftClickBlockEvent','BlockBreakEvent'):call(eventListener)
end
return pkg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment