diff --git a/build.properties b/build.properties index aa608a076..5a3ca15d3 100644 --- a/build.properties +++ b/build.properties @@ -29,7 +29,7 @@ gc.version=3.0.7 gt.version=5.04.06 ic2.version=2.3.131-ex18 igwmod.version=1.1.3-18 -jei.version=2.28.7.174 +jei.version=2.28.18.186 mcmp.version=1.0.8 mekanism.build=5 mekanism.version=7.1.2 diff --git a/src/main/java/li/cil/oc/api/IMC.java b/src/main/java/li/cil/oc/api/IMC.java index e1632093b..11c404d39 100644 --- a/src/main/java/li/cil/oc/api/IMC.java +++ b/src/main/java/li/cil/oc/api/IMC.java @@ -166,9 +166,17 @@ public final class IMC { * Signature of callbacks must be: *
      * boolean select(ItemStack stack)
-     * ItemStack[] disassemble(ItemStack stack, ItemStack[] ingredients)
+     * Object disassemble(ItemStack stack, ItemStack[] ingredients)
      * 
*

+ * Where the Object returned from the disassemble + * method must be one of the following: + *

+ *

* Callbacks must be declared as packagePath.className.methodName. * For example: com.example.Integration.callbackMethod. * @@ -353,6 +361,17 @@ public final class IMC { FMLInterModComms.sendMessage(MOD_ID, "blacklistHost", nbt); } + /** + * Notifies OpenComputers that there is some 3rd-party power system present + * that adds integration on its side. + *

+ * This will suppress the "no power system found" message on start up, and + * avoid auto-disabling power use. + */ + public static void registerCustomPowerSystem() { + FMLInterModComms.sendMessage(MOD_ID, "registerCustomPowerSystem", "true"); + } + // ----------------------------------------------------------------------- // private static final String MOD_ID = "OpenComputers"; diff --git a/src/main/java/li/cil/oc/api/component/RackMountable.java b/src/main/java/li/cil/oc/api/component/RackMountable.java index 00555f759..a94820c2c 100644 --- a/src/main/java/li/cil/oc/api/component/RackMountable.java +++ b/src/main/java/li/cil/oc/api/component/RackMountable.java @@ -7,7 +7,6 @@ import li.cil.oc.api.util.StateAware; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; /** * Use this interface on environments provided by drivers for items that can @@ -63,11 +62,9 @@ public interface RackMountable extends ManagedEnvironment, StateAware { * pointlessly compressed fashion (because MC is a dummy like that). * * @param player the player activating the mountable. - * @param side the side (in global coordinate space) of the rack that was activated. - * @param hitX the relative x coordinate of the activation. - * @param hitY the relative y coordinate of the activation. - * @param hitZ the relative z coordinate of the activation. + * @param hitX the relative x coordinate of the activation on the mountable. + * @param hitY the relative y coordinate of the activation on the mountable. * @return whether the activation was handled (e.g. GUI opened). */ - boolean onActivate(EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ); + boolean onActivate(EntityPlayer player, float hitX, float hitY); } diff --git a/src/main/java/li/cil/oc/api/driver/DeviceInfo.java b/src/main/java/li/cil/oc/api/driver/DeviceInfo.java new file mode 100644 index 000000000..7b12d21fa --- /dev/null +++ b/src/main/java/li/cil/oc/api/driver/DeviceInfo.java @@ -0,0 +1,106 @@ +package li.cil.oc.api.driver; + +import java.util.Map; + +/** + * Implement this on {@link li.cil.oc.api.network.Environment}s if you wish to + * expose some (typically static) information about the device represented by + * that environment to a {@link li.cil.oc.api.Machine} connected to it. + *

+ * You may also implement this on a {@link li.cil.oc.api.machine.MachineHost} + * in which case the Machine will forward that information as + * its own (since MachineHosts usually use the machine's node as + * their own, this avoids a dummy environment used solely for device info). + *

+ * This is intended to permit programs to reflect on the hardware they are + * running on, typically for purely informational purposes, but possibly to + * toggle certain hardware specific features. + *

+ * For example, graphics cards may expose their timings via this interface, so + * that programs may determine at what speed they can redraw, and optimize + * execution order. + *

+ * While the format of the returned table of information is entirely up to you, + * it is recommended to orient yourself on the key values and names that + * lshw uses (http://www.ezix.org/project/wiki/HardwareLiSter), + * where applicable. + */ +public interface DeviceInfo { + /** + * Compile a list of device information strings as key-value pairs. + *

+ * For example, this may list the type of the device, a vendor (for example + * your mod name, or something more creative if you like), specifications + * of the device (speeds, capacities). + *

+ * For example, OC's tier one memory module returns the following: + * + * + * + * + * + * + *
classmemory
descriptionMemory bank
vendorMightyPirates GmbH & Co. KG
productMultipurpose RAM Type
clock500
+ * + * @return the table of information on this device, or null. + */ + Map getDeviceInfo(); + + /** + * Recommended list of key values for the device info table. + *

+ * You are strongly encouraged to at least define class, description, + * vendor and product, to allow a more homogenous experience for the + * end-user reading this information via a script. + *

+ * Feel free to be somewhat... flexible with the designated uses of these fields. For example, + * the capacity and size fields have differing meaning depending on the device in OpenComputers + * itself (e.g. they're used for maximum number of characters for graphics cards, width is + * used for bit depth on graphics cards, etc.), just try to stick with what's somewhat logical. + */ + final class DeviceAttribute { + public static final String Class = "class"; // device's class (see below), e.g. "processor" + public static final String Description = "description"; // human-readable description of the hardware node, e.g. "Ethernet interface" + public static final String Vendor = "vendor"; // vendor/manufacturer of the device, e.g. "Minecorp Inc." + public static final String Product = "product"; // product name of the device, e.g. "ATY Raderps 4200X" + public static final String Version = "version"; // version/release of the device, e.g. "2.1.0" + public static final String Serial = "serial"; // serial number of the device + public static final String Capacity = "capacity"; // maximum capacity reported by the device, e.g. unformatted size of a disk + public static final String Size = "size"; // actual size of the device, e.g. actual usable space on a disk + public static final String Clock = "clock"; // bus clock (in Hz) of the device, e.g. call speed(s) of a component + public static final String Width = "width"; // address width of the device, in the broadest sense + + private DeviceAttribute() { + } + } + + /** + * Recommended list of values for the class attribute (see above). + *

+ * Again, feel free to be somewhat creative with those. When in doubt, use generic. + */ + final class DeviceClass { + public static final String System = "system"; // used to refer to the whole machine, e.g. "Computer", "Server", "Robot" + public static final String Bridge = "bridge"; // internal bus converter, maybe useful for some low-level archs? + public static final String Memory = "memory"; // memory bank that can contain data, executable code, e.g. RAM, EEPROM + public static final String Processor = "processor"; // execution processor, e.g. CPU, cryptography support + public static final String Address = "address"; // memory address range, e.g. video memory (again, low-level archs maybe?) + public static final String Storage = "storage"; // storage controller, e.g. IDE controller (low-level...) + public static final String Disk = "disk"; // random-access storage device, e.g. floppies + public static final String Tape = "tape"; // sequential-access storage device, e.g. cassette tapes + public static final String Bus = "bus"; // device-connecting bus, e.g. USB + public static final String Network = "network"; // network interface, e.g. ethernet, wlan + public static final String Display = "display"; // display adapter, e.g. graphics cards + public static final String Input = "input"; // user input device, e.g. keyboard, mouse + public static final String Printer = "printer"; // printing device, e.g. printer, 3D-printer + public static final String Multimedia = "multimedia"; // audio/video device, e.g. sound cards + public static final String Communication = "communication"; // line communication device, e.g. modem, serial ports + public static final String Power = "power"; // energy source, e.g. battery, power supply + public static final String Volume = "volume"; // disk volume, e.g. file system + public static final String Generic = "generic"; // generic device (used when no other class is suitable) + + private DeviceClass() { + } + } + +} diff --git a/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java b/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java index 415a295ed..97d6f6ef3 100644 --- a/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java +++ b/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java @@ -2,6 +2,7 @@ package li.cil.oc.api.prefab; import li.cil.oc.api.manual.TabIconRenderer; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; @@ -25,7 +26,7 @@ public class TextureTabIconRenderer implements TabIconRenderer { @SideOnly(Side.CLIENT) public void render() { Minecraft.getMinecraft().getTextureManager().bindTexture(location); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, Minecraft.getMinecraft().getTextureManager().getTexture(location).getGlTextureId()); + GlStateManager.bindTexture(Minecraft.getMinecraft().getTextureManager().getTexture(location).getGlTextureId()); final Tessellator t = Tessellator.getInstance(); final WorldRenderer r = t.getWorldRenderer(); r.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index a8cc09b7d..3c306a9fa 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -1249,6 +1249,9 @@ opencomputers { # is decided in an extra roll of the dice. lootProbability: 5 + # Whether to allow loot disk cycling by crafting them with a wrench. + lootRecrafting: true + # The range, in blocks, in which the Geolyzer can scan blocks. Note that # it uses the maximum-distance, not the euclidean one, i.e. it can scan # in a cube surrounding it with twice this value as its edge length. diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/nanomachines.md b/src/main/resources/assets/opencomputers/doc/en_US/item/nanomachines.md index eff8bfbe8..ac87a14e9 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/nanomachines.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/nanomachines.md @@ -27,6 +27,7 @@ Nanomachines react to a simple, proprietary protocol: each packet must consist o - `getInput(index:number)` - Request the current state of the input with the specified index. - `setInput(index:number, value:boolean)` - Set the state of the input with the specified index to the specified value. - `getActiveEffects()` - Request a list of active effects. Note that some effects may not show up in this list. +- `saveConfiguration()` - Requires a set of nanomachines in the players inventory, will store the current configuration to it. For example, in OpenOS: - `component.modem.broadcast(1, "nanomachines", "setInput", 1, true)` will enable the first input. diff --git a/src/main/resources/assets/opencomputers/loot/README.md b/src/main/resources/assets/opencomputers/loot/README.md index a0da8107a..05528523a 100644 --- a/src/main/resources/assets/opencomputers/loot/README.md +++ b/src/main/resources/assets/opencomputers/loot/README.md @@ -7,4 +7,4 @@ To add a disk, create a folder and put the files the disk should contain into th You are invited to submit your own programs as pull requests! The more the merrier :-) -For example, say you have a program named "chat.lua". You'd create a folder, say `NetChat` or whatever the program likes to call itself, and put the `chat.lua` file into that folder. You then add the line `NetChat=chat` to the `loot.properties` file. And that's it. Make a pull request and your program is in OpenComputers - unless it fails the arbitrary quality check, of course. Feel free to submit pull requests for fixes to your submitted programs (or of others) at any time! +For example, say you have a program named "chat.lua". You'd create a folder, say `netchat` or whatever the program likes to call itself, and put the `chat.lua` file into that folder. You then add the line `netchat=NetChat` to the `loot.properties` file. And that's it. Make a pull request and your program is in OpenComputers - unless it fails the arbitrary quality check, of course. Feel free to submit pull requests for fixes to your submitted programs (or of others) at any time! diff --git a/src/main/resources/assets/opencomputers/loot/Builder/build.lua b/src/main/resources/assets/opencomputers/loot/builder/build.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Builder/build.lua rename to src/main/resources/assets/opencomputers/loot/builder/build.lua diff --git a/src/main/resources/assets/opencomputers/loot/Builder/build.man b/src/main/resources/assets/opencomputers/loot/builder/build.man similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Builder/build.man rename to src/main/resources/assets/opencomputers/loot/builder/build.man diff --git a/src/main/resources/assets/opencomputers/loot/Builder/example.plan b/src/main/resources/assets/opencomputers/loot/builder/example.plan similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Builder/example.plan rename to src/main/resources/assets/opencomputers/loot/builder/example.plan diff --git a/src/main/resources/assets/opencomputers/lua/component/data/.autorun.lua b/src/main/resources/assets/opencomputers/loot/data/.autorun.lua similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/data/.autorun.lua rename to src/main/resources/assets/opencomputers/loot/data/.autorun.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/base64.lua b/src/main/resources/assets/opencomputers/loot/data/bin/base64.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/base64.lua rename to src/main/resources/assets/opencomputers/loot/data/bin/base64.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/deflate.lua b/src/main/resources/assets/opencomputers/loot/data/bin/deflate.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/deflate.lua rename to src/main/resources/assets/opencomputers/loot/data/bin/deflate.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/data/bin/gpg.lua b/src/main/resources/assets/opencomputers/loot/data/bin/gpg.lua similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/data/bin/gpg.lua rename to src/main/resources/assets/opencomputers/loot/data/bin/gpg.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/inflate.lua b/src/main/resources/assets/opencomputers/loot/data/bin/inflate.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/inflate.lua rename to src/main/resources/assets/opencomputers/loot/data/bin/inflate.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/data/bin/md5sum.lua b/src/main/resources/assets/opencomputers/loot/data/bin/md5sum.lua similarity index 96% rename from src/main/resources/assets/opencomputers/lua/component/data/bin/md5sum.lua rename to src/main/resources/assets/opencomputers/loot/data/bin/md5sum.lua index ebdb3ba2c..65c45a962 100644 --- a/src/main/resources/assets/opencomputers/lua/component/data/bin/md5sum.lua +++ b/src/main/resources/assets/opencomputers/loot/data/bin/md5sum.lua @@ -1,27 +1,27 @@ -local shell = require("shell") -local data = require("data") - -local args = shell.parse(...) -if #args == 0 then - local read = "" - repeat - local current = io.read("*a") - read = read .. current - until current ~= "" - io.write(data.toHex(data.md5(read))) -else - for i = 1, #args do - local read = "" - local file, reason = io.open(shell.resolve(args[i])) - if not file then - io.stderr:write(tostring(reason) .. "\n") - os.exit(false) - end - repeat - local current = file:read("*a") - read = read .. current - until current ~= "" - file:close() - io.write(data.toHex(data.md5(read)) .. "\t".. args[i] .. "\n") - end -end +local shell = require("shell") +local data = require("data") + +local args = shell.parse(...) +if #args == 0 then + local read = "" + repeat + local current = io.read("*a") + read = read .. current + until current ~= "" + io.write(data.toHex(data.md5(read))) +else + for i = 1, #args do + local read = "" + local file, reason = io.open(shell.resolve(args[i])) + if not file then + io.stderr:write(tostring(reason) .. "\n") + os.exit(false) + end + repeat + local current = file:read("*a") + read = read .. current + until current ~= "" + file:close() + io.write(data.toHex(data.md5(read)) .. "\t".. args[i] .. "\n") + end +end diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/sha256sum.lua b/src/main/resources/assets/opencomputers/loot/data/bin/sha256sum.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/sha256sum.lua rename to src/main/resources/assets/opencomputers/loot/data/bin/sha256sum.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/lib/data.lua b/src/main/resources/assets/opencomputers/loot/data/lib/data.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/lib/data.lua rename to src/main/resources/assets/opencomputers/loot/data/lib/data.lua diff --git a/src/main/resources/assets/opencomputers/loot/TheDig/dig.lua b/src/main/resources/assets/opencomputers/loot/dig/dig.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/TheDig/dig.lua rename to src/main/resources/assets/opencomputers/loot/dig/dig.lua diff --git a/src/main/resources/assets/opencomputers/loot/TheDig/dig.man b/src/main/resources/assets/opencomputers/loot/dig/dig.man similarity index 100% rename from src/main/resources/assets/opencomputers/loot/TheDig/dig.man rename to src/main/resources/assets/opencomputers/loot/dig/dig.man diff --git a/src/main/resources/assets/opencomputers/lua/component/generator/.autorun.lua b/src/main/resources/assets/opencomputers/loot/generator/.autorun.lua similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/generator/.autorun.lua rename to src/main/resources/assets/opencomputers/loot/generator/.autorun.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/generator/bin/refuel.lua b/src/main/resources/assets/opencomputers/loot/generator/bin/refuel.lua similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/generator/bin/refuel.lua rename to src/main/resources/assets/opencomputers/loot/generator/bin/refuel.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/internet/.autorun.lua b/src/main/resources/assets/opencomputers/loot/internet/.autorun.lua similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/internet/.autorun.lua rename to src/main/resources/assets/opencomputers/loot/internet/.autorun.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/internet/bin/pastebin.lua b/src/main/resources/assets/opencomputers/loot/internet/bin/pastebin.lua similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/internet/bin/pastebin.lua rename to src/main/resources/assets/opencomputers/loot/internet/bin/pastebin.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/internet/bin/wget.lua b/src/main/resources/assets/opencomputers/loot/internet/bin/wget.lua similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/internet/bin/wget.lua rename to src/main/resources/assets/opencomputers/loot/internet/bin/wget.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/internet/lib/internet.lua b/src/main/resources/assets/opencomputers/loot/internet/lib/internet.lua similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/internet/lib/internet.lua rename to src/main/resources/assets/opencomputers/loot/internet/lib/internet.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/internet/usr/man/pastebin b/src/main/resources/assets/opencomputers/loot/internet/usr/man/pastebin similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/internet/usr/man/pastebin rename to src/main/resources/assets/opencomputers/loot/internet/usr/man/pastebin diff --git a/src/main/resources/assets/opencomputers/lua/component/internet/usr/man/wget b/src/main/resources/assets/opencomputers/loot/internet/usr/man/wget similarity index 100% rename from src/main/resources/assets/opencomputers/lua/component/internet/usr/man/wget rename to src/main/resources/assets/opencomputers/loot/internet/usr/man/wget diff --git a/src/main/resources/assets/opencomputers/loot/OpenIRC/irc.lua b/src/main/resources/assets/opencomputers/loot/irc/irc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenIRC/irc.lua rename to src/main/resources/assets/opencomputers/loot/irc/irc.lua diff --git a/src/main/resources/assets/opencomputers/loot/loot.properties b/src/main/resources/assets/opencomputers/loot/loot.properties index 22fc94ac4..aab1c027a 100644 --- a/src/main/resources/assets/opencomputers/loot/loot.properties +++ b/src/main/resources/assets/opencomputers/loot/loot.properties @@ -5,15 +5,21 @@ # weight 2 is two times as likely to be generated than an item with # weight 1. Weight 0 means it will not spawn at all. #The color defaults to gray. It must be a dye's ore-dict name. -Builder=build:1:dyeYellow -MazeGen=maze:1:dyeOrange -Network=network:1:dyeLime -Plan9k=plan9k:1:dyeRed -OpenIRC=irc:1:dyeLightBlue -OpenLoader=openloader:1:dyeMagenta -OpenOS=openOS:0:dyeGreen -OPPM=oppm:0:dyeCyan -# Higher chance to find the dig program, because it has the most immediate -# use - OpenOS is craftable and IRC can be downloaded once an internet card -# is available - which one needs anyway, to use the program... -TheDig=dig:2:dyeBrown + +# General purpose. +network=Network (Network Stack):1:dyeLime +plan9k=Plan9k (Operating System):1:dyeRed +irc=OpenIRC (IRC Client):1:dyeLightBlue +openloader=OpenLoader (Boot Loader):1:dyeMagenta +openos=OpenOS (Operating System):0:dyeGreen +oppm=OPPM (Package Manager):0:dyeCyan + +# Robot utilities. +builder=Builder:1:dyeYellow +dig=Digger:2:dyeBrown +maze=Mazer:1:dyeOrange + +# Drivers for components. +data=Data Card Software:0:dyePink +generator=Generator Upgrade Software:0:dyePurple +internet=Internet Card Software:0:dyeBlue \ No newline at end of file diff --git a/src/main/resources/assets/opencomputers/loot/MazeGen/maze.lua b/src/main/resources/assets/opencomputers/loot/maze/maze.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/MazeGen/maze.lua rename to src/main/resources/assets/opencomputers/loot/maze/maze.lua diff --git a/src/main/resources/assets/opencomputers/loot/MazeGen/maze.man b/src/main/resources/assets/opencomputers/loot/maze/maze.man similarity index 100% rename from src/main/resources/assets/opencomputers/loot/MazeGen/maze.man rename to src/main/resources/assets/opencomputers/loot/maze/maze.man diff --git a/src/main/resources/assets/opencomputers/loot/Network/autorun.lua b/src/main/resources/assets/opencomputers/loot/network/autorun.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/autorun.lua rename to src/main/resources/assets/opencomputers/loot/network/autorun.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/bin/arp.lua b/src/main/resources/assets/opencomputers/loot/network/data/bin/arp.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/bin/arp.lua rename to src/main/resources/assets/opencomputers/loot/network/data/bin/arp.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/bin/ifconfig.lua b/src/main/resources/assets/opencomputers/loot/network/data/bin/ifconfig.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/bin/ifconfig.lua rename to src/main/resources/assets/opencomputers/loot/network/data/bin/ifconfig.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/bin/ping.lua b/src/main/resources/assets/opencomputers/loot/network/data/bin/ping.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/bin/ping.lua rename to src/main/resources/assets/opencomputers/loot/network/data/bin/ping.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/bin/route.lua b/src/main/resources/assets/opencomputers/loot/network/data/bin/route.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/bin/route.lua rename to src/main/resources/assets/opencomputers/loot/network/data/bin/route.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/boot/80_network.lua b/src/main/resources/assets/opencomputers/loot/network/data/boot/80_network.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/boot/80_network.lua rename to src/main/resources/assets/opencomputers/loot/network/data/boot/80_network.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/boot/95_hostname.lua b/src/main/resources/assets/opencomputers/loot/network/data/boot/95_hostname.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/boot/95_hostname.lua rename to src/main/resources/assets/opencomputers/loot/network/data/boot/95_hostname.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/lib/network.lua b/src/main/resources/assets/opencomputers/loot/network/data/lib/network.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/lib/network.lua rename to src/main/resources/assets/opencomputers/loot/network/data/lib/network.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/lib/network/loopback.lua b/src/main/resources/assets/opencomputers/loot/network/data/lib/network/loopback.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/lib/network/loopback.lua rename to src/main/resources/assets/opencomputers/loot/network/data/lib/network/loopback.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/lib/network/modem.lua b/src/main/resources/assets/opencomputers/loot/network/data/lib/network/modem.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/lib/network/modem.lua rename to src/main/resources/assets/opencomputers/loot/network/data/lib/network/modem.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/lib/network/tunnel.lua b/src/main/resources/assets/opencomputers/loot/network/data/lib/network/tunnel.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/lib/network/tunnel.lua rename to src/main/resources/assets/opencomputers/loot/network/data/lib/network/tunnel.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/usr/bin/nc.lua b/src/main/resources/assets/opencomputers/loot/network/data/usr/bin/nc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/usr/bin/nc.lua rename to src/main/resources/assets/opencomputers/loot/network/data/usr/bin/nc.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/usr/man/ifconfig b/src/main/resources/assets/opencomputers/loot/network/data/usr/man/ifconfig similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/usr/man/ifconfig rename to src/main/resources/assets/opencomputers/loot/network/data/usr/man/ifconfig diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/usr/man/network b/src/main/resources/assets/opencomputers/loot/network/data/usr/man/network similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/usr/man/network rename to src/main/resources/assets/opencomputers/loot/network/data/usr/man/network diff --git a/src/main/resources/assets/opencomputers/loot/Network/data/usr/man/ping b/src/main/resources/assets/opencomputers/loot/network/data/usr/man/ping similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/data/usr/man/ping rename to src/main/resources/assets/opencomputers/loot/network/data/usr/man/ping diff --git a/src/main/resources/assets/opencomputers/loot/Network/installNetwork.lua b/src/main/resources/assets/opencomputers/loot/network/installNetwork.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/installNetwork.lua rename to src/main/resources/assets/opencomputers/loot/network/installNetwork.lua diff --git a/src/main/resources/assets/opencomputers/loot/Network/protocol b/src/main/resources/assets/opencomputers/loot/network/protocol similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Network/protocol rename to src/main/resources/assets/opencomputers/loot/network/protocol diff --git a/src/main/resources/assets/opencomputers/loot/OpenLoader/OpenLoader.man b/src/main/resources/assets/opencomputers/loot/openloader/OpenLoader.man similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenLoader/OpenLoader.man rename to src/main/resources/assets/opencomputers/loot/openloader/OpenLoader.man diff --git a/src/main/resources/assets/opencomputers/loot/OpenLoader/autorun.lua b/src/main/resources/assets/opencomputers/loot/openloader/autorun.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenLoader/autorun.lua rename to src/main/resources/assets/opencomputers/loot/openloader/autorun.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenLoader/bin/opl-flash.lua b/src/main/resources/assets/opencomputers/loot/openloader/bin/opl-flash.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenLoader/bin/opl-flash.lua rename to src/main/resources/assets/opencomputers/loot/openloader/bin/opl-flash.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenLoader/init.lua b/src/main/resources/assets/opencomputers/loot/openloader/init.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenLoader/init.lua rename to src/main/resources/assets/opencomputers/loot/openloader/init.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/.osprop b/src/main/resources/assets/opencomputers/loot/openos/.osprop similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/.osprop rename to src/main/resources/assets/opencomputers/loot/openos/.osprop diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/address.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/address.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/address.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/address.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/alias.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/alias.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/alias.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/alias.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/cat.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/cat.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/cat.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/cat.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/cd.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/cd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/cd.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/cd.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/clear.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/clear.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/clear.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/clear.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/components.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/components.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/components.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/components.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/cp.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/cp.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/cp.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/cp.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/date.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/date.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/date.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/date.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/df.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/df.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/df.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/df.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/dmesg.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/dmesg.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/du.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/du.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/du.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/du.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/echo.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/echo.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/echo.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/echo.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/edit.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/edit.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/find.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/find.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/find.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/find.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/flash.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/flash.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/grep.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/grep.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/grep.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/grep.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/head.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/head.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/head.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/head.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/hostname.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/hostname.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/hostname.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/hostname.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/install.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/install.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/install.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/install.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/label.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/label.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/label.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/label.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/ln.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/ln.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/ln.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/ln.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/ls.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/ls.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/ls.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/ls.lua diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/lshw.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/lshw.lua new file mode 100644 index 000000000..60459422e --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/lshw.lua @@ -0,0 +1,42 @@ +local computer = require("computer") +local shell = require("shell") +local text = require("text") + +local args, options = shell.parse(...) + +local devices = computer.getDeviceInfo() +local columns = {} + +if not next(options, nil) then + options.t = true + options.d = true + options.p = true +end +if options.t then table.insert(columns, "Class") end +if options.d then table.insert(columns, "Description") end +if options.p then table.insert(columns, "Product") end +if options.v then table.insert(columns, "Vendor") end +if options.c then table.insert(columns, "Capacity") end +if options.w then table.insert(columns, "Width") end +if options.s then table.insert(columns, "Clock") end + +local m = {} +for address, info in pairs(devices) do + for col, name in ipairs(columns) do + m[col] = math.max(m[col] or 1, (info[name:lower()] or ""):len()) + end +end + +io.write(text.padRight("Address", 10)) +for col, name in ipairs(columns) do + io.write(text.padRight(name, m[col] + 2)) +end +io.write("\n") + +for address, info in pairs(devices) do + io.write(text.padRight(address:sub(1, 5).."...", 10)) + for col, name in ipairs(columns) do + io.write(text.padRight(info[name:lower()] or "", m[col] + 2)) + end + io.write("\n") +end diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/lua.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/lua.lua similarity index 95% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/lua.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/lua.lua index f93854273..7e8042de5 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/lua.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/lua.lua @@ -85,7 +85,9 @@ if #args == 0 or options.i then end end local function hint(line, index) - line = (line or ""):sub(1, index - 1) + line = (line or "") + local tail = line:sub(index) + line = line:sub(1, index - 1) local path = string.match(line, "[a-zA-Z_][a-zA-Z0-9_.]*$") if not path then return nil end local suffix = string.match(path, "[^.]+$") or "" @@ -95,7 +97,7 @@ if #args == 0 or options.i then local r1, r2 = {}, {} findKeys(t, r1, string.sub(line, 1, #line - #suffix), suffix) for k in pairs(r1) do - table.insert(r2, k) + table.insert(r2, k .. tail) end table.sort(r2) if #r2 == 1 then @@ -103,10 +105,11 @@ if #args == 0 or options.i then __index=function(tbl, key) if key==2 then local prev=tbl[1] - tbl[1]=nil local next = hint(prev,#prev+1) - for i,v in ipairs(next) do - tbl[i] = v + if next then + for i,v in ipairs(next) do + tbl[i] = v + end end setmetatable(tbl,getmetatable(next)) return tbl[1] diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/man.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/man.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/man.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/man.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/mkdir.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/mkdir.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/mkdir.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/mkdir.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/mktmp.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/mktmp.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/mktmp.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/mktmp.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/more.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/more.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/more.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/more.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/mount.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/mount.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/mount.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/mount.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/mv.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/mv.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/mv.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/mv.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/primary.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/primary.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/primary.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/primary.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/pwd.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/pwd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/pwd.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/pwd.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/rc.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/rc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/rc.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/rc.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/reboot.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/reboot.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/reboot.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/reboot.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/redstone.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/redstone.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/redstone.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/redstone.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/resolution.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/resolution.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/resolution.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/resolution.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/rm.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/rm.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/rm.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/rm.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/rmdir.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/rmdir.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/rmdir.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/rmdir.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/set.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/set.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/set.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/set.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/sh.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/sh.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/shutdown.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/shutdown.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/shutdown.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/shutdown.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/sleep.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/sleep.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/sleep.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/sleep.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/source.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/source.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/source.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/source.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/time.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/time.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/time.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/time.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/touch.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/touch.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/touch.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/touch.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/umount.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/umount.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/umount.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/umount.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/unalias.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/unalias.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/unalias.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/unalias.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/unset.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/unset.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/unset.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/unset.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/uptime.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/uptime.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/uptime.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/uptime.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/useradd.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/useradd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/useradd.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/useradd.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/userdel.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/userdel.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/userdel.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/userdel.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/which.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/which.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/which.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/which.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/yes.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/yes.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/bin/yes.lua rename to src/main/resources/assets/opencomputers/loot/openos/bin/yes.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/00_base.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/00_base.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/00_base.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/00_base.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/01_process.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/01_process.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/01_process.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/01_process.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/02_os.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/02_os.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/02_os.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/02_os.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/03_io.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/03_io.lua similarity index 86% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/03_io.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/03_io.lua index 945ae2fa0..34a58b172 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/03_io.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/boot/03_io.lua @@ -33,14 +33,19 @@ function stdoutStream:write(str) end function stderrStream:write(str) - local component = require("component") - if component.isAvailable("gpu") and component.gpu.getDepth() and component.gpu.getDepth() > 1 then - local foreground = component.gpu.setForeground(0xFF0000) - term.write(str, true) - component.gpu.setForeground(foreground) - else - term.write(str, true) + local gpu = term.gpu() + local set_depth = gpu and gpu.getDepth() and gpu.getDepth() > 1 + + if set_depth then + set_depth = gpu.setForeground(0xFF0000) end + + term.drawText(str, true) + + if set_depth then + gpu.setForeground(set_depth) + end + return self end diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/04_component.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/04_component.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/04_component.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/04_component.lua diff --git a/src/main/resources/assets/opencomputers/loot/openos/boot/10_devfs.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/10_devfs.lua new file mode 100644 index 000000000..0da8de199 --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/openos/boot/10_devfs.lua @@ -0,0 +1,7 @@ +require("filesystem").mount( +setmetatable({ + isReadOnly = function()return false end +}, +{ + __index=function(tbl,key)return require("devfs")[key]end +}), "/dev") diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/90_filesystem.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/90_filesystem.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/90_filesystem.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/90_filesystem.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/91_gpu.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/91_gpu.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/91_gpu.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/91_gpu.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/92_keyboard.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/92_keyboard.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/92_keyboard.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/92_keyboard.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/93_term.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/93_term.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/93_term.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/93_term.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/94_shell.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/94_shell.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/94_shell.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/94_shell.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/99_rc.lua b/src/main/resources/assets/opencomputers/loot/openos/boot/99_rc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/boot/99_rc.lua rename to src/main/resources/assets/opencomputers/loot/openos/boot/99_rc.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/etc/motd b/src/main/resources/assets/opencomputers/loot/openos/etc/motd similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/etc/motd rename to src/main/resources/assets/opencomputers/loot/openos/etc/motd diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/etc/profile b/src/main/resources/assets/opencomputers/loot/openos/etc/profile similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/etc/profile rename to src/main/resources/assets/opencomputers/loot/openos/etc/profile diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/etc/rc.cfg b/src/main/resources/assets/opencomputers/loot/openos/etc/rc.cfg similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/etc/rc.cfg rename to src/main/resources/assets/opencomputers/loot/openos/etc/rc.cfg diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/etc/rc.d/example.lua b/src/main/resources/assets/opencomputers/loot/openos/etc/rc.d/example.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/etc/rc.d/example.lua rename to src/main/resources/assets/opencomputers/loot/openos/etc/rc.d/example.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/home/.shrc b/src/main/resources/assets/opencomputers/loot/openos/home/.shrc similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/home/.shrc rename to src/main/resources/assets/opencomputers/loot/openos/home/.shrc diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/init.lua b/src/main/resources/assets/opencomputers/loot/openos/init.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/init.lua rename to src/main/resources/assets/opencomputers/loot/openos/init.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/bit32.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/bit32.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/bit32.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/bit32.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/buffer.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/buffer.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/buffer.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/buffer.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/colors.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/colors.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/colors.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/colors.lua diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/devfs.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/devfs.lua new file mode 100644 index 000000000..bee88b701 --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/devfs.lua @@ -0,0 +1,111 @@ +local fs = require("filesystem") + +local proxy = {points={},address=require("guid").next()} + +local nop = function()end + +function proxy.getLabel() + return "devfs" +end + +function proxy.setLabel(value) + error("drive does not support labeling") +end + +function proxy.spaceTotal() + return 0 +end + +function proxy.spaceUsed() + return 0 +end + +function proxy.exists(path) + return not not proxy.points[path] +end + +function proxy.size(path) + return 0 +end + +function proxy.isDirectory(path) + return false +end + +function proxy.lastModified(path) + return fs.lastModified("/dev/") +end + +function proxy.list() + local keys = {} + for k,v in pairs(proxy.points) do + table.insert(keys, k) + end + return keys +end + +function proxy.makeDirectory(path) + return false +end + +function proxy.remove(path) + if not proxy.exists(path) then return false end + proxy.points[path] = nil + return true +end + +function proxy.rename(from, to) + return false +end + +proxy.close = nop + +function proxy.open(path, mode) + checkArg(1, path, "string") + + local handle = proxy.points[path] + if not handle then return nil, "device point [" .. path .. "] does not exist" end + + local msg = "device point [" .. path .. "] cannot be opened for " + + if mode == "r" then + if not handle.read then + return nil, msg .. "read" + end + else + if not handle.write then + return nil, msg .. "write" + end + end + + return handle +end + +function proxy.read(h,...) + return h:read(...) +end + +function proxy.seek(h,...) + return h:seek(...) +end + +function proxy.write(h,...) + return h:write(...) +end + +function proxy.create(path, handle) + handle.close = handle.close or nop + proxy.points[path] = handle + return true +end + +proxy.create("null", {write = nop}) +proxy.create("random", {read = function(_,n) + local chars = {} + for i=1,n do + table.insert(chars,string.char(math.random(0,255))) + end + return table.concat(chars) +end}) + +return proxy diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/event.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/event.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/event.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/event.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/filesystem.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/filesystem.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/filesystem.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/filesystem.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/guid.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/guid.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/guid.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/guid.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/io.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/io.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/io.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/io.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/keyboard.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/keyboard.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/keyboard.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/keyboard.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/note.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/note.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/note.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/note.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/package.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/package.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/package.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/package.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/pipes.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/pipes.lua similarity index 89% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/pipes.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/pipes.lua index 9231a25f1..8c1e972a8 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/pipes.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/pipes.lua @@ -15,16 +15,14 @@ function pipeStream.new(pm) return setmetatable(stream, metatable) end function pipeStream:resume() - local yield_args = table.pack(self.pm.pco.resume_all(table.unpack(self.pm.args))) + local yield_args = table.pack(self.pm.pco.resume_all()) if not yield_args[1] then - self.pm.args = {false} self.pm.dead = true if not yield_args[1] and yield_args[2] then io.stderr:write(tostring(yield_args[2]) .. "\n") end end - self.pm.args = {true} return table.unpack(yield_args) end function pipeStream:close() @@ -134,7 +132,6 @@ function plib.internal.create(fp) local pco = setmetatable( { stack = {}, - args = {}, next = nil, create = _co.create, wrap = _co.wrap, @@ -318,7 +315,7 @@ function pipeManager.new(prog, mode, env) end local pm = setmetatable( - {dead=false,closed=false,args={},prog=prog,mode=mode,env=env}, + {dead=false,closed=false,prog=prog,mode=mode,env=env}, {__index=pipeManager} ) pm.prog_id = pm.mode == "r" and 1 or 2 @@ -328,37 +325,29 @@ function pipeManager.new(prog, mode, env) function()pm.dead=true end pm.commands = {} - pm.commands[pm.prog_id] = {shellPath, sh.internal.buildCommandRedirects({})} - pm.commands[pm.self_id] = {pm.handler, sh.internal.buildCommandRedirects({})} + pm.commands[pm.prog_id] = {shellPath, {}} + pm.commands[pm.self_id] = {pm.handler, {}} pm.root = function() + local startup_args = {} + local reason - pm.threads, reason, pm.inputs, pm.outputs = - sh.internal.buildPipeStream(pm.commands, pm.env) + pm.threads, reason = sh.internal.createThreads(pm.commands, {}, pm.env) if not pm.threads then pm.dead = true - return false, reason -- 2nd return is reason, not pipes, on error :) + return false, reason end - pm.pipe = reason[1] -- an array of pipes of length 1 - local startup_args = {} + pm.pipe = process.info(pm.threads[1]).data.io[1] + process.info(pm.threads[pm.prog_id]).data.args = {pm.env,pm.prog} + -- if we are the writer, we need args to resume prog if pm.mode == "w" then - pm.pipe.stream.args = {pm.env,pm.prog,n=2} - startup_args = {true,n=1} - -- also, if we are the writer, we need to intercept the reader - pm.pipe.stream.redirect.read = plib.internal.redirectRead(pm) - else - startup_args = {true,pm.env,pm.prog,n=3} + pm.pipe.stream.redirect[0] = plib.internal.redirectRead(pm) end - return sh.internal.executePipeStream( - pm.threads, - {pm.pipe}, - pm.inputs, - pm.outputs, - startup_args) + return sh.internal.runThreads(pm.threads) end return pm diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/process.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/process.lua similarity index 89% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/process.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/process.lua index b7d3b9b81..f62b8b1b2 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/process.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/process.lua @@ -81,7 +81,7 @@ function process.load(path, env, init, name) return string.format('%s:\n%s', msg or '', stack) end, ...) } - process.list[thread] = nil + process.internal.close(thread) if not result[1] then -- msg can be a custom error object local msg = result[2] @@ -100,6 +100,7 @@ function process.load(path, env, init, name) env = env, data = setmetatable( { + handles = {}, io = setmetatable({}, {__index=p and p.data and p.data.io or nil}), coroutine_handler = setmetatable({}, {__index=p and p.data and p.data.coroutine_handler or nil}), }, {__index=p and p.data or nil}), @@ -133,4 +134,16 @@ function process.info(levelOrThread) end end +--table of undocumented api subject to change and intended for internal use +process.internal = {} +--this is a future stub for a more complete method to kill a process +function process.internal.close(thread) + checkArg(1,thread,"thread") + local pdata = process.info(thread).data + for k,v in pairs(pdata.handles) do + v:close() + end + process.list[thread] = nil +end + return process diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/rc.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/rc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/rc.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/rc.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/serialization.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/serialization.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/serialization.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/serialization.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/sh.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/sh.lua similarity index 67% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/sh.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/sh.lua index fb63e7a19..5da1ef026 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/sh.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/sh.lua @@ -8,13 +8,7 @@ local tx = require("transforms") local unicode = require("unicode") local sh = {} - -sh.internal = setmetatable({}, -{ - __tostring=function() - return "table of undocumented api subject to change and intended for internal use" - end -}) +sh.internal = {} -- --[[@@]] are not just comments, but custom annotations for delayload methods. -- See package.lua and the api wiki for more information @@ -133,29 +127,36 @@ function sh.internal.isIdentifier(key) end function sh.expand(value) - return value + local expanded = value :gsub("%$([_%w%?]+)", function(key) if key == "?" then return tostring(sh.getLastExitCode()) end - return os.getenv(key) or '' end) + return os.getenv(key) or '' + end) :gsub("%${(.*)}", function(key) if sh.internal.isIdentifier(key) then return sh.internal.expandKey(key) end error("${" .. key .. "}: bad substitution") end) + if expanded:find('`') then + expanded = sh.internal.parse_sub(expanded) + end + return expanded end function sh.internal.expand(word) if #word == 0 then return {} end - local result = '' for i=1,#word do local part = word[i] - result = result .. (not (part.qr and part.qr[3]) and sh.expand(part.txt) or part.txt) + -- sh.expand runs command substitution on backticks + -- if the entire quoted area is backtick quoted, then + -- we can save some checks by adding them back in + local q = part.qr and part.qr[1] == '`' and '`' or '' + result = result .. (not (part.qr and part.qr[3]) and sh.expand(q..part.txt..q) or part.txt) end - return {result} end @@ -205,49 +206,6 @@ function sh.hintHandler(full_line, cursor) return sh.internal.hintHandlerImpl(full_line, cursor) end -function sh.internal.buildCommandRedirects(args) - local input, output, mode = nil, nil, "write" - local tokens = args - args = {} - local function smt(call) -- state metatable factory - local function index(_, token) - if token == "<" or token == ">" or token == ">>" then - return "parse error near " .. token - end - call(token) - return "args" -- default, return to normal arg parsing - end - return {__index=index} - end - local sm = { -- state machine for redirect parsing - args = setmetatable({["<"]="input", [">"]="output", [">>"]="append"}, - smt(function(token) - table.insert(args, token) - end)), - input = setmetatable({}, smt(function(token) - input = token - end)), - output = setmetatable({}, smt(function(token) - output = token - mode = "write" - end)), - append = setmetatable({}, smt(function(token) - output = token - mode = "append" - end)) - } - -- Run state machine over tokens. - local state = "args" - for i = 1, #tokens do - local token = tokens[i] - state = sm[state][token] - if not sm[state] then - return nil, state - end - end - return args, input, output, mode -end - function sh.internal.parseCommand(words) checkArg(1, words, "table") if #words == 0 then @@ -263,10 +221,11 @@ function sh.internal.parseCommand(words) if not program then return nil, evaluated_words[1] .. ": " .. reason end - return program, sh.internal.buildCommandRedirects(tx.sub(evaluated_words, 2)) + evaluated_words = tx.sub(evaluated_words, 2) + return program, evaluated_words end -function sh.internal.buildPipeStream(commands, env) +function sh.internal.createThreads(commands, eargs, env) -- Piping data between programs works like so: -- program1 gets its output replaced with our custom stream. -- program2 gets its input replaced with our custom stream. @@ -274,109 +233,70 @@ function sh.internal.buildPipeStream(commands, env) -- custom stream triggers execution of "next" program after write. -- custom stream triggers yield before read if buffer is empty. -- custom stream may have "redirect" entries for fallback/duplication. - local threads, pipes, inputs, outputs = {}, {}, {}, {} + local threads = {} for i = 1, #commands do - local program, args, input, output, mode = table.unpack(commands[i]) - local process_name = tostring(program) - local reason + local program, args = table.unpack(commands[i]) + local name, thread = tostring(program) local thread_env = type(program) == "string" and env or nil - threads[i], reason = process.load(program, thread_env, function() - os.setenv("_", program) - if input then - local file, reason = io.open(shell.resolve(input)) - if not file then - error("could not open '" .. input .. "': " .. reason, 0) - end - table.insert(inputs, file) - if pipes[i - 1] then - pipes[i - 1].stream.redirect.read = file - io.input(pipes[i - 1]) - else - io.input(file) - end - elseif pipes[i - 1] then - io.input(pipes[i - 1]) + local thread, reason = process.load(program, thread_env, function() + os.setenv("_", name) + -- popen expects each process to first write an empty string + -- this is required for proper thread order + io.write('') + end, name) + + threads[i] = thread + + if thread then + -- smart check if ios should be loaded + if tx.first(args, function(token) return token == "<" or token:find(">") end) then + args, reason = sh.internal.buildCommandRedirects(thread, args) end - if output then - local file, reason = io.open(shell.resolve(output), mode == "append" and "a" or "w") - if not file then - error("could not open '" .. output .. "': " .. reason, 0) - end - table.insert(outputs, file) - if pipes[i] then - pipes[i].stream.redirect.write = file - io.output(pipes[i]) - else - io.output(file) - end - elseif pipes[i] then - io.output(pipes[i]) + end + + if not args or not thread then + for i,t in ipairs(threads) do + process.internal.close(t) end - io.write('') - end, process_name) - if not threads[i] then - return false, reason + return nil, reason end - if i < #commands then - pipes[i] = require("buffer").new("rw", sh.internal.newMemoryStream()) - pipes[i]:setvbuf("no") - end - if i > 1 then - pipes[i - 1].stream.next = threads[i] - pipes[i - 1].stream.args = args - end + process.info(thread).data.args = tx.concat(args, eargs or {}) end - return threads, pipes, inputs, outputs + + if #threads > 1 then + sh.internal.buildPipeChain(threads) + end + + return threads end -function sh.internal.executePipeStream(threads, pipes, inputs, outputs, args) +function sh.internal.runThreads(threads) local result = {} for i = 1, #threads do -- Emulate CC behavior by making yields a filtered event.pull() - while args[1] and coroutine.status(threads[i]) ~= "dead" do - result = table.pack(coroutine.resume(threads[i], table.unpack(args, 2, args.n))) - if coroutine.status(threads[i]) ~= "dead" then - local action = result[2] - if action == nil or type(action) == "number" then - args = table.pack(pcall(event.pull, table.unpack(result, 2, result.n))) - else - args = table.pack(coroutine.yield(table.unpack(result, 2, result.n))) - end + local thread, args = threads[i] + while coroutine.status(thread) ~= "dead" do + args = args or process.info(thread).data.args + result = table.pack(coroutine.resume(thread, table.unpack(args))) + if coroutine.status(thread) ~= "dead" then + args = sh.internal.handleThreadYield(result) -- in case this was the end of the line, args is returned result = args + if table.remove(args, 1) then + break + end end end - if pipes[i] then - pcall(pipes[i].close, pipes[i]) - end if not result[1] then - if type(result[2]) == "table" and result[2].reason == "terminated" then - if result[2].code then - result[1] = true - result.n = 1 - else - result[2] = "terminated" - end - elseif type(result[2]) == "string" then - result[2] = debug.traceback(threads[i], result[2]) - end + sh.internal.handleThreadCrash(thread, result) break end end - for _, input in ipairs(inputs) do input:close() end - for _, output in ipairs(outputs) do output:close() end return table.unpack(result) end -function sh.internal.executeStatement(env, commands, eargs) - local threads, pipes, inputs, outputs = sh.internal.buildPipeStream(commands, env) - if not threads then return false, pipes end - local args = tx.concat({true,n=1},commands[1][2] or {}, eargs) - return sh.internal.executePipeStream(threads, pipes, inputs, outputs, args) -end - -function sh.internal.executePipes(pipe_parts, eargs) +function sh.internal.executePipes(pipe_parts, eargs, env) local commands = {} for i=1,#pipe_parts do commands[i] = table.pack(sh.internal.parseCommand(pipe_parts[i])) @@ -388,9 +308,14 @@ function sh.internal.executePipes(pipe_parts, eargs) return sh.internal.ec.parseCommand end end - local result = table.pack(sh.internal.executeStatement(env,commands,eargs)) - local cmd_result = result[2] - if not result[1] then + local threads, reason = sh.internal.createThreads(commands, eargs, env) + if not threads then + io.stderr:write(reason,"\n") + return false + end + local result, cmd_result = sh.internal.runThreads(threads) + + if not result then if cmd_result then if type(cmd_result) == "string" then cmd_result = cmd_result:gsub("^/lib/process%.lua:%d+: /", '/') @@ -404,7 +329,6 @@ end function sh.execute(env, command, ...) checkArg(2, command, "string") - local eargs = {...} if command:find("^%s*#") then return true, 0 end local statements, reason = sh.internal.statements(command) if not statements or statements == true then @@ -413,15 +337,105 @@ function sh.execute(env, command, ...) return true, 0 end + local eargs = {...} + -- simple if reason then - sh.internal.ec.last = sh.internal.command_result_as_code(sh.internal.executePipes(statements,eargs)) + sh.internal.ec.last = sh.internal.command_result_as_code(sh.internal.executePipes(statements, eargs, env)) return true end - return sh.internal.execute_complex(statements) + return sh.internal.execute_complex(statements, eargs, env) end +function --[[@delayloaded-start@]] sh.internal.handleThreadYield(result) + local action = result[2] + if action == nil or type(action) == "number" then + return table.pack(pcall(event.pull, table.unpack(result, 2, result.n))) + else + return table.pack(coroutine.yield(table.unpack(result, 2, result.n))) + end +end --[[@delayloaded-end@]] + +function --[[@delayloaded-start@]] sh.internal.handleThreadCrash(thread, result) + if type(result[2]) == "table" and result[2].reason == "terminated" then + if result[2].code then + result[1] = true + result.n = 1 + else + result[2] = "terminated" + end + elseif type(result[2]) == "string" then + result[2] = debug.traceback(thread, result[2]) + end +end --[[@delayloaded-end@]] + +function --[[@delayloaded-start@]] sh.internal.buildCommandRedirects(thread, args) + local data = process.info(thread).data + local tokens, ios, handles = args, data.io, data.handles + args = {} + local from_io, to_io, mode + for i = 1, #tokens do + local token = tokens[i] + if token == "<" then + from_io = 0 + mode = "r" + else + local first_index, last_index, from_io_txt, mode_txt, to_io_txt = token:find("(%d*)(>>?)(.*)") + if mode_txt then + mode = mode_txt == ">>" and "a" or "w" + from_io = from_io_txt and tonumber(from_io_txt) or 1 + if to_io_txt ~= "" then + to_io = tonumber(to_io_txt:sub(2)) + ios[from_io] = ios[to_io] + mode = nil + end + else -- just an arg + if not mode then + table.insert(args, token) + else + local file, reason = io.open(shell.resolve(token), mode) + if not file then + return nil, "could not open '" .. token .. "': " .. reason + end + table.insert(handles, file) + ios[from_io] = file + end + mode = nil + end + end + end + + return args +end --[[@delayloaded-end@]] + +function --[[@delayloaded-start@]] sh.internal.buildPipeChain(threads) + local prev_pipe + for i=1,#threads do + local thread = threads[i] + local data = process.info(thread).data + local pio = data.io + + local pipe + if i < #threads then + pipe = require("buffer").new("rw", sh.internal.newMemoryStream()) + pipe:setvbuf("no") + pipe.stream.redirect[1] = rawget(pio, 1) + pio[1] = pipe + table.insert(data.handles, pipe) + end + + if prev_pipe then + prev_pipe.stream.redirect[0] = rawget(pio, 0) + prev_pipe.stream.next = thread + pio[0] = prev_pipe + end + + prev_pipe = pipe + end + +end --[[@delayloaded-end@]] + function --[[@delayloaded-start@]] sh.internal.glob(glob_pattern) local segments = text.split(glob_pattern, {"/"}, true) local hiddens = tx.select(segments,function(e)return e:match("^%%%.")==nil end) @@ -539,36 +553,55 @@ function --[[@delayloaded-start@]] sh.internal.hintHandlerSplit(line) end --[[@delayloaded-end@]] function --[[@delayloaded-start@]] sh.internal.hintHandlerImpl(full_line, cursor) + -- line: text preceding the cursor: we want to hint this part (expand it) local line = unicode.sub(full_line, 1, cursor - 1) + -- suffix: text following the cursor (if any, else empty string) to append to the hints local suffix = unicode.sub(full_line, cursor) + -- if there is no text to hint, there are no hints if not line or #line < 1 then return {} end + -- hintHandlerSplit helps make the hints work even after delimiters such as ; + -- it also catches parse errors such as unclosed quotes local prev,line = sh.internal.hintHandlerSplit(line) if not prev then -- failed to parse, e.g. unclosed quote, no hints return {} end local result - local prefix, partial = line:match("^(.*=)(.*)$") + -- prefix: text (if any) that will not be expanded (such as a command word preceding a file name that we are expanding) + -- partial: text that we want to expand + -- this first match determines if partial comes after redirect symbols such as > + local prefix, partial = line:match("^(.*[=><]%s*)(.*)$") + -- if redirection was not found, partial could just be arguments following a command if not prefix then prefix, partial = line:match("^(.+%s+)(.*)$") end + -- partialPrefix: text of the partial that will not be expanded (i.e. a diretory path ending with /) + -- first, partialPrefix holds the whole text being expanded (we truncate later) local partialPrefix = (partial or line) - local name = partialPrefix:gsub(".*/", "") + -- name: text of the partial file name being expanded + local name = partialPrefix:gsub("^.*/", "") + -- here we remove the name text from the partialPrefix partialPrefix = partialPrefix:sub(1, -unicode.len(name) - 1) + -- if no prefix was found and partialPrefix did not specify a closed directory path then we are expanding the first argument + -- i.e. the command word (a program name) local searchInPath = not prefix and not partialPrefix:find("/") if searchInPath then result = sh.getMatchingPrograms(line) else result = sh.getMatchingFiles(partialPrefix, name) end + -- in very special cases, the suffix should include a blank space to indicate to the user that the hint is discrete local resultSuffix = suffix if #result > 0 and unicode.sub(result[1], -1) ~= "/" and not suffix:sub(1,1):find('%s') and (#result == 1 or searchInPath or not prefix) then resultSuffix = " " .. resultSuffix end + -- prefix no longer needs to refer to just the expanding section of the text + -- here we reintroduce the previous section of the text that hintHandlerSplit cut for us prefix = prev .. (prefix or "") table.sort(result) for i = 1, #result do + -- the hints define the whole line of text result[i] = prefix .. result[i] .. resultSuffix end return result @@ -583,10 +616,11 @@ function --[[@delayloaded-start@]] sh.internal.hasValidPiping(words, pipes) return true end - pipes = pipes or tx.sub(text.syntax, 2) -- first text syntax is ; which CAN be repeated + local semi_split = tx.find(text.syntax, {";"}) -- all symbols before ; in syntax CAN be repeated + pipes = pipes or tx.sub(text.syntax, semi_split + 1) - local pies = tx.select(words, function(parts, i, t) - return (#parts == 1 and tx.first(pipes, {{parts[1].txt}}) and true or false), i + local pies = tx.select(words, function(parts, i) + return #parts == 1 and #text.split(parts[1].txt, pipes, true) == 0 and true or false end) local bad_pipe @@ -718,6 +752,7 @@ function --[[@delayloaded-start@]] sh.internal.newMemoryStream() function memoryStream:close() self.closed = true + self.redirect = {} end function memoryStream:seek() @@ -728,12 +763,12 @@ function --[[@delayloaded-start@]] sh.internal.newMemoryStream() if self.closed then return nil -- eof end - if self.redirect.read then + if self.redirect[0] then -- popen could be using this code path -- if that is the case, it is important to leave stream.buffer alone - return self.redirect.read:read(n) + return self.redirect[0]:read(n) elseif self.buffer == "" then - self.args = table.pack(coroutine.yield(table.unpack(self.result))) + process.info(self.next).data.args = table.pack(coroutine.yield(table.unpack(self.result))) end local result = string.sub(self.buffer, 1, n) self.buffer = string.sub(self.buffer, n + 1) @@ -741,16 +776,17 @@ function --[[@delayloaded-start@]] sh.internal.newMemoryStream() end function memoryStream:write(value) - if not self.redirect.write and self.closed then + if not self.redirect[1] and self.closed then -- if next is dead, ignore all writes if coroutine.status(self.next) ~= "dead" then error("attempt to use a closed stream") end - elseif self.redirect.write then - return self.redirect.write:write(value) + elseif self.redirect[1] then + return self.redirect[1]:write(value) elseif not self.closed then self.buffer = self.buffer .. value - self.result = table.pack(coroutine.resume(self.next, table.unpack(self.args))) + local args = process.info(self.next).data.args + self.result = table.pack(coroutine.resume(self.next, table.unpack(args))) if coroutine.status(self.next) == "dead" then self:close() end @@ -764,26 +800,52 @@ function --[[@delayloaded-start@]] sh.internal.newMemoryStream() end local stream = {closed = false, buffer = "", - redirect = {}, result = {}, args = {}} + redirect = {}, result = {}} local metatable = {__index = memoryStream, __metatable = "memorystream"} return setmetatable(stream, metatable) end --[[@delayloaded-end@]] -function --[[@delayloaded-start@]] sh.internal.execute_complex(statements) +function --[[@delayloaded-start@]] sh.internal.execute_complex(statements, eargs, env) for si=1,#statements do local s = statements[si] local chains = sh.internal.groupChains(s) - local last_code,br = sh.internal.boolean_executor(chains, function(chain, chain_index) + local last_code = sh.internal.boolean_executor(chains, function(chain, chain_index) local pipe_parts = sh.internal.splitChains(chain) - return sh.internal.executePipes(pipe_parts, - chain_index == #chains and si == #statements and eargs or {}) + local next_args = chain_index == #chains and si == #statements and eargs or {} + return sh.internal.executePipes(pipe_parts, next_args, env) end) - if br then - io.stderr:write(br,"\n") - end sh.internal.ec.last = sh.internal.command_result_as_code(last_code) end - return true, br + return true +end --[[@delayloaded-end@]] + + +function --[[@delayloaded-start@]] sh.internal.parse_sub(input) + -- cannot use gsub here becuase it is a [C] call, and io.popen needs to yield at times + local packed = {} + -- not using for i... because i can skip ahead + local i, len = 1, #input + + while i < len do + + local fi, si, capture = input:find("`([^`]*)`", i) + + if not fi then + table.insert(packed, input:sub(i)) + break + end + + local sub = io.popen(capture) + local result = sub:read("*a") + sub:close() + -- all whitespace is replaced by single spaces + -- we requote the result because tokenize will respect this as text + table.insert(packed, (text.trim(result):gsub("%s+"," "))) + + i = si+1 + end + + return table.concat(packed) end --[[@delayloaded-end@]] return sh, local_env diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/shell.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/shell.lua similarity index 99% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/shell.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/shell.lua index 259216f4e..9813f767b 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/shell.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/shell.lua @@ -35,7 +35,7 @@ local function findFile(name, ext) dir = fs.concat(fs.concat(dir, name), "..") local name = fs.name(name) local list = fs.list(dir) - if list then + if list and name then local files = {} for file in list do files[file] = true diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/sides.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/sides.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/sides.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/sides.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/term.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua similarity index 93% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/term.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/term.lua index dd8f640cb..d2a02ef32 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/term.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua @@ -245,7 +245,7 @@ function term.readKeyboard(ops) if db ~= false then draw("\n") end term.internal.read_history(history,input) return input.data.."\n" - elseif char==8 then + elseif code==keys.back then input:update(-1) elseif code==keys.left then input:move(ctrl and term.internal.ctrl_movement(input, -1) or -1) @@ -400,11 +400,31 @@ function --[[@delayloaded-start@]] term.internal.ctrl_movement(input, dir) end --[[@delayloaded-end@]] function --[[@delayloaded-start@]] term.internal.onTouch(input,gx,gy) - input:move(math.huge) + if input.data == "" then return end + input:move(-math.huge) local w = W() gx,gy=gx-w.dx,gy-w.dy local x2,y2,d = input.w.x,input.w.y,input.w.w - input:move((gy*d+gx)-(y2*d+x2)) + local char_width_to_move = ((gy*d+gx)-(y2*d+x2)) + if char_width_to_move <= 0 then return end + local total_wlen = unicode.wlen(input.data) + if char_width_to_move >= total_wlen then + input:move(math.huge) + else + local chars_to_move = unicode.wtrunc(input.data, char_width_to_move + 1) + input:move(unicode.len(chars_to_move)) + end + -- fake white space can make the index off, redo adjustment for alignment + x2,y2,d = input.w.x,input.w.y,input.w.w + char_width_to_move = ((gy*d+gx)-(y2*d+x2)) + if (char_width_to_move < 0) then + -- using char_width_to_move as a type of index is wrong, but large enough and helps to speed this up + local up_to_cursor = unicode.sub(input.data, input.index+char_width_to_move, input.index) + local full_wlen = unicode.wlen(up_to_cursor) + local without_tail = unicode.wtrunc(up_to_cursor, full_wlen + char_width_to_move + 1) + local chars_cut = unicode.len(up_to_cursor) - unicode.len(without_tail) + input:move(-chars_cut) + end end --[[@delayloaded-end@]] function --[[@delayloaded-start@]] term.internal.build_horizontal_reader(input) @@ -497,7 +517,7 @@ function --[[@delayloaded-start@]] term.internal.tab(input,hints) c.i=(c.i+change)%math.max(#c,1) local next=c[c.i+1] if next then - local tail = unicode.wlen(input.data) - input.index - 1 + local tail = unicode.len(input.data) - input.index input:clear() input:update(next) input:move(-tail) diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/text.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/text.lua similarity index 95% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/text.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/text.lua index 2c7e97d4c..9afc1c32b 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/text.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/text.lua @@ -8,14 +8,8 @@ local text = {} local local_env = {tx=tx,unicode=unicode} text.internal = {} -setmetatable(text.internal, -{ - __tostring=function() - return 'table of undocumented api subject to change and intended for internal use' - end -}) -text.syntax = {";","&&","||","|",">>",">","<"} +text.syntax = {"^%d*>>?&%d+$",";","&&","||?","^%d*>>?",">>?","<"} function --[[@delayloaded-start@]] text.detab(value, tabWidth) checkArg(1, value, "string") @@ -163,11 +157,12 @@ function text.internal.tokenize(value, quotes, delimiters) checkArg(1, value, "string") checkArg(2, quotes, "table", "nil") checkArg(3, delimiters, "table", "nil") + local custom = not not delimiters delimiters = delimiters or text.syntax local words, reason = text.internal.words(value, quotes) - local splitter = text.escapeMagic(table.concat(delimiters)) + local splitter = text.escapeMagic(custom and table.concat(delimiters) or "<>|;&") if type(words) ~= "table" or #splitter == 0 or not value:find("["..splitter.."]") then @@ -182,7 +177,7 @@ function text.internal.words(input, quotes) checkArg(1, input, "string") checkArg(2, quotes, "table", "nil") local qr = nil - quotes = quotes or {{"'","'",true},{'"','"'}} + quotes = quotes or {{"'","'",true},{'"','"'},{'`','`'}} local function append(dst, txt, qr) local size = #dst if size == 0 or dst[size].qr ~= qr then @@ -253,9 +248,6 @@ function --[[@delayloaded-start@]] text.internal.splitWords(words, delimiters) table.insert(split_words[#split_words], part) next_word = false end - local delimLookup = tx.select(delimiters, function(e,i) - return i, e - end) for wi=1,#words do local word = words[wi] next_word = true for pi=1,#word do local part = word[pi] @@ -265,7 +257,7 @@ function --[[@delayloaded-start@]] text.internal.splitWords(words, delimiters) else local part_text_splits = text.split(part.txt, delimiters) tx.foreach(part_text_splits, function(sub_txt, spi) - local delim = delimLookup[sub_txt] + local delim = #text.split(sub_txt, delimiters, true) == 0 next_word = next_word or delim add_part({txt=sub_txt,qr=qr}) next_word = delim diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/tools/delayLookup.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/delayLookup.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/tools/delayLookup.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/tools/delayLookup.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/tools/delayParse.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/delayParse.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/tools/delayParse.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/tools/delayParse.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/tools/keyboard_full.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/keyboard_full.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/tools/keyboard_full.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/tools/keyboard_full.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/transforms.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/transforms.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/lib/transforms.lua rename to src/main/resources/assets/opencomputers/loot/openos/lib/transforms.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/address b/src/main/resources/assets/opencomputers/loot/openos/usr/man/address similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/address rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/address diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/alias b/src/main/resources/assets/opencomputers/loot/openos/usr/man/alias similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/alias rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/alias diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/cat b/src/main/resources/assets/opencomputers/loot/openos/usr/man/cat similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/cat rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/cat diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/cd b/src/main/resources/assets/opencomputers/loot/openos/usr/man/cd similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/cd rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/cd diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/clear b/src/main/resources/assets/opencomputers/loot/openos/usr/man/clear similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/clear rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/clear diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/cp b/src/main/resources/assets/opencomputers/loot/openos/usr/man/cp similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/cp rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/cp diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/date b/src/main/resources/assets/opencomputers/loot/openos/usr/man/date similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/date rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/date diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/df b/src/main/resources/assets/opencomputers/loot/openos/usr/man/df similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/df rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/df diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/dmesg b/src/main/resources/assets/opencomputers/loot/openos/usr/man/dmesg similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/dmesg rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/dmesg diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/echo b/src/main/resources/assets/opencomputers/loot/openos/usr/man/echo similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/echo rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/echo diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/edit b/src/main/resources/assets/opencomputers/loot/openos/usr/man/edit similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/edit rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/edit diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/grep b/src/main/resources/assets/opencomputers/loot/openos/usr/man/grep similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/grep rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/grep diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/head b/src/main/resources/assets/opencomputers/loot/openos/usr/man/head similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/head rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/head diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/hostname b/src/main/resources/assets/opencomputers/loot/openos/usr/man/hostname similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/hostname rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/hostname diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/label b/src/main/resources/assets/opencomputers/loot/openos/usr/man/label similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/label rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/label diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/ln b/src/main/resources/assets/opencomputers/loot/openos/usr/man/ln similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/ln rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/ln diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/ls b/src/main/resources/assets/opencomputers/loot/openos/usr/man/ls similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/ls rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/ls diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/lua b/src/main/resources/assets/opencomputers/loot/openos/usr/man/lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/lua rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/man b/src/main/resources/assets/opencomputers/loot/openos/usr/man/man similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/man rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/man diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/mkdir b/src/main/resources/assets/opencomputers/loot/openos/usr/man/mkdir similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/mkdir rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/mkdir diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/more b/src/main/resources/assets/opencomputers/loot/openos/usr/man/more similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/more rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/more diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/mount b/src/main/resources/assets/opencomputers/loot/openos/usr/man/mount similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/mount rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/mount diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/mv b/src/main/resources/assets/opencomputers/loot/openos/usr/man/mv similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/mv rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/mv diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/primary b/src/main/resources/assets/opencomputers/loot/openos/usr/man/primary similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/primary rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/primary diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/pwd b/src/main/resources/assets/opencomputers/loot/openos/usr/man/pwd similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/pwd rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/pwd diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/rc b/src/main/resources/assets/opencomputers/loot/openos/usr/man/rc similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/rc rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/rc diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/reboot b/src/main/resources/assets/opencomputers/loot/openos/usr/man/reboot similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/reboot rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/reboot diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/redstone b/src/main/resources/assets/opencomputers/loot/openos/usr/man/redstone similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/redstone rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/redstone diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/resolution b/src/main/resources/assets/opencomputers/loot/openos/usr/man/resolution similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/resolution rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/resolution diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/rm b/src/main/resources/assets/opencomputers/loot/openos/usr/man/rm similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/rm rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/rm diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/sh b/src/main/resources/assets/opencomputers/loot/openos/usr/man/sh similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/sh rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/sh diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/shutdown b/src/main/resources/assets/opencomputers/loot/openos/usr/man/shutdown similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/shutdown rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/shutdown diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/umount b/src/main/resources/assets/opencomputers/loot/openos/usr/man/umount similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/umount rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/umount diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/unalias b/src/main/resources/assets/opencomputers/loot/openos/usr/man/unalias similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/unalias rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/unalias diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/uptime b/src/main/resources/assets/opencomputers/loot/openos/usr/man/uptime similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/uptime rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/uptime diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/useradd b/src/main/resources/assets/opencomputers/loot/openos/usr/man/useradd similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/useradd rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/useradd diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/userdel b/src/main/resources/assets/opencomputers/loot/openos/usr/man/userdel similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/userdel rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/userdel diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/which b/src/main/resources/assets/opencomputers/loot/openos/usr/man/which similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/which rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/which diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/yes b/src/main/resources/assets/opencomputers/loot/openos/usr/man/yes similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/yes rename to src/main/resources/assets/opencomputers/loot/openos/usr/man/yes diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/misc/greetings.txt b/src/main/resources/assets/opencomputers/loot/openos/usr/misc/greetings.txt similarity index 96% rename from src/main/resources/assets/opencomputers/loot/OpenOS/usr/misc/greetings.txt rename to src/main/resources/assets/opencomputers/loot/openos/usr/misc/greetings.txt index 68d49726b..17467d51d 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/misc/greetings.txt +++ b/src/main/resources/assets/opencomputers/loot/openos/usr/misc/greetings.txt @@ -23,6 +23,6 @@ You can get a list of all attached components using the `components` program. If you encounter out of memory errors, throw more RAM at your computer. Have you tried turning it off and on again? To disable this greeting, install OpenOS to a writeable medium and delete `/etc/motd`. -Did you know OpenComputers has a forum? No? Well, it's at http://oc.cil.li/. +Did you know OpenComputers has a forum? No? Well, it's at https://oc.cil.li/. Please report bugs on the Github issue tracker, thank you! Beware of cycles when building networks, or you may get duplicate messages! diff --git a/src/main/resources/assets/opencomputers/loot/OPPM/autorun.lua b/src/main/resources/assets/opencomputers/loot/oppm/autorun.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OPPM/autorun.lua rename to src/main/resources/assets/opencomputers/loot/oppm/autorun.lua diff --git a/src/main/resources/assets/opencomputers/loot/OPPM/etc/oppm.cfg b/src/main/resources/assets/opencomputers/loot/oppm/etc/oppm.cfg similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OPPM/etc/oppm.cfg rename to src/main/resources/assets/opencomputers/loot/oppm/etc/oppm.cfg diff --git a/src/main/resources/assets/opencomputers/loot/OPPM/oppm.lua b/src/main/resources/assets/opencomputers/loot/oppm/oppm.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/OPPM/oppm.lua rename to src/main/resources/assets/opencomputers/loot/oppm/oppm.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/arp.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/arp.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/arp.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/arp.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/cat.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/cat.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/cat.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/cat.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/clear.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/clear.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/clear.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/clear.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/components.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/components.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/components.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/components.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/cp.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/cp.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/cp.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/cp.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/dd.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/dd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/dd.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/dd.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/df.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/df.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/df.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/df.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/dmesg.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/dmesg.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/dmesg.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/dmesg.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/du.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/du.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/du.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/du.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/echo.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/echo.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/echo.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/echo.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/edit.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/edit.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/edit.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/edit.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/getty.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/getty.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/getty.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/getty.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/hostname.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/hostname.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/hostname.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/hostname.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/ifconfig.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/ifconfig.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/ifconfig.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/ifconfig.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/init.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/init.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/init.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/init.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/install.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/install.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/install.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/install.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/kill.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/kill.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/kill.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/kill.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/label.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/label.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/label.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/label.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/ln.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/ln.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/ln.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/ln.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/ls.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/ls.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/ls.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/ls.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/lua.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/lua.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/lua.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/lua.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/mkdir.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/mkdir.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/mkdir.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/mkdir.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/more.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/more.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/more.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/more.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/mount.cow.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/mount.cow.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/mount.cow.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/mount.cow.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/mount.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/mount.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/mount.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/mount.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/mount.msdos.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/mount.msdos.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/mount.msdos.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/mount.msdos.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/mv.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/mv.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/mv.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/mv.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/passwd.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/passwd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/passwd.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/passwd.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/pastebin.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/pastebin.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/pastebin.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/pastebin.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/ping.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/ping.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/ping.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/ping.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/ps.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/ps.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/ps.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/ps.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/pwd.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/pwd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/pwd.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/pwd.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/rc.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/rc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/rc.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/rc.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/readkey.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/readkey.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/readkey.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/readkey.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/reboot.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/reboot.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/reboot.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/reboot.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/resolution.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/resolution.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/resolution.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/resolution.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/rm.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/rm.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/rm.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/rm.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/route.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/route.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/route.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/route.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/sandbox.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/sandbox.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/sandbox.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/sandbox.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/sh.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/sh.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/sh.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/sh.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/shutdown.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/shutdown.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/shutdown.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/shutdown.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/sleep.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/sleep.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/sleep.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/sleep.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/sshd.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/sshd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/sshd.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/sshd.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/tee.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/tee.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/tee.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/tee.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/touch.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/touch.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/touch.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/touch.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/uptime.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/uptime.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/uptime.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/uptime.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/watch.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/watch.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/watch.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/watch.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/wc.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/wc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/wc.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/wc.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/bin/wget.lua b/src/main/resources/assets/opencomputers/loot/plan9k/bin/wget.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/bin/wget.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/bin/wget.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/boot/kernel/pipes b/src/main/resources/assets/opencomputers/loot/plan9k/boot/kernel/pipes similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/boot/kernel/pipes rename to src/main/resources/assets/opencomputers/loot/plan9k/boot/kernel/pipes diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/etc/rc.d/autoupdate.lua b/src/main/resources/assets/opencomputers/loot/plan9k/etc/rc.d/autoupdate.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/etc/rc.d/autoupdate.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/etc/rc.d/autoupdate.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/etc/rc.d/sshd.lua b/src/main/resources/assets/opencomputers/loot/plan9k/etc/rc.d/sshd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/etc/rc.d/sshd.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/etc/rc.d/sshd.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/init.lua b/src/main/resources/assets/opencomputers/loot/plan9k/init.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/init.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/init.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/event.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/event.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/event.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/event.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/internet.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/internet.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/internet.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/internet.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/01_gc.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/01_gc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/01_gc.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/01_gc.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/01_util.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/01_util.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/01_util.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/01_util.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/02_cmd.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/02_cmd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/02_cmd.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/02_cmd.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/05_vfs.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/05_vfs.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/05_vfs.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/05_vfs.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/06_cowfs.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/06_cowfs.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/06_cowfs.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/06_cowfs.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/09_rootfs.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/09_rootfs.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/09_rootfs.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/09_rootfs.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/10_devfs.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/10_devfs.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/10_devfs.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/10_devfs.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/10_procfs.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/10_procfs.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/10_procfs.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/10_procfs.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/15_keventd.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/15_keventd.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/15_keventd.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/15_keventd.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/15_userspace.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/15_userspace.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/15_userspace.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/15_userspace.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/16_buffer.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/16_buffer.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/16_buffer.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/16_buffer.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/16_component.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/16_component.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/16_component.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/16_component.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/16_require.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/16_require.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/16_require.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/16_require.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_chatbox.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_chatbox.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_chatbox.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_chatbox.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_data.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_data.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_data.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_data.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_drive.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_drive.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_drive.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_drive.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_eeprom.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_eeprom.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_eeprom.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_eeprom.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_io.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_io.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_io.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_io.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_ipc.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_ipc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_ipc.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_ipc.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_keyboard.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_keyboard.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_keyboard.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_keyboard.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_network.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_network.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_network.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_network.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_nfc.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_nfc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_nfc.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_nfc.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_tape.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_tape.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/17_tape.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/17_tape.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/18_pty.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/18_pty.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/18_pty.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/18_pty.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/18_syscall.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/18_syscall.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/18_syscall.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/18_syscall.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/19_cgroups.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/19_cgroups.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/19_cgroups.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/19_cgroups.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/19_libnetwork.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/19_libnetwork.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/19_libnetwork.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/19_libnetwork.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/19_manageg.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/19_manageg.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/19_manageg.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/19_manageg.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/20_threading.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/20_threading.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/20_threading.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/20_threading.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/21_threadUtil.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/21_threadUtil.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/21_threadUtil.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/21_threadUtil.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/21_timer.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/21_timer.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/21_timer.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/21_timer.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/25_init.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/25_init.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/base/25_init.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/base/25_init.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/network/loopback.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/network/loopback.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/network/loopback.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/network/loopback.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/network/modem.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/network/modem.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/network/modem.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/network/modem.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/network/tunnel.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/network/tunnel.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/modules/network/tunnel.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/modules/network/tunnel.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/msdosfs.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/msdosfs.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/msdosfs.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/msdosfs.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/rc.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/rc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/rc.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/rc.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/serialization.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/serialization.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/serialization.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/serialization.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/shell.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/shell.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/shell.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/shell.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/term.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/term.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/term.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/term.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/lib/text.lua b/src/main/resources/assets/opencomputers/loot/plan9k/lib/text.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/lib/text.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/lib/text.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/data/bin/base64.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/base64.lua similarity index 95% rename from src/main/resources/assets/opencomputers/lua/component/data/bin/base64.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/base64.lua index 155dba981..2a5d9d58f 100644 --- a/src/main/resources/assets/opencomputers/lua/component/data/bin/base64.lua +++ b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/base64.lua @@ -1,42 +1,42 @@ -local shell = require("shell") -local data = require("data") - - -local args, parms = shell.parse(...) -if parms.h or parms.help then - io.stderr:write("See: man base64" .. "\n") - os.exit(true) -end -local encodingfun = nil -local encode -if parms.d or parms.decode then - encodingfun = data.decode64 - encode = false -else - encodingfun = data.encode64 - encode = true -end - -if #args == 0 then - repeat - local read = io.read(encode and 3 or 4) - if read then - io.write(encodingfun(read)) - end - until not read -else - for i = 1, #args do - local file, reason = io.open(shell.resolve(args[i])) - if not file then - io.stderr:write(tostring(reason) .. "\n") - os.exit(false) - end - repeat - local line = file:read(encode and 3 or 4) - if line then - io.write(encodingfun(line)) - end - until not line - file:close() - end -end +local shell = require("shell") +local data = require("data") + + +local args, parms = shell.parse(...) +if parms.h or parms.help then + io.stderr:write("See: man base64" .. "\n") + os.exit(true) +end +local encodingfun = nil +local encode +if parms.d or parms.decode then + encodingfun = data.decode64 + encode = false +else + encodingfun = data.encode64 + encode = true +end + +if #args == 0 then + repeat + local read = io.read(encode and 3 or 4) + if read then + io.write(encodingfun(read)) + end + until not read +else + for i = 1, #args do + local file, reason = io.open(shell.resolve(args[i])) + if not file then + io.stderr:write(tostring(reason) .. "\n") + os.exit(false) + end + repeat + local line = file:read(encode and 3 or 4) + if line then + io.write(encodingfun(line)) + end + until not line + file:close() + end +end diff --git a/src/main/resources/assets/opencomputers/lua/component/data/bin/deflate.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/deflate.lua similarity index 95% rename from src/main/resources/assets/opencomputers/lua/component/data/bin/deflate.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/deflate.lua index 0ba356e3a..cd8660ac2 100644 --- a/src/main/resources/assets/opencomputers/lua/component/data/bin/deflate.lua +++ b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/deflate.lua @@ -1,25 +1,25 @@ -local shell = require("shell") -local data = require("data") - -local args = shell.parse(...) -if #args == 0 then - local read = "" - repeat - local current = io.read("*a") - read = read .. current - until current ~= "" - io.write(data.deflate(read)) -else - local read = "" - local file, reason = io.open(shell.resolve(args[1])) - if not file then - io.stderr:write(tostring(reason) .. "\n") - os.exit(false) - end - repeat - local current = file:read("*a") - read = read .. current - until current ~= "" - file:close() - io.write(data.deflate(read)) -end +local shell = require("shell") +local data = require("data") + +local args = shell.parse(...) +if #args == 0 then + local read = "" + repeat + local current = io.read("*a") + read = read .. current + until current ~= "" + io.write(data.deflate(read)) +else + local read = "" + local file, reason = io.open(shell.resolve(args[1])) + if not file then + io.stderr:write(tostring(reason) .. "\n") + os.exit(false) + end + repeat + local current = file:read("*a") + read = read .. current + until current ~= "" + file:close() + io.write(data.deflate(read)) +end diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/gpg.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/gpg.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/gpg.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/gpg.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/data/bin/inflate.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/inflate.lua similarity index 95% rename from src/main/resources/assets/opencomputers/lua/component/data/bin/inflate.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/inflate.lua index c78fd7287..349c5f18b 100644 --- a/src/main/resources/assets/opencomputers/lua/component/data/bin/inflate.lua +++ b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/inflate.lua @@ -1,25 +1,25 @@ -local shell = require("shell") -local data = require("data") - -local args = shell.parse(...) -if #args == 0 then - local read = "" - repeat - local current = io.read("*a") - read = read .. current - until current ~= "" - io.write(data.inflate(read)) -else - local read = "" - local file, reason = io.open(shell.resolve(args[1])) - if not file then - io.stderr:write(tostring(reason) .. "\n") - os.exit(false) - end - repeat - local current = file:read("*a") - read = read .. current - until current ~= "" - file:close() - io.write(data.inflate(read)) -end +local shell = require("shell") +local data = require("data") + +local args = shell.parse(...) +if #args == 0 then + local read = "" + repeat + local current = io.read("*a") + read = read .. current + until current ~= "" + io.write(data.inflate(read)) +else + local read = "" + local file, reason = io.open(shell.resolve(args[1])) + if not file then + io.stderr:write(tostring(reason) .. "\n") + os.exit(false) + end + repeat + local current = file:read("*a") + read = read .. current + until current ~= "" + file:close() + io.write(data.inflate(read)) +end diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/md5sum.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/md5sum.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/md5sum.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/md5sum.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/mkdosfs.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/mkdosfs.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/mkdosfs.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/mkdosfs.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/mpt.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/mpt.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/mpt.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/mpt.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/nc.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/nc.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/nc.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/nc.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/data/bin/sha256sum.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/sha256sum.lua similarity index 96% rename from src/main/resources/assets/opencomputers/lua/component/data/bin/sha256sum.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/sha256sum.lua index 5e63c7c61..33d5b25c7 100644 --- a/src/main/resources/assets/opencomputers/lua/component/data/bin/sha256sum.lua +++ b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/sha256sum.lua @@ -1,27 +1,27 @@ -local shell = require("shell") -local data = require("data") - -local args = shell.parse(...) -if #args == 0 then - local read = "" - repeat - local current = io.read("*a") - read = read .. current - until current ~= "" - io.write(data.toHex(data.sha256(read))) -else - for i = 1, #args do - local read = "" - local file, reason = io.open(shell.resolve(args[i])) - if not file then - io.stderr:write(tostring(reason) .. "\n") - os.exit(false) - end - repeat - local current = file:read("*a") - read = read .. current - until current ~= "" - file:close() - io.write(data.toHex(data.sha256(read)) .. "\t".. args[i] .. "\n") - end -end +local shell = require("shell") +local data = require("data") + +local args = shell.parse(...) +if #args == 0 then + local read = "" + repeat + local current = io.read("*a") + read = read .. current + until current ~= "" + io.write(data.toHex(data.sha256(read))) +else + for i = 1, #args do + local read = "" + local file, reason = io.open(shell.resolve(args[i])) + if not file then + io.stderr:write(tostring(reason) .. "\n") + os.exit(false) + end + repeat + local current = file:read("*a") + read = read .. current + until current ~= "" + file:close() + io.write(data.toHex(data.sha256(read)) .. "\t".. args[i] .. "\n") + end +end diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/ssh.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/ssh.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/bin/ssh.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/bin/ssh.lua diff --git a/src/main/resources/assets/opencomputers/lua/component/data/lib/data.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/lib/data.lua similarity index 96% rename from src/main/resources/assets/opencomputers/lua/component/data/lib/data.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/lib/data.lua index 38251a926..04fa9ff9c 100644 --- a/src/main/resources/assets/opencomputers/lua/component/data/lib/data.lua +++ b/src/main/resources/assets/opencomputers/loot/plan9k/usr/lib/data.lua @@ -1,26 +1,26 @@ -local component = require("component") - -local data = {} - -------------------------------------------------------------------------------- - --- Converts binary data into hexadecimal string. -function data.toHex(data) - return (data:gsub('.', function (c) - return string.format('%02X', string.byte(c)) - end)) -end - --- Converts hexadecimal string into binary data. -function data.fromHex(hex) - return (hex:gsub('..', function (cc) - return string.char(tonumber(cc, 16)) - end)) -end - --- Forward everything else to the primary data card. -setmetatable(data, { __index = function(_, key) return component.data[key] end }) - -------------------------------------------------------------------------------- - -return data +local component = require("component") + +local data = {} + +------------------------------------------------------------------------------- + +-- Converts binary data into hexadecimal string. +function data.toHex(data) + return (data:gsub('.', function (c) + return string.format('%02X', string.byte(c)) + end)) +end + +-- Converts hexadecimal string into binary data. +function data.fromHex(hex) + return (hex:gsub('..', function (cc) + return string.char(tonumber(cc, 16)) + end)) +end + +-- Forward everything else to the primary data card. +setmetatable(data, { __index = function(_, key) return component.data[key] end }) + +------------------------------------------------------------------------------- + +return data diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/man/pipes b/src/main/resources/assets/opencomputers/loot/plan9k/usr/man/pipes similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/man/pipes rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/man/pipes diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/usr/sbin/sshsession.lua b/src/main/resources/assets/opencomputers/loot/plan9k/usr/sbin/sshsession.lua similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/usr/sbin/sshsession.lua rename to src/main/resources/assets/opencomputers/loot/plan9k/usr/sbin/sshsession.lua diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/var/lib/mpt/config.db b/src/main/resources/assets/opencomputers/loot/plan9k/var/lib/mpt/config.db similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/var/lib/mpt/config.db rename to src/main/resources/assets/opencomputers/loot/plan9k/var/lib/mpt/config.db diff --git a/src/main/resources/assets/opencomputers/loot/Plan9k/var/lib/mpt/mpt.db b/src/main/resources/assets/opencomputers/loot/plan9k/var/lib/mpt/mpt.db similarity index 100% rename from src/main/resources/assets/opencomputers/loot/Plan9k/var/lib/mpt/mpt.db rename to src/main/resources/assets/opencomputers/loot/plan9k/var/lib/mpt/mpt.db diff --git a/src/main/resources/assets/opencomputers/lua/machine.lua b/src/main/resources/assets/opencomputers/lua/machine.lua index 0ecc007e5..23b3e45b1 100644 --- a/src/main/resources/assets/opencomputers/lua/machine.lua +++ b/src/main/resources/assets/opencomputers/lua/machine.lua @@ -1332,7 +1332,10 @@ local libcomputer = { end, beep = function(...) - libcomponent.invoke(computer.address(), "beep", ...) + return libcomponent.invoke(computer.address(), "beep", ...) + end, + getDeviceInfo = function(...) + return libcomponent.invoke(computer.address(), "getDeviceInfo", ...) end, getArchitectures = function(...) diff --git a/src/main/resources/assets/opencomputers/models/item/hoverBoots.json b/src/main/resources/assets/opencomputers/models/item/hoverBoots.json index aced9a6a0..cf951b1a4 100644 --- a/src/main/resources/assets/opencomputers/models/item/hoverBoots.json +++ b/src/main/resources/assets/opencomputers/models/item/hoverBoots.json @@ -1,6 +1,7 @@ { "parent": "opencomputers:item/flat", "textures": { - "layer0": "opencomputers:items/hoverBoots" + "layer0": "opencomputers:items/hoverBoots", + "layer1": "opencomputers:items/hoverBootsLight" } } diff --git a/src/main/resources/assets/opencomputers/recipes/default.recipes b/src/main/resources/assets/opencomputers/recipes/default.recipes index 2853fc6c7..66af1dc68 100644 --- a/src/main/resources/assets/opencomputers/recipes/default.recipes +++ b/src/main/resources/assets/opencomputers/recipes/default.recipes @@ -32,12 +32,12 @@ wrench { } lootDisks: [ { - name: OpenOS + name: "OpenComputers:openos" type: shapeless input: ["oc:floppy", "oc:manual"] }, { - name: OPPM + name: "OpenComputers:oppm" type: shapeless input: ["oc:floppy", "oc:materialInterweb"] } diff --git a/src/main/resources/assets/opencomputers/robot.names b/src/main/resources/assets/opencomputers/robot.names index 4e4593fde..fd43fa689 100644 --- a/src/main/resources/assets/opencomputers/robot.names +++ b/src/main/resources/assets/opencomputers/robot.names @@ -16,6 +16,7 @@ Anson Argyris # Perry Rhodan ASIMO # Honda Atlas # Portal Augustus # Perry Rhodan +Ava # Ex Machina Baymax # Big Hero 6 BB-8 # Star Wars Bender # Futurama @@ -42,10 +43,12 @@ Deep Thought # Hitchhiker's Guide to the Galaxy Deputy ANDY # Eureka Dog # Half-Life Donald Duck # Perry Rhodan +EDI # Mass Effect Eliza Cassan # Deus Ex Elmer # One of the first two robots developed by William Gray Walter. Elsie # One of the first two robots developed by William Gray Walter. *Emilia # Digital: A Love Story +E.V.E # Anno 2070 Eve # Wall-E Fact Core # Portal Flexo # Futurama diff --git a/src/main/resources/assets/opencomputers/textures/items/HoverBootsLight.png b/src/main/resources/assets/opencomputers/textures/items/hoverBootsLight.png similarity index 100% rename from src/main/resources/assets/opencomputers/textures/items/HoverBootsLight.png rename to src/main/resources/assets/opencomputers/textures/items/hoverBootsLight.png diff --git a/src/main/scala/li/cil/oc/Constants.scala b/src/main/scala/li/cil/oc/Constants.scala index a6a64b633..e2b28608f 100644 --- a/src/main/scala/li/cil/oc/Constants.scala +++ b/src/main/scala/li/cil/oc/Constants.scala @@ -125,7 +125,7 @@ object Constants { final val NavigationUpgrade = "navigationUpgrade" final val NetworkCard = "lanCard" final val NumPad = "numPad" - final val OpenOS = "openOS" + final val OpenOS = "openos" final val PistonUpgrade = "pistonUpgrade" final val Present = "present" final val PrintedCircuitBoard = "printedCircuitBoard" @@ -170,4 +170,10 @@ object Constants { def TabletCase(tier: Int) = ItemUtils.caseNameWithTierSuffix("tabletCase", tier) } + object DeviceInfo { + + final val DefaultVendor = "MightyPirates GmbH & Co. KG" + + } + } diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index ad8e808e6..4506dd950 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -135,8 +135,9 @@ class Settings(val config: Config) { // ----------------------------------------------------------------------- // // power + var is3rdPartyPowerSystemPresent = false val pureIgnorePower = config.getBoolean("power.ignorePower") - lazy val ignorePower = pureIgnorePower || !Mods.isPowerProvidingModPresent + lazy val ignorePower = pureIgnorePower || (!is3rdPartyPowerSystemPresent && !Mods.isPowerProvidingModPresent) val tickFrequency = config.getDouble("power.tickFrequency") max 1 val chargeRateExternal = config.getDouble("power.chargerChargeRate") val chargeRateTablet = config.getDouble("power.chargerChargeRateTablet") @@ -331,6 +332,7 @@ class Settings(val config: Config) { val terminalsPerServer = 4 val updateCheck = config.getBoolean("misc.updateCheck") val lootProbability = config.getInt("misc.lootProbability") + val lootRecrafting = config.getBoolean("misc.lootRecrafting") val geolyzerRange = config.getInt("misc.geolyzerRange") val geolyzerNoise = config.getDouble("misc.geolyzerNoise").toFloat max 0 val disassembleAllTheThings = config.getBoolean("misc.disassembleAllTheThings") diff --git a/src/main/scala/li/cil/oc/client/PacketHandler.scala b/src/main/scala/li/cil/oc/client/PacketHandler.scala index 3f12ee4dd..2b3b38f0a 100644 --- a/src/main/scala/li/cil/oc/client/PacketHandler.scala +++ b/src/main/scala/li/cil/oc/client/PacketHandler.scala @@ -3,6 +3,7 @@ package li.cil.oc.client import java.io.EOFException import li.cil.oc.Localization +import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.event.FileSystemAccessEvent @@ -45,6 +46,7 @@ object PacketHandler extends CommonPacketHandler { p.packetType match { case PacketType.Analyze => onAnalyze(p) case PacketType.ChargerState => onChargerState(p) + case PacketType.ClientLog => onClientLog(p) case PacketType.ColorChange => onColorChange(p) case PacketType.ComputerState => onComputerState(p) case PacketType.ComputerUserList => onComputerUserList(p) @@ -113,6 +115,10 @@ object PacketHandler extends CommonPacketHandler { case _ => // Invalid packet. } + def onClientLog(p: PacketParser) = { + OpenComputers.log.info(p.readUTF()) + } + def onColorChange(p: PacketParser) = p.readTileEntity[Colored]() match { case Some(t) => diff --git a/src/main/scala/li/cil/oc/client/gui/Assembler.scala b/src/main/scala/li/cil/oc/client/gui/Assembler.scala index 5010f239c..13887ff24 100644 --- a/src/main/scala/li/cil/oc/client/gui/Assembler.scala +++ b/src/main/scala/li/cil/oc/client/gui/Assembler.scala @@ -8,6 +8,7 @@ import li.cil.oc.common.container import li.cil.oc.common.container.ComponentSlot import li.cil.oc.common.template.AssemblerTemplates import li.cil.oc.common.tileentity +import li.cil.oc.util.RenderState import net.minecraft.client.gui.GuiButton import net.minecraft.client.renderer.GlStateManager import net.minecraft.entity.player.InventoryPlayer @@ -55,7 +56,7 @@ class Assembler(playerInventory: InventoryPlayer, val assembler: tileentity.Asse } override def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) = { - GlStateManager.pushAttrib() + RenderState.pushAttrib() if (!inventoryContainer.isAssembling) { val message = if (!inventoryContainer.getSlot(0).getHasStack) { @@ -84,7 +85,7 @@ class Assembler(playerInventory: InventoryPlayer, val assembler: tileentity.Asse tooltip.add(Localization.Assembler.Progress(inventoryContainer.assemblyProgress, timeRemaining)) copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj) } - GlStateManager.popAttrib() + RenderState.popAttrib() } private def formatTime(seconds: Int) = { diff --git a/src/main/scala/li/cil/oc/client/gui/Drone.scala b/src/main/scala/li/cil/oc/client/gui/Drone.scala index 7f0ac6b16..dc8b7224c 100644 --- a/src/main/scala/li/cil/oc/client/gui/Drone.scala +++ b/src/main/scala/li/cil/oc/client/gui/Drone.scala @@ -78,18 +78,18 @@ class Drone(playerInventory: InventoryPlayer, val drone: entity.Drone) extends D RenderState.disableEntityLighting() RenderState.makeItBlend() GlStateManager.scale(scale, scale, 1) - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.depthMask(false) GlStateManager.color(0.5f, 0.5f, 1f) TextBufferRenderCache.render(bufferRenderer) - GlStateManager.popAttrib() + RenderState.popAttrib() } override protected def changeSize(w: Double, h: Double, recompile: Boolean) = 2.0 override protected def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) { drawBufferLayer() - GlStateManager.pushAttrib() + RenderState.pushAttrib() if (isPointInRegion(power.x, power.y, power.width, power.height, mouseX, mouseY)) { val tooltip = new java.util.ArrayList[String] val format = Localization.Computer.Power + ": %d%% (%d/%d)" @@ -104,7 +104,7 @@ class Drone(playerInventory: InventoryPlayer, val drone: entity.Drone) extends D tooltip.addAll(asJavaCollection(if (drone.isRunning) Localization.Computer.TurnOff.lines.toIterable else Localization.Computer.TurnOn.lines.toIterable)) copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj) } - GlStateManager.popAttrib() + RenderState.popAttrib() } override protected def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { diff --git a/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala b/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala index fa7d87353..bfe04ca37 100644 --- a/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala +++ b/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala @@ -36,7 +36,7 @@ abstract class DynamicGuiContainer[C <: Container](container: C) extends CustomG } override protected def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() drawSecondaryForegroundLayer(mouseX, mouseY) @@ -44,7 +44,7 @@ abstract class DynamicGuiContainer[C <: Container](container: C) extends CustomG drawSlotHighlight(inventorySlots.inventorySlots.get(slot)) } - GlStateManager.popAttrib() + RenderState.popAttrib() } protected def drawSecondaryBackgroundLayer() {} @@ -56,7 +56,7 @@ abstract class DynamicGuiContainer[C <: Container](container: C) extends CustomG drawSecondaryBackgroundLayer() RenderState.makeItBlend() - RenderState.disableLighting() + GlStateManager.disableLighting() drawInventorySlots() } @@ -82,10 +82,10 @@ abstract class DynamicGuiContainer[C <: Container](container: C) extends CustomG super.drawScreen(mouseX, mouseY, dt) if (Mods.NotEnoughItems.isAvailable) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.makeItBlend() // TODO NEI drawNEIHighlights() - GlStateManager.popAttrib() + RenderState.popAttrib() } } diff --git a/src/main/scala/li/cil/oc/client/gui/ImageButton.scala b/src/main/scala/li/cil/oc/client/gui/ImageButton.scala index c80f8e901..e5c573b73 100644 --- a/src/main/scala/li/cil/oc/client/gui/ImageButton.scala +++ b/src/main/scala/li/cil/oc/client/gui/ImageButton.scala @@ -53,7 +53,7 @@ class ImageButton(id: Int, x: Int, y: Int, w: Int, h: Int, r.pos(x0, y0, zLevel).tex(u0, v0).endVertex() } else if (isHovered) { - GL11.glColor4f(1, 1, 1, 0.8f) + GlStateManager.color(1, 1, 1, 0.8f) r.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) r.pos(x0, y1, zLevel).endVertex() @@ -62,7 +62,7 @@ class ImageButton(id: Int, x: Int, y: Int, w: Int, h: Int, r.pos(x0, y0, zLevel).endVertex() } else { - GL11.glColor4f(1, 1, 1, 0.4f) + GlStateManager.color(1, 1, 1, 0.4f) r.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) r.pos(x0, y1, zLevel).endVertex() diff --git a/src/main/scala/li/cil/oc/client/gui/Printer.scala b/src/main/scala/li/cil/oc/client/gui/Printer.scala index cd6f5c705..3b5b6f8c0 100644 --- a/src/main/scala/li/cil/oc/client/gui/Printer.scala +++ b/src/main/scala/li/cil/oc/client/gui/Printer.scala @@ -6,6 +6,7 @@ import li.cil.oc.client.gui.widget.ProgressBar import li.cil.oc.common.container import li.cil.oc.common.container.ComponentSlot import li.cil.oc.common.tileentity +import li.cil.oc.util.RenderState import net.minecraft.client.renderer.GlStateManager import net.minecraft.entity.player.InventoryPlayer @@ -44,7 +45,7 @@ class Printer(playerInventory: InventoryPlayer, val printer: tileentity.Printer) fontRendererObj.drawString( Localization.localizeImmediately(printer.getName), 8, 6, 0x404040) - GlStateManager.pushAttrib() + RenderState.pushAttrib() if (isPointInRegion(materialBar.x, materialBar.y, materialBar.width, materialBar.height, mouseX, mouseY)) { val tooltip = new java.util.ArrayList[String] tooltip.add(inventoryContainer.amountMaterial + "/" + printer.maxAmountMaterial) @@ -55,7 +56,7 @@ class Printer(playerInventory: InventoryPlayer, val printer: tileentity.Printer) tooltip.add(inventoryContainer.amountInk + "/" + printer.maxAmountInk) copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj) } - GlStateManager.popAttrib() + RenderState.popAttrib() } override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { diff --git a/src/main/scala/li/cil/oc/client/gui/Rack.scala b/src/main/scala/li/cil/oc/client/gui/Rack.scala index 27edd8ee2..d8d074986 100644 --- a/src/main/scala/li/cil/oc/client/gui/Rack.scala +++ b/src/main/scala/li/cil/oc/client/gui/Rack.scala @@ -5,6 +5,7 @@ import li.cil.oc.client.Textures import li.cil.oc.client.{PacketSender => ClientPacketSender} import li.cil.oc.common.container import li.cil.oc.common.tileentity +import li.cil.oc.util.RenderState import net.minecraft.client.gui.GuiButton import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.Tessellator @@ -160,7 +161,7 @@ class Rack(playerInventory: InventoryPlayer, val rack: tileentity.Rack) extends override def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) = { super.drawSecondaryForegroundLayer(mouseX, mouseY) - GlStateManager.pushAttrib() // Prevents NEI render glitch. + RenderState.pushAttrib() // Prevents NEI render glitch. fontRendererObj.drawString( Localization.localizeImmediately(rack.getName), @@ -250,7 +251,7 @@ class Rack(playerInventory: InventoryPlayer, val rack: tileentity.Rack) extends x, y, 0x404040) } - GlStateManager.popAttrib() + RenderState.popAttrib() } override def drawSecondaryBackgroundLayer() { diff --git a/src/main/scala/li/cil/oc/client/gui/Robot.scala b/src/main/scala/li/cil/oc/client/gui/Robot.scala index d80f3eb87..7daa6d006 100644 --- a/src/main/scala/li/cil/oc/client/gui/Robot.scala +++ b/src/main/scala/li/cil/oc/client/gui/Robot.scala @@ -128,7 +128,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten override protected def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) { drawBufferLayer() - GlStateManager.pushAttrib() + RenderState.pushAttrib() if (isPointInRegion(power.x, power.y, power.width, power.height, mouseX, mouseY)) { val tooltip = new java.util.ArrayList[String] val format = Localization.Computer.Power + ": %d%% (%d/%d)" @@ -143,7 +143,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten tooltip.addAll(asJavaCollection(if (robot.isRunning) Localization.Computer.TurnOff.lines.toIterable else Localization.Computer.TurnOn.lines.toIterable)) copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj) } - GlStateManager.popAttrib() + RenderState.popAttrib() } override protected def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { diff --git a/src/main/scala/li/cil/oc/client/renderer/HighlightRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/HighlightRenderer.scala index 7573f68e6..259742520 100644 --- a/src/main/scala/li/cil/oc/client/renderer/HighlightRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/HighlightRenderer.scala @@ -49,7 +49,7 @@ object HighlightRenderer { val renderPos = blockPos.offset(-playerPos.xCoord, -playerPos.yCoord, -playerPos.zCoord) GlStateManager.pushMatrix() - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.makeItBlend() Textures.bind(Textures.Model.HologramEffect) @@ -102,7 +102,8 @@ object HighlightRenderer { } t.draw() - GlStateManager.popAttrib() + RenderState.disableBlend() + RenderState.popAttrib() GlStateManager.popMatrix() } } diff --git a/src/main/scala/li/cil/oc/client/renderer/PetRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/PetRenderer.scala index 7b456bc01..978cd43bb 100644 --- a/src/main/scala/li/cil/oc/client/renderer/PetRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/PetRenderer.scala @@ -60,7 +60,7 @@ object PetRenderer { }) GlStateManager.pushMatrix() - GlStateManager.pushAttrib() + RenderState.pushAttrib() val localPos = Minecraft.getMinecraft.thePlayer.getPositionEyes(e.partialRenderTick) val playerPos = e.entityPlayer.getPositionEyes(e.partialRenderTick) val correction = 1.62 - (if (e.entityPlayer.isSneaking) 0.125 else 0) @@ -84,7 +84,7 @@ object PetRenderer { RenderState.disableEntityLighting() GlStateManager.disableRescaleNormal() - GlStateManager.popAttrib() + RenderState.popAttrib() GlStateManager.popMatrix() rendering = None diff --git a/src/main/scala/li/cil/oc/client/renderer/TextBufferRenderCache.scala b/src/main/scala/li/cil/oc/client/renderer/TextBufferRenderCache.scala index 571d04f37..fa2120688 100644 --- a/src/main/scala/li/cil/oc/client/renderer/TextBufferRenderCache.scala +++ b/src/main/scala/li/cil/oc/client/renderer/TextBufferRenderCache.scala @@ -71,10 +71,14 @@ object TextBufferRenderCache extends Callable[Int] with RemovalListener[TileEnti } else { GL11.glCallList(list) - RenderState.bindTexture(0) GlStateManager.depthMask(true) GlStateManager.color(1, 1, 1) + // Because display lists and the GlStateManager don't like each other, apparently. + RenderState.bindTexture(0) + GL11.glDepthMask(true) + GL11.glColor4f(1, 1, 1, 1) + RenderState.checkError(getClass.getName + ".compileOrDraw: glCallList") } } diff --git a/src/main/scala/li/cil/oc/client/renderer/WirelessNetworkDebugRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/WirelessNetworkDebugRenderer.scala index 22017b65d..627828840 100644 --- a/src/main/scala/li/cil/oc/client/renderer/WirelessNetworkDebugRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/WirelessNetworkDebugRenderer.scala @@ -28,7 +28,7 @@ object WirelessNetworkDebugRenderer { val py = player.lastTickPosY + (player.posY - player.lastTickPosY) * e.partialTicks val pz = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * e.partialTicks - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.pushMatrix() GL11.glTranslated(-px, -py, -pz) RenderState.makeItBlend() @@ -91,7 +91,7 @@ object WirelessNetworkDebugRenderer { } GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL) - GlStateManager.popAttrib() + RenderState.popAttrib() GlStateManager.popMatrix() case _ => } diff --git a/src/main/scala/li/cil/oc/client/renderer/entity/DroneRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/entity/DroneRenderer.scala index f22721d1e..3f4d1ab44 100644 --- a/src/main/scala/li/cil/oc/client/renderer/entity/DroneRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/entity/DroneRenderer.scala @@ -2,6 +2,7 @@ package li.cil.oc.client.renderer.entity import li.cil.oc.client.Textures import li.cil.oc.common.entity.Drone +import li.cil.oc.util.RenderState import net.minecraft.client.Minecraft import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.entity.Render @@ -12,13 +13,13 @@ object DroneRenderer extends Render[Drone](Minecraft.getMinecraft.getRenderManag override def doRender(entity: Drone, x: Double, y: Double, z: Double, yaw: Float, dt: Float) { bindEntityTexture(entity) GlStateManager.pushMatrix() - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.translate(x, y + 2 / 16f, z) model.render(entity, 0, 0, 0, 0, 0, dt) - GlStateManager.popAttrib() + RenderState.popAttrib() GlStateManager.popMatrix() } diff --git a/src/main/scala/li/cil/oc/client/renderer/font/TextureFontRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/font/TextureFontRenderer.scala index 5f2d204b1..0104ae4d2 100644 --- a/src/main/scala/li/cil/oc/client/renderer/font/TextureFontRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/font/TextureFontRenderer.scala @@ -26,7 +26,7 @@ abstract class TextureFontRenderer { * be generated inside the draw call. */ def generateChars(chars: Array[Char]) { - GL11.glEnable(GL11.GL_TEXTURE_2D) + GlStateManager.enableTexture2D() for (char <- chars) { generateChar(char) } @@ -36,7 +36,7 @@ abstract class TextureFontRenderer { val format = buffer.format GlStateManager.pushMatrix() - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.scale(0.5f, 0.5f, 1) @@ -92,10 +92,10 @@ abstract class TextureFontRenderer { // Check if color changed. if (col != cfg) { cfg = col - GL11.glColor3ub( - ((cfg & 0xFF0000) >> 16).toByte, - ((cfg & 0x00FF00) >> 8).toByte, - ((cfg & 0x0000FF) >> 0).toByte) + GlStateManager.color( + ((cfg & 0xFF0000) >> 16) / 255f, + ((cfg & 0x00FF00) >> 8) / 255f, + ((cfg & 0x0000FF) >> 0) / 255f) } // Don't render whitespace. if (ch != ' ') { @@ -112,7 +112,8 @@ abstract class TextureFontRenderer { GlStateManager.bindTexture(0) GlStateManager.depthMask(true) GlStateManager.color(1, 1, 1) - GlStateManager.popAttrib() + RenderState.disableBlend() + RenderState.popAttrib() GlStateManager.popMatrix() RenderState.checkError(getClass.getName + ".drawBuffer: leaving") @@ -120,7 +121,7 @@ abstract class TextureFontRenderer { def drawString(s: String, x: Int, y: Int): Unit = { GlStateManager.pushMatrix() - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.translate(x, y, 0) GlStateManager.scale(0.5f, 0.5f, 1) @@ -141,7 +142,7 @@ abstract class TextureFontRenderer { GL11.glEnd() } - GlStateManager.popAttrib() + RenderState.popAttrib() GlStateManager.popMatrix() GlStateManager.color(1, 1, 1) } @@ -163,7 +164,10 @@ abstract class TextureFontRenderer { val x1 = (x + width) * charWidth val y0 = y * charHeight val y1 = (y + 1) * charHeight - GL11.glColor3ub(((color >> 16) & 0xFF).toByte, ((color >> 8) & 0xFF).toByte, (color & 0xFF).toByte) + GlStateManager.color( + ((color >> 16) & 0xFF) / 255f, + ((color >> 8) & 0xFF) / 255f, + (color & 0xFF) / 255f) GL11.glVertex3d(x0, y1, 0) GL11.glVertex3d(x1, y1, 0) GL11.glVertex3d(x1, y0, 0) diff --git a/src/main/scala/li/cil/oc/client/renderer/gui/BufferRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/gui/BufferRenderer.scala index 10b0567fd..54023d938 100644 --- a/src/main/scala/li/cil/oc/client/renderer/gui/BufferRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/gui/BufferRenderer.scala @@ -89,11 +89,11 @@ object BufferRenderer { def drawText(screen: api.internal.TextBuffer) = if (textureManager.isDefined) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.depthMask(false) val changed = screen.renderText() GlStateManager.depthMask(true) - GlStateManager.popAttrib() + RenderState.popAttrib() changed } else false diff --git a/src/main/scala/li/cil/oc/client/renderer/item/HoverBootRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/item/HoverBootRenderer.scala index c5d67782e..5970b7b47 100644 --- a/src/main/scala/li/cil/oc/client/renderer/item/HoverBootRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/item/HoverBootRenderer.scala @@ -1,6 +1,7 @@ package li.cil.oc.client.renderer.item import li.cil.oc.Settings +import li.cil.oc.util.RenderState import net.minecraft.client.model.ModelBase import net.minecraft.client.model.ModelBiped import net.minecraft.client.model.ModelRenderer @@ -103,7 +104,7 @@ object HoverBootRenderer extends ModelBiped { class LightModelRenderer(modelBase: ModelBase, name: String) extends ModelRenderer(modelBase, name) { override def render(dt: Float): Unit = { - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.disableLighting() GlStateManager.depthFunc(GL11.GL_LEQUAL) GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE) @@ -117,7 +118,7 @@ object HoverBootRenderer extends ModelBiped { GlStateManager.color(1, 1, 1) GlStateManager.enableLighting() RenderHelper.enableStandardItemLighting() - GlStateManager.popAttrib() + RenderState.popAttrib() } } diff --git a/src/main/scala/li/cil/oc/client/renderer/markdown/Document.scala b/src/main/scala/li/cil/oc/client/renderer/markdown/Document.scala index b5e1ef7f1..82ca004ff 100644 --- a/src/main/scala/li/cil/oc/client/renderer/markdown/Document.scala +++ b/src/main/scala/li/cil/oc/client/renderer/markdown/Document.scala @@ -3,6 +3,7 @@ package li.cil.oc.client.renderer.markdown import li.cil.oc.api import li.cil.oc.client.renderer.markdown.segment.InteractiveSegment import li.cil.oc.client.renderer.markdown.segment.Segment +import li.cil.oc.util.RenderState import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer import net.minecraft.client.renderer.GlStateManager @@ -69,7 +70,7 @@ object Document { def render(document: Segment, x: Int, y: Int, maxWidth: Int, maxHeight: Int, yOffset: Int, renderer: FontRenderer, mouseX: Int, mouseY: Int): Option[InteractiveSegment] = { val mc = Minecraft.getMinecraft - GlStateManager.pushAttrib() + RenderState.pushAttrib() // On some systems/drivers/graphics cards the next calls won't update the // depth buffer correctly if alpha test is enabled. Guess how we found out? @@ -86,7 +87,7 @@ object Document { GlStateManager.colorMask(false, false, false, false) GlStateManager.pushMatrix() - GL11.glTranslatef(0, 0, 500) + GlStateManager.translate(0, 0, 500) GL11.glBegin(GL11.GL_QUADS) GL11.glVertex2f(0, y) GL11.glVertex2f(mc.displayWidth, y) @@ -120,7 +121,7 @@ object Document { if (mouseX < x || mouseX > x + maxWidth || mouseY < y || mouseY > y + maxHeight) hovered = None hovered.foreach(_.notifyHover()) - GlStateManager.popAttrib() + RenderState.popAttrib() GlStateManager.bindTexture(0) hovered diff --git a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/CodeSegment.scala b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/CodeSegment.scala index 5356e55e4..692019483 100644 --- a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/CodeSegment.scala +++ b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/CodeSegment.scala @@ -3,7 +3,7 @@ package li.cil.oc.client.renderer.markdown.segment import li.cil.oc.client.renderer.TextBufferRenderCache import li.cil.oc.client.renderer.markdown.MarkupFormat import net.minecraft.client.gui.FontRenderer -import org.lwjgl.opengl.GL11 +import net.minecraft.client.renderer.GlStateManager private[markdown] class CodeSegment(val parent: Segment, val text: String) extends BasicTextSegment { override def render(x: Int, y: Int, indent: Int, maxWidth: Int, renderer: FontRenderer, mouseX: Int, mouseY: Int): Option[InteractiveSegment] = { @@ -16,7 +16,7 @@ private[markdown] class CodeSegment(val parent: Segment, val text: String) exten var numChars = maxChars(chars, maxWidth - indent, maxWidth - wrapIndent, renderer) while (chars.length > 0) { val part = chars.take(numChars) - GL11.glColor4f(0.75f, 0.8f, 1, 1) + GlStateManager.color(0.75f, 0.8f, 1, 1) TextBufferRenderCache.renderer.drawString(part, currentX, currentY) currentX = x + wrapIndent currentY += lineHeight(renderer) diff --git a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/RenderSegment.scala b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/RenderSegment.scala index d635e98d5..4f484c354 100644 --- a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/RenderSegment.scala +++ b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/RenderSegment.scala @@ -5,6 +5,7 @@ import li.cil.oc.api.manual.InteractiveImageRenderer import li.cil.oc.client.renderer.markdown.Document import li.cil.oc.client.renderer.markdown.MarkupFormat import net.minecraft.client.gui.FontRenderer +import net.minecraft.client.renderer.GlStateManager import org.lwjgl.opengl.GL11 private[markdown] class RenderSegment(val parent: Segment, val title: String, val imageRenderer: ImageRenderer) extends InteractiveSegment { @@ -43,34 +44,34 @@ private[markdown] class RenderSegment(val parent: Segment, val title: String, va val hovered = checkHovered(mouseX, mouseY, x + xOffset, y + yOffset, width, height) - GL11.glPushMatrix() - GL11.glTranslatef(x + xOffset, y + yOffset, 0) - GL11.glScalef(s, s, s) + GlStateManager.pushMatrix() + GlStateManager.translate(x + xOffset, y + yOffset, 0) + GlStateManager.scale(s, s, s) - GL11.glEnable(GL11.GL_BLEND) - GL11.glEnable(GL11.GL_ALPHA_TEST) + GlStateManager.enableBlend() + GlStateManager.enableAlpha() if (hovered.isDefined) { - GL11.glColor4f(1, 1, 1, 0.15f) - GL11.glDisable(GL11.GL_TEXTURE_2D) + GlStateManager.color(1, 1, 1, 0.15f) + GlStateManager.disableTexture2D() GL11.glBegin(GL11.GL_QUADS) GL11.glVertex2f(0, 0) GL11.glVertex2f(0, imageRenderer.getHeight) GL11.glVertex2f(imageRenderer.getWidth, imageRenderer.getHeight) GL11.glVertex2f(imageRenderer.getWidth, 0) GL11.glEnd() - GL11.glEnable(GL11.GL_TEXTURE_2D) + GlStateManager.enableTexture2D() } - GL11.glColor4f(1, 1, 1, 1) + GlStateManager.color(1, 1, 1, 1) imageRenderer.render(mouseX - x, mouseY - y) - GL11.glDisable(GL11.GL_BLEND) - GL11.glDisable(GL11.GL_ALPHA_TEST) - GL11.glDisable(GL11.GL_LIGHTING) + GlStateManager.disableBlend() + GlStateManager.disableAlpha() + GlStateManager.disableLighting() - GL11.glPopMatrix() + GlStateManager.popMatrix() hovered } diff --git a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/TextSegment.scala b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/TextSegment.scala index 491c6faad..f89032ba5 100644 --- a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/TextSegment.scala +++ b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/TextSegment.scala @@ -2,6 +2,7 @@ package li.cil.oc.client.renderer.markdown.segment import li.cil.oc.client.renderer.markdown.Document import net.minecraft.client.gui.FontRenderer +import net.minecraft.client.renderer.GlStateManager import org.lwjgl.opengl.GL11 import scala.collection.mutable @@ -19,12 +20,12 @@ private[markdown] class TextSegment(val parent: Segment, val text: String) exten while (chars.length > 0) { val part = chars.take(numChars) hovered = hovered.orElse(resolvedInteractive.fold(None: Option[InteractiveSegment])(_.checkHovered(mouseX, mouseY, currentX, currentY, stringWidth(part, renderer), (Document.lineHeight(renderer) * resolvedScale).toInt))) - GL11.glPushMatrix() - GL11.glTranslatef(currentX, currentY, 0) - GL11.glScalef(resolvedScale, resolvedScale, resolvedScale) - GL11.glTranslatef(-currentX, -currentY, 0) + GlStateManager.pushMatrix() + GlStateManager.translate(currentX, currentY, 0) + GlStateManager.scale(resolvedScale, resolvedScale, resolvedScale) + GlStateManager.translate(-currentX, -currentY, 0) renderer.drawString(resolvedFormat + part, currentX, currentY, resolvedColor) - GL11.glPopMatrix() + GlStateManager.popMatrix() currentX = x + wrapIndent currentY += lineHeight(renderer) chars = chars.drop(numChars).dropWhile(_.isWhitespace) diff --git a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/render/ItemStackImageRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/render/ItemStackImageRenderer.scala index bb9e7c1ce..277591b0f 100644 --- a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/render/ItemStackImageRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/render/ItemStackImageRenderer.scala @@ -2,6 +2,7 @@ package li.cil.oc.client.renderer.markdown.segment.render import li.cil.oc.api.manual.ImageRenderer import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.OpenGlHelper import net.minecraft.client.renderer.RenderHelper import net.minecraft.item.ItemStack @@ -21,8 +22,8 @@ private[markdown] class ItemStackImageRenderer(val stacks: Array[ItemStack]) ext val index = (System.currentTimeMillis() % (cycleSpeed * stacks.length)).toInt / cycleSpeed val stack = stacks(index) - GL11.glScalef(getWidth / 16, getHeight / 16, getWidth / 16) - GL11.glEnable(GL12.GL_RESCALE_NORMAL) + GlStateManager.scale(getWidth / 16, getHeight / 16, getWidth / 16) + GlStateManager.enableRescaleNormal() RenderHelper.enableGUIStandardItemLighting() OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240) mc.getRenderItem.renderItemAndEffectIntoGUI(stack, 0, 0) diff --git a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/render/TextureImageRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/render/TextureImageRenderer.scala index e43d3308a..4af762c09 100644 --- a/src/main/scala/li/cil/oc/client/renderer/markdown/segment/render/TextureImageRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/markdown/segment/render/TextureImageRenderer.scala @@ -6,6 +6,7 @@ import javax.imageio.ImageIO import li.cil.oc.api.manual.ImageRenderer import li.cil.oc.client.Textures import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.texture.AbstractTexture import net.minecraft.client.renderer.texture.TextureUtil import net.minecraft.client.resources.IResourceManager @@ -33,7 +34,7 @@ class TextureImageRenderer(val location: ResourceLocation) extends ImageRenderer override def render(mouseX: Int, mouseY: Int): Unit = { Textures.bind(location) - GL11.glColor4f(1, 1, 1, 1) + GlStateManager.color(1, 1, 1, 1) GL11.glBegin(GL11.GL_QUADS) GL11.glTexCoord2f(0, 0) GL11.glVertex2f(0, 0) diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/AssemblerRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/AssemblerRenderer.scala index 11df10a7e..b49866a0d 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/AssemblerRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/AssemblerRenderer.scala @@ -14,7 +14,7 @@ object AssemblerRenderer extends TileEntitySpecialRenderer[Assembler] { override def renderTileEntityAt(assembler: Assembler, x: Double, y: Double, z: Double, f: Float, damage: Int) { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -65,10 +65,11 @@ object AssemblerRenderer extends TileEntitySpecialRenderer[Assembler] { GlStateManager.rotate(90, 0, 1, 0) } + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/CaseRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/CaseRenderer.scala index 1b305ab7e..23bb968b6 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/CaseRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/CaseRenderer.scala @@ -4,6 +4,7 @@ import li.cil.oc.client.Textures import li.cil.oc.common.tileentity.Case import li.cil.oc.util.RenderState import net.minecraft.client.renderer.GlStateManager +import net.minecraft.client.renderer.RenderHelper import net.minecraft.client.renderer.Tessellator import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer import net.minecraft.client.renderer.vertex.DefaultVertexFormats @@ -15,7 +16,7 @@ object CaseRenderer extends TileEntitySpecialRenderer[Case] { override def renderTileEntityAt(computer: Case, x: Double, y: Double, z: Double, f: Float, damage: Int) { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -45,10 +46,11 @@ object CaseRenderer extends TileEntitySpecialRenderer[Case] { renderFrontOverlay(Textures.Block.CaseFrontError) } + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/ChargerRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/ChargerRenderer.scala index bd6c82e1d..7a68ec85e 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/ChargerRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/ChargerRenderer.scala @@ -15,7 +15,7 @@ object ChargerRenderer extends TileEntitySpecialRenderer[Charger] { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") if (charger.chargeSpeed > 0) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -72,10 +72,11 @@ object ChargerRenderer extends TileEntitySpecialRenderer[Charger] { t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() } RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/DisassemblerRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/DisassemblerRenderer.scala index f8c5fe78a..f7f044b19 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/DisassemblerRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/DisassemblerRenderer.scala @@ -14,7 +14,7 @@ object DisassemblerRenderer extends TileEntitySpecialRenderer[tileentity.Disasse RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") if (disassembler.isActive) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -64,10 +64,11 @@ object DisassemblerRenderer extends TileEntitySpecialRenderer[tileentity.Disasse t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() } RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/DiskDriveRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/DiskDriveRenderer.scala index 0a60c59b1..785137b4e 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/DiskDriveRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/DiskDriveRenderer.scala @@ -18,7 +18,7 @@ object DiskDriveRenderer extends TileEntitySpecialRenderer[DiskDrive] { override def renderTileEntityAt(drive: DiskDrive, x: Double, y: Double, z: Double, f: Float, damage: Int) { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.color(1, 1, 1, 1) GlStateManager.pushMatrix() @@ -73,11 +73,12 @@ object DiskDriveRenderer extends TileEntitySpecialRenderer[DiskDrive] { t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() } GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/GeolyzerRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/GeolyzerRenderer.scala index 065c306ff..cd148d708 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/GeolyzerRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/GeolyzerRenderer.scala @@ -13,12 +13,12 @@ object GeolyzerRenderer extends TileEntitySpecialRenderer[Geolyzer] { override def renderTileEntityAt(geolyzer: Geolyzer, x: Double, y: Double, z: Double, f: Float, damage: Int) { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() RenderState.setBlendAlpha(1) - RenderState.color(1, 1, 1, 1) + GlStateManager.color(1, 1, 1, 1) GlStateManager.pushMatrix() @@ -40,10 +40,11 @@ object GeolyzerRenderer extends TileEntitySpecialRenderer[Geolyzer] { t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRenderer.scala index 61c4c4006..b69825c13 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRenderer.scala @@ -76,7 +76,7 @@ object HologramRenderer extends TileEntitySpecialRenderer[Hologram] with Callabl if (!hologram.hasPower) return GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS) - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.makeItBlend() GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE) @@ -151,7 +151,9 @@ object HologramRenderer extends TileEntitySpecialRenderer[Hologram] with Callabl GlStateManager.depthFunc(GL11.GL_LEQUAL) GlStateManager.popMatrix() - GlStateManager.popAttrib() + + RenderState.disableBlend() + RenderState.popAttrib() GL11.glPopClientAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRendererFallback.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRendererFallback.scala index e75977077..16b301216 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRendererFallback.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/HologramRendererFallback.scala @@ -14,14 +14,14 @@ object HologramRendererFallback extends TileEntitySpecialRenderer[Hologram] { val fontRenderer = Minecraft.getMinecraft.fontRendererObj - RenderState.pushMatrix() + GlStateManager.pushMatrix() GlStateManager.translate(x + 0.5, y + 0.75, z + 0.5) GlStateManager.scale(1 / 128f, -1 / 128f, 1 / 128f) - RenderState.disableCullFace() + GlStateManager.disableCull() fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, 0, 0xFFFFFFFF) - RenderState.popMatrix() + GlStateManager.popMatrix() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/MicrocontrollerRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/MicrocontrollerRenderer.scala index 5b001857b..23bd2354c 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/MicrocontrollerRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/MicrocontrollerRenderer.scala @@ -16,12 +16,12 @@ object MicrocontrollerRenderer extends TileEntitySpecialRenderer[Microcontroller override def renderTileEntityAt(mcu: Microcontroller, x: Double, y: Double, z: Double, f: Float, damage: Int) { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() RenderState.setBlendAlpha(1) - RenderState.color(1, 1, 1, 1) + GlStateManager.color(1, 1, 1, 1) GlStateManager.pushMatrix() @@ -54,10 +54,11 @@ object MicrocontrollerRenderer extends TileEntitySpecialRenderer[Microcontroller t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/NetSplitterRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/NetSplitterRenderer.scala index 8e53afece..7dc54cca4 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/NetSplitterRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/NetSplitterRenderer.scala @@ -16,7 +16,7 @@ object NetSplitterRenderer extends TileEntitySpecialRenderer[tileentity.NetSplit RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") if (splitter.openSides.contains(!splitter.isInverted)) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -80,10 +80,11 @@ object NetSplitterRenderer extends TileEntitySpecialRenderer[tileentity.NetSplit t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() } RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/PowerDistributorRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/PowerDistributorRenderer.scala index fcd8fda91..cd6b3bf77 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/PowerDistributorRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/PowerDistributorRenderer.scala @@ -14,7 +14,7 @@ object PowerDistributorRenderer extends TileEntitySpecialRenderer[tileentity.Pow RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") if (distributor.globalBuffer > 0) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -65,10 +65,11 @@ object PowerDistributorRenderer extends TileEntitySpecialRenderer[tileentity.Pow t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() } RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/PrinterRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/PrinterRenderer.scala index c0e12bb71..427337e21 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/PrinterRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/PrinterRenderer.scala @@ -6,9 +6,9 @@ import li.cil.oc.util.RenderState import net.minecraft.client.Minecraft import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.OpenGlHelper +import net.minecraft.client.renderer.RenderHelper import net.minecraft.client.renderer.block.model.ItemCameraTransforms import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer -import net.minecraft.entity.item.EntityItem object PrinterRenderer extends TileEntitySpecialRenderer[Printer] { override def renderTileEntityAt(printer: Printer, x: Double, y: Double, z: Double, f: Float, damage: Int) { @@ -17,7 +17,7 @@ object PrinterRenderer extends TileEntitySpecialRenderer[Printer] { if (printer.data.stateOff.nonEmpty) { val stack = printer.data.createItemStack() - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.pushMatrix() GlStateManager.translate(x + 0.5, y + 0.5 + 0.3, z + 0.5) @@ -28,14 +28,11 @@ object PrinterRenderer extends TileEntitySpecialRenderer[Printer] { val brightness = printer.world.getCombinedLight(printer.getPos, 0) OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightness % 65536, brightness / 65536) - // This is very 'meh', but item frames do it like this, too! - val entity = new EntityItem(printer.world, 0, 0, 0, stack) - entity.hoverStart = 0 Textures.Block.bind() - Minecraft.getMinecraft.getRenderItem.renderItem(entity.getEntityItem, ItemCameraTransforms.TransformType.FIXED) + Minecraft.getMinecraft.getRenderItem.renderItem(stack, ItemCameraTransforms.TransformType.FIXED) GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() } RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/RackRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/RackRenderer.scala index 063828ffe..4863f0031 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/RackRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/RackRenderer.scala @@ -16,7 +16,7 @@ object RackRenderer extends TileEntitySpecialRenderer[Rack] { override def renderTileEntityAt(rack: Rack, x: Double, y: Double, z: Double, partialTicks: Float, destroyStage: Int): Unit = { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") - GlStateManager.popAttrib() + RenderState.pushAttrib() GlStateManager.pushMatrix() @@ -36,20 +36,20 @@ object RackRenderer extends TileEntitySpecialRenderer[Rack] { for (i <- 0 until rack.getSizeInventory) { if (rack.getStackInSlot(i) != null) { GlStateManager.pushMatrix() - GlStateManager.pushAttrib() + RenderState.pushAttrib() val v0 = vOffset + i * vSize val v1 = vOffset + (i + 1) * vSize val event = new RackMountableRenderEvent.TileEntity(rack, i, rack.lastData(i), v0, v1) MinecraftForge.EVENT_BUS.post(event) - GlStateManager.popAttrib() + RenderState.popAttrib() GlStateManager.popMatrix() } } GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/RaidRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/RaidRenderer.scala index 6cccd0d58..ad441e11b 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/RaidRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/RaidRenderer.scala @@ -16,11 +16,11 @@ object RaidRenderer extends TileEntitySpecialRenderer[Raid] { override def renderTileEntityAt(raid: Raid, x: Double, y: Double, z: Double, f: Float, damage: Int) { RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)") - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() - RenderState.color(1, 1, 1, 1) + GlStateManager.color(1, 1, 1, 1) GlStateManager.pushMatrix() @@ -62,10 +62,11 @@ object RaidRenderer extends TileEntitySpecialRenderer[Raid] { t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala index af48b2fbf..3f15bf4ea 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala @@ -299,7 +299,7 @@ object RobotRenderer extends TileEntitySpecialRenderer[tileentity.RobotProxy] { val worldTime = robot.getWorld.getTotalWorldTime + f GlStateManager.pushMatrix() - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.translate(x + 0.5, y + 0.5, z + 0.5) // If the move started while we were rendering and we have a reference to @@ -349,7 +349,7 @@ object RobotRenderer extends TileEntitySpecialRenderer[tileentity.RobotProxy] { Option(robot.getStackInSlot(0)) match { case Some(stack) => - GlStateManager.pushAttrib() + RenderState.pushAttrib() GlStateManager.pushMatrix() try { // Copy-paste from player render code, with minor adjustments for @@ -408,7 +408,7 @@ object RobotRenderer extends TileEntitySpecialRenderer[tileentity.RobotProxy] { GlStateManager.enableCull() GlStateManager.disableRescaleNormal() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() case _ => } @@ -489,13 +489,13 @@ object RobotRenderer extends TileEntitySpecialRenderer[tileentity.RobotProxy] { GlStateManager.depthMask(true) GlStateManager.enableLighting() - GlStateManager.disableBlend() + RenderState.disableBlend() GlStateManager.popMatrix() } GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala index 3d63e4dce..547719d98 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala @@ -59,7 +59,7 @@ object ScreenRenderer extends TileEntitySpecialRenderer[Screen] { RenderState.checkError(getClass.getName + ".renderTileEntityAt: checks") - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -89,11 +89,11 @@ object ScreenRenderer extends TileEntitySpecialRenderer[Screen] { draw() } + RenderState.disableBlend() RenderState.enableEntityLighting() - GlStateManager.color(1, 1, 1, 1) // #1648 GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") } diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/SwitchRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/SwitchRenderer.scala index 5ae0d5273..eb3f68b10 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/SwitchRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/SwitchRenderer.scala @@ -15,7 +15,7 @@ class SwitchRenderer[T <: tileentity.traits.SwitchLike] extends TileEntitySpecia val activity = math.max(0, 1 - (System.currentTimeMillis() - switch.lastMessage) / 1000.0) if (activity > 0) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -56,10 +56,11 @@ class SwitchRenderer[T <: tileentity.traits.SwitchLike] extends TileEntitySpecia t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() } RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/TransposerRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/TransposerRenderer.scala index a7821a075..c9e738d0e 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/TransposerRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/TransposerRenderer.scala @@ -15,7 +15,7 @@ object TransposerRenderer extends TileEntitySpecialRenderer[tileentity.Transpose val activity = math.max(0, 1 - (System.currentTimeMillis() - transposer.lastOperation) / 1000.0) if (activity > 0) { - GlStateManager.pushAttrib() + RenderState.pushAttrib() RenderState.disableEntityLighting() RenderState.makeItBlend() @@ -66,10 +66,11 @@ object TransposerRenderer extends TileEntitySpecialRenderer[tileentity.Transpose t.draw() + RenderState.disableBlend() RenderState.enableEntityLighting() GlStateManager.popMatrix() - GlStateManager.popAttrib() + RenderState.popAttrib() } RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving") diff --git a/src/main/scala/li/cil/oc/common/IMC.scala b/src/main/scala/li/cil/oc/common/IMC.scala index 746142731..c4245b71a 100644 --- a/src/main/scala/li/cil/oc/common/IMC.scala +++ b/src/main/scala/li/cil/oc/common/IMC.scala @@ -91,6 +91,9 @@ object IMC { case t: Throwable => OpenComputers.log.warn("Failed registering ink provider.", t) } } + else if (message.key == "registerCustomPowerSystem" && message.isStringMessage) { + Settings.get.is3rdPartyPowerSystemPresent = message.getStringValue == "true" + } else { OpenComputers.log.warn(s"Got an unrecognized or invalid IMC message '${message.key}' from mod ${message.getSender}.") } diff --git a/src/main/scala/li/cil/oc/common/Loot.scala b/src/main/scala/li/cil/oc/common/Loot.scala index 0efb72d79..77993557e 100644 --- a/src/main/scala/li/cil/oc/common/Loot.scala +++ b/src/main/scala/li/cil/oc/common/Loot.scala @@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.WeightedRandomChestContent import net.minecraftforge.common.ChestGenHooks import net.minecraftforge.common.DimensionManager +import net.minecraftforge.common.util.Constants.NBT import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.Loader import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -44,14 +45,16 @@ object Loot { val factories = mutable.Map.empty[String, Callable[FileSystem]] - val globalDisks = mutable.Map.empty[String, (ItemStack, Int)] + val globalDisks = mutable.ArrayBuffer.empty[(ItemStack, Int)] - val worldDisks = mutable.Map.empty[String, (ItemStack, Int)] + val worldDisks = mutable.ArrayBuffer.empty[(ItemStack, Int)] val disksForSampling = mutable.ArrayBuffer.empty[ItemStack] val disksForClient = mutable.ArrayBuffer.empty[ItemStack] + def isLootDisk(stack: ItemStack): Boolean = api.Items.get(stack) == api.Items.get(Constants.ItemName.Floppy) && stack.hasTagCompound && stack.getTagCompound.hasKey(Settings.namespace + "lootFactory", NBT.TAG_STRING) + def randomDisk(rng: Random) = if (disksForSampling.nonEmpty) Some(disksForSampling(rng.nextInt(disksForSampling.length))) else None @@ -115,26 +118,26 @@ object Loot { } } } - for ((name, entry) <- globalDisks if !worldDisks.contains(name)) { - worldDisks += name -> entry + for (entry <- globalDisks if !worldDisks.contains(entry)) { + worldDisks += entry } - for ((_, (stack, count)) <- worldDisks) { + for ((stack, count) <- worldDisks) { for (i <- 0 until count) { disksForSampling += stack } } } - private def parseLootDisks(list: java.util.Properties, acc: mutable.Map[String, (ItemStack, Int)], external: Boolean) { + private def parseLootDisks(list: java.util.Properties, acc: mutable.ArrayBuffer[(ItemStack, Int)], external: Boolean) { for (key <- list.stringPropertyNames) { val value = list.getProperty(key) try value.split(":") match { case Array(name, count, color) => - acc += key -> ((createLootDisk(name, key, external, Color.byOreName.get(color)), count.toInt)) + acc += ((createLootDisk(name, key, external, Color.byOreName.get(color)), count.toInt)) case Array(name, count) => - acc += key -> ((createLootDisk(name, key, external), count.toInt)) + acc += ((createLootDisk(name, key, external), count.toInt)) case _ => - acc += key -> ((createLootDisk(value, key, external), 1)) + acc += ((createLootDisk(value, key, external), 1)) } catch { case t: Throwable => OpenComputers.log.warn("Bad loot descriptor: " + value, t) @@ -148,9 +151,10 @@ object Loot { } else new Callable[FileSystem] { override def call(): FileSystem = api.FileSystem.fromClass(OpenComputers.getClass, Settings.resourceDomain, "loot/" + path) } - val stack = registerLootDisk(name, color.getOrElse(EnumDyeColor.SILVER), callable) + val stack = registerLootDisk(path, color.getOrElse(EnumDyeColor.SILVER), callable) + stack.setStackDisplayName(name) if (!external) { - Items.registerStack(stack, name) + Items.registerStack(stack, path) } stack } diff --git a/src/main/scala/li/cil/oc/common/PacketHandler.scala b/src/main/scala/li/cil/oc/common/PacketHandler.scala index c985ee647..77ab78fc1 100644 --- a/src/main/scala/li/cil/oc/common/PacketHandler.scala +++ b/src/main/scala/li/cil/oc/common/PacketHandler.scala @@ -13,6 +13,7 @@ import li.cil.oc.common.block.RobotAfterimage import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedWorld._ import net.minecraft.entity.player.EntityPlayer +import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.item.ItemStack import net.minecraft.nbt.CompressedStreamTools import net.minecraft.network.INetHandler @@ -50,6 +51,13 @@ abstract class PacketHandler { case e: Throwable => OpenComputers.log.warn("Received a badly formatted packet.", e) } + + // Avoid AFK kicks by marking players as non-idle when they send packets. + // This will usually be stuff like typing while in screen GUIs. + player match { + case mp: EntityPlayerMP => mp.markPlayerActive() + case _ => // Uh... OK? + } } /** diff --git a/src/main/scala/li/cil/oc/common/PacketType.scala b/src/main/scala/li/cil/oc/common/PacketType.scala index 04a1c32d0..8d1f04fd3 100644 --- a/src/main/scala/li/cil/oc/common/PacketType.scala +++ b/src/main/scala/li/cil/oc/common/PacketType.scala @@ -5,6 +5,7 @@ object PacketType extends Enumeration { // Server -> Client Analyze, ChargerState, + ClientLog, ColorChange, ComputerState, ComputerUserList, diff --git a/src/main/scala/li/cil/oc/common/block/Printer.scala b/src/main/scala/li/cil/oc/common/block/Printer.scala index 0dc6d0218..cfd44775a 100644 --- a/src/main/scala/li/cil/oc/common/block/Printer.scala +++ b/src/main/scala/li/cil/oc/common/block/Printer.scala @@ -2,7 +2,6 @@ package li.cil.oc.common.block import li.cil.oc.common.GuiType import li.cil.oc.common.tileentity -import net.minecraft.block.state.IBlockState import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing import net.minecraft.world.IBlockAccess diff --git a/src/main/scala/li/cil/oc/common/block/Rack.scala b/src/main/scala/li/cil/oc/common/block/Rack.scala index ab60d0b51..c7482585f 100644 --- a/src/main/scala/li/cil/oc/common/block/Rack.scala +++ b/src/main/scala/li/cil/oc/common/block/Rack.scala @@ -10,6 +10,8 @@ import net.minecraft.block.state.IBlockState import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing +import net.minecraft.util.EnumFacing.Axis +import net.minecraft.util.Vec3 import net.minecraft.world.IBlockAccess import net.minecraft.world.World import net.minecraftforge.common.property.ExtendedBlockState @@ -67,14 +69,31 @@ class Rack extends RedstoneAware with traits.PowerAcceptor with traits.StateAwar override def localOnBlockActivated(world: World, pos: BlockPos, player: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean = { world.getTileEntity(pos) match { case rack: tileentity.Rack => rack.slotAt(side, hitX, hitY, hitZ) match { - case Some(slot) => rack.getMountable(slot) match { - case mountable: RackMountable if mountable.onActivate(player, side, hitX, hitY, hitZ) => return true // Activation handled by mountable. - case _ => - } + case Some(slot) => + val hitVec = new Vec3(hitX, hitY, hitZ) + val rotation = side match { + case EnumFacing.WEST => Math.toRadians(90).toFloat + case EnumFacing.NORTH => Math.toRadians(180).toFloat + case EnumFacing.EAST => Math.toRadians(270).toFloat + case _ => 0 + } + val rotatedHitVec = rotate(hitVec.addVector(-0.5, -0.5, -0.5), rotation).addVector(0.5, 0.5, 0.5) + val x = ((if (side.getAxis != Axis.Z) 1 - rotatedHitVec.xCoord else rotatedHitVec.xCoord) * 16 - 1) / 14f + val y = ((1 - rotatedHitVec.yCoord) * 16 - 2 - 3 * slot) / 3f + rack.getMountable(slot) match { + case mountable: RackMountable if mountable.onActivate(player, x.toFloat, y.toFloat) => return true // Activation handled by mountable. + case _ => + } case _ => } case _ => } super.localOnBlockActivated(world, pos, player, side, hitX, hitY, hitZ) } + + def rotate(v: Vec3, t: Float): Vec3 = { + val cos = Math.cos(t) + val sin = Math.sin(t) + new Vec3(v.xCoord * cos - v.zCoord * sin, v.yCoord, v.xCoord * sin + v.zCoord * cos) + } } diff --git a/src/main/scala/li/cil/oc/common/block/RedstoneAware.scala b/src/main/scala/li/cil/oc/common/block/RedstoneAware.scala index e99eb7666..2891b4cf7 100644 --- a/src/main/scala/li/cil/oc/common/block/RedstoneAware.scala +++ b/src/main/scala/li/cil/oc/common/block/RedstoneAware.scala @@ -54,11 +54,7 @@ abstract class RedstoneAware extends SimpleBlock /* with IRedNetOmniNode TODO MF } */ world.getTileEntity(pos) match { - case redstone: tileentity.traits.RedstoneAware => - if (redstone.canUpdate) - redstone.checkRedstoneInputChanged() - else - EnumFacing.values().foreach(redstone.updateRedstoneInput) + case redstone: tileentity.traits.RedstoneAware => redstone.checkRedstoneInputChanged() case _ => // Ignore. } } diff --git a/src/main/scala/li/cil/oc/common/component/TerminalServer.scala b/src/main/scala/li/cil/oc/common/component/TerminalServer.scala index 647f44375..1266e230d 100644 --- a/src/main/scala/li/cil/oc/common/component/TerminalServer.scala +++ b/src/main/scala/li/cil/oc/common/component/TerminalServer.scala @@ -4,10 +4,13 @@ import java.util import java.util.UUID import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.component.RackBusConnectable import li.cil.oc.api.component.RackMountable +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal.Keyboard.UsabilityChecker import li.cil.oc.api.network.Analyzable import li.cil.oc.api.network.Environment @@ -28,9 +31,10 @@ import net.minecraft.nbt.NBTTagString import net.minecraft.util.EnumFacing import net.minecraftforge.common.util.Constants.NBT +import scala.collection.convert.WrapAsJava._ import scala.collection.mutable -class TerminalServer(val rack: api.internal.Rack, val slot: Int) extends Environment with EnvironmentHost with Analyzable with RackMountable with Lifecycle { +class TerminalServer(val rack: api.internal.Rack, val slot: Int) extends Environment with EnvironmentHost with Analyzable with RackMountable with Lifecycle with DeviceInfo { val node = api.Network.newNode(this, Visibility.None).create() lazy val buffer = { @@ -67,6 +71,18 @@ class TerminalServer(val rack: api.internal.Rack, val slot: Int) extends Environ else rack.getMountableData(slot).getTagList("keys", NBT.TAG_STRING).map((tag: NBTTagString) => tag.getString) } + // ----------------------------------------------------------------------- // + // DeviceInfo + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Terminal server", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "RemoteViewing EX" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // // Environment @@ -117,7 +133,7 @@ class TerminalServer(val rack: api.internal.Rack, val slot: Int) extends Environ override def getConnectableAt(index: Int): RackBusConnectable = null - override def onActivate(player: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean = { + override def onActivate(player: EntityPlayer, hitX: Float, hitY: Float): Boolean = { val stack = player.getHeldItem if (api.Items.get(stack) == api.Items.get(Constants.ItemName.Terminal)) { if (!world.isRemote) { diff --git a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala index 591cfee1d..ff913c3cc 100644 --- a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala @@ -2,9 +2,12 @@ package li.cil.oc.common.component import com.google.common.base.Strings import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -32,10 +35,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ import scala.collection.mutable -class TextBuffer(val host: EnvironmentHost) extends prefab.ManagedEnvironment with api.internal.TextBuffer { +class TextBuffer(val host: EnvironmentHost) extends prefab.ManagedEnvironment with api.internal.TextBuffer with DeviceInfo { override val node = api.Network.newNode(this, Visibility.Network). withComponent("screen"). withConnector(). @@ -99,6 +103,17 @@ class TextBuffer(val host: EnvironmentHost) extends prefab.ManagedEnvironment wi relativeLitArea = -1 // Recompute lit area, avoid screens blanking out until something changes. } + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Display, + DeviceAttribute.Description -> "Text buffer", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Text Screen V0", + DeviceAttribute.Capacity -> (maxResolution._1 * maxResolution._2).toString, + DeviceAttribute.Width -> Array("1", "4", "8").apply(maxDepth.ordinal()) + ) + + override def getDeviceInfo: java.util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // override val canUpdate = true @@ -113,16 +128,21 @@ class TextBuffer(val host: EnvironmentHost) extends prefab.ManagedEnvironment wi // origin. val w = getViewportWidth val h = getViewportHeight - relativeLitArea = (data.buffer, data.color).zipped.foldLeft(0) { - case (acc, (line, colors)) => acc + (line, colors).zipped.foldLeft(0) { - case (acc2, (char, color)) => - val bg = PackedColor.unpackBackground(color, data.format) - val fg = PackedColor.unpackForeground(color, data.format) - acc2 + (if (char == ' ') if (bg == 0) 0 else 1 - else if (char == 0x2588) if (fg == 0) 0 else 1 - else if (fg == 0 && bg == 0) 0 else 1) + var acc = 0f + for (y <- 0 until h) { + val line = data.buffer(y) + val colors = data.color(y) + for (x <- 0 until w) { + val char = line(x) + val color = colors(x) + val bg = PackedColor.unpackBackground(color, data.format) + val fg = PackedColor.unpackForeground(color, data.format) + acc += (if (char == ' ') if (bg == 0) 0 else 1 + else if (char == 0x2588) if (fg == 0) 0 else 1 + else if (fg == 0 && bg == 0) 0 else 1) } - } / (w * h).toDouble + } + relativeLitArea = acc / (w * h).toDouble } if (node != null) { val hadPower = hasPower @@ -246,8 +266,8 @@ class TextBuffer(val host: EnvironmentHost) extends prefab.ManagedEnvironment wi // backwards compatibility, and partially to enforce a valid one. val sizeChanged = data.size = (w, h) val viewportChanged = setViewport(w, h) - if (sizeChanged && !viewportChanged) { - if (node != null) { + if (sizeChanged || viewportChanged) { + if (!viewportChanged && node != null) { node.sendToReachable("computer.signal", "screen_resized", Int.box(w), Int.box(h)) } true diff --git a/src/main/scala/li/cil/oc/common/event/RackMountableRenderHandler.scala b/src/main/scala/li/cil/oc/common/event/RackMountableRenderHandler.scala index 42c20339c..e2e4b4527 100644 --- a/src/main/scala/li/cil/oc/common/event/RackMountableRenderHandler.scala +++ b/src/main/scala/li/cil/oc/common/event/RackMountableRenderHandler.scala @@ -61,6 +61,7 @@ object RackMountableRenderHandler { e.renderOverlayFromAtlas(Textures.Block.RackDiskDriveActivity) + RenderState.disableBlend() RenderState.enableEntityLighting() } } @@ -82,6 +83,7 @@ object RackMountableRenderHandler { e.renderOverlayFromAtlas(Textures.Block.RackServerNetworkActivity) } + RenderState.disableBlend() RenderState.enableEntityLighting() } else if (e.data != null && TerminalServer == api.Items.get(e.rack.getStackInSlot(e.mountable))) { @@ -98,6 +100,7 @@ object RackMountableRenderHandler { e.renderOverlayFromAtlas(Textures.Block.RackTerminalServerPresence, u0, u1) } + RenderState.disableBlend() RenderState.enableEntityLighting() } } diff --git a/src/main/scala/li/cil/oc/common/inventory/ServerInventory.scala b/src/main/scala/li/cil/oc/common/inventory/ServerInventory.scala index 0fb6ea968..4033a7f2a 100644 --- a/src/main/scala/li/cil/oc/common/inventory/ServerInventory.scala +++ b/src/main/scala/li/cil/oc/common/inventory/ServerInventory.scala @@ -8,7 +8,7 @@ import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack trait ServerInventory extends ItemStackInventory { - def tier: Int = ItemUtils.caseTier(container) + def tier: Int = ItemUtils.caseTier(container) max 0 override def getSizeInventory = InventorySlots.server(tier).length diff --git a/src/main/scala/li/cil/oc/common/item/EEPROM.scala b/src/main/scala/li/cil/oc/common/item/EEPROM.scala index 736011fdc..f0f1bdc1b 100644 --- a/src/main/scala/li/cil/oc/common/item/EEPROM.scala +++ b/src/main/scala/li/cil/oc/common/item/EEPROM.scala @@ -1,6 +1,8 @@ package li.cil.oc.common.item import li.cil.oc.Settings +import li.cil.oc.util.BlockPosition +import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack class EEPROM(val parent: Delegator) extends traits.Delegate { @@ -16,4 +18,6 @@ class EEPROM(val parent: Delegator) extends traits.Delegate { } super.displayName(stack) } + + override def doesSneakBypassUse(position: BlockPosition, player: EntityPlayer): Boolean = true } diff --git a/src/main/scala/li/cil/oc/common/item/data/NavigationUpgradeData.scala b/src/main/scala/li/cil/oc/common/item/data/NavigationUpgradeData.scala index 7ec24ff14..ca0759bd8 100644 --- a/src/main/scala/li/cil/oc/common/item/data/NavigationUpgradeData.scala +++ b/src/main/scala/li/cil/oc/common/item/data/NavigationUpgradeData.scala @@ -20,6 +20,11 @@ class NavigationUpgradeData extends ItemData(Constants.ItemName.NavigationUpgrad case _: Throwable => throw new Exception("invalid map") } + def getSize(world: World) = { + val info = mapData(world) + 128 * (1 << info.scale) + } + override def load(stack: ItemStack) { if (stack.hasTagCompound) { load(stack.getTagCompound.getCompoundTag(Settings.namespace + "data")) diff --git a/src/main/scala/li/cil/oc/common/nanomachines/NeuralNetwork.scala b/src/main/scala/li/cil/oc/common/nanomachines/NeuralNetwork.scala index 47f7d6602..cbec0f8eb 100644 --- a/src/main/scala/li/cil/oc/common/nanomachines/NeuralNetwork.scala +++ b/src/main/scala/li/cil/oc/common/nanomachines/NeuralNetwork.scala @@ -6,14 +6,15 @@ import li.cil.oc.api import li.cil.oc.api.Persistable import li.cil.oc.api.nanomachines.Behavior import li.cil.oc.api.nanomachines.BehaviorProvider +import li.cil.oc.server.PacketSender import li.cil.oc.util.ExtendedNBT._ import net.minecraft.entity.player.EntityPlayer +import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.ChatComponentText import net.minecraft.util.EnumChatFormatting import net.minecraftforge.common.util.Constants.NBT -import scala.StringBuilder import scala.collection.convert.WrapAsScala._ import scala.collection.mutable import scala.util.Random @@ -97,7 +98,11 @@ class NeuralNetwork(controller: ControllerImpl) extends Persistable { // Enter debug configuration, one input -> one behavior, and list mapping in console. def debug(): Unit = { - OpenComputers.log.info(s"Creating debug configuration for nanomachines in player ${controller.player.getDisplayName}.") + val log = controller.player match { + case playerMP: EntityPlayerMP => (s: String) => PacketSender.sendClientLog(s, playerMP) + case _ => (s: String) => OpenComputers.log.info(s) + } + log(s"Creating debug configuration for nanomachines in player ${controller.player.getDisplayName}.") behaviors.clear() behaviors ++= api.Nanomachines.getProviders. @@ -114,7 +119,7 @@ class NeuralNetwork(controller: ControllerImpl) extends Persistable { triggers += trigger behavior.inputs += trigger - OpenComputers.log.info(s"$i -> ${behavior.behavior.getNameHint} (${behavior.behavior.getClass.toString})") + log(s"$i -> ${behavior.behavior.getNameHint} (${behavior.behavior.getClass.toString})") } } diff --git a/src/main/scala/li/cil/oc/common/recipe/ContainerItemAwareRecipe.scala b/src/main/scala/li/cil/oc/common/recipe/ContainerItemAwareRecipe.scala index f065e11b3..5448fb454 100644 --- a/src/main/scala/li/cil/oc/common/recipe/ContainerItemAwareRecipe.scala +++ b/src/main/scala/li/cil/oc/common/recipe/ContainerItemAwareRecipe.scala @@ -2,12 +2,8 @@ package li.cil.oc.common.recipe import net.minecraft.inventory.InventoryCrafting import net.minecraft.item.crafting.IRecipe +import net.minecraftforge.common.ForgeHooks trait ContainerItemAwareRecipe extends IRecipe { - override def getRemainingItems(inv: InventoryCrafting) = - (0 until inv.getSizeInventory). - map(inv.getStackInSlot). - map(net.minecraftforge.common.ForgeHooks.getContainerItem). - filter(_ != null). - toArray + override def getRemainingItems(inv: InventoryCrafting) = ForgeHooks.defaultRecipeGetRemainingItems(inv) } diff --git a/src/main/scala/li/cil/oc/common/recipe/LootDiskCyclingRecipe.scala b/src/main/scala/li/cil/oc/common/recipe/LootDiskCyclingRecipe.scala new file mode 100644 index 000000000..f87e3edcb --- /dev/null +++ b/src/main/scala/li/cil/oc/common/recipe/LootDiskCyclingRecipe.scala @@ -0,0 +1,48 @@ +package li.cil.oc.common.recipe + +import li.cil.oc.Settings +import li.cil.oc.common.Loot +import li.cil.oc.integration.util.Wrench +import net.minecraft.inventory.InventoryCrafting +import net.minecraft.item.ItemStack +import net.minecraft.item.crafting.IRecipe +import net.minecraft.world.World + +class LootDiskCyclingRecipe extends IRecipe { + override def matches(crafting: InventoryCrafting, world: World): Boolean = { + val stacks = collectStacks(crafting).toArray + stacks.length == 2 && stacks.exists(Loot.isLootDisk) && stacks.exists(Wrench.isWrench) + } + + override def getCraftingResult(crafting: InventoryCrafting): ItemStack = { + collectStacks(crafting).find(Loot.isLootDisk) match { + case Some(lootDisk) => + val lootFactoryName = getLootFactoryName(lootDisk) + val lootDiskStacks = Loot.worldDisks.map(_._1) + val oldIndex = lootDiskStacks.indexWhere(s => getLootFactoryName(s) == lootFactoryName) + val newIndex = (oldIndex + 1) % lootDiskStacks.length + lootDiskStacks(newIndex).copy() + case _ => null + } + } + + def getLootFactoryName(stack: ItemStack) = stack.getTagCompound.getString(Settings.namespace + "lootFactory") + + def collectStacks(crafting: InventoryCrafting) = (0 until crafting.getSizeInventory).flatMap(i => Option(crafting.getStackInSlot(i))) + + override def getRecipeSize: Int = 2 + + override def getRecipeOutput: ItemStack = null + + override def getRemainingItems(crafting: InventoryCrafting): Array[ItemStack] = { + val result = new Array[ItemStack](crafting.getSizeInventory) + for (slot <- 0 until crafting.getSizeInventory) { + val stack = crafting.getStackInSlot(slot) + if (Wrench.isWrench(stack)) { + result(slot) = stack.copy() + stack.stackSize = 0 + } + } + result + } +} diff --git a/src/main/scala/li/cil/oc/common/recipe/Recipes.scala b/src/main/scala/li/cil/oc/common/recipe/Recipes.scala index 03dd2f886..b07d8c842 100644 --- a/src/main/scala/li/cil/oc/common/recipe/Recipes.scala +++ b/src/main/scala/li/cil/oc/common/recipe/Recipes.scala @@ -104,6 +104,7 @@ object Recipes { RecipeSorter.register(Settings.namespace + "extshapeless", classOf[ExtendedShapelessOreRecipe], Category.SHAPELESS, "after:forge:shapelessore") RecipeSorter.register(Settings.namespace + "colorizer", classOf[ColorizeRecipe], Category.SHAPELESS, "after:forge:shapelessore") RecipeSorter.register(Settings.namespace + "decolorizer", classOf[DecolorizeRecipe], Category.SHAPELESS, "after:oc:colorizer") + RecipeSorter.register(Settings.namespace + "lootcycler", classOf[LootDiskCyclingRecipe], Category.SHAPELESS, "after:forge:shapelessore") for ((name, stack) <- oreDictEntries) { if (!OreDictionary.getOres(name).contains(stack)) { @@ -170,10 +171,11 @@ object Recipes { // Register all unknown recipes. Well. Loot disk recipes. if (recipes.hasPath("lootDisks")) try { val lootRecipes = recipes.getConfigList("lootDisks") + val lootStacks = Loot.globalDisks.map(_._1) for (recipe <- lootRecipes) { val name = recipe.getString("name") - Loot.globalDisks.get(name) match { - case Some((stack, _)) => addRecipe(stack, recipe, s"loot disk '$name'") + lootStacks.find(s => s.getTagCompound.getString(Settings.namespace + "lootFactory") == name) match { + case Some(stack) => addRecipe(stack, recipe, s"loot disk '$name'") case _ => OpenComputers.log.warn(s"Failed adding recipe for loot disk '$name': No such global loot disk.") hadErrors = true @@ -205,16 +207,21 @@ object Recipes { } // Recrafting operations. - val navigationUpgrade = api.Items.get(Constants.ItemName.NavigationUpgrade) - val mcu = api.Items.get(Constants.BlockName.Microcontroller) - val floppy = api.Items.get(Constants.ItemName.Floppy) - val drone = api.Items.get(Constants.ItemName.Drone) - val eeprom = api.Items.get(Constants.ItemName.EEPROM) - val robot = api.Items.get(Constants.BlockName.Robot) - val tablet = api.Items.get(Constants.ItemName.Tablet) + val accessPoint = api.Items.get(Constants.BlockName.AccessPoint) + val cable = api.Items.get(Constants.BlockName.Cable) val chamelium = api.Items.get(Constants.ItemName.Chamelium) val chameliumBlock = api.Items.get(Constants.BlockName.ChameliumBlock) + val drone = api.Items.get(Constants.ItemName.Drone) + val eeprom = api.Items.get(Constants.ItemName.EEPROM) + val floppy = api.Items.get(Constants.ItemName.Floppy) + val hoverBoots = api.Items.get(Constants.ItemName.HoverBoots) + val mcu = api.Items.get(Constants.BlockName.Microcontroller) + val navigationUpgrade = api.Items.get(Constants.ItemName.NavigationUpgrade) val print = api.Items.get(Constants.BlockName.Print) + val relay = api.Items.get(Constants.BlockName.Relay) + val robot = api.Items.get(Constants.BlockName.Robot) + val switch = api.Items.get(Constants.BlockName.Switch) + val tablet = api.Items.get(Constants.ItemName.Tablet) // Navigation upgrade recrafting. GameRegistry.addRecipe(new ExtendedShapelessOreRecipe( @@ -331,18 +338,21 @@ object Recipes { print.createItemStack(1), new ItemStack(net.minecraft.init.Blocks.glowstone))) // Switch/AccessPoint -> Relay conversion - GameRegistry.addShapelessRecipe(api.Items.get(Constants.BlockName.Relay).createItemStack(1), - api.Items.get(Constants.BlockName.AccessPoint).createItemStack(1)) - GameRegistry.addShapelessRecipe(api.Items.get(Constants.BlockName.Relay).createItemStack(1), - api.Items.get(Constants.BlockName.Switch).createItemStack(1)) + GameRegistry.addShapelessRecipe(relay.createItemStack(1), accessPoint.createItemStack(1)) + GameRegistry.addShapelessRecipe(relay.createItemStack(1), switch.createItemStack(1)) // Hover Boot dyeing - GameRegistry.addRecipe(new ColorizeRecipe(api.Items.get(Constants.ItemName.HoverBoots).item())) - GameRegistry.addRecipe(new DecolorizeRecipe(api.Items.get(Constants.ItemName.HoverBoots).item())) + GameRegistry.addRecipe(new ColorizeRecipe(hoverBoots.item())) + GameRegistry.addRecipe(new DecolorizeRecipe(hoverBoots.item())) // Cable dyeing - GameRegistry.addRecipe(new ColorizeRecipe(api.Items.get(Constants.BlockName.Cable).block())) - GameRegistry.addRecipe(new DecolorizeRecipe(api.Items.get(Constants.BlockName.Cable).block())) + GameRegistry.addRecipe(new ColorizeRecipe(cable.block())) + GameRegistry.addRecipe(new DecolorizeRecipe(cable.block())) + + // Loot disk cycling. + if (Settings.get.lootRecrafting) { + GameRegistry.addRecipe(new LootDiskCyclingRecipe()) + } } catch { case e: Throwable => OpenComputers.log.error("Error parsing recipes, you may not be able to craft any items from this mod!", e) diff --git a/src/main/scala/li/cil/oc/common/template/TabletTemplate.scala b/src/main/scala/li/cil/oc/common/template/TabletTemplate.scala index 1ab9b3820..457c89c61 100644 --- a/src/main/scala/li/cil/oc/common/template/TabletTemplate.scala +++ b/src/main/scala/li/cil/oc/common/template/TabletTemplate.scala @@ -57,9 +57,9 @@ object TabletTemplate extends Template { def disassemble(stack: ItemStack, ingredients: Array[ItemStack]) = { val info = new TabletData(stack) val itemName = Constants.ItemName.TabletCase(info.tier) - Array(api.Items.get(itemName).createItemStack(1)) ++ info.items.collect { + (Array(api.Items.get(itemName).createItemStack(1), info.container.orNull) ++ info.items.collect { case Some(item) => item - }.drop(1) // Screen. + }.drop(1) /* Screen */).filter(_ != null) } def register() { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Adapter.scala b/src/main/scala/li/cil/oc/common/tileentity/Adapter.scala index 73740bf41..9dec385c9 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Adapter.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Adapter.scala @@ -1,8 +1,14 @@ package li.cil.oc.common.tileentity +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.Driver +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal import li.cil.oc.api.network.Analyzable import li.cil.oc.api.network._ @@ -14,9 +20,10 @@ import net.minecraft.nbt.NBTTagList import net.minecraft.util.EnumFacing import net.minecraftforge.common.util.Constants.NBT +import scala.collection.convert.WrapAsJava._ import scala.collection.mutable -class Adapter extends traits.Environment with traits.ComponentInventory with Analyzable with internal.Adapter { +class Adapter extends traits.Environment with traits.ComponentInventory with traits.Tickable with Analyzable with internal.Adapter with DeviceInfo { val node = api.Network.newNode(this, Visibility.Network).create() private val blocks = Array.fill[Option[(ManagedEnvironment, api.driver.SidedBlock)]](6)(None) @@ -25,6 +32,15 @@ class Adapter extends traits.Environment with traits.ComponentInventory with Ana private val blocksData = Array.fill[Option[BlockData]](6)(None) + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Bus, + DeviceAttribute.Description -> "Adapter", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Multiplug Ext.1" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // override def onAnalyze(player: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float) = blocks collect { @@ -33,11 +49,9 @@ class Adapter extends traits.Environment with traits.ComponentInventory with Ana // ----------------------------------------------------------------------- // - override def canUpdate = isServer - override def updateEntity() { super.updateEntity() - if (updatingBlocks.nonEmpty) { + if (isServer && updatingBlocks.nonEmpty) { for (block <- updatingBlocks) { block.update() } @@ -151,11 +165,11 @@ class Adapter extends traits.Environment with traits.ComponentInventory with Ana map(blocksNbt.getCompoundTagAt). zipWithIndex. foreach { - case (blockNbt, i) => - if (blockNbt.hasKey("name") && blockNbt.hasKey("data")) { - blocksData(i) = Some(new BlockData(blockNbt.getString("name"), blockNbt.getCompoundTag("data"))) - } - } + case (blockNbt, i) => + if (blockNbt.hasKey("name") && blockNbt.hasKey("data")) { + blocksData(i) = Some(new BlockData(blockNbt.getString("name"), blockNbt.getCompoundTag("data"))) + } + } } override def writeToNBTForServer(nbt: NBTTagCompound) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Assembler.scala b/src/main/scala/li/cil/oc/common/tileentity/Assembler.scala index 65cf13549..765c978bd 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Assembler.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Assembler.scala @@ -2,8 +2,12 @@ package li.cil.oc.common.tileentity import java.util +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -17,7 +21,9 @@ import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -class Assembler extends traits.Environment with traits.PowerAcceptor with traits.Inventory with SidedEnvironment with traits.StateAware { +import scala.collection.convert.WrapAsJava._ + +class Assembler extends traits.Environment with traits.PowerAcceptor with traits.Inventory with SidedEnvironment with traits.StateAware with traits.Tickable with DeviceInfo { val node = api.Network.newNode(this, Visibility.Network). withComponent("assembler"). withConnector(Settings.get.bufferConverter). @@ -29,6 +35,15 @@ class Assembler extends traits.Environment with traits.PowerAcceptor with traits var requiredEnergy = 0.0 + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Assembler", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Factorizer R1D1" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @SideOnly(Side.CLIENT) @@ -106,8 +121,6 @@ class Assembler extends traits.Environment with traits.PowerAcceptor with traits // ----------------------------------------------------------------------- // - override def canUpdate = isServer - override def updateEntity() { super.updateEntity() if (output.isDefined && world.getTotalWorldTime % Settings.get.tickFrequency == 0) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Cable.scala b/src/main/scala/li/cil/oc/common/tileentity/Cable.scala index 022f4b053..7c2596260 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Cable.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Cable.scala @@ -40,7 +40,5 @@ class Cable extends traits.Environment with traits.NotAnalyzable with traits.Imm } } - override def canUpdate = false - override def getRenderBoundingBox = common.block.Cable.bounds(world, getPos).offset(x, y, z) } diff --git a/src/main/scala/li/cil/oc/common/tileentity/Capacitor.scala b/src/main/scala/li/cil/oc/common/tileentity/Capacitor.scala index 93236c49c..06a2f8dde 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Capacitor.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Capacitor.scala @@ -1,21 +1,37 @@ package li.cil.oc.common.tileentity +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.Node import li.cil.oc.api.network.Visibility import net.minecraft.util.EnumFacing -class Capacitor extends traits.Environment { +import scala.collection.convert.WrapAsJava._ + +class Capacitor extends traits.Environment with DeviceInfo { // Start with maximum theoretical capacity, gets reduced after validation. // This is done so that we don't lose energy while loading. val node = api.Network.newNode(this, Visibility.Network). withConnector(maxCapacity). create() - // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Power, + DeviceAttribute.Description -> "Battery", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "CapBank3x", + DeviceAttribute.Capacity -> maxCapacity.toString + ) - override def canUpdate = false + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // override def dispose() { super.dispose() diff --git a/src/main/scala/li/cil/oc/common/tileentity/Case.scala b/src/main/scala/li/cil/oc/common/tileentity/Case.scala index 8b440c30b..b0d0dc84d 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Case.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Case.scala @@ -1,7 +1,13 @@ package li.cil.oc.common.tileentity +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Driver +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal import li.cil.oc.api.network.Connector import li.cil.oc.common @@ -17,7 +23,9 @@ import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with traits.Colored with internal.Case { +import scala.collection.convert.WrapAsJava._ + +class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with traits.Colored with internal.Case with DeviceInfo { def this() = this(0) // Used on client side to check whether to render disk activity/network indicators. @@ -26,6 +34,18 @@ class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with setColor(Color.rgbValues(Color.byTier(tier))) + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.System, + DeviceAttribute.Description -> "Computer", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Blocker", + DeviceAttribute.Capacity -> getSizeInventory.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @SideOnly(Side.CLIENT) override protected def hasConnector(side: EnumFacing) = side != facing @@ -33,7 +53,6 @@ class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with override def energyThroughput = Settings.get.caseRate(tier) - def isCreative = tier == Tier.Four // ----------------------------------------------------------------------- // @@ -42,8 +61,6 @@ class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with // ----------------------------------------------------------------------- // - override def canUpdate = isServer - override def updateEntity() { if (isServer && isCreative && world.getTotalWorldTime % Settings.get.tickFrequency == 0) { // Creative case, make it generate power. diff --git a/src/main/scala/li/cil/oc/common/tileentity/Charger.scala b/src/main/scala/li/cil/oc/common/tileentity/Charger.scala index df74e40f0..59b17274d 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Charger.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Charger.scala @@ -2,10 +2,14 @@ package li.cil.oc.common.tileentity import java.util +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Localization import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.Driver +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.nanomachines.Controller import li.cil.oc.api.network._ import li.cil.oc.common.Slot @@ -23,10 +27,11 @@ import net.minecraft.util.Vec3 import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ import scala.collection.mutable -class Charger extends traits.Environment with traits.PowerAcceptor with traits.RedstoneAware with traits.Rotatable with traits.ComponentInventory with Analyzable with traits.StateAware { +class Charger extends traits.Environment with traits.PowerAcceptor with traits.RedstoneAware with traits.Rotatable with traits.ComponentInventory with traits.Tickable with Analyzable with traits.StateAware with DeviceInfo { val node = api.Network.newNode(this, Visibility.None). withConnector(Settings.get.bufferConverter). create() @@ -39,6 +44,15 @@ class Charger extends traits.Environment with traits.PowerAcceptor with traits.R var invertSignal = false + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Charger", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "PowerUpper" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @SideOnly(Side.CLIENT) @@ -64,8 +78,6 @@ class Charger extends traits.Environment with traits.PowerAcceptor with traits.R // ----------------------------------------------------------------------- // - override def canUpdate = true - override def updateEntity() { super.updateEntity() diff --git a/src/main/scala/li/cil/oc/common/tileentity/Disassembler.scala b/src/main/scala/li/cil/oc/common/tileentity/Disassembler.scala index 6c9623570..79624b9b4 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Disassembler.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Disassembler.scala @@ -2,8 +2,12 @@ package li.cil.oc.common.tileentity import java.util +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.Visibility import li.cil.oc.common.template.DisassemblerTemplates import li.cil.oc.server.{PacketSender => ServerPacketSender} @@ -19,9 +23,10 @@ import net.minecraftforge.common.util.Constants.NBT import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import scala.collection.convert.WrapAsJava._ import scala.collection.mutable -class Disassembler extends traits.Environment with traits.PowerAcceptor with traits.Inventory with traits.StateAware with traits.PlayerInputAware { +class Disassembler extends traits.Environment with traits.PowerAcceptor with traits.Inventory with traits.StateAware with traits.PlayerInputAware with traits.Tickable with DeviceInfo { val node = api.Network.newNode(this, Visibility.None). withConnector(Settings.get.bufferConverter). create() @@ -44,6 +49,15 @@ class Disassembler extends traits.Environment with traits.PowerAcceptor with tra world.notifyNeighborsOfStateChange(getPos, getBlockType) } + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Disassembler", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Break.3R-100" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @SideOnly(Side.CLIENT) @@ -61,11 +75,9 @@ class Disassembler extends traits.Environment with traits.PowerAcceptor with tra // ----------------------------------------------------------------------- // - override def canUpdate = isServer - override def updateEntity() { super.updateEntity() - if (world.getTotalWorldTime % Settings.get.tickFrequency == 0) { + if (isServer && world.getTotalWorldTime % Settings.get.tickFrequency == 0) { if (queue.isEmpty) { val instant = disassembleNextInstantly // Is reset via decrStackSize disassemble(decrStackSize(0, 1), instant) diff --git a/src/main/scala/li/cil/oc/common/tileentity/DiskDrive.scala b/src/main/scala/li/cil/oc/common/tileentity/DiskDrive.scala index 7a15a352e..f7bcfb4d3 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/DiskDrive.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/DiskDrive.scala @@ -1,7 +1,13 @@ package li.cil.oc.common.tileentity +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.api import li.cil.oc.api.Driver +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -21,7 +27,9 @@ import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -class DiskDrive extends traits.Environment with traits.ComponentInventory with traits.Rotatable with Analyzable { +import scala.collection.convert.WrapAsJava._ + +class DiskDrive extends traits.Environment with traits.ComponentInventory with traits.Rotatable with Analyzable with DeviceInfo { // Used on client side to check whether to render disk activity indicators. var lastAccess = 0L @@ -30,6 +38,15 @@ class DiskDrive extends traits.Environment with traits.ComponentInventory with t case _ => None } + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Disk, + DeviceAttribute.Description -> "Floppy disk drive", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Spinner 520p1" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // // Environment @@ -102,8 +119,6 @@ class DiskDrive extends traits.Environment with traits.ComponentInventory with t // ----------------------------------------------------------------------- // // TileEntity - override def canUpdate = false - @SideOnly(Side.CLIENT) override def readFromNBTForClient(nbt: NBTTagCompound) { super.readFromNBTForClient(nbt) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Geolyzer.scala b/src/main/scala/li/cil/oc/common/tileentity/Geolyzer.scala index ff2c8aeba..f5e8e9bb8 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Geolyzer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Geolyzer.scala @@ -8,8 +8,6 @@ class Geolyzer extends traits.Environment { def node = geolyzer.node - override def canUpdate = false - override def readFromNBTForServer(nbt: NBTTagCompound) { super.readFromNBTForServer(nbt) geolyzer.load(nbt) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala b/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala index 36028eb0b..74f48e081 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala @@ -1,7 +1,11 @@ package li.cil.oc.common.tileentity -import li.cil.oc.Settings -import li.cil.oc.api +import java.util + +import li.cil.oc._ +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -18,9 +22,10 @@ import net.minecraft.util.Vec3 import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import scala.collection.convert.WrapAsJava._ import scala.collection.mutable -class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment with Analyzable with traits.Rotatable { +class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment with Analyzable with traits.Rotatable with traits.Tickable with DeviceInfo { def this() = this(0) val node = api.Network.newNode(this, Visibility.Network). @@ -32,6 +37,19 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w final val height = 2 * 16 // 32 bit in an int + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Display, + DeviceAttribute.Description -> "Holographic projector", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> ("VirtualViewer H1-" + (tier + 1).toString), + DeviceAttribute.Capacity -> (width * width * height).toString, + DeviceAttribute.Width -> colors.length.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + // Layout is: first half is lower bit, second half is higher bit for the // voxels in the cube. This is to retain compatibility with pre 1.3 saves. val volume = new Array[Int](width * width * 2) @@ -367,8 +385,6 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w // ----------------------------------------------------------------------- // - override def canUpdate = isServer - override def updateEntity() { super.updateEntity() if (isServer) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Keyboard.scala b/src/main/scala/li/cil/oc/common/tileentity/Keyboard.scala index a3a05d1fd..4b8053490 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Keyboard.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Keyboard.scala @@ -37,8 +37,6 @@ class Keyboard extends traits.Environment with traits.Rotatable with traits.Immi // ----------------------------------------------------------------------- // - override def canUpdate = false - override def readFromNBTForServer(nbt: NBTTagCompound) { super.readFromNBTForServer(nbt) if (isServer) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala b/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala index 7a08eb146..17ae6fbef 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala @@ -1,8 +1,13 @@ package li.cil.oc.common.tileentity +import java.util + import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback @@ -22,7 +27,7 @@ import net.minecraftforge.fml.relauncher.SideOnly import scala.collection.convert.WrapAsJava._ -class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.Computer with internal.Microcontroller { +class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.Computer with internal.Microcontroller with DeviceInfo { val info = new MicrocontrollerData() override def node = null @@ -47,6 +52,16 @@ class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.C override protected def runSound = None // Microcontrollers are silent. + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.System, + DeviceAttribute.Description -> "Microcontroller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Cubicle", + DeviceAttribute.Capacity -> getSizeInventory.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @SideOnly(Side.CLIENT) @@ -111,13 +126,11 @@ class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.C // ----------------------------------------------------------------------- // - override def canUpdate = isServer - override def updateEntity() { super.updateEntity() // Pump energy into the internal network. - if (world.getTotalWorldTime % Settings.get.tickFrequency == 0) { + if (isServer && world.getTotalWorldTime % Settings.get.tickFrequency == 0) { for (side <- EnumFacing.values if side != facing) { sidedNode(side) match { case connector: Connector => diff --git a/src/main/scala/li/cil/oc/common/tileentity/MotionSensor.scala b/src/main/scala/li/cil/oc/common/tileentity/MotionSensor.scala index c30fcc629..c238ca2a5 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/MotionSensor.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/MotionSensor.scala @@ -1,7 +1,13 @@ package li.cil.oc.common.tileentity +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -12,10 +18,11 @@ import net.minecraft.potion.Potion import net.minecraft.util.AxisAlignedBB import net.minecraft.util.Vec3 +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ import scala.collection.mutable -class MotionSensor extends traits.Environment { +class MotionSensor extends traits.Environment with traits.Tickable with DeviceInfo { val node = api.Network.newNode(this, Visibility.Network). withComponent("motion_sensor"). withConnector(). @@ -27,18 +34,25 @@ class MotionSensor extends traits.Environment { private val trackedEntities = mutable.Map.empty[EntityLivingBase, (Double, Double, Double)] - // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Motion sensor", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Blinker M1K0", + DeviceAttribute.Capacity -> radius.toString + ) - override def canUpdate = isServer + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // override def updateEntity() { super.updateEntity() - if (world.getTotalWorldTime % 10 == 0) { + if (isServer && world.getTotalWorldTime % 10 == 0) { // Get a list of all living entities we could possibly detect, using a rough // bounding box check, then refining it using the actual distance and an // actual visibility check. val entities = world.getEntitiesWithinAABB(classOf[EntityLivingBase], sensorBounds) - .map(_.asInstanceOf[EntityLivingBase]) .filter(entity => entity.isEntityAlive && isInRange(entity) && isVisible(entity)) .toSet // Get rid of all tracked entities that are no longer visible. diff --git a/src/main/scala/li/cil/oc/common/tileentity/NetSplitter.scala b/src/main/scala/li/cil/oc/common/tileentity/NetSplitter.scala index ae3ed49f3..e097d50cc 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/NetSplitter.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/NetSplitter.scala @@ -54,8 +54,6 @@ class NetSplitter extends traits.Environment with traits.RedstoneAware with api. // ----------------------------------------------------------------------- // - override def canUpdate = false - override protected def initialize(): Unit = { super.initialize() EventHandler.scheduleServer(this) diff --git a/src/main/scala/li/cil/oc/common/tileentity/PowerConverter.scala b/src/main/scala/li/cil/oc/common/tileentity/PowerConverter.scala index ecb375fe6..cf6ad933b 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/PowerConverter.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/PowerConverter.scala @@ -1,23 +1,39 @@ package li.cil.oc.common.tileentity +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network._ import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -class PowerConverter extends traits.PowerAcceptor with traits.Environment with traits.NotAnalyzable { +import scala.collection.convert.WrapAsJava._ + +class PowerConverter extends traits.PowerAcceptor with traits.Environment with traits.NotAnalyzable with DeviceInfo { val node = api.Network.newNode(this, Visibility.None). withConnector(Settings.get.bufferConverter). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Power, + DeviceAttribute.Description -> "Power converter", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Transgizer-PX5", + DeviceAttribute.Capacity -> energyThroughput.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + @SideOnly(Side.CLIENT) override protected def hasConnector(side: EnumFacing) = true override protected def connector(side: EnumFacing) = Option(node) override def energyThroughput = Settings.get.powerConverterRate - - override def canUpdate = isServer } diff --git a/src/main/scala/li/cil/oc/common/tileentity/PowerDistributor.scala b/src/main/scala/li/cil/oc/common/tileentity/PowerDistributor.scala index e6439a904..f30e7e345 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/PowerDistributor.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/PowerDistributor.scala @@ -19,8 +19,6 @@ class PowerDistributor extends traits.Environment with traits.PowerBalancer with override protected def isConnected = nodes.exists(node => node.address != null && node.network != null) - override def canUpdate = isServer - // ----------------------------------------------------------------------- // @SideOnly(Side.CLIENT) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Print.scala b/src/main/scala/li/cil/oc/common/tileentity/Print.scala index c527b6521..eeba5768e 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Print.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Print.scala @@ -139,8 +139,6 @@ class Print(val canToggle: Option[() => Boolean], val scheduleUpdate: Option[Int } } - override def canUpdate = false - override protected def onRedstoneInputChanged(side: EnumFacing, oldMaxValue: Int, newMaxValue: Int): Unit = { super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue) val newState = newMaxValue > 0 diff --git a/src/main/scala/li/cil/oc/common/tileentity/Printer.scala b/src/main/scala/li/cil/oc/common/tileentity/Printer.scala index dc130f321..48bf685d2 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Printer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Printer.scala @@ -2,8 +2,12 @@ package li.cil.oc.common.tileentity import java.util +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -19,7 +23,9 @@ import net.minecraft.util.EnumFacing import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -class Printer extends traits.Environment with traits.Inventory with traits.Rotatable with SidedEnvironment with traits.StateAware with ISidedInventory { +import scala.collection.convert.WrapAsJava._ + +class Printer extends traits.Environment with traits.Inventory with traits.Rotatable with SidedEnvironment with traits.StateAware with traits.Tickable with ISidedInventory with DeviceInfo { val node = api.Network.newNode(this, Visibility.Network). withComponent("printer3d"). withConnector(Settings.get.bufferConverter). @@ -41,6 +47,15 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat val slotInk = 1 val slotOutput = 2 + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Printer, + DeviceAttribute.Description -> "3D Printer", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Omni-Materializer T6.1" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @SideOnly(Side.CLIENT) @@ -209,11 +224,13 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat // ----------------------------------------------------------------------- // - override def canUpdate = isServer - - override def updateEntity() { + override def updateEntity(): Unit = { super.updateEntity() + if (isClient) { + return + } + def canMergeOutput = { val presentStack = getStackInSlot(slotOutput) val outputStack = data.createItemStack() diff --git a/src/main/scala/li/cil/oc/common/tileentity/Rack.scala b/src/main/scala/li/cil/oc/common/tileentity/Rack.scala index a69ecafc4..0097dbcb0 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Rack.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Rack.scala @@ -19,15 +19,15 @@ import li.cil.oc.integration.opencomputers.DriverRedstoneCard import li.cil.oc.server.{PacketSender => ServerPacketSender} import li.cil.oc.util.ExtendedInventory._ import li.cil.oc.util.ExtendedNBT._ -import _root_.net.minecraft.entity.player.EntityPlayer -import _root_.net.minecraft.inventory.IInventory -import _root_.net.minecraft.item.ItemStack -import _root_.net.minecraft.nbt.NBTTagCompound -import _root_.net.minecraft.nbt.NBTTagIntArray -import _root_.net.minecraft.util.EnumFacing -import _root_.net.minecraftforge.common.util.Constants.NBT -import _root_.net.minecraftforge.fml.relauncher.Side -import _root_.net.minecraftforge.fml.relauncher.SideOnly +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.inventory.IInventory +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NBTTagCompound +import net.minecraft.nbt.NBTTagIntArray +import net.minecraft.util.EnumFacing +import net.minecraftforge.common.util.Constants.NBT +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalancer with traits.ComponentInventory with traits.Rotatable with traits.BundledRedstoneAware with Analyzable with internal.Rack with traits.StateAware { var isRelayEnabled = true diff --git a/src/main/scala/li/cil/oc/common/tileentity/Raid.scala b/src/main/scala/li/cil/oc/common/tileentity/Raid.scala index cc86452c1..26a9aed21 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Raid.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Raid.scala @@ -36,8 +36,6 @@ class Raid extends traits.Environment with traits.Inventory with traits.Rotatabl override def onAnalyze(player: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float) = Array(filesystem.map(_.node).orNull) - override def canUpdate = false - // ----------------------------------------------------------------------- // override def getSizeInventory = 3 diff --git a/src/main/scala/li/cil/oc/common/tileentity/Redstone.scala b/src/main/scala/li/cil/oc/common/tileentity/Redstone.scala index 8101e61ef..aae0cb7b5 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Redstone.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Redstone.scala @@ -9,7 +9,7 @@ import li.cil.oc.util.ExtendedNBT._ import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.EnumFacing -class Redstone extends traits.Environment with traits.BundledRedstoneAware { +class Redstone extends traits.Environment with traits.BundledRedstoneAware with traits.Tickable { val instance = if (BundledRedstone.isAvailable) new component.Redstone.Bundled(this) @@ -24,8 +24,6 @@ class Redstone extends traits.Environment with traits.BundledRedstoneAware { } else null - override def canUpdate = isServer - // ----------------------------------------------------------------------- // override def readFromNBTForServer(nbt: NBTTagCompound) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Relay.scala b/src/main/scala/li/cil/oc/common/tileentity/Relay.scala index e0bd75f8e..17392445e 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Relay.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Relay.scala @@ -50,8 +50,6 @@ class Relay extends traits.SwitchLike with traits.ComponentInventory with traits withComponent("relay"). create()) - override def canUpdate = isServer - // ----------------------------------------------------------------------- // @SideOnly(Side.CLIENT) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Screen.scala b/src/main/scala/li/cil/oc/common/tileentity/Screen.scala index 0b0befaac..45f7d3d00 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Screen.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Screen.scala @@ -178,8 +178,6 @@ class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with // ----------------------------------------------------------------------- // - override def canUpdate = true - override def updateEntity() { super.updateEntity() if (shouldCheckForMultiBlock && ((isClient && isClientReadyForMultiBlockCheck) || (isServer && isConnected))) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Switch.scala b/src/main/scala/li/cil/oc/common/tileentity/Switch.scala index 2069df42d..59f7ac4ca 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Switch.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Switch.scala @@ -17,8 +17,6 @@ class Switch extends traits.SwitchLike with traits.NotAnalyzable with traits.Com override def isLinkedEnabled = false - override def canUpdate = isServer - // ----------------------------------------------------------------------- // protected def queueMessage(source: String, destination: String, port: Int, answerPort: Int, args: Array[AnyRef]) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Transposer.scala b/src/main/scala/li/cil/oc/common/tileentity/Transposer.scala index 4860a866f..78a7fc8e9 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Transposer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Transposer.scala @@ -11,8 +11,6 @@ class Transposer extends traits.Environment { // Used on client side to check whether to render activity indicators. var lastOperation = 0L - override def canUpdate = false - override def readFromNBTForServer(nbt: NBTTagCompound) { super.readFromNBTForServer(nbt) transposer.load(nbt) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Waypoint.scala b/src/main/scala/li/cil/oc/common/tileentity/Waypoint.scala index 0c9f9c820..a136c2243 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Waypoint.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Waypoint.scala @@ -13,7 +13,7 @@ import net.minecraft.util.EnumParticleTypes import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -class Waypoint extends traits.Environment with traits.Rotatable with traits.RedstoneAware { +class Waypoint extends traits.Environment with traits.Rotatable with traits.RedstoneAware with traits.Tickable { val node = api.Network.newNode(this, Visibility.Network). withComponent("waypoint"). create() diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/ComponentInventory.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/ComponentInventory.scala index f7cfbe60a..e4fa049bc 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/ComponentInventory.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/ComponentInventory.scala @@ -8,6 +8,9 @@ import li.cil.oc.common.inventory import li.cil.oc.util.ExtendedInventory._ import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound +import net.minecraft.util.EnumFacing +import net.minecraftforge.common.capabilities.Capability +import net.minecraftforge.common.capabilities.ICapabilityProvider import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly @@ -120,6 +123,20 @@ trait ComponentInventory extends Environment with Inventory with inventory.Compo // ----------------------------------------------------------------------- // + override protected def initialize(): Unit = { + super.initialize() + if (isClient) { + connectComponents() + } + } + + override def dispose(): Unit = { + super.dispose() + if (isClient) { + disconnectComponents() + } + } + override def onConnect(node: Node) { super.onConnect(node) if (node == this.node) { @@ -134,6 +151,27 @@ trait ComponentInventory extends Environment with Inventory with inventory.Compo } } + override def hasCapability(capability: Capability[_], facing: EnumFacing): Boolean = { + val localFacing = this match { + case rotatable: Rotatable => rotatable.toLocal(facing) + case _ => facing + } + super.hasCapability(capability, facing) || components.exists { + case Some(component: ICapabilityProvider) => component.hasCapability(capability, localFacing) + case _ => false + } + } + + override def getCapability[T](capability: Capability[T], facing: EnumFacing): T = { + val localFacing = this match { + case rotatable: Rotatable => rotatable.toLocal(facing) + case _ => facing + } + Option(super.getCapability(capability, facing)).orElse(components.collectFirst { + case Some(component: ICapabilityProvider) if component.hasCapability(capability, localFacing) => component.getCapability(capability, localFacing) + }).getOrElse(null.asInstanceOf[T]) + } + override def writeToNBTForClient(nbt: NBTTagCompound) { connectComponents() super.writeToNBTForClient(nbt) @@ -144,5 +182,6 @@ trait ComponentInventory extends Environment with Inventory with inventory.Compo override def readFromNBTForClient(nbt: NBTTagCompound) { super.readFromNBTForClient(nbt) load(nbt) + connectComponents() } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala index ee79e08f2..3e8feef8e 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Computer.scala @@ -24,7 +24,7 @@ import net.minecraftforge.fml.relauncher.SideOnly import scala.collection.convert.WrapAsJava._ import scala.collection.mutable -trait Computer extends Environment with ComponentInventory with Rotatable with BundledRedstoneAware with api.network.Analyzable with api.machine.MachineHost with StateAware { +trait Computer extends Environment with ComponentInventory with Rotatable with BundledRedstoneAware with api.network.Analyzable with api.machine.MachineHost with StateAware with Tickable { private lazy val _machine = if (isServer) api.Machine.create(this) else null def machine = _machine diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Environment.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Environment.scala index 9aa550d30..6d75c3463 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Environment.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Environment.scala @@ -25,7 +25,7 @@ trait Environment extends TileEntity with network.Environment with network.Envir override def zPosition = z + 0.5 - override def markChanged() = if (canUpdate) isChangeScheduled = true else world.markChunkDirty(getPos, this) + override def markChanged() = if (this.isInstanceOf[Tickable]) isChangeScheduled = true else world.markChunkDirty(getPos, this) protected def isConnected = node.address != null && node.network != null diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala index 5659d43d7..f069138fd 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Hub.scala @@ -14,7 +14,7 @@ import net.minecraftforge.fml.relauncher.SideOnly import scala.collection.mutable -trait Hub extends traits.Environment with SidedEnvironment { +trait Hub extends traits.Environment with SidedEnvironment with Tickable { override def node: Node = null override protected def isConnected = plugs.exists(plug => plug.node.address != null && plug.node.network != null) diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/PowerBalancer.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/PowerBalancer.scala index 070d5b215..debe38bae 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/PowerBalancer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/PowerBalancer.scala @@ -5,7 +5,7 @@ import li.cil.oc.api.network.Connector import li.cil.oc.api.network.SidedEnvironment import net.minecraft.util.EnumFacing -trait PowerBalancer extends PowerInformation with SidedEnvironment { +trait PowerBalancer extends PowerInformation with SidedEnvironment with Tickable { var globalBuffer, globalBufferSize = 0.0 protected def isConnected: Boolean diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/RedstoneAware.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/RedstoneAware.scala index a660c00d2..7dc091082 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/RedstoneAware.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/RedstoneAware.scala @@ -69,7 +69,11 @@ trait RedstoneAware extends RotationAware /* with IConnectable with IRedstoneEmi } def checkRedstoneInputChanged() { - shouldUpdateInput = isServer + if (this.isInstanceOf[Tickable]) { + shouldUpdateInput = isServer + } else { + EnumFacing.values().foreach(updateRedstoneInput) + } } // ----------------------------------------------------------------------- // @@ -86,7 +90,7 @@ trait RedstoneAware extends RotationAware /* with IConnectable with IRedstoneEmi override def validate(): Unit = { super.validate() - if (!canUpdate) { + if (!this.isInstanceOf[Tickable]) { EventHandler.scheduleServer(() => EnumFacing.values().foreach(updateRedstoneInput)) } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala index b887ce3e2..233a0f991 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala @@ -122,6 +122,7 @@ trait Rotatable extends RotationAware with internal.Rotatable { def setState(newState: IBlockState): Boolean = { if (oldState.hashCode() != newState.hashCode()) { world.setBlockState(getPos, newState) + updateTranslation() true } else false diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/TextBuffer.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/TextBuffer.scala index 1e1181562..ffcb64e49 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/TextBuffer.scala @@ -7,7 +7,7 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -trait TextBuffer extends Environment { +trait TextBuffer extends Environment with Tickable { lazy val buffer = { val screenItem = api.Items.get(Constants.BlockName.ScreenTier1).createItemStack(1) val buffer = api.Driver.driverFor(screenItem, getClass).createEnvironment(screenItem, this).asInstanceOf[api.internal.TextBuffer] diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Tickable.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Tickable.scala new file mode 100644 index 000000000..9632cb67e --- /dev/null +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Tickable.scala @@ -0,0 +1,7 @@ +package li.cil.oc.common.tileentity.traits + +import net.minecraft.util.ITickable + +trait Tickable extends TileEntity with ITickable { + override def update(): Unit = updateEntity() +} diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/TileEntity.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/TileEntity.scala index 8d5e8eb8f..4a901513f 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/TileEntity.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/TileEntity.scala @@ -16,8 +16,7 @@ import net.minecraft.world.World import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly -// TODO only implement ticking interface where needed. -trait TileEntity extends net.minecraft.tileentity.TileEntity with ITickable { +trait TileEntity extends net.minecraft.tileentity.TileEntity { def world = getWorld def x = getPos.getX @@ -34,12 +33,6 @@ trait TileEntity extends net.minecraft.tileentity.TileEntity with ITickable { // ----------------------------------------------------------------------- // - def canUpdate = true - - override def update(): Unit = { - if (canUpdate) updateEntity() - } - def updateEntity() { if (Settings.get.periodicallyForceLightUpdate && world.getTotalWorldTime % 40 == 0 && getBlockType.getLightValue(world, getPos) > 0) { world.markBlockForUpdate(getPos) diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Experimental.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Experimental.scala index 0ef26dd21..4cf3b591d 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Experimental.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Experimental.scala @@ -5,6 +5,7 @@ import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.common.EventHandler import li.cil.oc.common.asm.Injectable +import li.cil.oc.common.tileentity.traits import li.cil.oc.integration.Mods import li.cil.oc.integration.util.Power import net.minecraft.nbt.NBTTagCompound @@ -14,7 +15,7 @@ import net.minecraftforge.fml.common.Optional import net.minecraftforge.fml.common.eventhandler.Event @Injectable.Interface(value = "ic2.api.energy.tile.IEnergySink", modid = Mods.IDs.IndustrialCraft2) -trait IndustrialCraft2Experimental extends Common with IndustrialCraft2Common { +trait IndustrialCraft2Experimental extends Common with IndustrialCraft2Common with traits.Tickable { private var conversionBuffer = 0.0 private lazy val useIndustrialCraft2Power = isServer && Mods.IndustrialCraft2.isAvailable diff --git a/src/main/scala/li/cil/oc/integration/buildcraft/recipes/LootDiskProgrammableRecipe.scala b/src/main/scala/li/cil/oc/integration/buildcraft/recipes/LootDiskProgrammableRecipe.scala index 4af8c2c39..137802cc3 100644 --- a/src/main/scala/li/cil/oc/integration/buildcraft/recipes/LootDiskProgrammableRecipe.scala +++ b/src/main/scala/li/cil/oc/integration/buildcraft/recipes/LootDiskProgrammableRecipe.scala @@ -24,7 +24,7 @@ object LootDiskProgrammableRecipe extends IProgrammingRecipe { val options = mutable.ArrayBuffer.empty[ItemStack] options.sizeHint(width * height) - for ((name, (stack, chance)) <- Loot.worldDisks) { + for ((stack, _) <- Loot.worldDisks) { options += stack.copy() } diff --git a/src/main/scala/li/cil/oc/integration/ic2/ElectricItemManager.scala b/src/main/scala/li/cil/oc/integration/ic2/ElectricItemManager.scala index 4b007d1b8..cb0f13511 100644 --- a/src/main/scala/li/cil/oc/integration/ic2/ElectricItemManager.scala +++ b/src/main/scala/li/cil/oc/integration/ic2/ElectricItemManager.scala @@ -40,7 +40,7 @@ object ElectricItemManager extends IElectricItemManager { false // TODO if we ever need it... } - override def getToolTip(stack: ItemStack): String = null + override def getToolTip(stack: ItemStack): String = "" override def getMaxCharge(stack: ItemStack): Double = Option(stack).map(_.getItem) match { case Some(item: IElectricItem) => item.getMaxCharge(stack) diff --git a/src/main/scala/li/cil/oc/integration/jei/ModPluginOpenComputers.scala b/src/main/scala/li/cil/oc/integration/jei/ModPluginOpenComputers.scala index 93e1f0622..6201ac40f 100644 --- a/src/main/scala/li/cil/oc/integration/jei/ModPluginOpenComputers.scala +++ b/src/main/scala/li/cil/oc/integration/jei/ModPluginOpenComputers.scala @@ -1,5 +1,12 @@ package li.cil.oc.integration.jei +import java.util + +import li.cil.oc.Constants +import li.cil.oc.Settings +import li.cil.oc.api +import li.cil.oc.common.Loot +import li.cil.oc.common.recipe.LootDiskCyclingRecipe import li.cil.oc.integration.util.ItemBlacklist import mezz.jei.api.IItemRegistry import mezz.jei.api.IJeiHelpers @@ -8,6 +15,14 @@ import mezz.jei.api.IModPlugin import mezz.jei.api.IModRegistry import mezz.jei.api.IRecipeRegistry import mezz.jei.api.JEIPlugin +import mezz.jei.api.recipe.BlankRecipeWrapper +import mezz.jei.api.recipe.IRecipeHandler +import mezz.jei.api.recipe.IRecipeWrapper +import mezz.jei.api.recipe.VanillaRecipeCategoryUid +import mezz.jei.api.recipe.wrapper.ICraftingRecipeWrapper +import net.minecraft.item.ItemStack + +import scala.collection.convert.WrapAsJava._ @JEIPlugin class ModPluginOpenComputers extends IModPlugin { @@ -19,6 +34,9 @@ class ModPluginOpenComputers extends IModPlugin { } override def register(registry: IModRegistry): Unit = { + if (Settings.get.lootRecrafting) { + registry.addRecipeHandlers(LootDiskCyclingRecipeHandler) + } } override def onRecipeRegistryAvailable(recipeRegistry: IRecipeRegistry): Unit = { @@ -26,4 +44,21 @@ class ModPluginOpenComputers extends IModPlugin { override def onRuntimeAvailable(jeiRuntime: IJeiRuntime): Unit = { } + + object LootDiskCyclingRecipeHandler extends IRecipeHandler[LootDiskCyclingRecipe] { + override def getRecipeClass: Class[LootDiskCyclingRecipe] = classOf[LootDiskCyclingRecipe] + + override def getRecipeCategoryUid: String = VanillaRecipeCategoryUid.CRAFTING + + override def getRecipeWrapper(recipe: LootDiskCyclingRecipe): IRecipeWrapper = new LootDiskCyclingRecipeWrapper(recipe) + + override def isRecipeValid(recipe: LootDiskCyclingRecipe): Boolean = true + } + + class LootDiskCyclingRecipeWrapper(val recipe: LootDiskCyclingRecipe) extends BlankRecipeWrapper with ICraftingRecipeWrapper { + override def getInputs: util.List[_] = List(seqAsJavaList(Loot.worldDisks.map(_._1)), api.Items.get(Constants.ItemName.Wrench).createItemStack(1)) + + override def getOutputs: util.List[ItemStack] = Loot.worldDisks.map(_._1).toList + } + } diff --git a/src/main/scala/li/cil/oc/integration/mcmp/MCMultiPart.scala b/src/main/scala/li/cil/oc/integration/mcmp/MCMultiPart.scala index 00ee92361..613e3e34b 100644 --- a/src/main/scala/li/cil/oc/integration/mcmp/MCMultiPart.scala +++ b/src/main/scala/li/cil/oc/integration/mcmp/MCMultiPart.scala @@ -3,16 +3,11 @@ package li.cil.oc.integration.mcmp import li.cil.oc.Constants import li.cil.oc.Settings import li.cil.oc.api -import li.cil.oc.client.renderer.block.ModelInitialization import mcmultipart.item.PartPlacementWrapper import mcmultipart.multipart.MultipartRegistry -import net.minecraft.client.resources.model.IBakedModel import net.minecraft.client.resources.model.ModelResourceLocation -import net.minecraft.util.RegistrySimple -import net.minecraftforge.client.event.ModelBakeEvent -import net.minecraftforge.common.MinecraftForge -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.FMLCommonHandler +import net.minecraftforge.fml.relauncher.Side object MCMultiPart { final val CableMultipartLocation = new ModelResourceLocation(Settings.resourceDomain + ":" + Constants.BlockName.Cable, "multipart") @@ -28,17 +23,8 @@ object MCMultiPart { new PartPlacementWrapper(api.Items.get(Constants.BlockName.Cable).createItemStack(1), PartFactory).register(PartFactory.PartTypeCable) new PartPlacementWrapper(api.Items.get(Constants.BlockName.Print).createItemStack(1), PartFactory).register(PartFactory.PartTypePrint) - MinecraftForge.EVENT_BUS.register(this) - } - - @SubscribeEvent(priority = EventPriority.LOW) - def onModelBake(e: ModelBakeEvent): Unit = { - val registry = e.modelRegistry.asInstanceOf[RegistrySimple[ModelResourceLocation, IBakedModel]] - - // Replace default cable model with part model to properly handle connection - // rendering to multipart cables. - registry.putObject(ModelInitialization.CableBlockLocation, PartCableModel) - registry.putObject(CableMultipartLocation, PartCableModel) - registry.putObject(PrintMultipartLocation, PartPrintModel) + if (FMLCommonHandler.instance.getSide == Side.CLIENT) { + MCMultiPartClient.init() + } } } diff --git a/src/main/scala/li/cil/oc/integration/mcmp/MCMultiPartClient.scala b/src/main/scala/li/cil/oc/integration/mcmp/MCMultiPartClient.scala new file mode 100644 index 000000000..33bd2b40f --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/mcmp/MCMultiPartClient.scala @@ -0,0 +1,27 @@ +package li.cil.oc.integration.mcmp + +import li.cil.oc.client.renderer.block.ModelInitialization +import net.minecraft.client.resources.model.IBakedModel +import net.minecraft.client.resources.model.ModelResourceLocation +import net.minecraft.util.RegistrySimple +import net.minecraftforge.client.event.ModelBakeEvent +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object MCMultiPartClient { + def init(): Unit = { + MinecraftForge.EVENT_BUS.register(this) + } + + @SubscribeEvent(priority = EventPriority.LOW) + def onModelBake(e: ModelBakeEvent): Unit = { + val registry = e.modelRegistry.asInstanceOf[RegistrySimple[ModelResourceLocation, IBakedModel]] + + // Replace default cable model with part model to properly handle connection + // rendering to multipart cables. + registry.putObject(ModelInitialization.CableBlockLocation, PartCableModel) + registry.putObject(MCMultiPart.CableMultipartLocation, PartCableModel) + registry.putObject(MCMultiPart.PrintMultipartLocation, PartPrintModel) + } +} diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/DriverAPU.scala b/src/main/scala/li/cil/oc/integration/opencomputers/DriverAPU.scala index f1a9329d6..4072a146f 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/DriverAPU.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/DriverAPU.scala @@ -20,9 +20,9 @@ object DriverAPU extends DriverCPU with HostAware { override def createEnvironment(stack: ItemStack, host: EnvironmentHost) = if (host.world != null && host.world.isRemote) null else gpuTier(stack) match { - case Tier.One => new component.GraphicsCard(Tier.One) - case Tier.Two => new component.GraphicsCard(Tier.Two) - case Tier.Three => new component.GraphicsCard(Tier.Three) + case Tier.One => new component.APU(Tier.One) + case Tier.Two => new component.APU(Tier.Two) + case Tier.Three => new component.APU(Tier.Three) case _ => null } diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/DriverCPU.scala b/src/main/scala/li/cil/oc/integration/opencomputers/DriverCPU.scala index 98c662727..ee5a35adc 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/DriverCPU.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/DriverCPU.scala @@ -8,6 +8,7 @@ import li.cil.oc.common.Slot import li.cil.oc.common.Tier import li.cil.oc.common.item import li.cil.oc.common.item.Delegator +import li.cil.oc.server.component import li.cil.oc.server.machine.luac.NativeLuaArchitecture import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound @@ -23,7 +24,7 @@ abstract class DriverCPU extends Item with api.driver.item.MutableProcessor with api.Items.get(Constants.ItemName.CPUTier2), api.Items.get(Constants.ItemName.CPUTier3)) - override def createEnvironment(stack: ItemStack, host: api.network.EnvironmentHost): api.network.ManagedEnvironment = null + override def createEnvironment(stack: ItemStack, host: api.network.EnvironmentHost): api.network.ManagedEnvironment = new component.CPU(tier(stack)) override def slot(stack: ItemStack) = Slot.CPU diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/DriverMemory.scala b/src/main/scala/li/cil/oc/integration/opencomputers/DriverMemory.scala index 9491ae387..2d3a4f099 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/DriverMemory.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/DriverMemory.scala @@ -7,6 +7,7 @@ import li.cil.oc.common.Slot import li.cil.oc.common.Tier import li.cil.oc.common.item import li.cil.oc.common.item.Delegator +import li.cil.oc.server.component import net.minecraft.item.ItemStack object DriverMemory extends Item with api.driver.item.Memory with api.driver.item.CallBudget { @@ -25,7 +26,7 @@ object DriverMemory extends Item with api.driver.item.Memory with api.driver.ite api.Items.get(Constants.ItemName.RAMTier5), api.Items.get(Constants.ItemName.RAMTier6)) - override def createEnvironment(stack: ItemStack, host: api.network.EnvironmentHost) = null + override def createEnvironment(stack: ItemStack, host: api.network.EnvironmentHost) = new component.Memory(tier(stack)) override def slot(stack: ItemStack) = Slot.Memory diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/DriverUpgradeTractorBeam.scala b/src/main/scala/li/cil/oc/integration/opencomputers/DriverUpgradeTractorBeam.scala index 8d01e4232..63306e940 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/DriverUpgradeTractorBeam.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/DriverUpgradeTractorBeam.scala @@ -34,7 +34,7 @@ object DriverUpgradeTractorBeam extends Item with HostAware { object Provider extends EnvironmentProvider { override def getEnvironment(stack: ItemStack): Class[_] = if (worksWith(stack)) - classOf[component.UpgradeTractorBeam] + classOf[component.UpgradeTractorBeam.Common] else null } diff --git a/src/main/scala/li/cil/oc/server/PacketSender.scala b/src/main/scala/li/cil/oc/server/PacketSender.scala index 1c4cda596..0fc8bf3ff 100644 --- a/src/main/scala/li/cil/oc/server/PacketSender.scala +++ b/src/main/scala/li/cil/oc/server/PacketSender.scala @@ -44,6 +44,14 @@ object PacketSender { pb.sendToPlayersNearTileEntity(t) } + def sendClientLog(line: String, player: EntityPlayerMP) { + val pb = new CompressedPacketBuilder(PacketType.ClientLog) + + pb.writeUTF(line) + + pb.sendToPlayer(player) + } + def sendColorChange(t: Colored) { val pb = new SimplePacketBuilder(PacketType.ColorChange) @@ -273,7 +281,7 @@ object PacketSender { def sendLootDisks(p: EntityPlayerMP): Unit = { // Sending as separate packets, because CompressedStreamTools hiccups otherwise... - val stacks = Loot.worldDisks.values.map(_._1) + val stacks = Loot.worldDisks.map(_._1) for (stack <- stacks) { val pb = new SimplePacketBuilder(PacketType.LootDisk) diff --git a/src/main/scala/li/cil/oc/server/component/APU.scala b/src/main/scala/li/cil/oc/server/component/APU.scala new file mode 100644 index 000000000..cb3e3a948 --- /dev/null +++ b/src/main/scala/li/cil/oc/server/component/APU.scala @@ -0,0 +1,24 @@ +package li.cil.oc.server.component + +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass +import li.cil.oc.Settings + +import scala.collection.convert.WrapAsJava._ + +class APU(tier: Int) extends GraphicsCard(tier) { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Processor, + DeviceAttribute.Description -> "APU", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> ("FlexiArch " + (tier + 1).toString + " Processor (Builtin Graphics)"), + DeviceAttribute.Capacity -> capacityInfo, + DeviceAttribute.Width -> widthInfo, + DeviceAttribute.Clock -> ((Settings.get.callBudgets(tier) * 1000).toInt.toString + "+" + clockInfo) + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo +} diff --git a/src/main/scala/li/cil/oc/server/component/CPU.scala b/src/main/scala/li/cil/oc/server/component/CPU.scala new file mode 100644 index 000000000..185d95e5b --- /dev/null +++ b/src/main/scala/li/cil/oc/server/component/CPU.scala @@ -0,0 +1,29 @@ +package li.cil.oc.server.component + +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass +import li.cil.oc.Settings +import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo +import li.cil.oc.api.network.Visibility +import li.cil.oc.api.prefab + +import scala.collection.convert.WrapAsJava._ + +class CPU(val tier: Int) extends prefab.ManagedEnvironment with DeviceInfo { + override val node = Network.newNode(this, Visibility.Neighbors). + create() + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Processor, + DeviceAttribute.Description -> "CPU", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> ("FlexiArch " + (tier + 1).toString + " Processor"), + DeviceAttribute.Clock -> (Settings.get.callBudgets(tier) * 1000).toInt.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo +} diff --git a/src/main/scala/li/cil/oc/server/component/DataCard.scala b/src/main/scala/li/cil/oc/server/component/DataCard.scala index bb5189960..a416242ce 100644 --- a/src/main/scala/li/cil/oc/server/component/DataCard.scala +++ b/src/main/scala/li/cil/oc/server/component/DataCard.scala @@ -4,6 +4,7 @@ import java.security._ import java.security.interfaces.ECPublicKey import java.security.spec.PKCS8EncodedKeySpec import java.security.spec.X509EncodedKeySpec +import java.util import java.util.zip.DeflaterOutputStream import java.util.zip.InflaterOutputStream import javax.crypto.Cipher @@ -13,30 +14,28 @@ import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec import com.google.common.hash.Hashing -import li.cil.oc.OpenComputers +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings -import li.cil.oc.api import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context -import li.cil.oc.api.network.Node import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab -import li.cil.oc.util.ExtendedNBT._ import net.minecraft.nbt.NBTTagCompound import org.apache.commons.codec.binary.Base64 import org.apache.commons.io.output.ByteArrayOutputStream -abstract class DataCard extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +abstract class DataCard extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Neighbors). withComponent("data", Visibility.Neighbors). withConnector(). create() - val romData = Option(api.FileSystem.asManagedEnvironment(api.FileSystem. - fromClass(OpenComputers.getClass, Settings.resourceDomain, "lua/component/data"), "data")) - // ----------------------------------------------------------------------- // protected def checkCost(context: Context, args: Arguments, baseCost: Double, byteCost: Double): Array[Byte] = { @@ -70,32 +69,6 @@ abstract class DataCard extends prefab.ManagedEnvironment { def getLimit(context: Context, args: Arguments): Array[AnyRef] = { result(Settings.get.dataCardHardLimit) } - - // ----------------------------------------------------------------------- // - - override def onConnect(node: Node) { - super.onConnect(node) - if (node.isNeighborOf(this.node)) { - romData.foreach(fs => node.connect(fs.node)) - } - } - - override def onDisconnect(node: Node) { - super.onDisconnect(node) - if (node == this.node) { - romData.foreach(_.node.remove()) - } - } - - override def load(nbt: NBTTagCompound) { - super.load(nbt) - romData.foreach(_.load(nbt.getCompoundTag("romData"))) - } - - override def save(nbt: NBTTagCompound) { - super.save(nbt) - romData.foreach(fs => nbt.setNewCompoundTag("romData", fs.save)) - } } object DataCard { @@ -104,6 +77,17 @@ object DataCard { } class Tier1 extends DataCard { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Processor, + DeviceAttribute.Description -> "Data processor card", + DeviceAttribute.Vendor -> "S.C. Ltd.", + DeviceAttribute.Product -> "SC01D H45h3r" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(direct = true, limit = 32, doc = """function(data:string):string -- Applies base64 encoding to the data.""") def encode64(context: Context, args: Arguments): Array[AnyRef] = { result(Base64.encodeBase64(trivialCost(context, args))) @@ -154,6 +138,17 @@ object DataCard { } class Tier2 extends Tier1 { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Processor, + DeviceAttribute.Description -> "Data processor card", + DeviceAttribute.Vendor -> "S.C. Ltd.", + DeviceAttribute.Product -> "SC02D Cryptic" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(direct = true, limit = 8, doc = """function(data:string[, hmacKey:string]):string -- Computes MD5 hash of the data. Result is binary data.""") override def md5(context: Context, args: Arguments): Array[AnyRef] = if (args.count() > 1) { @@ -217,6 +212,17 @@ object DataCard { } class Tier3 extends Tier2 { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Processor, + DeviceAttribute.Description -> "Data processor card", + DeviceAttribute.Vendor -> "S.C. Ltd.", + DeviceAttribute.Product -> "SC03D Signer" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(direct = true, limit = 1, doc = """function([bitLen:number]):userdata, userdata -- Generates key pair. Returns: public, private keys. Allowed key lengths: 256, 384 bits.""") def generateKeyPair(context: Context, args: Arguments): Array[AnyRef] = { checkCost(Settings.get.dataCardAsymmetric) diff --git a/src/main/scala/li/cil/oc/server/component/DiskDriveMountable.scala b/src/main/scala/li/cil/oc/server/component/DiskDriveMountable.scala index 7c593680a..e5c4033f3 100644 --- a/src/main/scala/li/cil/oc/server/component/DiskDriveMountable.scala +++ b/src/main/scala/li/cil/oc/server/component/DiskDriveMountable.scala @@ -2,10 +2,14 @@ package li.cil.oc.server.component import java.util +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.api import li.cil.oc.api.Driver import li.cil.oc.api.component.RackBusConnectable import li.cil.oc.api.component.RackMountable +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -27,7 +31,9 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.EnumFacing -class DiskDriveMountable(val rack: api.internal.Rack, val slot: Int) extends prefab.ManagedEnvironment with ItemStackInventory with ComponentInventory with RackMountable with Analyzable { +import scala.collection.convert.WrapAsJava._ + +class DiskDriveMountable(val rack: api.internal.Rack, val slot: Int) extends prefab.ManagedEnvironment with ItemStackInventory with ComponentInventory with RackMountable with Analyzable with DeviceInfo { // Stored for filling data packet when queried. var lastAccess = 0L @@ -36,6 +42,18 @@ class DiskDriveMountable(val rack: api.internal.Rack, val slot: Int) extends pre case _ => None } + // ----------------------------------------------------------------------- // + // DeviceInfo + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Disk, + DeviceAttribute.Description -> "Floppy disk drive", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "RackDrive 100 Rev. 2" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // // Environment @@ -147,7 +165,7 @@ class DiskDriveMountable(val rack: api.internal.Rack, val slot: Int) extends pre override def getConnectableAt(index: Int): RackBusConnectable = null - override def onActivate(player: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean = { + override def onActivate(player: EntityPlayer, hitX: Float, hitY: Float): Boolean = { if (player.isSneaking) { val isDiskInDrive = getStackInSlot(0) != null val isHoldingDisk = isItemValidForSlot(0, player.getHeldItem) diff --git a/src/main/scala/li/cil/oc/server/component/Drive.scala b/src/main/scala/li/cil/oc/server/component/Drive.scala index 62ef1cba5..3d44eab6a 100644 --- a/src/main/scala/li/cil/oc/server/component/Drive.scala +++ b/src/main/scala/li/cil/oc/server/component/Drive.scala @@ -3,25 +3,32 @@ package li.cil.oc.server.component import java.io import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream +import java.util import java.util.zip.GZIPInputStream import java.util.zip.GZIPOutputStream import com.google.common.io.Files +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.api.Network -import li.cil.oc.api.network.EnvironmentHost +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.fs.Label import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context +import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab import li.cil.oc.server.{PacketSender => ServerPacketSender} import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.common.DimensionManager -class Drive(val capacity: Int, val platterCount: Int, val label: Label, host: Option[EnvironmentHost], val sound: Option[String], val speed: Int) extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +class Drive(val capacity: Int, val platterCount: Int, val label: Label, host: Option[EnvironmentHost], val sound: Option[String], val speed: Int) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("drive", Visibility.Neighbors). withConnector(). @@ -39,6 +46,25 @@ class Drive(val capacity: Int, val platterCount: Int, val label: Label, host: Op private var headPos = 0 + final val readSectorCosts = Array(1.0 / 10, 1.0 / 20, 1.0 / 30, 1.0 / 40, 1.0 / 50, 1.0 / 60) + final val writeSectorCosts = Array(1.0 / 5, 1.0 / 10, 1.0 / 15, 1.0 / 20, 1.0 / 25, 1.0 / 30) + final val readByteCosts = Array(1.0 / 48, 1.0 / 64, 1.0 / 80, 1.0 / 96, 1.0 / 112, 1.0 / 128) + final val writeByteCosts = Array(1.0 / 24, 1.0 / 32, 1.0 / 40, 1.0 / 48, 1.0 / 56, 1.0 / 64) + + // ----------------------------------------------------------------------- // + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Disk, + DeviceAttribute.Description -> "Hard disk drive", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> ("MPD" + (capacity / 1024).toString + "L" + platterCount.toString), + DeviceAttribute.Capacity -> (capacity * 1.024).toInt.toString, + DeviceAttribute.Size -> capacity.toString, + DeviceAttribute.Clock -> (((2000 / readSectorCosts(speed)).toInt / 100).toString + "/" + ((2000 / writeSectorCosts(speed)).toInt / 100).toString + "/" + ((2000 / readByteCosts(speed)).toInt / 100).toString + "/" + ((2000 / writeByteCosts(speed)).toInt / 100).toString) + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @Callback(direct = true, doc = """function():string -- Get the current label of the drive.""") @@ -73,8 +99,6 @@ class Drive(val capacity: Int, val platterCount: Int, val label: Label, host: Op result(sectorData) } - final val readSectorCosts = Array(1.0 / 10, 1.0 / 20, 1.0 / 30, 1.0 / 40, 1.0 / 50, 1.0 / 60) - @Callback(direct = true, doc = """function(sector:number, value:string) -- Write the specified contents to the specified sector.""") def writeSector(context: Context, args: Arguments): Array[AnyRef] = this.synchronized { context.consumeCallBudget(writeSectorCosts(speed)) @@ -85,8 +109,6 @@ class Drive(val capacity: Int, val platterCount: Int, val label: Label, host: Op null } - final val writeSectorCosts = Array(1.0 / 5, 1.0 / 10, 1.0 / 15, 1.0 / 20, 1.0 / 25, 1.0 / 30) - @Callback(direct = true, doc = """function(offset:number):number -- Read a single byte at the specified offset.""") def readByte(context: Context, args: Arguments): Array[AnyRef] = this.synchronized { context.consumeCallBudget(readByteCosts(speed)) @@ -96,8 +118,6 @@ class Drive(val capacity: Int, val platterCount: Int, val label: Label, host: Op result(data(offset)) } - final val readByteCosts = Array(1.0 / 48, 1.0 / 64, 1.0 / 80, 1.0 / 96, 1.0 / 112, 1.0 / 128) - @Callback(direct = true, doc = """function(offset:number, value:number) -- Write a single byte to the specified offset.""") def writeByte(context: Context, args: Arguments): Array[AnyRef] = this.synchronized { context.consumeCallBudget(writeByteCosts(speed)) @@ -109,8 +129,6 @@ class Drive(val capacity: Int, val platterCount: Int, val label: Label, host: Op null } - final val writeByteCosts = Array(1.0 / 24, 1.0 / 32, 1.0 / 40, 1.0 / 48, 1.0 / 56, 1.0 / 64) - // ----------------------------------------------------------------------- // override def load(nbt: NBTTagCompound) = this.synchronized { diff --git a/src/main/scala/li/cil/oc/server/component/Drone.scala b/src/main/scala/li/cil/oc/server/component/Drone.scala index d8f37d8b6..48a5994d1 100644 --- a/src/main/scala/li/cil/oc/server/component/Drone.scala +++ b/src/main/scala/li/cil/oc/server/component/Drone.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -16,12 +22,24 @@ import net.minecraft.util.EnumFacing import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ -class Drone(val agent: entity.Drone) extends prefab.ManagedEnvironment with Agent { +import scala.collection.convert.WrapAsJava._ + +class Drone(val agent: entity.Drone) extends prefab.ManagedEnvironment with Agent with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("drone"). withConnector(Settings.get.bufferDrone). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.System, + DeviceAttribute.Description -> "Drone", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Overwatcher", + DeviceAttribute.Capacity -> agent.inventorySize.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + override protected def checkSideForAction(args: Arguments, n: Int) = args.checkSideAny(n) diff --git a/src/main/scala/li/cil/oc/server/component/EEPROM.scala b/src/main/scala/li/cil/oc/server/component/EEPROM.scala index 27720f128..cc907aff6 100644 --- a/src/main/scala/li/cil/oc/server/component/EEPROM.scala +++ b/src/main/scala/li/cil/oc/server/component/EEPROM.scala @@ -1,8 +1,14 @@ package li.cil.oc.server.component +import java.util + import com.google.common.hash.Hashing +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -10,7 +16,9 @@ import li.cil.oc.api.network._ import li.cil.oc.api.prefab import net.minecraft.nbt.NBTTagCompound -class EEPROM extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +class EEPROM extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Neighbors). withComponent("eeprom", Visibility.Neighbors). withConnector(). @@ -28,6 +36,19 @@ class EEPROM extends prefab.ManagedEnvironment { // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Memory, + DeviceAttribute.Description -> "EEPROM", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "FlashStick2k", + DeviceAttribute.Capacity -> Settings.get.eepromSize.toString, + DeviceAttribute.Size -> Settings.get.eepromSize.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(direct = true, doc = """function():string -- Get the currently stored byte array.""") def get(context: Context, args: Arguments): Array[AnyRef] = result(codeData) diff --git a/src/main/scala/li/cil/oc/server/component/FileSystem.scala b/src/main/scala/li/cil/oc/server/component/FileSystem.scala index ec43a01c1..1b529e6fb 100644 --- a/src/main/scala/li/cil/oc/server/component/FileSystem.scala +++ b/src/main/scala/li/cil/oc/server/component/FileSystem.scala @@ -2,9 +2,14 @@ package li.cil.oc.server.component import java.io.FileNotFoundException import java.io.IOException +import java.util +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.fs.Label import li.cil.oc.api.fs.Mode import li.cil.oc.api.fs.{FileSystem => IFileSystem} @@ -23,9 +28,10 @@ import net.minecraft.nbt.NBTTagIntArray import net.minecraft.nbt.NBTTagList import net.minecraftforge.common.util.Constants.NBT +import scala.collection.convert.WrapAsJava._ import scala.collection.mutable -class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option[EnvironmentHost], val sound: Option[String], val speed: Int) extends prefab.ManagedEnvironment { +class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option[EnvironmentHost], val sound: Option[String], val speed: Int) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("filesystem", Visibility.Neighbors). withConnector(). @@ -33,6 +39,24 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option private val owners = mutable.Map.empty[String, mutable.Set[Int]] + final val readCosts = Array(1.0 / 1, 1.0 / 4, 1.0 / 7, 1.0 / 10, 1.0 / 13, 1.0 / 15) + final val seekCosts = Array(1.0 / 1, 1.0 / 4, 1.0 / 7, 1.0 / 10, 1.0 / 13, 1.0 / 15) + final val writeCosts = Array(1.0 / 1, 1.0 / 2, 1.0 / 3, 1.0 / 4, 1.0 / 5, 1.0 / 6) + + // ----------------------------------------------------------------------- // + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Volume, + DeviceAttribute.Description -> "Filesystem", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "MPFS.21.6", + DeviceAttribute.Capacity -> (fileSystem.spaceTotal * 1.024).toInt.toString, + DeviceAttribute.Size -> fileSystem.spaceTotal.toString, + DeviceAttribute.Clock -> (((2000 / readCosts(speed)).toInt / 100).toString + "/" + ((2000 / seekCosts(speed)).toInt / 100).toString + "/" + ((2000 / writeCosts(speed)).toInt / 100).toString) + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @Callback(direct = true, doc = """function():string -- Get the current label of the drive.""") @@ -178,8 +202,6 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option } } - final val readCosts = Array(1.0 / 1, 1.0 / 4, 1.0 / 7, 1.0 / 10, 1.0 / 13, 1.0 / 15) - @Callback(direct = true, doc = """function(handle:userdata, whence:string, offset:number):number -- Seeks in an open file descriptor with the specified handle. Returns the new pointer position.""") def seek(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized { context.consumeCallBudget(seekCosts(speed)) @@ -200,8 +222,6 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option } } - final val seekCosts = Array(1.0 / 1, 1.0 / 4, 1.0 / 7, 1.0 / 10, 1.0 / 13, 1.0 / 15) - @Callback(direct = true, doc = """function(handle:userdata, value:string):boolean -- Writes the specified data to an open file descriptor with the specified handle.""") def write(context: Context, args: Arguments): Array[AnyRef] = fileSystem.synchronized { context.consumeCallBudget(writeCosts(speed)) @@ -220,8 +240,6 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option } } - final val writeCosts = Array(1.0 / 1, 1.0 / 2, 1.0 / 3, 1.0 / 4, 1.0 / 5, 1.0 / 6) - // ----------------------------------------------------------------------- // def checkHandle(args: Arguments, index: Int) = { diff --git a/src/main/scala/li/cil/oc/server/component/Geolyzer.scala b/src/main/scala/li/cil/oc/server/component/Geolyzer.scala index d1ac7faec..147523c90 100644 --- a/src/main/scala/li/cil/oc/server/component/Geolyzer.scala +++ b/src/main/scala/li/cil/oc/server/component/Geolyzer.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.event.GeolyzerEvent import li.cil.oc.api.event.GeolyzerEvent.Analyze @@ -27,12 +33,24 @@ import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ import scala.language.existentials -class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment { +class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment with DeviceInfo { override val node = api.Network.newNode(this, Visibility.Network). withComponent("geolyzer"). withConnector(). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Geolyzer", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Terrain Analyzer MkII", + DeviceAttribute.Capacity -> Settings.get.geolyzerRange.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(doc = """function(x:number, z:number[, y:number, w:number, d:number, h:number][, ignoreReplaceable:boolean|options:table]):table -- Analyzes the density of the column at the specified relative coordinates.""") def scan(computer: Context, args: Arguments): Array[AnyRef] = { val (minX, minY, minZ, maxX, maxY, maxZ, optIndex) = getScanArgs(args) diff --git a/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala b/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala index 49d0d3d3c..0fe212ccf 100644 --- a/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala +++ b/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala @@ -1,9 +1,15 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Localization import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -12,6 +18,7 @@ import li.cil.oc.api.prefab import li.cil.oc.util.PackedColor import net.minecraft.nbt.NBTTagCompound +import scala.collection.convert.WrapAsJava._ import scala.util.matching.Regex // IMPORTANT: usually methods with side effects should *not* be direct @@ -26,7 +33,7 @@ import scala.util.matching.Regex // saved, but before the computer was saved, leading to mismatching states in // the save file - a Bad Thing (TM). -class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment { +class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Neighbors). withComponent("gpu"). withConnector(). @@ -45,6 +52,31 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment { case _ => Array(Unit, "no screen") } + final val setBackgroundCosts = Array(1.0 / 32, 1.0 / 64, 1.0 / 128) + final val setForegroundCosts = Array(1.0 / 32, 1.0 / 64, 1.0 / 128) + final val setPaletteColorCosts = Array(1.0 / 2, 1.0 / 8, 1.0 / 16) + final val setCosts = Array(1.0 / 64, 1.0 / 128, 1.0 / 256) + final val copyCosts = Array(1.0 / 16, 1.0 / 32, 1.0 / 64) + final val fillCosts = Array(1.0 / 32, 1.0 / 64, 1.0 / 128) + + // ----------------------------------------------------------------------- // + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Display, + DeviceAttribute.Description -> "Graphics controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> ("MPG" + ((tier + 1) * 1000).toString + " GTZ"), + DeviceAttribute.Capacity -> capacityInfo, + DeviceAttribute.Width -> widthInfo, + DeviceAttribute.Clock -> clockInfo + ) + + def capacityInfo = (maxResolution._1 * maxResolution._2).toString + def widthInfo = Array("1", "4", "8").apply(maxDepth.ordinal()) + def clockInfo = ((2000 / setBackgroundCosts(tier)).toInt / 100).toString + "/" + ((2000 / setForegroundCosts(tier)).toInt / 100).toString + "/" + ((2000 / setPaletteColorCosts(tier)).toInt / 100).toString + "/" + ((2000 / setCosts(tier)).toInt / 100).toString + "/" + ((2000 / copyCosts(tier)).toInt / 100).toString + "/" + ((2000 / fillCosts(tier)).toInt / 100).toString + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // override val canUpdate = true @@ -117,8 +149,6 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment { }) } - final val setBackgroundCosts = Array(1.0 / 32, 1.0 / 64, 1.0 / 128) - @Callback(direct = true, doc = """function():number, boolean -- Get the current foreground color and whether it's from the palette or not.""") def getForeground(context: Context, args: Arguments): Array[AnyRef] = screen(s => result(s.getForegroundColor, s.isForegroundFromPalette)) @@ -141,8 +171,6 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment { }) } - final val setForegroundCosts = Array(1.0 / 32, 1.0 / 64, 1.0 / 128) - @Callback(direct = true, doc = """function(index:number):number -- Get the palette color at the specified palette index.""") def getPaletteColor(context: Context, args: Arguments): Array[AnyRef] = { val index = args.checkInteger(0) @@ -167,8 +195,6 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment { }) } - final val setPaletteColorCosts = Array(1.0 / 2, 1.0 / 8, 1.0 / 16) - @Callback(direct = true, doc = """function():number -- Returns the currently set color depth.""") def getDepth(context: Context, args: Arguments): Array[AnyRef] = screen(s => result(PackedColor.Depth.bits(s.getColorDepth))) @@ -281,8 +307,6 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment { }) } - final val setCosts = Array(1.0 / 64, 1.0 / 128, 1.0 / 256) - @Callback(direct = true, doc = """function(x:number, y:number, width:number, height:number, tx:number, ty:number):boolean -- Copies a portion of the screen from the specified location with the specified size by the specified translation.""") def copy(context: Context, args: Arguments): Array[AnyRef] = { context.consumeCallBudget(copyCosts(tier)) @@ -301,8 +325,6 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment { }) } - final val copyCosts = Array(1.0 / 16, 1.0 / 32, 1.0 / 64) - @Callback(direct = true, doc = """function(x:number, y:number, width:number, height:number, char:string):boolean -- Fills a portion of the screen at the specified position with the specified size with the specified character.""") def fill(context: Context, args: Arguments): Array[AnyRef] = { context.consumeCallBudget(fillCosts(tier)) @@ -325,8 +347,6 @@ class GraphicsCard(val tier: Int) extends prefab.ManagedEnvironment { else throw new Exception("invalid fill value") } - final val fillCosts = Array(1.0 / 32, 1.0 / 64, 1.0 / 128) - private def consumePower(n: Double, cost: Double) = node.tryChangeBuffer(-n * cost) // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/server/component/InternetCard.scala b/src/main/scala/li/cil/oc/server/component/InternetCard.scala index 425585d0e..1b82aeb27 100644 --- a/src/main/scala/li/cil/oc/server/component/InternetCard.scala +++ b/src/main/scala/li/cil/oc/server/component/InternetCard.scala @@ -8,43 +8,53 @@ import java.io.OutputStreamWriter import java.net._ import java.nio.ByteBuffer import java.nio.channels.SocketChannel +import java.util import java.util.concurrent.Callable import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.ExecutionException import java.util.concurrent.Future -import li.cil.oc.OpenComputers +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings -import li.cil.oc.api import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context import li.cil.oc.api.network._ import li.cil.oc.api.prefab import li.cil.oc.api.prefab.AbstractValue -import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.ThreadPoolFactory -import net.minecraft.nbt.NBTTagCompound import net.minecraft.server.MinecraftServer +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ import scala.collection.mutable -class InternetCard extends prefab.ManagedEnvironment { +class InternetCard extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("internet", Visibility.Neighbors). create() - val romInternet = Option(api.FileSystem.asManagedEnvironment(api.FileSystem. - fromClass(OpenComputers.getClass, Settings.resourceDomain, "lua/component/internet"), "internet")) - protected var owner: Option[Context] = None protected val connections = mutable.Set.empty[InternetCard.Closable] // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Communication, + DeviceAttribute.Description -> "Internet modem", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "SuperLink X-D4NK" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(direct = true, doc = """function():boolean -- Returns whether HTTP requests can be made (config setting).""") def isHttpEnabled(context: Context, args: Arguments): Array[AnyRef] = result(Settings.get.httpEnabled) @@ -60,8 +70,9 @@ class InternetCard extends prefab.ManagedEnvironment { } val post = if (args.isString(1)) Option(args.checkString(1)) else None val headers = if (args.isTable(2)) args.checkTable(2).collect { - case (key: String, value: AnyRef) => (key, value.toString) - }.toMap else Map.empty[String, String] + case (key: String, value: AnyRef) => (key, value.toString) + }.toMap + else Map.empty[String, String] if (!Settings.get.httpHeadersEnabled && headers.nonEmpty) { return result(Unit, "http request headers are unavailable") } @@ -102,7 +113,6 @@ class InternetCard extends prefab.ManagedEnvironment { super.onConnect(node) if (owner.isEmpty && node.host.isInstanceOf[Context] && node.isNeighborOf(this.node)) { owner = Some(node.host.asInstanceOf[Context]) - romInternet.foreach(fs => node.connect(fs.node)) } } @@ -114,7 +124,6 @@ class InternetCard extends prefab.ManagedEnvironment { connections.foreach(_.close()) connections.clear() } - romInternet.foreach(_.node.remove()) } } @@ -132,18 +141,6 @@ class InternetCard extends prefab.ManagedEnvironment { // ----------------------------------------------------------------------- // - override def load(nbt: NBTTagCompound) { - super.load(nbt) - romInternet.foreach(_.load(nbt.getCompoundTag("romInternet"))) - } - - override def save(nbt: NBTTagCompound) { - super.save(nbt) - romInternet.foreach(fs => nbt.setNewCompoundTag("romInternet", fs.save)) - } - - // ----------------------------------------------------------------------- // - private def checkUri(address: String, port: Int): URI = { try { val parsed = new URI(address) @@ -287,10 +284,10 @@ object InternetCard { } def checkLists(inetAddress: InetAddress, host: String) { - if (Settings.get.httpHostWhitelist.length > 0 && !Settings.get.httpHostWhitelist.exists(_(inetAddress, host))) { + if (Settings.get.httpHostWhitelist.length > 0 && !Settings.get.httpHostWhitelist.exists(_ (inetAddress, host))) { throw new FileNotFoundException("address is not whitelisted") } - if (Settings.get.httpHostBlacklist.length > 0 && Settings.get.httpHostBlacklist.exists(_(inetAddress, host))) { + if (Settings.get.httpHostBlacklist.length > 0 && Settings.get.httpHostBlacklist.exists(_ (inetAddress, host))) { throw new FileNotFoundException("address is blacklisted") } } diff --git a/src/main/scala/li/cil/oc/server/component/Keyboard.scala b/src/main/scala/li/cil/oc/server/component/Keyboard.scala index 103d8621c..6661a0179 100644 --- a/src/main/scala/li/cil/oc/server/component/Keyboard.scala +++ b/src/main/scala/li/cil/oc/server/component/Keyboard.scala @@ -1,8 +1,14 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal.Keyboard.UsabilityChecker import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.network.Message @@ -10,12 +16,13 @@ import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab import net.minecraft.entity.player.EntityPlayer +import scala.collection.convert.WrapAsJava._ import scala.collection.mutable // TODO key up when screen is disconnected from which the key down came // TODO key up after load for anything that was pressed -class Keyboard(val host: EnvironmentHost) extends prefab.ManagedEnvironment with api.internal.Keyboard { +class Keyboard(val host: EnvironmentHost) extends prefab.ManagedEnvironment with api.internal.Keyboard with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("keyboard"). create() @@ -28,6 +35,17 @@ class Keyboard(val host: EnvironmentHost) extends prefab.ManagedEnvironment with // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Input, + DeviceAttribute.Description -> "Keyboard", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Fancytyper MX-Stone" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + def releasePressedKeys(player: EntityPlayer) { pressedKeys.get(player) match { case Some(keys) => for ((code, char) <- keys) { diff --git a/src/main/scala/li/cil/oc/server/component/LinkedCard.scala b/src/main/scala/li/cil/oc/server/component/LinkedCard.scala index 980609515..9c4331e87 100644 --- a/src/main/scala/li/cil/oc/server/component/LinkedCard.scala +++ b/src/main/scala/li/cil/oc/server/component/LinkedCard.scala @@ -1,18 +1,25 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context import li.cil.oc.api.network._ +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.prefab import li.cil.oc.server.network.QuantumNetwork import net.minecraft.nbt.NBTTagCompound +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ -class LinkedCard extends prefab.ManagedEnvironment with QuantumNetwork.QuantumNode { +class LinkedCard extends prefab.ManagedEnvironment with QuantumNetwork.QuantumNode with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("tunnel", Visibility.Neighbors). withConnector(). @@ -22,6 +29,18 @@ class LinkedCard extends prefab.ManagedEnvironment with QuantumNetwork.QuantumNo // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Network, + DeviceAttribute.Description -> "Quantumnet controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "HyperLink IV: Ender Edition", + DeviceAttribute.Capacity -> Settings.get.maxNetworkPacketSize.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(doc = """function(data...) -- Sends the specified data to the card this one is linked to.""") def send(context: Context, args: Arguments): Array[AnyRef] = { val endpoints = QuantumNetwork.getEndpoints(tunnel).filter(_ != this) diff --git a/src/main/scala/li/cil/oc/server/component/Memory.scala b/src/main/scala/li/cil/oc/server/component/Memory.scala new file mode 100644 index 000000000..64b63d5a0 --- /dev/null +++ b/src/main/scala/li/cil/oc/server/component/Memory.scala @@ -0,0 +1,29 @@ +package li.cil.oc.server.component + +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass +import li.cil.oc.Settings +import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo +import li.cil.oc.api.network.Visibility +import li.cil.oc.api.prefab + +import scala.collection.convert.WrapAsJava._ + +class Memory(val tier: Int) extends prefab.ManagedEnvironment with DeviceInfo { + override val node = Network.newNode(this, Visibility.Neighbors). + create() + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Memory, + DeviceAttribute.Description -> "Memory bank", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Multipurpose RAM Type", + DeviceAttribute.Clock -> (Settings.get.callBudgets(tier) * 1000).toInt.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo +} diff --git a/src/main/scala/li/cil/oc/server/component/NetworkCard.scala b/src/main/scala/li/cil/oc/server/component/NetworkCard.scala index e0e7a0421..d5823d184 100644 --- a/src/main/scala/li/cil/oc/server/component/NetworkCard.scala +++ b/src/main/scala/li/cil/oc/server/component/NetworkCard.scala @@ -1,10 +1,16 @@ package li.cil.oc.server.component +import java.util + import com.google.common.base.Charsets +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.Network import li.cil.oc.api.component.RackBusConnectable +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal.Rack import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback @@ -15,10 +21,11 @@ import li.cil.oc.api.prefab import li.cil.oc.server.{PacketSender => ServerPacketSender} import net.minecraft.nbt._ +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ import scala.collection.mutable -class NetworkCard(val host: EnvironmentHost) extends prefab.ManagedEnvironment with RackBusConnectable { +class NetworkCard(val host: EnvironmentHost) extends prefab.ManagedEnvironment with RackBusConnectable with DeviceInfo { protected val visibility = host match { case _: Rack => Visibility.Neighbors case _ => Visibility.Network @@ -36,6 +43,18 @@ class NetworkCard(val host: EnvironmentHost) extends prefab.ManagedEnvironment w // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Network, + DeviceAttribute.Description -> "Ethernet controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "42i520 (MPN-01)", + DeviceAttribute.Capacity -> Settings.get.maxNetworkPacketSize.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(doc = """function(port:number):boolean -- Opens the specified port. Returns true if the port was opened.""") def open(context: Context, args: Arguments): Array[AnyRef] = { val port = checkPort(args.checkInteger(0)) @@ -87,6 +106,7 @@ class NetworkCard(val host: EnvironmentHost) extends prefab.ManagedEnvironment w result(true) } + // TODO 1.7 Remove, covered by device info now @Callback(direct = true, doc = """function():number -- Gets the maximum packet size (config setting).""") def maxPacketSize(context: Context, args: Arguments): Array[AnyRef] = result(Settings.get.maxNetworkPacketSize) diff --git a/src/main/scala/li/cil/oc/server/component/Redstone.scala b/src/main/scala/li/cil/oc/server/component/Redstone.scala index 8fc0b1fcb..93cdd36fd 100644 --- a/src/main/scala/li/cil/oc/server/component/Redstone.scala +++ b/src/main/scala/li/cil/oc/server/component/Redstone.scala @@ -1,10 +1,17 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.common.tileentity.traits.BundledRedstoneAware import li.cil.oc.common.tileentity.traits.RedstoneAware import li.cil.oc.server.component +import scala.collection.convert.WrapAsJava._ + object Redstone { class Vanilla(val redstone: EnvironmentHost with RedstoneAware) @@ -20,6 +27,17 @@ object Redstone { extends component.RedstoneVanilla with component.RedstoneWireless class BundledWireless(val redstone: EnvironmentHost with BundledRedstoneAware) - extends component.RedstoneVanilla with component.RedstoneBundled with component.RedstoneWireless + extends component.RedstoneVanilla with component.RedstoneBundled with component.RedstoneWireless { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Communication, + DeviceAttribute.Description -> "Combined redstone controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Rx900-M", + DeviceAttribute.Capacity -> "65536", + DeviceAttribute.Width -> "16" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + } } diff --git a/src/main/scala/li/cil/oc/server/component/RedstoneBundled.scala b/src/main/scala/li/cil/oc/server/component/RedstoneBundled.scala index 17783792d..616da070e 100644 --- a/src/main/scala/li/cil/oc/server/component/RedstoneBundled.scala +++ b/src/main/scala/li/cil/oc/server/component/RedstoneBundled.scala @@ -1,5 +1,10 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.machine.Arguments @@ -7,7 +12,22 @@ import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context import li.cil.oc.common.tileentity.traits.BundledRedstoneAware +import scala.collection.convert.WrapAsJava._ + trait RedstoneBundled extends RedstoneVanilla { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Communication, + DeviceAttribute.Description -> "Advanced redstone controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Rb800-M", + DeviceAttribute.Capacity -> "65536", + DeviceAttribute.Width -> "16" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + override def redstone: EnvironmentHost with BundledRedstoneAware @Callback(direct = true, doc = """function(side:number[, color:number]):number or table -- Get the bundled redstone input on the specified side and with the specified color.""") diff --git a/src/main/scala/li/cil/oc/server/component/RedstoneVanilla.scala b/src/main/scala/li/cil/oc/server/component/RedstoneVanilla.scala index 5126fb6ab..f1ada55da 100644 --- a/src/main/scala/li/cil/oc/server/component/RedstoneVanilla.scala +++ b/src/main/scala/li/cil/oc/server/component/RedstoneVanilla.scala @@ -1,6 +1,12 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback @@ -12,11 +18,26 @@ import li.cil.oc.util.ExtendedBlock._ import li.cil.oc.util.ExtendedWorld._ import net.minecraft.util.EnumFacing -trait RedstoneVanilla extends RedstoneSignaller { +import scala.collection.convert.WrapAsJava._ + +trait RedstoneVanilla extends RedstoneSignaller with DeviceInfo { def redstone: EnvironmentHost with RedstoneAware // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Communication, + DeviceAttribute.Description -> "Redstone controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Rs100-V", + DeviceAttribute.Capacity -> "16", + DeviceAttribute.Width -> "1" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(direct = true, doc = """function(side:number):number -- Get the redstone input on the specified side.""") def getInput(context: Context, args: Arguments): Array[AnyRef] = { val side = checkSide(args, 0) diff --git a/src/main/scala/li/cil/oc/server/component/RedstoneWireless.scala b/src/main/scala/li/cil/oc/server/component/RedstoneWireless.scala index 9ec2d9181..3d57f94d4 100644 --- a/src/main/scala/li/cil/oc/server/component/RedstoneWireless.scala +++ b/src/main/scala/li/cil/oc/server/component/RedstoneWireless.scala @@ -6,7 +6,11 @@ import codechicken.wirelessredstone.core.WirelessReceivingDevice import codechicken.wirelessredstone.core.WirelessTransmittingDevice */ +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback @@ -18,11 +22,13 @@ import li.cil.oc.integration.util import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.fml.common.Optional +import scala.collection.convert.WrapAsJava._ + @Optional.InterfaceList(Array( new Optional.Interface(iface = "codechicken.wirelessredstone.core.WirelessReceivingDevice", modid = Mods.IDs.WirelessRedstoneCBE), new Optional.Interface(iface = "codechicken.wirelessredstone.core.WirelessTransmittingDevice", modid = Mods.IDs.WirelessRedstoneCBE) )) -trait RedstoneWireless extends RedstoneSignaller /* with WirelessReceivingDevice with WirelessTransmittingDevice TODO WRCBE */ { +trait RedstoneWireless extends RedstoneSignaller /* with WirelessReceivingDevice with WirelessTransmittingDevice TODO WRCBE */ with DeviceInfo { def redstone: EnvironmentHost var wirelessFrequency = 0 @@ -33,6 +39,19 @@ trait RedstoneWireless extends RedstoneSignaller /* with WirelessReceivingDevice // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Communication, + DeviceAttribute.Description -> "Wireless redstone controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Rw400-M", + DeviceAttribute.Capacity -> "1", + DeviceAttribute.Width -> "1" + ) + + override def getDeviceInfo: java.util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + @Callback(doc = """function():number -- Get the wireless redstone input.""") def getWirelessInput(context: Context, args: Arguments): Array[AnyRef] = { wirelessInput = util.WirelessRedstone.getInput(this) diff --git a/src/main/scala/li/cil/oc/server/component/Robot.scala b/src/main/scala/li/cil/oc/server/component/Robot.scala index 1f209e49b..8359d3d46 100644 --- a/src/main/scala/li/cil/oc/server/component/Robot.scala +++ b/src/main/scala/li/cil/oc/server/component/Robot.scala @@ -1,8 +1,14 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -18,7 +24,9 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.EnumFacing import net.minecraft.util.EnumParticleTypes -class Robot(val agent: tileentity.Robot) extends prefab.ManagedEnvironment with Agent { +import scala.collection.convert.WrapAsJava._ + +class Robot(val agent: tileentity.Robot) extends prefab.ManagedEnvironment with Agent with DeviceInfo { override val node = api.Network.newNode(this, Visibility.Network). withComponent("robot"). withConnector(Settings.get.bufferRobot). @@ -27,6 +35,16 @@ class Robot(val agent: tileentity.Robot) extends prefab.ManagedEnvironment with val romRobot = Option(api.FileSystem.asManagedEnvironment(api.FileSystem. fromClass(OpenComputers.getClass, Settings.resourceDomain, "lua/component/robot"), "robot")) + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.System, + DeviceAttribute.Description -> "Robot", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Caterpillar", + DeviceAttribute.Capacity -> agent.getSizeInventory.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // override protected def checkSideForAction(args: Arguments, n: Int) = agent.toGlobal(args.checkSideForAction(n)) diff --git a/src/main/scala/li/cil/oc/server/component/Server.scala b/src/main/scala/li/cil/oc/server/component/Server.scala index e0f21d9f4..442b9dc15 100644 --- a/src/main/scala/li/cil/oc/server/component/Server.scala +++ b/src/main/scala/li/cil/oc/server/component/Server.scala @@ -3,10 +3,14 @@ package li.cil.oc.server.component import java.lang.Iterable import java.util +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.OpenComputers import li.cil.oc.api import li.cil.oc.api.Machine import li.cil.oc.api.component.RackBusConnectable +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal import li.cil.oc.api.machine.MachineHost import li.cil.oc.api.network.Analyzable @@ -28,10 +32,12 @@ import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.EnumFacing +import net.minecraftforge.common.capabilities.Capability +import net.minecraftforge.common.capabilities.ICapabilityProvider import scala.collection.convert.WrapAsJava._ -class Server(val rack: api.internal.Rack, val slot: Int) extends Environment with MachineHost with ServerInventory with ComponentInventory with Analyzable with internal.Server { +class Server(val rack: api.internal.Rack, val slot: Int) extends Environment with MachineHost with ServerInventory with ComponentInventory with Analyzable with internal.Server with ICapabilityProvider with DeviceInfo { lazy val machine = Machine.create(this) val node = if (!rack.world.isRemote) machine.node else null @@ -41,6 +47,16 @@ class Server(val rack: api.internal.Rack, val slot: Int) extends Environment wit var lastFileSystemAccess = 0L var lastNetworkActivity = 0L + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.System, + DeviceAttribute.Description -> "Server", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Blader", + DeviceAttribute.Capacity -> getSizeInventory.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // // Environment @@ -157,7 +173,7 @@ class Server(val rack: api.internal.Rack, val slot: Int) extends Environment wit case Some(busConnectable: RackBusConnectable) => busConnectable }.apply(index) - override def onActivate(player: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean = { + override def onActivate(player: EntityPlayer, hitX: Float, hitY: Float): Boolean = { if (!player.getEntityWorld.isRemote) { if (player.isSneaking) { if (!machine.isRunning && isUseableByPlayer(player)) { @@ -208,4 +224,16 @@ class Server(val rack: api.internal.Rack, val slot: Int) extends Environment wit // Analyzable override def onAnalyze(player: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float) = Array(machine.node) + + // ----------------------------------------------------------------------- // + // ICapabilityProvider + + override def hasCapability(capability: Capability[_], facing: EnumFacing): Boolean = components.exists { + case Some(component: ICapabilityProvider) => component.hasCapability(capability, host.toLocal(facing)) + case _ => false + } + + override def getCapability[T](capability: Capability[T], facing: EnumFacing): T = components.collectFirst { + case Some(component: ICapabilityProvider) if component.hasCapability(capability, host.toLocal(facing)) => component.getCapability[T](capability, host.toLocal(facing)) + }.getOrElse(null.asInstanceOf[T]) } diff --git a/src/main/scala/li/cil/oc/server/component/Tablet.scala b/src/main/scala/li/cil/oc/server/component/Tablet.scala index 2b53ed0e5..bb9aae736 100644 --- a/src/main/scala/li/cil/oc/server/component/Tablet.scala +++ b/src/main/scala/li/cil/oc/server/component/Tablet.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -9,12 +15,24 @@ import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab import li.cil.oc.common.item.TabletWrapper -class Tablet(val tablet: TabletWrapper) extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +class Tablet(val tablet: TabletWrapper) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("tablet"). withConnector(Settings.get.bufferTablet). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.System, + DeviceAttribute.Description -> "Tablet", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Jogger", + DeviceAttribute.Capacity -> tablet.getSizeInventory.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @Callback(doc = """function():number -- Gets the pitch of the player holding the tablet.""") diff --git a/src/main/scala/li/cil/oc/server/component/Transposer.scala b/src/main/scala/li/cil/oc/server/component/Transposer.scala index 721de5d3b..2340b4bbb 100644 --- a/src/main/scala/li/cil/oc/server/component/Transposer.scala +++ b/src/main/scala/li/cil/oc/server/component/Transposer.scala @@ -1,9 +1,15 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api -import li.cil.oc.api.network.EnvironmentHost +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments +import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab import li.cil.oc.common.tileentity @@ -11,16 +17,26 @@ import li.cil.oc.server.{PacketSender => ServerPacketSender} import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedArguments._ +import scala.collection.convert.WrapAsJava._ import scala.language.existentials object Transposer { - abstract class Common extends prefab.ManagedEnvironment with traits.WorldInventoryAnalytics with traits.WorldTankAnalytics with traits.InventoryTransfer { + abstract class Common extends prefab.ManagedEnvironment with traits.WorldInventoryAnalytics with traits.WorldTankAnalytics with traits.InventoryTransfer with DeviceInfo { override val node = api.Network.newNode(this, Visibility.Network). withComponent("transposer"). withConnector(). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Transposer", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "TP4k-iX" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + override protected def checkSideForAction(args: Arguments, n: Int) = args.checkSideAny(n) diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeAngel.scala b/src/main/scala/li/cil/oc/server/component/UpgradeAngel.scala index 6198cdb2b..77c370224 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeAngel.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeAngel.scala @@ -1,13 +1,33 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass +import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab +import scala.collection.convert.WrapAsJava._ + // Note-to-self: this has a component to allow the robot telling it has the // upgrade. -class UpgradeAngel extends prefab.ManagedEnvironment { +// TODO Remove component in OC 1.7 (device info is sufficient) +class UpgradeAngel extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("angel"). create() + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Angel upgrade", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "FreePlacer (TM)", + DeviceAttribute.Capacity -> Settings.get.maxNetworkPacketSize.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo } diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeBattery.scala b/src/main/scala/li/cil/oc/server/component/UpgradeBattery.scala index 56a2cdf6c..6932f4009 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeBattery.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeBattery.scala @@ -1,12 +1,30 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab -class UpgradeBattery(val tier: Int) extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +class UpgradeBattery(val tier: Int) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withConnector(Settings.get.bufferCapacitorUpgrades(tier)). create() + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Power, + DeviceAttribute.Description -> "Battery", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Unlimited Power (Almost Ed.)", + DeviceAttribute.Capacity -> Settings.get.bufferCapacitorUpgrades(tier).toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo } diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeChunkloader.scala b/src/main/scala/li/cil/oc/server/component/UpgradeChunkloader.scala index b5d6c9d2d..c16322761 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeChunkloader.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeChunkloader.scala @@ -1,8 +1,14 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -13,12 +19,23 @@ import li.cil.oc.common.event.ChunkloaderUpgradeHandler import net.minecraftforge.common.ForgeChunkManager import net.minecraftforge.common.ForgeChunkManager.Ticket -class UpgradeChunkloader(val host: EnvironmentHost) extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +class UpgradeChunkloader(val host: EnvironmentHost) extends prefab.ManagedEnvironment with DeviceInfo { override val node = api.Network.newNode(this, Visibility.Network). withComponent("chunkloader"). withConnector(). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "World stabilizer", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Realizer9001-CL" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + var ticket: Option[Ticket] = None override val canUpdate = true diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala b/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala index 9a8af2873..ce51a7800 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala @@ -1,6 +1,12 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments @@ -17,14 +23,24 @@ import net.minecraftforge.common.MinecraftForge import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent import net.minecraftforge.fml.common.FMLCommonHandler +import scala.collection.convert.WrapAsJava._ import scala.collection.mutable import scala.util.control.Breaks._ -class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends prefab.ManagedEnvironment { +class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("crafting"). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Assembly controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "MultiCombinator-9S" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + @Callback(doc = """function([count:number]):number -- Tries to craft the specified number of items in the top left area of the inventory.""") def craft(context: Context, args: Arguments): Array[AnyRef] = { val count = args.optInteger(0, 64) max 0 min 64 diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeDatabase.scala b/src/main/scala/li/cil/oc/server/component/UpgradeDatabase.scala index 43712f227..38b5b7733 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeDatabase.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeDatabase.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + import com.google.common.hash.Hashing +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback @@ -14,12 +20,24 @@ import li.cil.oc.util.ItemUtils import net.minecraft.inventory.IInventory import net.minecraft.item.ItemStack -class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment with internal.Database { +import scala.collection.convert.WrapAsJava._ + +class UpgradeDatabase(val data: IInventory) extends prefab.ManagedEnvironment with internal.Database with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("database"). create() - override def size() = data.getSizeInventory + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Object catalogue", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "iCatalogue (patent pending)", + DeviceAttribute.Capacity -> size.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + override def size = data.getSizeInventory override def getStackInSlot(slot: Int) = Option(data.getStackInSlot(slot)).map(_.copy()).orNull diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeExperience.scala b/src/main/scala/li/cil/oc/server/component/UpgradeExperience.scala index d57a37cf3..d90a81c81 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeExperience.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeExperience.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments @@ -14,14 +20,25 @@ import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Items import net.minecraft.nbt.NBTTagCompound +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ -class UpgradeExperience(val host: EnvironmentHost with internal.Agent) extends prefab.ManagedEnvironment { +class UpgradeExperience(val host: EnvironmentHost with internal.Agent) extends prefab.ManagedEnvironment with DeviceInfo { override val node = api.Network.newNode(this, Visibility.Network). withComponent("experience"). withConnector(30 * Settings.get.bufferPerLevel). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Knowledge database", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "ERSO (Event Recorder and Self-Optimizer)", + DeviceAttribute.Capacity -> "30" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + var experience = 0.0 var level = 0 diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeGenerator.scala b/src/main/scala/li/cil/oc/server/component/UpgradeGenerator.scala index e249e4c70..7276dfd03 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeGenerator.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeGenerator.scala @@ -1,14 +1,18 @@ package li.cil.oc.server.component -import li.cil.oc.OpenComputers +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings -import li.cil.oc.api import li.cil.oc.api.Network -import li.cil.oc.api.network.EnvironmentHost +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context +import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.network._ import li.cil.oc.api.prefab import li.cil.oc.util.ExtendedNBT._ @@ -17,19 +21,28 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraft.tileentity.TileEntityFurnace -class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("generator", Visibility.Neighbors). withConnector(). create() - val romGenerator = Option(api.FileSystem.asManagedEnvironment(api.FileSystem. - fromClass(OpenComputers.getClass, Settings.resourceDomain, "lua/component/generator"), "generator")) - var inventory: Option[ItemStack] = None var remainingTicks = 0 + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Power, + DeviceAttribute.Description -> "Generator", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Portagen 2.0 (Rev. 3)", + DeviceAttribute.Capacity -> "1" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @Callback(doc = """function([count:number]):boolean -- Tries to insert fuel from the selected slot into the generator's queue.""") @@ -94,13 +107,16 @@ class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends pr if (remainingTicks <= 0 && inventory.isDefined) { val stack = inventory.get remainingTicks = TileEntityFurnace.getItemBurnTime(stack) - updateClient() - stack.stackSize -= 1 - if (stack.stackSize <= 0) { - if (stack.getItem.hasContainerItem(stack)) - inventory = Option(stack.getItem.getContainerItem(stack)) - else - inventory = None + if (remainingTicks > 0) { + // If not we probably have a container item now (e.g. bucket after lava bucket). + updateClient() + stack.stackSize -= 1 + if (stack.stackSize <= 0) { + if (stack.getItem.hasContainerItem(stack)) + inventory = Option(stack.getItem.getContainerItem(stack)) + else + inventory = None + } } } if (remainingTicks > 0) { @@ -119,13 +135,6 @@ class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends pr // ----------------------------------------------------------------------- // - override def onConnect(node: Node) { - super.onConnect(node) - if (node.isNeighborOf(this.node)) { - romGenerator.foreach(fs => node.connect(fs.node)) - } - } - override def onDisconnect(node: Node) { super.onDisconnect(node) if (node == this.node) { @@ -140,13 +149,11 @@ class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends pr case _ => } remainingTicks = 0 - romGenerator.foreach(_.node.remove()) } } override def load(nbt: NBTTagCompound) { super.load(nbt) - romGenerator.foreach(_.load(nbt.getCompoundTag("romGenerator"))) if (nbt.hasKey("inventory")) { inventory = Option(ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("inventory"))) } @@ -155,7 +162,6 @@ class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends pr override def save(nbt: NBTTagCompound) { super.save(nbt) - romGenerator.foreach(fs => nbt.setNewCompoundTag("romGenerator", fs.save)) inventory match { case Some(stack) => nbt.setNewCompoundTag("inventory", stack.writeToNBT) case _ => diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeInventoryController.scala b/src/main/scala/li/cil/oc/server/component/UpgradeInventoryController.scala index 4eeccdc62..f7c7818ab 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeInventoryController.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeInventoryController.scala @@ -1,6 +1,12 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback @@ -12,9 +18,22 @@ import li.cil.oc.common.tileentity import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedArguments._ +import scala.collection.convert.WrapAsJava._ + object UpgradeInventoryController { - class Adapter(val host: EnvironmentHost) extends prefab.ManagedEnvironment with traits.WorldInventoryAnalytics { + trait Common extends DeviceInfo { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Inventory controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Item Cataloguer R1" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + } + + class Adapter(val host: EnvironmentHost) extends prefab.ManagedEnvironment with traits.WorldInventoryAnalytics with Common { override val node = Network.newNode(this, Visibility.Network). withComponent("inventory_controller", Visibility.Network). create() @@ -26,7 +45,7 @@ object UpgradeInventoryController { override protected def checkSideForAction(args: Arguments, n: Int) = args.checkSideAny(n) } - class Drone(val host: EnvironmentHost with internal.Agent) extends prefab.ManagedEnvironment with traits.InventoryAnalytics with traits.InventoryWorldControlMk2 with traits.WorldInventoryAnalytics with traits.ItemInventoryControl { + class Drone(val host: EnvironmentHost with internal.Agent) extends prefab.ManagedEnvironment with traits.InventoryAnalytics with traits.InventoryWorldControlMk2 with traits.WorldInventoryAnalytics with traits.ItemInventoryControl with Common { override val node = Network.newNode(this, Visibility.Network). withComponent("inventory_controller", Visibility.Neighbors). create() @@ -44,7 +63,7 @@ object UpgradeInventoryController { override protected def checkSideForAction(args: Arguments, n: Int) = args.checkSideAny(n) } - class Robot(val host: EnvironmentHost with tileentity.Robot) extends prefab.ManagedEnvironment with traits.InventoryAnalytics with traits.InventoryWorldControlMk2 with traits.WorldInventoryAnalytics with traits.ItemInventoryControl { + class Robot(val host: EnvironmentHost with tileentity.Robot) extends prefab.ManagedEnvironment with traits.InventoryAnalytics with traits.InventoryWorldControlMk2 with traits.WorldInventoryAnalytics with traits.ItemInventoryControl with Common { override val node = Network.newNode(this, Visibility.Network). withComponent("inventory_controller", Visibility.Neighbors). create() diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeLeash.scala b/src/main/scala/li/cil/oc/server/component/UpgradeLeash.scala index 82999ef48..06cf73b93 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeLeash.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeLeash.scala @@ -1,9 +1,14 @@ package li.cil.oc.server.component +import java.util import java.util.UUID +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.OpenComputers import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -20,21 +25,34 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagString import net.minecraftforge.common.util.Constants.NBT +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ import scala.collection.mutable -class UpgradeLeash(val host: Entity) extends prefab.ManagedEnvironment with traits.WorldAware { +class UpgradeLeash(val host: Entity) extends prefab.ManagedEnvironment with traits.WorldAware with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("leash"). create() + final val MaxLeashedEntities = 8 + + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Leash", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "FlockControl (FC-3LS)", + DeviceAttribute.Capacity -> MaxLeashedEntities.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + val leashedEntities = mutable.Set.empty[UUID] override def position = BlockPosition(host) @Callback(doc = """function(side:number):boolean -- Tries to put an entity on the specified side of the device onto a leash.""") def leash(context: Context, args: Arguments): Array[AnyRef] = { - if (leashedEntities.size >= 8) return result(Unit, "too many leashed entities") + if (leashedEntities.size >= MaxLeashedEntities) return result(Unit, "too many leashed entities") val side = args.checkSideAny(0) val nearBounds = position.bounds val farBounds = nearBounds.offset(side.getFrontOffsetX * 2.0, side.getFrontOffsetY * 2.0, side.getFrontOffsetZ * 2.0) diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeNavigation.scala b/src/main/scala/li/cil/oc/server/component/UpgradeNavigation.scala index eeacfa51c..c862781b7 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeNavigation.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeNavigation.scala @@ -1,14 +1,20 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.Network -import li.cil.oc.api.network.EnvironmentHost +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.internal import li.cil.oc.api.internal.Rotatable import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context +import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.network._ import li.cil.oc.api.prefab import li.cil.oc.common.item.data.NavigationUpgradeData @@ -19,7 +25,9 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.EnumFacing -class UpgradeNavigation(val host: EnvironmentHost with Rotatable) extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +class UpgradeNavigation(val host: EnvironmentHost with Rotatable) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("navigation", Visibility.Neighbors). withConnector(). @@ -27,12 +35,22 @@ class UpgradeNavigation(val host: EnvironmentHost with Rotatable) extends prefab val data = new NavigationUpgradeData() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Navigation upgrade", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "PathFinder v3", + DeviceAttribute.Capacity -> data.getSize(host.world).toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // @Callback(doc = """function():number, number, number -- Get the current relative position of the robot.""") def getPosition(context: Context, args: Arguments): Array[AnyRef] = { val info = data.mapData(host.world) - val size = 128 * (1 << info.scale) + val size = data.getSize(host.world) val relativeX = host.xPosition - info.xCenter val relativeZ = host.zPosition - info.zCenter @@ -46,11 +64,7 @@ class UpgradeNavigation(val host: EnvironmentHost with Rotatable) extends prefab def getFacing(context: Context, args: Arguments): Array[AnyRef] = result(host.facing.ordinal) @Callback(doc = """function():number -- Get the operational range of the navigation upgrade.""") - def getRange(context: Context, args: Arguments): Array[AnyRef] = { - val info = data.mapData(host.world) - val size = 128 * (1 << info.scale) - result(size / 2) - } + def getRange(context: Context, args: Arguments): Array[AnyRef] = result(data.getSize(host.world) / 2) @Callback(doc = """function(range:number):table -- Find waypoints in the specified range.""") def findWaypoints(context: Context, args: Arguments): Array[AnyRef] = { diff --git a/src/main/scala/li/cil/oc/server/component/UpgradePiston.scala b/src/main/scala/li/cil/oc/server/component/UpgradePiston.scala index 2193f6754..72f29af0c 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradePiston.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradePiston.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments @@ -15,12 +21,23 @@ import li.cil.oc.util.ExtendedWorld._ import net.minecraft.init.Blocks import net.minecraft.util.EnumFacing -abstract class UpgradePiston(val host: EnvironmentHost) extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +abstract class UpgradePiston(val host: EnvironmentHost) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("piston"). withConnector(). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Piston upgrade", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Displacer II+" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + def pushDirection(args: Arguments, index: Int): EnumFacing def pushOrigin(side: EnumFacing) = BlockPosition(host) diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeSign.scala b/src/main/scala/li/cil/oc/server/component/UpgradeSign.scala index 64ee614f7..e33c1b868 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeSign.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeSign.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.internal import li.cil.oc.api.network.Message @@ -20,7 +26,18 @@ import net.minecraftforge.common.util.FakePlayerFactory import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.fml.common.eventhandler.Event -abstract class UpgradeSign extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +abstract class UpgradeSign extends prefab.ManagedEnvironment with DeviceInfo { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Sign upgrade", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Labelizer Deluxe" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + def host: EnvironmentHost protected def getValue(tileEntity: Option[TileEntitySign]): Array[AnyRef] = { diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeSolarGenerator.scala b/src/main/scala/li/cil/oc/server/component/UpgradeSolarGenerator.scala index dcd9e2ef5..81321759c 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeSolarGenerator.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeSolarGenerator.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab @@ -9,7 +15,9 @@ import li.cil.oc.util.BlockPosition import net.minecraft.util.EnumFacing import net.minecraft.world.biome.BiomeGenDesert -class UpgradeSolarGenerator(val host: EnvironmentHost) extends prefab.ManagedEnvironment { +import scala.collection.convert.WrapAsJava._ + +class UpgradeSolarGenerator(val host: EnvironmentHost) extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withConnector(). create() @@ -18,6 +26,15 @@ class UpgradeSolarGenerator(val host: EnvironmentHost) extends prefab.ManagedEnv var isSunShining = false + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Power, + DeviceAttribute.Description -> "Solar panel", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Enligh10" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + // ----------------------------------------------------------------------- // override val canUpdate = true diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeTank.scala b/src/main/scala/li/cil/oc/server/component/UpgradeTank.scala index 82ea720ed..46a5caa8a 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeTank.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeTank.scala @@ -1,6 +1,12 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab @@ -9,9 +15,23 @@ import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidTank import net.minecraftforge.fluids.IFluidTank -class UpgradeTank(val owner: EnvironmentHost, val capacity: Int) extends prefab.ManagedEnvironment with IFluidTank { +import scala.collection.convert.WrapAsJava._ + +class UpgradeTank(val owner: EnvironmentHost, val capacity: Int) extends prefab.ManagedEnvironment with IFluidTank with DeviceInfo { override val node = Network.newNode(this, Visibility.None).create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Tank upgrade", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Superblubb V10", + DeviceAttribute.Capacity -> capacity.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + val tank = new FluidTank(capacity) override def load(nbt: NBTTagCompound) { diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeTankController.scala b/src/main/scala/li/cil/oc/server/component/UpgradeTankController.scala index 7c7cfd508..620e50cb5 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeTankController.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeTankController.scala @@ -1,6 +1,12 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments @@ -10,9 +16,22 @@ import li.cil.oc.common.tileentity import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedArguments._ +import scala.collection.convert.WrapAsJava._ + object UpgradeTankController { - class Adapter(val host: EnvironmentHost) extends prefab.ManagedEnvironment with traits.WorldTankAnalytics { + trait Common extends DeviceInfo { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Tank controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "FlowCheckDX" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + } + + class Adapter(val host: EnvironmentHost) extends prefab.ManagedEnvironment with traits.WorldTankAnalytics with Common { override val node = Network.newNode(this, Visibility.Network). withComponent("tank_controller", Visibility.Network). create() @@ -24,7 +43,7 @@ object UpgradeTankController { override protected def checkSideForAction(args: Arguments, n: Int) = args.checkSideAny(n) } - class Drone(val host: EnvironmentHost with internal.Agent) extends prefab.ManagedEnvironment with traits.TankInventoryControl with traits.WorldTankAnalytics { + class Drone(val host: EnvironmentHost with internal.Agent) extends prefab.ManagedEnvironment with traits.TankInventoryControl with traits.WorldTankAnalytics with Common { override val node = Network.newNode(this, Visibility.Network). withComponent("tank_controller", Visibility.Neighbors). create() @@ -46,7 +65,7 @@ object UpgradeTankController { override protected def checkSideForAction(args: Arguments, n: Int) = args.checkSideAny(n) } - class Robot(val host: EnvironmentHost with tileentity.Robot) extends prefab.ManagedEnvironment with traits.TankInventoryControl with traits.WorldTankAnalytics { + class Robot(val host: EnvironmentHost with tileentity.Robot) extends prefab.ManagedEnvironment with traits.TankInventoryControl with traits.WorldTankAnalytics with Common { override val node = Network.newNode(this, Visibility.Network). withComponent("tank_controller", Visibility.Neighbors). create() diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeTractorBeam.scala b/src/main/scala/li/cil/oc/server/component/UpgradeTractorBeam.scala index 4ae7952af..e3fd2954d 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeTractorBeam.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeTractorBeam.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.network.EnvironmentHost import li.cil.oc.api.internal import li.cil.oc.api.machine.Arguments @@ -15,35 +21,27 @@ import net.minecraft.entity.item.EntityItem import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.BlockPos +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ object UpgradeTractorBeam { - class Player(val owner: EnvironmentHost, val player: () => EntityPlayer) extends UpgradeTractorBeam { - override protected def position = BlockPosition(owner) - - override protected def collectItem(item: EntityItem) = item.onCollideWithPlayer(player()) - } - - class Drone(val owner: internal.Agent) extends UpgradeTractorBeam { - override protected def position = BlockPosition(owner) - - override protected def collectItem(item: EntityItem) = { - InventoryUtils.insertIntoInventory(item.getEntityItem, owner.mainInventory, None, 64, simulate = false, Some(insertionSlots)) - } - - private def insertionSlots = (owner.selectedSlot until owner.mainInventory.getSizeInventory) ++ (0 until owner.selectedSlot) - } - -} - -abstract class UpgradeTractorBeam extends prefab.ManagedEnvironment { + abstract class Common extends prefab.ManagedEnvironment with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("tractor_beam"). create() private val pickupRadius = 3 + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Tractor beam", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "T313-K1N.3515" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + protected def position: BlockPosition protected def collectItem(item: EntityItem): Unit @@ -68,4 +66,22 @@ abstract class UpgradeTractorBeam extends prefab.ManagedEnvironment { } result(false) } + } + + class Player(val owner: EnvironmentHost, val player: () => EntityPlayer) extends Common { + override protected def position = BlockPosition(owner) + + override protected def collectItem(item: EntityItem) = item.onCollideWithPlayer(player()) + } + + class Drone(val owner: internal.Agent) extends Common { + override protected def position = BlockPosition(owner) + + override protected def collectItem(item: EntityItem) = { + InventoryUtils.insertIntoInventory(item.getEntityItem, owner.mainInventory, None, 64, simulate = false, Some(insertionSlots)) + } + + private def insertionSlots = (owner.selectedSlot until owner.mainInventory.getSizeInventory) ++ (0 until owner.selectedSlot) + } + } diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeTrading.scala b/src/main/scala/li/cil/oc/server/component/UpgradeTrading.scala index b01b1f5fe..0c1a0f513 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeTrading.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeTrading.scala @@ -1,7 +1,13 @@ package li.cil.oc.server.component +import java.util + +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api.Network +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.machine.Arguments import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context @@ -13,13 +19,23 @@ import net.minecraft.entity.Entity import net.minecraft.entity.IMerchant import net.minecraft.util.Vec3 +import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ -class UpgradeTrading(val host: EnvironmentHost) extends prefab.ManagedEnvironment with traits.WorldAware { +class UpgradeTrading(val host: EnvironmentHost) extends prefab.ManagedEnvironment with traits.WorldAware with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("trading"). create() + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Generic, + DeviceAttribute.Description -> "Trading upgrade", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "Capitalism H.O. 1200T" + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + override def position = BlockPosition(host) def maxRange = Settings.get.tradingRange diff --git a/src/main/scala/li/cil/oc/server/component/WirelessNetworkCard.scala b/src/main/scala/li/cil/oc/server/component/WirelessNetworkCard.scala index ec1cb07bb..94bef7ea8 100644 --- a/src/main/scala/li/cil/oc/server/component/WirelessNetworkCard.scala +++ b/src/main/scala/li/cil/oc/server/component/WirelessNetworkCard.scala @@ -1,7 +1,11 @@ package li.cil.oc.server.component import java.io._ +import java.util +import li.cil.oc.Constants +import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute +import li.cil.oc.api.driver.DeviceInfo.DeviceClass import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.Network @@ -14,6 +18,7 @@ import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedWorld._ import net.minecraft.nbt.NBTTagCompound +import scala.collection.convert.WrapAsJava._ import scala.language.implicitConversions class WirelessNetworkCard(host: EnvironmentHost) extends NetworkCard(host) with WirelessEndpoint { @@ -26,6 +31,19 @@ class WirelessNetworkCard(host: EnvironmentHost) extends NetworkCard(host) with // ----------------------------------------------------------------------- // + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Network, + DeviceAttribute.Description -> "Wireless ethernet controller", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "62i230 (MPW-01)", + DeviceAttribute.Capacity -> Settings.get.maxNetworkPacketSize.toString, + DeviceAttribute.Width -> Settings.get.maxWirelessRange.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + // ----------------------------------------------------------------------- // + def position = BlockPosition(host) override def x = position.x diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index e659ed8bf..2db01363c 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -1,5 +1,6 @@ package li.cil.oc.server.machine +import java.util import java.util.concurrent.TimeUnit import li.cil.oc.OpenComputers @@ -7,6 +8,7 @@ import li.cil.oc.Settings import li.cil.oc.api.Driver import li.cil.oc.api.Network import li.cil.oc.api.detail.MachineAPI +import li.cil.oc.api.driver.DeviceInfo import li.cil.oc.api.driver.item.CallBudget import li.cil.oc.api.driver.item.Processor import li.cil.oc.api.machine @@ -46,7 +48,7 @@ import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ import scala.collection.mutable -class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with machine.Machine with Runnable { +class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with machine.Machine with Runnable with DeviceInfo { override val node = Network.newNode(this, Visibility.Network). withComponent("computer", Visibility.Neighbors). withConnector(Settings.get.bufferComputer). @@ -177,6 +179,13 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach // ----------------------------------------------------------------------- // + override def getDeviceInfo: util.Map[String, String] = host match { + case deviceInfo: DeviceInfo => deviceInfo.getDeviceInfo + case _ => null + } + + // ----------------------------------------------------------------------- // + override def canInteract(player: String) = !Settings.get.canComputersBeOwned || _users.synchronized(_users.isEmpty || _users.contains(player)) || MinecraftServer.getServer.isSinglePlayer || { @@ -420,6 +429,29 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach null } + @Callback(direct = true, doc = """function():table -- Collect information on all connected devices.""") + def getDeviceInfo(context: Context, args: Arguments): Array[AnyRef] = { + context.pause(1) // Iterating all nodes is potentially expensive, and I see no practical reason for having to call this frequently. + Array[AnyRef](node.network.nodes.map(n => (n, n.host)).collect { + case (n: Component, deviceInfo: DeviceInfo) => + if (n.canBeSeenFrom(node) || n == node) { + Option(deviceInfo.getDeviceInfo) match { + case Some(info) => Option(n.address -> info) + case _ => None + } + } + else None + case (n, deviceInfo: DeviceInfo) => + if (n.canBeReachedFrom(node)) { + Option(deviceInfo.getDeviceInfo) match { + case Some(info) => Option(n.address -> info) + case _ => None + } + } + else None + }.collect { case Some(kvp) => kvp }.toMap) + } + // ----------------------------------------------------------------------- // def isExecuting = state.synchronized(state.contains(Machine.State.Running)) @@ -440,6 +472,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach // Component overflow check, crash if too many components are connected, to // avoid confusion on the user's side due to components not showing up. if (componentCount > maxComponents) { + beep("-..") crash("gui.Error.ComponentOverflow") } diff --git a/src/main/scala/li/cil/oc/util/FluidUtils.scala b/src/main/scala/li/cil/oc/util/FluidUtils.scala index 1a58af63b..f47de3843 100644 --- a/src/main/scala/li/cil/oc/util/FluidUtils.scala +++ b/src/main/scala/li/cil/oc/util/FluidUtils.scala @@ -4,6 +4,7 @@ import li.cil.oc.util.ExtendedBlock._ import li.cil.oc.util.ExtendedWorld._ import net.minecraft.block.Block import net.minecraft.block.BlockLiquid +import net.minecraft.block.BlockStaticLiquid import net.minecraft.util.EnumFacing import net.minecraftforge.fluids.Fluid import net.minecraftforge.fluids.FluidContainerRegistry @@ -72,11 +73,16 @@ object FluidUtils { def currentWrapper = if (position.world.get.blockExists(position)) position.world.get.getBlock(position) match { case block: IFluidBlock => Option(new FluidBlockWrapper(position, block)) - case block: BlockLiquid if FluidRegistry.lookupFluidForBlock(block) != null => Option(new LiquidBlockWrapper(position, block)) + case block: BlockStaticLiquid if FluidRegistry.lookupFluidForBlock(block) != null && isFullLiquidBlock => Option(new LiquidBlockWrapper(position, block)) case block: Block if block.isAir(position) || block.isReplaceable(position) => Option(new AirBlockWrapper(position, block)) case _ => None } else None + + def isFullLiquidBlock = { + val state = position.world.get.getBlockState(position.toBlockPos) + state.getValue(BlockLiquid.LEVEL) == 0 + } } private trait BlockWrapperBase extends IFluidHandler { @@ -141,7 +147,8 @@ object FluidUtils { if (resource != null && resource.getFluid.canBePlacedInWorld && resource.getFluid.getBlock != null) { if (doFill) { val world = position.world.get - world.breakBlock(position) + if (!world.isAirBlock(position) && !world.isAnyLiquid(position.bounds)) + world.breakBlock(position) world.setBlock(position, resource.getFluid.getBlock) // This fake neighbor update is required to get stills to start flowing. world.notifyBlockOfNeighborChange(position, world.getBlock(position)) diff --git a/src/main/scala/li/cil/oc/util/RenderState.scala b/src/main/scala/li/cil/oc/util/RenderState.scala index 701ff9dbc..5eb36f76e 100644 --- a/src/main/scala/li/cil/oc/util/RenderState.scala +++ b/src/main/scala/li/cil/oc/util/RenderState.scala @@ -34,95 +34,31 @@ object RenderState { else false } - def pushAttrib(mask: Int = 8256): Unit = { - GL11.glPushAttrib(mask) + // pushAttrib/popAttrib currently breaks the GlStateManager because it doesn't + // accordingly pushes/pops its cache, so it gets into an illegal state... + // See https://gist.github.com/fnuecke/9a5b2499835fca9b52419277dc6239ca + def pushAttrib(): Unit = { +// GlStateManager.glPushAttrib(mask) } def popAttrib(): Unit = { - GlStateManager.popAttrib() - } - - def pushMatrix(): Unit = { - GlStateManager.pushMatrix() - } - - def popMatrix(): Unit = { - GlStateManager.popMatrix() - } - - def color(r: Float, g: Float, b: Float, a: Float = 1f): Unit = { - GlStateManager.color(r, g, b, a) - GL11.glColor4f(r, g, b, a) - } - - def disableColorMask(): Unit = { - GlStateManager.colorMask(false, false, false, false) - GL11.glColorMask(false, false, false, false) - } - - def enableColorMask(): Unit = { - GlStateManager.colorMask(true, true, true, true) - GL11.glColorMask(true, true, true, true) - } - - def disableCullFace(): Unit = { - GlStateManager.disableCull() - GL11.glDisable(GL11.GL_CULL_FACE) - } - - def enableCullFace(): Unit = { - GlStateManager.enableCull() - GL11.glEnable(GL11.GL_CULL_FACE) - } - - def disableDepth(): Unit = { - GlStateManager.disableDepth() - GL11.glDisable(GL11.GL_DEPTH_TEST) - } - - def enableDepth(): Unit = { - GlStateManager.enableDepth() - GL11.glEnable(GL11.GL_DEPTH_TEST) - } - - def disableDepthMask(): Unit = { - GlStateManager.depthMask(false) - GL11.glDepthMask(false) - } - - def enableDepthMask(): Unit = { - GlStateManager.depthMask(true) - GL11.glDepthMask(true) - } - - def disableLighting(): Unit = { - GlStateManager.disableLighting() - GL11.glDisable(GL11.GL_LIGHTING) - } - - def enableLighting(): Unit = { - GlStateManager.enableLighting() - GL11.glEnable(GL11.GL_LIGHTING) +// GlStateManager.popAttrib() } def disableEntityLighting() { Minecraft.getMinecraft.entityRenderer.disableLightmap() - RenderHelper.disableStandardItemLighting() + GlStateManager.disableLighting() + GlStateManager.disableLight(0) + GlStateManager.disableLight(1) + GlStateManager.disableColorMaterial() } def enableEntityLighting() { Minecraft.getMinecraft.entityRenderer.enableLightmap() - RenderHelper.enableStandardItemLighting() - } - - def disableRescaleNormal(): Unit = { - GlStateManager.disableRescaleNormal() - GL11.glDisable(GL12.GL_RESCALE_NORMAL) - } - - def enableRescaleNormal(): Unit = { - GlStateManager.enableRescaleNormal() - GL11.glEnable(GL12.GL_RESCALE_NORMAL) + GlStateManager.enableLighting() + GlStateManager.enableLight(0) + GlStateManager.enableLight(1) + GlStateManager.enableColorMaterial() } def makeItBlend() { @@ -131,26 +67,11 @@ object RenderState { GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) } - def disableBlend(): Unit = { + def disableBlend() { GlStateManager.disableBlend() GL11.glDisable(GL11.GL_BLEND) } - def blendFunc(sFactor: Int, dFactor: Int): Unit = { - GlStateManager.blendFunc(sFactor, dFactor) - GL11.glBlendFunc(sFactor, dFactor) - } - - def cullFace(mode: Int): Unit = { - GlStateManager.cullFace(mode) - GL11.glCullFace(mode) - } - - def depthFunc(func: Int): Unit = { - GlStateManager.depthFunc(func) - GL11.glDepthFunc(func) - } - def setBlendAlpha(alpha: Float) = { GlStateManager.color(1, 1, 1, alpha) GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)