mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 12:17:17 -04:00
Merge branch 'master-MC1.10' into master-MC1.12
# Conflicts: # src/main/scala/li/cil/oc/server/component/MotionSensor.scala
This commit is contained in:
commit
583762c739
@ -35,7 +35,7 @@ This mod is [licensed under the **MIT license**](https://github.com/MightyPirate
|
||||
2. **Features**
|
||||
If you'd like to propose a new feature, take it to the [forums][] or the [issue tracker][issues]. If you'd like to contribute code that adds new features, please make sure to discuss the feature with me, first - again, the issue tracker is an OK place for this, there are a couple of feature requests there, already. Alternatively start a topic on the forums to discuss the feature, and / or stop by the [IRC][irc] to talk about it. Blind / unexpected feature pull requests might very well not make it, so save yourself some time by talking about it, first! Thanks.
|
||||
3. **Scripts / Programs**
|
||||
OpenComputers generates floppy disks in dungeon chests that can contain data from a selection of 'loot' directories. For example, the IRC client and the Better Shell (besh) are two programs that can be found on such loot disks. If you'd like to contribute a program that can be found this way, please have a look at [the loot readme][loot], which explains how to add custom loot. Simply pull request your loot!
|
||||
OpenComputers generates floppy disks in dungeon chests that can contain data from a selection of 'loot' directories. For example, the IRC client and OPPM (a package manager) are two programs that can be found on such loot disks. If you'd like to contribute a program that can be found this way, please have a look at [the loot readme][loot], which explains how to add custom loot. Simply pull request your loot!
|
||||
4. **Core Scripts**
|
||||
If you would like to contribute scripts to the "core" Lua code (which basically defines 'OpenOS'), please have a look at the [code conventions][] for Lua to save us all some time. Bug fixes are always welcome. Additional programs and features should be kept small. Bigger programs (rule of thumb: larger than 3KiB) should go onto loot disks.
|
||||
5. **Drivers**
|
||||
|
@ -35,3 +35,5 @@ for i = 1, #args do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
io.stdout:close()
|
||||
|
@ -51,7 +51,7 @@ local function loadConfig()
|
||||
pageUp = {{"pageUp"}},
|
||||
pageDown = {{"pageDown"}},
|
||||
|
||||
backspace = {{"back"}},
|
||||
backspace = {{"back"}, {"shift", "back"}},
|
||||
delete = {{"delete"}},
|
||||
deleteLine = {{"control", "delete"}, {"shift", "delete"}},
|
||||
newline = {{"enter"}},
|
||||
|
@ -45,7 +45,7 @@ local cols =
|
||||
{"THREADS", function(_,p)
|
||||
-- threads are handles with mt.close == thread.waitForAll
|
||||
local count = 0
|
||||
for h in pairs(p.data.handles) do
|
||||
for _,h in ipairs(p.data.handles) do
|
||||
local mt = getmetatable(h)
|
||||
if mt and mt.__status then
|
||||
count = count + 1
|
||||
@ -55,7 +55,7 @@ local cols =
|
||||
end},
|
||||
{"PARENT", function(_,p)
|
||||
for _,process_info in pairs(process.list) do
|
||||
for handle in pairs(process_info.data.handles) do
|
||||
for i,handle in ipairs(process_info.data.handles) do
|
||||
local mt = getmetatable(handle)
|
||||
if mt and mt.__status then
|
||||
if mt.process == p then
|
||||
@ -67,12 +67,7 @@ local cols =
|
||||
return thread_id(nil, p.parent)
|
||||
end},
|
||||
{"HANDLES", function(_, p)
|
||||
local count = 0
|
||||
for _,closure in pairs(p.data.handles) do
|
||||
if closure then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
local count = #p.data.handles
|
||||
return count == 0 and "-" or tostring(count)
|
||||
end},
|
||||
{"CMD", function(_,p) return p.command end},
|
||||
|
@ -41,9 +41,5 @@ if #args == 0 then
|
||||
end
|
||||
else
|
||||
-- execute command.
|
||||
local result = table.pack(sh.execute(...))
|
||||
if not result[1] then
|
||||
error(result[2], 0)
|
||||
end
|
||||
return table.unpack(result, 2)
|
||||
return sh.execute(...)
|
||||
end
|
||||
|
@ -72,11 +72,11 @@ process.list[init_thread] = {
|
||||
}
|
||||
|
||||
-- intercept fs open
|
||||
local fs_open = fs.open
|
||||
local fs_open = fs.open
|
||||
fs.open = function(...)
|
||||
local fs_open_result = table.pack(fs_open(...))
|
||||
if fs_open_result[1] then
|
||||
process.closeOnExit(fs_open_result[1])
|
||||
process.addHandle(fs_open_result[1])
|
||||
end
|
||||
return table.unpack(fs_open_result, 1, fs_open_result.n)
|
||||
end
|
||||
|
@ -166,7 +166,7 @@ function buffer:write(...)
|
||||
if self.bufferMode == "no" then
|
||||
result, reason = self.stream:write(arg)
|
||||
else
|
||||
result, reason = self:buffered_write(arg)
|
||||
result, reason = buffer.buffered_write(self, arg)
|
||||
end
|
||||
|
||||
if not result then
|
||||
|
@ -1,12 +1,14 @@
|
||||
local adapter_api = ...
|
||||
|
||||
return function(proxy)
|
||||
local screen = proxy.getScreen()
|
||||
screen = screen and ("../" .. screen)
|
||||
return
|
||||
{
|
||||
viewport = {write = adapter_api.createWriter(proxy.setViewport, 2, "number", "number"), proxy.getViewport()},
|
||||
resolution = {write = adapter_api.createWriter(proxy.setResolution, 2, "number", "number"), proxy.getResolution()},
|
||||
maxResolution = {proxy.maxResolution()},
|
||||
screen = {link="../"..proxy.getScreen(),isAvailable=proxy.getScreen},
|
||||
screen = {link=screen,isAvailable=proxy.getScreen},
|
||||
depth = {write = adapter_api.createWriter(proxy.setDepth, 1, "number"), proxy.getDepth()},
|
||||
maxDepth = {proxy.maxDepth()},
|
||||
background = {write = adapter_api.createWriter(proxy.setBackground, 1, "number", "boolean"), proxy.getBackground()},
|
||||
|
@ -7,6 +7,5 @@ return function(proxy)
|
||||
write= function(msg) return proxy.setWakeMessage(msg) end,
|
||||
},
|
||||
wireless = {proxy.isWireless()},
|
||||
maxPacketSize = {proxy.maxPacketSize()},
|
||||
}
|
||||
end
|
||||
|
@ -509,7 +509,7 @@ function sh.internal.execute_complex(words, eargs, env)
|
||||
end)
|
||||
sh.internal.ec.last = sh.internal.command_result_as_code(last_code, reason)
|
||||
end
|
||||
return true
|
||||
return sh.internal.ec.last == 0
|
||||
end
|
||||
|
||||
-- params: words[tokenized word list]
|
||||
|
@ -2,6 +2,7 @@ local text = require("text")
|
||||
local tx = require("transforms")
|
||||
local unicode = require("unicode")
|
||||
local process = require("process")
|
||||
local buffer = require("buffer")
|
||||
|
||||
-- separate string value into an array of words delimited by whitespace
|
||||
-- groups by quotes
|
||||
@ -179,9 +180,7 @@ function text.internal.reader(txt, mode)
|
||||
return true
|
||||
end,
|
||||
}, {__index=text.internal.stream_base((mode or ""):match("b"))})
|
||||
process.closeOnExit(reader)
|
||||
|
||||
return require("buffer").new((mode or "r"):match("[rb]+"), reader)
|
||||
return process.addHandle(buffer.new((mode or "r"):match("[rb]+"), reader))
|
||||
end
|
||||
|
||||
function text.internal.writer(ostream, mode, append_txt)
|
||||
@ -221,9 +220,7 @@ function text.internal.writer(ostream, mode, append_txt)
|
||||
return true
|
||||
end,
|
||||
}, {__index=text.internal.stream_base((mode or ""):match("b"))})
|
||||
process.closeOnExit(writer)
|
||||
|
||||
return require("buffer").new((mode or "w"):match("[awb]+"), writer)
|
||||
return process.addHandle(buffer.new((mode or "w"):match("[awb]+"), writer))
|
||||
end
|
||||
|
||||
function text.detab(value, tabWidth)
|
||||
|
@ -75,7 +75,7 @@ end
|
||||
rules[{"%[", "6", "n"}] = function(window)
|
||||
-- this solution puts the response on stdin, but it isn't echo'd
|
||||
-- I'm personally fine with the lack of echo
|
||||
io.stdin.bufferRead = string.format("%s%s%d;%dR", io.stdin.bufferRead, string.char(0x1b), window.y, window.x)
|
||||
io.stdin.bufferRead = string.format("%s%s[%d;%dR", io.stdin.bufferRead, string.char(0x1b), window.y, window.x)
|
||||
end
|
||||
|
||||
-- D scroll up one line -- moves cursor down
|
||||
|
@ -70,14 +70,12 @@ function require(module)
|
||||
end
|
||||
|
||||
function package.delay(lib, file)
|
||||
local mt = {
|
||||
__index = function(tbl, key)
|
||||
setmetatable(lib, nil)
|
||||
setmetatable(lib.internal or {}, nil)
|
||||
dofile(file)
|
||||
return tbl[key]
|
||||
end
|
||||
}
|
||||
local mt = {}
|
||||
function mt.__index(tbl, key)
|
||||
mt.__index = nil
|
||||
dofile(file)
|
||||
return tbl[key]
|
||||
end
|
||||
if lib.internal then
|
||||
setmetatable(lib.internal, mt)
|
||||
end
|
||||
|
@ -133,7 +133,7 @@ function pipe.buildPipeChain(progs)
|
||||
local piped_stream
|
||||
if i < #progs then
|
||||
local handle = setmetatable({buffer = ""}, {__index = pipe_stream})
|
||||
process.closeOnExit(handle, proc)
|
||||
process.addHandle(handle, proc)
|
||||
piped_stream = buffer.new("rw", handle)
|
||||
piped_stream:setvbuf("no", 1024)
|
||||
pio[1] = piped_stream
|
||||
|
@ -131,12 +131,11 @@ function process.internal.close(thread, result)
|
||||
checkArg(1,thread,"thread")
|
||||
local pdata = process.info(thread).data
|
||||
pdata.result = result
|
||||
local handles = {}
|
||||
for s,_ in pairs(pdata.handles) do
|
||||
table.insert(handles, s)
|
||||
end
|
||||
for _,v in ipairs(handles) do
|
||||
pcall(v.close, v)
|
||||
while pdata.handles[1] do
|
||||
local h = table.remove(pdata.handles)
|
||||
if h.close then
|
||||
pcall(h.close, h)
|
||||
end
|
||||
end
|
||||
process.list[thread] = nil
|
||||
end
|
||||
@ -156,20 +155,30 @@ function process.internal.continue(co, ...)
|
||||
return table.unpack(result, 2, result.n)
|
||||
end
|
||||
|
||||
function process.closeOnExit(stream, proc)
|
||||
function process.removeHandle(handle, proc)
|
||||
local handles = (proc or process.info()).data.handles
|
||||
if not handles[stream] then
|
||||
handles[stream] = stream.close
|
||||
stream.close = function(...)
|
||||
local close = handles[stream]
|
||||
handles[stream] = nil
|
||||
if close then
|
||||
return close(...)
|
||||
end
|
||||
for pos, h in ipairs(handles) do
|
||||
if h == handle then
|
||||
return table.remove(handles, pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function process.addHandle(handle, proc)
|
||||
local _close = handle.close
|
||||
local handles = (proc or process.info()).data.handles
|
||||
table.insert(handles, handle)
|
||||
function handle:close(...)
|
||||
if _close then
|
||||
self.close = _close
|
||||
_close = nil
|
||||
process.removeHandle(self, proc)
|
||||
return self:close(...)
|
||||
end
|
||||
end
|
||||
return handle
|
||||
end
|
||||
|
||||
function process.running(level) -- kept for backwards compat, prefer process.info
|
||||
local info = process.info(level)
|
||||
if info then
|
||||
|
@ -207,7 +207,7 @@ function sh.execute(env, command, ...)
|
||||
-- simple
|
||||
if not command:find("[;%$&|!<>]") then
|
||||
sh.internal.ec.last = sh.internal.command_result_as_code(sh.internal.executePipes({words}, eargs, env))
|
||||
return true
|
||||
return sh.internal.ec.last == 0
|
||||
end
|
||||
|
||||
return sh.internal.execute_complex(words, eargs, env)
|
||||
|
@ -114,7 +114,7 @@ function box_thread:attach(parent)
|
||||
if mt.attached then
|
||||
-- registration happens on the attached proc, unregister before reparenting
|
||||
waiting_handler = mt.unregister()
|
||||
mt.attached.data.handles[self] = nil
|
||||
process.removeHandle(self, mt.attached)
|
||||
end
|
||||
|
||||
-- fix close
|
||||
@ -122,7 +122,7 @@ function box_thread:attach(parent)
|
||||
|
||||
-- attach to parent or the current process
|
||||
mt.attached = proc
|
||||
process.closeOnExit(self, proc)
|
||||
process.addHandle(self, proc)
|
||||
|
||||
-- register on the new parent
|
||||
if waiting_handler then -- event-waiting
|
||||
@ -137,7 +137,7 @@ function thread.current()
|
||||
local thread_root
|
||||
while proc do
|
||||
if thread_root then
|
||||
for handle in pairs(proc.data.handles) do
|
||||
for _,handle in ipairs(proc.data.handles) do
|
||||
if handle.pco and handle.pco.root == thread_root then
|
||||
return handle
|
||||
end
|
||||
@ -264,7 +264,7 @@ function thread.create(fp, ...)
|
||||
function mt.close()
|
||||
local old_status = t:status()
|
||||
mt.__status = "dead"
|
||||
mt.attached.data.handles[t] = nil
|
||||
process.removeHandle(t, mt.attached)
|
||||
if old_status ~= "dead" then
|
||||
event.push("thread_exit")
|
||||
end
|
||||
|
@ -45,7 +45,7 @@ OPTIONS
|
||||
Do not colorize the output (default colorized)
|
||||
|
||||
--help
|
||||
display this help and exit]])
|
||||
display this help and exit
|
||||
|
||||
-p
|
||||
append / indicator to directories
|
||||
@ -77,4 +77,4 @@ EXAMPLES
|
||||
Displays the contents of the current directory.
|
||||
|
||||
ls /bin /mnt
|
||||
Displays the contents of the `/bin`/ and `/mnt` directories, one after the other.
|
||||
Displays the contents of the `/bin`/ and `/mnt` directories, one after the other.
|
||||
|
@ -33,6 +33,7 @@ Clank # Ratchet & Clank
|
||||
Claptrap # Borderlands
|
||||
Codsworth # Fallout 4
|
||||
Continuity # Mona Lisa Overdrive
|
||||
Cortana # Halo
|
||||
Crypto # Kodos
|
||||
Curiosity # Mars Rover
|
||||
Daedalus # Deus Ex
|
||||
|
@ -242,6 +242,11 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
||||
case ox if ox >= 0 && ox < width =>
|
||||
volume(nz * width + nx) = volume(oz * width + ox)
|
||||
volume(nz * width + nx + width * width) = volume(oz * width + ox + width * width)
|
||||
// previous, we set the volume area as dirty. but this is error prone
|
||||
// in case the update sends the values - we only send the corners of the copied arae
|
||||
// it is FAR better to mark each bit as dirty, and let the optimized update do what
|
||||
// it was designed to do
|
||||
setDirty(nx, nz)
|
||||
case _ => /* Got no source column. */
|
||||
}
|
||||
}
|
||||
@ -249,10 +254,6 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
||||
}
|
||||
}
|
||||
|
||||
// Mark target rectangle dirty.
|
||||
setDirty(math.min(dx0, dx1), math.min(dz0, dz1))
|
||||
setDirty(math.max(dx0, dx1), math.max(dz0, dz1))
|
||||
|
||||
// The reasoning here is: it'd take 18 ticks to do the whole are with fills,
|
||||
// so make this slightly more efficient (15 ticks - 0.75 seconds). Make it
|
||||
// 'free' if it's less than 0.25 seconds, i.e. for small copies.
|
||||
@ -358,6 +359,9 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
||||
else result(Unit, "not supported")
|
||||
}
|
||||
|
||||
@Callback(direct = true, doc = "function():number, number, number -- Get the dimension of the x,y,z axes.")
|
||||
def getDimensions(context: Context, args: Arguments): Array[AnyRef] = result(width, height, width)
|
||||
|
||||
private def checkCoordinates(args: Arguments, idxX: Int = 0, idxY: Int = 1, idxZ: Int = 2) = {
|
||||
val x = if (idxX >= 0) args.checkInteger(idxX) - 1 else 0
|
||||
if (x < 0 || x >= width) throw new ArrayIndexOutOfBoundsException("x")
|
||||
|
@ -18,7 +18,7 @@ import li.cil.oc.util.SideTracker
|
||||
import net.minecraft.entity.EntityLivingBase
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.potion.Potion
|
||||
import net.minecraft.util.math.{AxisAlignedBB, Vec3d}
|
||||
import net.minecraft.util.math.{AxisAlignedBB, BlockPos, Vec3d}
|
||||
|
||||
import scala.collection.convert.WrapAsJava._
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
@ -96,21 +96,22 @@ class MotionSensor(val host: EnvironmentHost) extends prefab.AbstractManagedEnvi
|
||||
|
||||
private def isInRange(entity: EntityLivingBase) = entity.getDistanceSq(x + 0.5, y + 0.5, z + 0.5) <= radius * radius
|
||||
|
||||
private def isClearPath(target: BlockPos): Boolean = {
|
||||
val origin = new Vec3d(x, y, z)
|
||||
val targetVec = new Vec3d(target.getX, target.getY, target.getZ)
|
||||
val path = origin.subtract(targetVec).normalize()
|
||||
val eye = origin.add(path)
|
||||
world.rayTraceBlocks(eye, targetVec) == null
|
||||
}
|
||||
|
||||
private def isVisible(entity: EntityLivingBase) =
|
||||
entity.getActivePotionEffect(Potion.getPotionFromResourceLocation("invisibility")) == null &&
|
||||
// Note: it only working in lit conditions works and is neat, but this
|
||||
// is pseudo-infrared driven (it only works for *living* entities, after
|
||||
// all), so I think it makes more sense for it to work in the dark, too.
|
||||
/* entity.getBrightness(0) > 0.2 && */ {
|
||||
val origin = new Vec3d(x, y, z)
|
||||
val target = new Vec3d(entity.posX, entity.posY, entity.posZ)
|
||||
val path = target.subtract(origin).normalize()
|
||||
val moved_origin = origin.addVector(
|
||||
path.x * 0.75,
|
||||
path.y * 0.75,
|
||||
path.z * 0.75
|
||||
)
|
||||
world.rayTraceBlocks(moved_origin, target) == null
|
||||
val target = entity.getPosition
|
||||
isClearPath(target) || isClearPath(target.add(0, entity.getEyeHeight, 0))
|
||||
}
|
||||
|
||||
private def sendSignal(entity: EntityLivingBase) {
|
||||
|
@ -48,8 +48,11 @@ class UpgradeBarcodeReader(val host: EnvironmentHost) extends AbstractManagedEnv
|
||||
processNodes(Array(host.sidedNode(side)), nbt)
|
||||
case host: Environment =>
|
||||
processNodes(Array(host.node), nbt)
|
||||
case _ => // Ignore
|
||||
}
|
||||
case _ => // Ignore
|
||||
}
|
||||
case _ => // Ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user