This is a mod, that says what the shift are you need. This toll you are need when you make your own graphics with shadows, but your graphics is not in the middle of the collision box.
For example:
Entity type = "assembling-machine",
name = "assembling-machine-3",
debug = false
script.on_event(defines.events.on_built_entity, function(event)
if (event.created_entity.name == "arrow-belt") then
onBuildHandler(event)
end
end)
function onBuildHandler (event)
local entity = event.created_entity
printAll("001 ".. entity.name .. " " .. entity.direction)
local targetEntity = findNearestEntity(entity.position, 5)
printAll("002 ".. entity.name .. " " .. entity.position.x .. " " .. entity.position.y)
initEntity (targetEntity)
if (targetEntity and targetEntity.name) then
printAll("003 ".. "targetEntity.name " .. targetEntity.name .. " " .. targetEntity.type .. " " .. targetEntity.force.name .. " " )
local newPos = directionToPosition(targetEntity.position, entity.direction, 1/32)
printAll("004 ".. "newPos.x " .. newPos.x .. " targetEntity.position.x " .. targetEntity.position.x )
targetEntity.teleport(newPos)
local globEntity = tableContains(global.entities, targetEntity)
if globEntity then printAll("globEntity is true! " .. type(globEntity)) end
printAll(globEntity)
local pShift = globEntity.pShift
local firstPos = globEntity.position
local ID = globEntity.ID
local nowPos = targetEntity.position
pShift = vectorDelta (nowPos, firstPos)
printAll(pShift)
printAll(global)
global.entities[ID].pShift = pShift
printAll("shift = {x=" .. pShift.x .. ", y=" .. pShift.y.."}", true)
end
entity.destroy()
game.players[event.player_index].insert{name="arrow-belt", count=1}
end
function vectorDelta (p1, p2)
return {x=p1.x-p2.x, y=p1.y-p2.y}
end
-- init
function initEntity (entity)
if not entity then return end
if not global.entities then global.entities = {} end
if not global.ID then global.ID = 1 else global.ID = global.ID + 1 end
printAll("101 ".. entity.name .. " start init: " .. #global.entities)
local taCo = tableContains(global.entities, entity)
if taCo then return end
local NewEntity = {
name = entity.name,
position = entity.position,
pShift = {x=0, y=0},
entity = entity,
ID = global.ID
}
global.entities[global.ID] = NewEntity
-- table.insert(global.entities, NewEntity)
printAll("102 ".. entity.name .. " end init: " .. #global.entities)
end
function tableContains(table, element)
for _, value in pairs(table) do
if value == element then
return value
end
if type(value) == "table" then
local valueOrFalse = tableContains(value, element)
if valueOrFalse then return value end
end
end
return false
end
function printAll(text, bool)
if (debug or bool) then
local text2 = ""
if type(text) == "table" then text2 = serpent.block(text, {comment=false})
for i in pairs (game.players) do
game.players[i].print(text2)
end
else
for i in pairs (game.players) do
game.players[i].print(text)
end
end
end
end
function findNearestEntity(position, radius)
local radius = radius or 5
local entities = game.surfaces["nauvis"].find_entities({{position.x-radius, position.y-radius}, {position.x + radius, position.y + radius}})
local minRad = 20
local nearestEntity = nil
local mustBeAdded = false
for i, entity in pairs(entities) do
local mustBeAdded = false
local nextRad = lenght(position, entity.position)
--printAll(i .. " " .. entity.name .. " " .. nextRad)
if not (minRad) then
mustBeAdded = true
minRad = nextRad
end
if (minRad > nextRad) then mustBeAdded = true end
if (entity.name == "arrow-belt") or (entity.type == "player") then mustBeAdded = false end
if (entity.force.name == "neutral") or (entity.force.name == "enemy") then mustBeAdded = false end
if mustBeAdded then
minRad = nextRad
nearestEntity = entity
end
end
if nearestEntity then printAll(nearestEntity.name .. " " .. minRad) end
return nearestEntity
end
function lenght(position1, position2)
local position1 = {x = position1.x, y = position1.y} or {x = 0, y = 0}
local position2 = {x = position2.x, y = position2.y} or {x = 0, y = 0}
return math.sqrt((position1.x - position2.x)^2 + (position1.y - position2.y)^2)
end
function directionToPosition(position, direction, radius)
-- makes position from direction, absolute or relative
local x = position.x or 0
local y = position.y or 0
local radius = radius or 5
if direction == 0 then return { x=x, y=y-radius}
elseif direction == 2 then return { x=x+radius, y=y}
elseif direction == 4 then return { x=x, y=y+radius}
elseif direction == 6 then return { x=x-radius, y=y}
else return {x=x, y=y}
end
end
New shift in this example is the same like in vanilla. Yey!
Re: [Mod 0.14] Shift Tool
Posted: Wed Apr 19, 2017 8:36 pm
by darkfrei
The mod is not for playing, please don't use it for the game.
Re: [Mod 0.15] Shift Tool
Posted: Sat Dec 16, 2017 8:32 pm
by Shenpen
This one I need, so that I can stop facepalming.Thank you for sharing!
Re: [Mod 0.16] Shift Tool
Posted: Tue Jul 03, 2018 2:26 pm
by moon69
Hi Darkfrei,
I'm trying to use this tool in 0.16.51... it loads correctly, I can make the tool, select it and rotate it, but no matter where I click the entity graphic (stone furnace) doesn't move and the tool just generates:
shift = {x=0, y=0}
No other mods are enabled, new game, no obvious errors in factorio-current.log.