Skip to content

Commit

Permalink
Merge branch '0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
protocol-1903 committed Feb 5, 2024
2 parents 92f048d + 7a79b24 commit e8952d2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 84 deletions.
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
---------------------------------------------------------------------------------------------------
Version: 0.1.2
Date: 2024-02-05
Changes:
- Hopefully fixed some compatability issues by checking if pipes have 4 fluidbox connections before copying :D
- Does not update on ghost pipe placement - improves blueprinting reliability and lowers script cost
- Does not update ghost pipes - improves blueprinting reliability and lowers script cost
- Pipes of differing type can be placed between pipes that have different fluids
- Fixes an issue where some pipes would not update correctly when a pipe was removed
- Probably something else I'm forgetting
---------------------------------------------------------------------------------------------------
Version: 0.1.1
Date: 2024-01-30
Changes:
Expand Down
147 changes: 68 additions & 79 deletions control.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
-- get the type of pipe
local function getType(entity)
log("get type")
-- if not pipe
if not entity then return; end
-- get name from ghost or normal
local name = entity.type == "entity-ghost" and entity.ghost_name or entity.type == "pipe" and entity.name
if not name then return; end
log(entity.type .. ": " .. name)
-- if npt
if name:find("-npt") then
return name:sub(1, -9)
Expand All @@ -13,24 +16,29 @@ local function getType(entity)
end
end

-- find number of blocked entities based on the position and type of pipe
local function findBlocked(entity, surface, skip)
log("find blocked")
local blocked = 0
for i, offset in pairs({{0,-1}, {1,0}, {0,1}, {-1,0}}) do
if not skip or entity.position.x + offset[1] ~= skip.x and entity.position.y + offset[2] ~= skip.y then
log("looking for blocking at" .. entity.position.x + offset[1] .. ", " .. entity.position.y + offset[2])
if not skip or (entity.position.x + offset[1] ~= skip.x and entity.position.y + offset[2] ~= skip.y) then
-- find pipe (?)
local pipe = surface.find_entities_filtered({type = 'pipe', position = {entity.position.x + offset[1], entity.position.y + offset[2]}})[1]
if not pipe then pipe = surface.find_entities_filtered({ghost_type = 'pipe', position = {entity.position.x + offset[1], entity.position.y + offset[2]}})[1] end
-- if not pipe then pipe = surface.find_entities_filtered({ghost_type = 'pipe', position = {entity.position.x + offset[1], entity.position.y + offset[2]}})[1] end
-- check pipe material
local type = getType(pipe)
log("found entity (?) at" .. entity.position.x + offset[1] .. ", " .. entity.position.y + offset[2])
local type = getType(pipe)
if type and type ~= getType(entity) then
log("found blocking at" .. entity.position.x + offset[1] .. ", " .. entity.position.y + offset[2])
blocked = blocked + 2^(i - 1)
end
end
end
return blocked
end

-- check the amount of blocked types for a pipe prototype
-- check the amount of blocked for a pipe entity, based on number
local function getPipeBlocked(entity)
-- if not pipe
if not entity then return; end
Expand Down Expand Up @@ -68,23 +76,28 @@ local function cancelConstruction(event)
end

local function updateAdjacent(position, surface, skip)
log("update adjacent")
for o, offset in pairs({{0,-1}, {1,0}, {0,1}, {-1,0}}) do
local adjacent_pipe = surface.find_entities_filtered({type = "pipe", position = {position.x + offset[1], position.y + offset[2]}})[1]
if not adjacent_pipe then
adjacent_pipe = surface.find_entities_filtered({ghost_type = "pipe", position = {position.x + offset[1], position.y + offset[2]}})[1]
end
-- if not adjacent_pipe then
-- adjacent_pipe = surface.find_entities_filtered({ghost_type = "pipe", position = {position.x + offset[1], position.y + offset[2]}})[1]
-- end
if adjacent_pipe then
log("found adjacent at" .. position.x + offset[1] .. ", " .. position.y + offset[2])
-- skip if marked for deconstruction
if adjacent_pipe.to_be_deconstructed() then goto continue; end
-- if adjacent_pipe.to_be_deconstructed() then goto continue; end
-- find blocked
local adj_blocked
if skip then
log("skip " .. position.x .. ", " .. position.y)
adj_blocked = findBlocked(adjacent_pipe, surface, position)
else
log("no skip")
adj_blocked = findBlocked(adjacent_pipe, surface, nil)
end
-- update the pipe if something is different
if adj_blocked ~= getPipeBlocked(adjacent_pipe) then
if adj_blocked ~= getPipeBlocked(adjacent_pipe) and not adjacent_pipe.to_be_deconstructed() then
log("creating new pipe")
-- create some local variables
local fluidbox = adjacent_pipe.fluidbox
local adj_type = adjacent_pipe.type
Expand All @@ -99,30 +112,17 @@ local function updateAdjacent(position, surface, skip)
else
name = type
end
if adj_type == "ghost_type" then
surface.create_entity({
inner_name = name,
name = "entity-ghost",
position = adj_position,
force = force,
player = last_user,
-- fast_replace = true,
-- spill = false,
create_build_effect_smoke = false
}).fluidbox = fluidbox
else
surface.create_entity({
name = name,
position = adj_position,
force = force,
player = last_user,
-- fast_replace = true,
-- spill = false,
create_build_effect_smoke = false
}).fluidbox = fluidbox
end
surface.create_entity({
name = name,
position = adj_position,
force = force,
player = last_user,
-- fast_replace = true,
-- spill = false,
create_build_effect_smoke = false
}).fluidbox = fluidbox
end
::continue::
-- ::continue::
end
end
end
Expand All @@ -147,12 +147,22 @@ end
-- filter items on ghost placement done i think
-- fix upgrade groups n
-- fix ghosts placing actual pipes n
-- fix placing a ghost pipe updating adjacent ghost pipes to pipes
-- fix placing a pipe next to a pipe that is next to another pipe connecting the two other pipes regardless of material
-- swap pipe item place result to null pipe
-- check fluid contents to make sure fluids dont mix
-- removing a pipe adjacent to a pipe turns it into a basic pipe in some cases, where another pipe is across the adjacent pipe but not registered

-- do not remove fluids from updated pipes
-- prevent pipe placement if it will connect different fluids
-- prevent construction if it will be completely blocked

script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function (event)
log("on place")
local entity = event.created_entity

-- check if pipe, otherwise return
if entity.type ~= "pipe" and entity.type ~= "entity-ghost" then return; end
if entity.type ~= "pipe" then return; end
local pipeType = getType(entity)

-- check if valid, otherwise return
Expand All @@ -163,8 +173,6 @@ script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_e
local type = entity.type
local force = entity.force
local position = entity.position
-- update adjacent pipes
updateAdjacent(position, surface, false)

-- find adjacent pipes
local blocked = findBlocked(entity, surface, nil)
Expand Down Expand Up @@ -195,34 +203,40 @@ script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_e
-- end
-- end
-- end

-- skip the rest if not a ghost
if entity.type == "ghost_type" then return; end

-- if nothing is blocked, return
if blocked == 0 then return; end
-- update adjacent pipes
updateAdjacent(position, surface, false)

-- if nothing is blocked, replace with the basic pipe
if blocked == 0 then
-- destroy the old entity
if not entity.destroy() then return; end -- return if something breaks
surface.create_entity({
name = pipeType,
position = position,
force = force
}).last_user = event.player_index
return
end

-- destroy the old entity
if not entity.destroy() then return; end -- return if something breaks

-- replace old entity
-- log("creating new pipe entity: " .. entity.type)
local pipe
if type == "pipe" then
pipe = surface.create_entity({
name = string.format("%s-npt[%02d]", pipeType, 15 - blocked),
position = position,
force = force
})
else
pipe = surface.create_entity({
name = "entity-ghost",
inner_name = string.format("%s-npt[%02d]", pipeType, 15 - blocked),
position = position,
force = force
local pipe = surface.create_entity({
name = string.format("%s-npt[%02d]", pipeType, 15 - blocked),
position = position,
force = force
})
end
if pipe and event.player_index then pipe.last_user = event.player_index; end
end)

script.on_event({defines.events.on_cancelled_deconstruction}, function (event)
log("on cancel deconstruct")
local entity = event.entity

-- check if pipe, otherwise return
Expand All @@ -243,33 +257,6 @@ script.on_event({defines.events.on_cancelled_deconstruction}, function (event)
-- find adjacent pipes
local blocked = findBlocked(entity, surface, nil)

-- if everything is blocked, cancel construction
-- if blocked == 15 then
-- cancelConstruction(event)
-- -- return so nothing else happens
-- return
-- end
-- check adjacent pipes and cancel if any are fully blocked
-- for o, offset in pairs({{0,-1}, {1,0}, {0,1}, {-1,0}}) do
-- log(3.1)
-- local adjacent_pipe = surface.find_entities_filtered({type = "pipe", position = {x + offset[1], y + offset[2]}})
-- if not adjacent_pipe then
-- adjacent_pipe = surface.find_entities_filtered({ghost_type = "pipe", position = {x + offset[1], y + offset[2]}})
-- end
-- if adjacent_pipe ~= nil then
-- log(3.2)
-- -- find blocked
-- local adj_blocked = findBlocked(adjacent_pipe, surface)
-- -- if fully blocked, cancel construction
-- if adj_blocked == 15 then
-- log(3.3)
-- cancelConstruction(event)
-- -- return so nothing else happens
-- return
-- end
-- end
-- end

-- if nothing is blocked, return
if blocked == 0 then return; end

Expand All @@ -286,6 +273,7 @@ script.on_event({defines.events.on_cancelled_deconstruction}, function (event)
force = force
})
else
log("--------------- un deconstruct entity ghost")
pipe = surface.create_entity({
name = "entity-ghost",
inner_name = string.format("%s-npt[%02d]", pipeType, 15 - blocked),
Expand All @@ -297,9 +285,10 @@ script.on_event({defines.events.on_cancelled_deconstruction}, function (event)
end)

script.on_event({defines.events.on_player_mined_entity, defines.events.on_robot_mined_entity}, function (event)
log("on mined")
local entity = event.entity
-- check if pipe, otherwise return
if entity.type ~= "pipe" and entity.type ~= "entity-ghost" then return; end
if entity.type ~= "pipe" then return; end
log("destroy pipe")
local pipeType = getType(entity)
-- check if valid, otherwise return
Expand Down
11 changes: 7 additions & 4 deletions data-updates.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
for p, prototype in pairs(data.raw.pipe) do
if (not string.find(p, "npt-")) then
if (not string.find(p, "npt-") and prototype.fluid_box and prototype.fluid_box.pipe_connections
and #prototype.fluid_box.pipe_connections == 4) then
-- log(string.format("creating pipes for: %s", p))
-- note that any modifications made here before copying are also copied
-- make sure it is fast replaceable with other pipes
prototype.fast_replaceable_group = "pipe"
prototype.placeable_by = {item = p, count = 1}
-- prototype.fast_replaceable_group = "pipe"
-- create variations
for i = 0, 14 do
local pip = util.table.deepcopy(prototype)
pip.name = string.format("%s-npt[%02d]", p, i)
-- pip.localised_name = {"item-name." .. p}
pip.placeable_by = {item = p, count = 1}
pip.fast_replaceable_group = "pipe"
-- pip.placeable_by = {item = p, count = 1}
-- pip.fast_replaceable_group = "pipe"
pip.build_sound = nil
pip.fluid_box.pipe_connections = {}
for j, pos in pairs({{0, -1}, {1, 0}, {0, 1}, {-1, 0}}) do
Expand All @@ -21,5 +23,6 @@ for p, prototype in pairs(data.raw.pipe) do
-- add entity
data.raw.pipe[string.format("%s-npt[%02d]", p, i)] = pip
end
data.raw.item[p].place_result = string.format("%s-npt[00]", p)
end
end
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "no-pipe-touching",
"version": "0.1.1",
"version": "0.1.2",
"title": "No Pipe Touching",
"description": "Allows you to place pipes of different materials next to each other without them connecting. Designed as a less fancy alternative to advanced fluid handling, without the recipe complexity of flow control.",
"author": "protocol_1903",
Expand Down
Binary file added thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e8952d2

Please sign in to comment.