Conflicts:
	li/cil/oc/common/block/Delegator.scala
	mcmod.info
This commit is contained in:
Florian Nücke 2014-01-18 14:17:55 +01:00
commit c12a59270d
5 changed files with 118 additions and 8 deletions

View File

@ -0,0 +1,95 @@
local package = {}
package.path = "./?.lua;/lib/?.lua;/usr/lib/?.lua;/home/lib/?.lua"
local loading = {}
local loaded = {}
package.loaded = loaded
local preload = {}
package.preload = preload
package.searchers = {}
function package.searchpath(name, path, sep, rep)
checkArg(1, name, "string")
checkArg(2, path, "string")
sep = sep or '.'
rep = rep or '/'
sep, rep = '%' .. sep, '%' .. rep
name = string.gsub(name, sep, rep)
local errorFiles = {}
for subPath in string.gmatch(path, "([^;]+)") do
subPath = string.gsub(subPath, "?", name)
subPath = shell.resolve(subPath)
if fs.exists(subPath) then
local file = io.open(subPath, "r")
if file then
file:close()
return subPath
end
end
table.insert(errorFiles, "\tno file '" .. subPath .. "'")
end
return nil, table.concat(errorFiles, "\n")
end
local function preloadSearcher(module)
if preload[module] ~= nil then
return preload[module]
else
return "\tno field package.preload['" .. module .. "']"
end
end
local function pathSearcher(module)
local filepath, reason = package.searchpath(module, package.path)
if filepath then
return loadfile(filepath, "bt", _G), filepath
else
return reason
end
end
table.insert(package.searchers, preloadSearcher)
table.insert(package.searchers, pathSearcher)
function require(module)
checkArg(1, module, "string")
if loaded[module] then
return loaded[module]
elseif not loading[module] then
loading[module] = true
local loader, value, errorMsg = nil, nil, {"module '" .. module .. "' not found:"}
for i=1, #package.searchers do
local f, extra = package.searchers[i](module)
if f and type(f) ~= "string" then
loader = f
value = extra
break
elseif f then
table.insert(errorMsg, f)
end
end
if loader then
local result = loader(module, value)
if result then
loaded[module] = result
elseif not loaded[module] then
loaded[module] = true
end
loading[module] = false
return loaded[module]
else
loading[module] = false
error(table.concat(errorMsg, "\n"))
end
else
error("already loading: " .. module)
end
end
-------------------------------------------------------------------------------
_G.package = package

View File

@ -2,10 +2,11 @@ package li.cil.oc
import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.common.block._
import li.cil.oc.common.tileentity
import li.cil.oc.common.{block, tileentity}
import net.minecraft.block.Block
import net.minecraft.item.ItemStack
import net.minecraftforge.oredict.OreDictionary
import net.minecraft.nbt.NBTTagCompound
object Blocks {
var blockSimple: SimpleDelegator = _
@ -33,7 +34,15 @@ object Blocks {
blockSimple = new SimpleDelegator(Settings.get.blockId1)
blockSimpleWithRedstone = new SimpleRedstoneDelegator(Settings.get.blockId2)
blockSpecial = new SpecialDelegator(Settings.get.blockId3)
blockSpecialWithRedstone = new SpecialRedstoneDelegator(Settings.get.blockId4)
blockSpecialWithRedstone = new SpecialRedstoneDelegator(Settings.get.blockId4) {
override def subBlockItemStacks() = super.subBlockItemStacks() ++ Iterable({
val stack = new ItemStack(this, 1, robotProxy.blockId)
stack.setTagCompound(new NBTTagCompound("tag"))
stack.getTagCompound.setDouble(Settings.namespace + "xp", Settings.get.baseXpToLevel + math.pow(30.0001 * Settings.get.constantXpGrowth, Settings.get.exponentialXpGrowth))
stack.getTagCompound.setInteger(Settings.namespace + "storedEnergy", (Settings.get.bufferRobot + Settings.get.bufferPerLevel * 30).toInt)
stack
})
}
GameRegistry.registerBlock(blockSimple, classOf[Item], Settings.namespace + "simple")
GameRegistry.registerBlock(blockSimpleWithRedstone, classOf[Item], Settings.namespace + "simple_redstone")

View File

@ -58,12 +58,13 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
override def getSubBlocks(itemId: Int, creativeTab: CreativeTabs, list: util.List[_]) = {
// Workaround for MC's untyped lists...
def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T])
(0 until subBlocks.length).filter(id => subBlocks(id).showInItemList && subBlocks(id).parent == this).
map(new ItemStack(this, 1, _)).
sortBy(_.getUnlocalizedName).
foreach(add(list, _))
subBlockItemStacks().sortBy(_.getUnlocalizedName).foreach(add(list, _))
}
def subBlockItemStacks() = (0 until subBlocks.length).
filter(id => subBlocks(id).showInItemList && subBlocks(id).parent == this).
map(id => new ItemStack(this, 1, id))
// ----------------------------------------------------------------------- //
// Rotation
// ----------------------------------------------------------------------- //

View File

@ -74,7 +74,9 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
var xp = 0.0
def xpForNextLevel = Settings.get.baseXpToLevel + Math.pow((level + 1) * Settings.get.constantXpGrowth, Settings.get.exponentialXpGrowth)
def xpForNextLevel = xpForLevel(level + 1)
def xpForLevel(level: Int) = Settings.get.baseXpToLevel + Math.pow(level * Settings.get.constantXpGrowth, Settings.get.exponentialXpGrowth)
var level = 0
@ -153,6 +155,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
if (created) {
assert(world.getBlockTileEntity(nx, ny, nz) == proxy)
assert(x == nx && y == ny && z == nz)
world.setBlock(ox, oy, oz, 0, 0, 1)
Blocks.robotAfterimage.setBlock(world, ox, oy, oz, 1)
assert(Delegator.subBlock(world, ox, oy, oz).exists(_ == Blocks.robotAfterimage))
// Here instead of Lua callback so that it gets called on client, too.

View File

@ -40,7 +40,9 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
@LuaCallback(value = "level", direct = true)
def level(context: Context, args: Arguments): Array[AnyRef] = {
result(robot.level + robot.xp / robot.xpForNextLevel)
val xpNeeded = robot.xpForNextLevel - robot.xpForLevel(robot.level)
val xpProgress = math.max(0, robot.xp - robot.xpForLevel(robot.level))
result(robot.level + xpProgress / xpNeeded)
}
// ----------------------------------------------------------------------- //