diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 295ee80ca..86dd28bda 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -599,6 +599,26 @@ opencomputers { nanomachines: 100000 } + # Carpeted Capacitor settings + # Carpeted Capacitors generate power when sheep or ocelots walk on them + # Power is generated when at least 2 of a type of animal are present. + # A single sheep and a single ocelot generates no power. Note that a + # computer constantly flashing the screen from white to black drains + # approximately 36 units of power per second. Thus, as an example with the + # default values, it would take 12 carpeted capacitors and 24 sheep + # (2 each) to keep the charge rate. Or, 6 carpeted capacitors and 12 + # ocelots to do the same. Values are: units of power per carpeted + # capacitor per second with 2 animals of a type. + carpetedCapacitors { + # Chance one animal (per capacitor) will take some damage per minute + # Damage chance is only dealt when power is generated + damageChance: 0.001 + # power generated from ocelots + ocelotPower: 6 + # power generated from sheep + sheepPower: 3 + } + # Default "costs", i.e. how much energy certain operations consume. cost { # The amount of energy a computer consumes per tick when running. diff --git a/src/main/resources/assets/opencomputers/blockstates/carpetedcapacitor.json b/src/main/resources/assets/opencomputers/blockstates/carpetedcapacitor.json new file mode 100644 index 000000000..f6c92cb33 --- /dev/null +++ b/src/main/resources/assets/opencomputers/blockstates/carpetedcapacitor.json @@ -0,0 +1,5 @@ +{ + "variants": { + "normal": { "model": "opencomputers:carpetedcapacitor" } + } +} diff --git a/src/main/resources/assets/opencomputers/lang/de_DE.lang b/src/main/resources/assets/opencomputers/lang/de_DE.lang index bb4f570c9..f46559bad 100644 --- a/src/main/resources/assets/opencomputers/lang/de_DE.lang +++ b/src/main/resources/assets/opencomputers/lang/de_DE.lang @@ -194,7 +194,6 @@ oc:gui.Chat.WarningClassTransformer=Es gab §cFehler§f beim Ausführen des Clas oc:gui.Chat.WarningFingerprint=§cWARNUNG§f - ungültige Signatur! Sollte '§a%s§f' sein, aber war '§e%s§f'. Falls du kein Modder bist und die "deobfuscated"-Version des Mods benutzt, solltest du OpenComputers erneut herunterladen, da die JAR, die du benutzt, vermutlich modifiziert wurde. oc:gui.Chat.WarningLink=Link konnte nicht geöffnet werden: %s oc:gui.Chat.WarningLuaFallback=Die native Lua-Implementierung ist nicht verfügbar. Computer können ihren Ausführungszustand nicht speichern. Sie werden automatisch neu starten, sobald ein Chunk neu geladen wird. -oc:gui.Chat.WarningPower=Es ist keine unterstützte, Strom erzeugende Mod verfügbar. Computer, Bildschirme und alle anderen Komponenten werden §lkeine§f Energie benötigen. Installiere eine der folgenden Mods, um Stromnutzung zu ermöglichen: BuildCraft, Electrical Age, IndustrialCraft2, Mekanism oder Thermal Expansion. Deaktiviere Stromverbrauch in der Konfiguration, um diese Warnung auszublenden. oc:gui.Chat.WarningProjectRed=Die verwendete Version von Project: Red ist nicht mit OpenComputers kompatibel. Aktualisiere bitte deine Version von Project: Red. oc:gui.Chat.WarningRecipes=Es gab Fehler beim Laden eines oder mehrerer Rezepte. Einige Gegenstände können unter Umständen nicht gefertigt werden. Bitte wirf einen Blick in deine Log-Datei für weitere Informationen. oc:gui.Chat.WarningSimpleComponent=Eine Erweiterung (deine?) welche das §aSimpleComponent§f-Interface verwendet, hat etwas §efalsch gemacht§f. Komponentenlogik konnte nicht eingefügt werden. Bitte wirf einen Blick in deine Log-Datei für weitere Informationen. diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index 35c56c213..38baa2d34 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -7,6 +7,7 @@ tile.oc.adapter.name=Adapter tile.oc.assembler.name=Electronics Assembler tile.oc.cable.name=Cable tile.oc.capacitor.name=Capacitor +tile.oc.carpetedcapacitor.name=Carpeted Capacitor tile.oc.case1.name=Computer Case (Tier 1) tile.oc.case2.name=Computer Case (Tier 2) tile.oc.case3.name=Computer Case (Tier 3) @@ -195,7 +196,6 @@ oc:gui.Chat.WarningClassTransformer=There were §cerrors§f running the class tr oc:gui.Chat.WarningFingerprint=§cWARNING§f - fingerprint mismatch! Expected '§a%s§f' but got '§e%s§f'. Unless you are a modder and are running the deobfuscated version of the mod, it is §lstrongly§f recommended to redownload OpenComputers, because the JAR you are using may have been tampered with. oc:gui.Chat.WarningLink=Could not open link: %s oc:gui.Chat.WarningLuaFallback=Native Lua libraries are not available, computers will not be able to persist their state. They will reboot on chunk reloads. -oc:gui.Chat.WarningPower=No supported power providing mod available. Computers, screens and all other components will §lnot§f require energy. Install one of the following mods to enable power: BuildCraft, Electrical Age, IndustrialCraft2, Mekanism or Thermal Expansion. Disable power in the config to suppress this warning. oc:gui.Chat.WarningProjectRed=You are using a version of Project: Red that is incompatible with OpenComputers. Try updating your version of Project: Red. oc:gui.Chat.WarningRecipes=There were errors loading one or more recipes. Some items may be uncraftable. Please check your log file for more information. oc:gui.Chat.WarningSimpleComponent=An addon (yours?) using the §aSimpleComponent§f interface did §esomething wrong§f. Component logic could not be injected. Please check your log file for more information. @@ -259,6 +259,7 @@ oc:tooltip.apu=This is a CPU with an integrated GPU (or IGP), when you just need oc:tooltip.assembler=Allows constructing robots and other devices from a number of different computer parts. oc:tooltip.cable=A cheap way of connecting blocks. oc:tooltip.capacitor=Stores energy for later use. Can be filled and emptied very quickly. +oc:tooltip.carpetedcapacitor=Stores energy for later use. Can be filled and emptied very quickly. Charges when Sheep or Ocelots walk on it oc:tooltip.cardbase=As the name indicates, this is the basic building block for all expansion cards. oc:tooltip.case=The Computer Case is the basic building block for computers and houses the computer's §fextension cards§7, §fRAM§7 and §fhard disks§7.[nl] Slots: §f%s§7 oc:tooltip.chamelium=Raw material for 3D prints. Do not swallow: may lead to blindness and temporary lack of presence. diff --git a/src/main/resources/assets/opencomputers/lang/fr_FR.lang b/src/main/resources/assets/opencomputers/lang/fr_FR.lang index 4385d8d02..eac2d692d 100644 --- a/src/main/resources/assets/opencomputers/lang/fr_FR.lang +++ b/src/main/resources/assets/opencomputers/lang/fr_FR.lang @@ -186,7 +186,6 @@ oc:gui.Chat.WarningClassTransformer=Il y a §cerrors§f lancement dans le transf oc:gui.Chat.WarningFingerprint=§cALERTE§f - Disparité d'empreinte digitale! Attendu '§a%s§f' mais eu '§e%s§f'. À moins que vous ne soyez un modder et que vous exécutiez la version deobfuscated du mod, Il est §lfortement§f recommendé de re-télécharger OpenComputers, parce que le JAR que vous utilisez peut avoir été falsifié. oc:gui.Chat.WarningLink=Impossible d'ouvrir le lien : %s oc:gui.Chat.WarningLuaFallback=Les bibliothèques natives Lua ne sont pas disponibles, les ordinateurs ne pourront pas persister en leur état. Ils réamorceront sur la recharge des chunks. -oc:gui.Chat.WarningPower=Aucun mod supporté produisant de la puissance. Les ordinateurs, écrans et autres composants §lne réclamerons pas§f d'énergie. Installez l'un de ses mods pour activer la puissance: BuildCraft, Electrical Age, IndustrialCraft2, Mekanism or Thermal Expansion. Mettez hors service la puissance dans la config pour supprimer cet avertissement. oc:gui.Chat.WarningProjectRed=Vous utilisez une version de Project: Red qui est incompatible avec OpenComputers. Essayez de mettre à jour votre version de Project: Red. oc:gui.Chat.WarningRecipes=il y a des erreurs au lancement de recettes. Certains éléments doivent être infabricables. Veuillez vérifier votre fichier log pour plus d'information. oc:gui.Chat.WarningSimpleComponent=Un ajout (le votre ?) utilisant l'interface §aComposant Simple§f produit §equelquechose de mauvais§f. Le composant logique ne peut être inséré. Veuillez vérifier votre fichier log pour plus d'information. diff --git a/src/main/resources/assets/opencomputers/lang/it_IT.lang b/src/main/resources/assets/opencomputers/lang/it_IT.lang index 91b34d13d..11dfb3ec6 100644 --- a/src/main/resources/assets/opencomputers/lang/it_IT.lang +++ b/src/main/resources/assets/opencomputers/lang/it_IT.lang @@ -140,7 +140,6 @@ oc:gui.Assembler.Warning.Screen=Schermo oc:gui.Chat.NewVersion=Una nuova versione è disponibile: %s oc:gui.Chat.WarningFingerprint=§cATTENZIONE§f - mancata corrispondenza dei fingerprint! Atteso '§a%s§f' ma ottenuto '§e%s§f'. Tranne nel caso tu sia un mod che stai utilizzando una versione decomppilata, è §lfortemente§f raccomantado riscaricare OpenComputers, perché il file JAR che stai utilizzando potrebbe essere stato corrotto. oc:gui.Chat.WarningLuaFallback=Le librerie Lua Native non sono disponibili, i computers non saranno in gredo di mantenere il loro stato di persostenza. Essi verranno riavviati quando il chunk viene ricaricato. -oc:gui.Chat.WarningPower=Nessun mod che fornisce energia disponibile. Computer, monitor e tutti gli altri componenti §lnon§f avranno bisogno di energia per funzionare. Installa uno dei seguenti mod per utilizzare il consumo di energia: BuildCraft, Electrical Age, IndustrialCraft2, Mekanism or Thermal Expansion. Disabilita l'utilizzo di energia nella configurazione per rimuovere questo avviso. oc:gui.Chat.WarningProjectRed=Stai utilizzando una versione di Project: Red che è incompatibile con OpenComputers. Prova ad aggriornare la tua versione di Project: Red. oc:gui.Error.ComponentOverflow=Troppi componenti connessi al computer. oc:gui.Error.InternalError=Errore interno, per favore vedi il file di log. Questo è probabilmente un bug. diff --git a/src/main/resources/assets/opencomputers/lang/pt_BR.lang b/src/main/resources/assets/opencomputers/lang/pt_BR.lang index 8d26b0f37..42174b4a4 100644 --- a/src/main/resources/assets/opencomputers/lang/pt_BR.lang +++ b/src/main/resources/assets/opencomputers/lang/pt_BR.lang @@ -194,7 +194,6 @@ oc:gui.Chat.WarningClassTransformer=Houve um erro §cerros§f ao rodar o 'class oc:gui.Chat.WarningFingerprint=§cATENÇÃO§f - impressão digital não reconhecida! Experado '§a%s§f' mas recebido '§e%s§f'. Há não ser que seja um moderador e esteja rodando uma versão desofuscada, é §lextremamente§f recomendável que baixe novamente o OpenComputers, por que o JAR que está usando talvez esteja adulterado. oc:gui.Chat.WarningLink=Não pode abrir o atalho: %s oc:gui.Chat.WarningLuaFallback=Bibliotecas de LUA nativas não disponíveis, computadores não serão capazes de persistir seus estados. Eles reiniciarizaram com chunkloaders. -oc:gui.Chat.WarningPower=Nenhum mod supprtado que provê energia foi encontrado. Computadores, monitores e todos os outros componentes §lnão§f requiriram energia. Instale um dos mods para habilitar a energia: BuildCraft, Electrical Age, IndustrialCraft2, Mekanism ou Thermal Expansion. Disabilite a energia nas confgurações para que esse aviso não apareça. oc:gui.Chat.WarningProjectRed=Você está usando a versão Project: Red que é incompativel com OpenComputers. Tente atualizar sua versão do Project: Red. oc:gui.Chat.WarningRecipes=Houve erros ao carregar uma ou mais receitas. Algumas não poderão ser construídas. Por favor verifique seu arquivo de log para mais informações. oc:gui.Chat.WarningSimpleComponent=Um addon (seu?) usa a interface §aSimpleComponent§f que faz §ealgo errado§f. A lógica de componente não pode ser injetada. Por favor verifique seu arquivo de log para mais informações. diff --git a/src/main/resources/assets/opencomputers/lang/ru_RU.lang b/src/main/resources/assets/opencomputers/lang/ru_RU.lang index 5708208da..d85e8a878 100644 --- a/src/main/resources/assets/opencomputers/lang/ru_RU.lang +++ b/src/main/resources/assets/opencomputers/lang/ru_RU.lang @@ -196,7 +196,6 @@ oc:gui.Chat.WarningClassTransformer=Возникли §cошибки§f при oc:gui.Chat.WarningFingerprint=§cВНИМАНИЕ§f - несовпадение отпечатка файла! Ожидаемый: '§a%s§f', полученный: '§e%s§f'. Если Вы не разработчик, использующий деобфусцированную версию мода, то §lкрайне§f желательно заново скачать OpenComputers, поскольку JAR-файл, возможно, был изменён. oc:gui.Chat.WarningLink=Невозможно открыть ссылку: %s oc:gui.Chat.WarningLuaFallback=Исходные библиотеки Lua не доступны, компьютеры не смогут сохранять своё состояние. Они перезагрузятся после выгрузки чанка. -oc:gui.Chat.WarningPower=Подходящие моды, предоставляющие энергию, не найдены. Компьютеры, мониторы и прочие компоненты §lне будут§f требовать энергию. Для активации данной функции установите один из следующих модов: BuildCraft, IndustrialCraft2, Thermal Expansion или Resonant Engine. Отключите требование энергии в файле конфигурации, чтобы скрыть это предупреждение. oc:gui.Chat.WarningProjectRed=Вы используете версию Project: Red, несовместимую с OpenComputers. Попробуйте обновить Project: Red. oc:gui.Chat.WarningRecipes=Произошла ошибка при загрузке одного или нескольких рецептов. Некоторые предметы могут не крафтиться. Проверьте логи, чобы узнать подробнее. oc:gui.Chat.WarningSimpleComponent=Некоторый мод §eневерно§f использует интрефейс §aSimpleComponent§f. Логика компонента не смогла быть внедрена. Проверьте логи, чобы узнать подробнее. diff --git a/src/main/resources/assets/opencomputers/lang/zh_CN.lang b/src/main/resources/assets/opencomputers/lang/zh_CN.lang index c215c5b2b..e3823759c 100644 --- a/src/main/resources/assets/opencomputers/lang/zh_CN.lang +++ b/src/main/resources/assets/opencomputers/lang/zh_CN.lang @@ -195,7 +195,6 @@ oc:gui.Chat.WarningClassTransformer=执行类转换器时发生§c错误§f. 请 oc:gui.Chat.WarningFingerprint=§c警告§f - 指纹校验不匹配! 预期对应 '§a%s§f' 但识别到 '§e%s§f'. 如果您不是模组的作者, 或运行的不是反混淆版本, 我§l强烈§f 建议你重新下载开放式电脑模组, 因为当前使用的JAR文件已被篡改. oc:gui.Chat.WarningLink=无法打开链接: %s oc:gui.Chat.WarningLuaFallback=无法使用原有的Lua库, 电脑不会持续现在的状态. 它们会在区块载入时重启. -oc:gui.Chat.WarningPower=没有检测到可提供能源的模组. 电脑,显示屏和所有其它组件将§l不需要§f能量来运作. 安装下列任意一个组来启用能量需求:建筑(Buildcraft),电子时代(Electrical Age),工业2(IndustrialCraft 2),通用机械(Mekanism)或热力膨胀(Thermal Expansion). 在配置文件中禁用能量设定可以让这条信息不再显示. oc:gui.Chat.WarningProjectRed=你目前使用的Project:Red版本不兼容OpenComputers. 请升级您的Project:Red后再试. oc:gui.Chat.WarningRecipes=加载合成表时遇到一个或多个错误. 部分物品或因此无法合成. 查阅日志文件以获取详细信息. oc:gui.Chat.WarningSimpleComponent=一个(您的?)扩展Mod使用了§aSimpleComponent§f接口但§e做错了一些事情§f. Component logic无法注入. 查阅日志文件以获取详细信息. diff --git a/src/main/resources/assets/opencomputers/lang/zh_TW.lang b/src/main/resources/assets/opencomputers/lang/zh_TW.lang index 1ec557339..0f7717bab 100644 --- a/src/main/resources/assets/opencomputers/lang/zh_TW.lang +++ b/src/main/resources/assets/opencomputers/lang/zh_TW.lang @@ -190,7 +190,6 @@ oc:gui.Chat.WarningClassTransformer=There were §cerrors§f running the class tr oc:gui.Chat.WarningFingerprint=§c警告§f - 指紋不符!預期 '§a%s§f' 但得到 '§e%s§f'. Unless you are a modder and are running the deobfuscated version of the mod, it is §lstrongly§f recommended to redownload OpenComputers, because the JAR you are using may have been tampered with. oc:gui.Chat.WarningLink=無法打開鏈接: %s oc:gui.Chat.WarningLuaFallback=本機 LUA 函式庫無法使用,電腦將無法維持狀態,他會重新啟動並且載入區塊 -oc:gui.Chat.WarningPower=沒有發現支援的能量供應模組. 電腦螢幕與全部其他的電腦設備 §lnot§f 需要能量. 安裝下列模組之一能夠提供能源: BuildCraft 或 IndustrialCraft2. 在配置裡面可以設定不使用這個電源警告 oc:gui.Chat.WarningProjectRed=你正在使用的 Project: Red 模組與 OpenComputers 不相容. 請嘗試更新 Project: Red. oc:gui.Chat.WarningRecipes=There were errors loading one or more recipes. Some items may be uncraftable. Please check your log file for more information. oc:gui.Chat.WarningSimpleComponent=An addon (yours?) using the §aSimpleComponent§f interface did §esomething wrong§f. Component logic could not be injected. Please check your log file for more information. diff --git a/src/main/resources/assets/opencomputers/models/block/carpetedcapacitor.json b/src/main/resources/assets/opencomputers/models/block/carpetedcapacitor.json new file mode 100644 index 000000000..2b8c02949 --- /dev/null +++ b/src/main/resources/assets/opencomputers/models/block/carpetedcapacitor.json @@ -0,0 +1,8 @@ +{ + "parent": "block/cube_bottom_top", + "textures": { + "bottom": "opencomputers:blocks/generic_top", + "top": "opencomputers:blocks/carpeted_capacitor_top", + "side": "opencomputers:blocks/capacitor_side" + } +} diff --git a/src/main/resources/assets/opencomputers/models/item/carpetedcapacitor.json b/src/main/resources/assets/opencomputers/models/item/carpetedcapacitor.json new file mode 100644 index 000000000..a717606ce --- /dev/null +++ b/src/main/resources/assets/opencomputers/models/item/carpetedcapacitor.json @@ -0,0 +1,10 @@ +{ + "parent": "opencomputers:block/carpetedcapacitor", + "display": { + "thirdperson": { + "rotation": [ 10, -45, 170 ], + "translation": [ 0, 1.5, -2.75 ], + "scale": [ 0.375, 0.375, 0.375 ] + } + } +} diff --git a/src/main/resources/assets/opencomputers/recipes/default.recipes b/src/main/resources/assets/opencomputers/recipes/default.recipes index 78d2bc3b3..e0b41c1f0 100644 --- a/src/main/resources/assets/opencomputers/recipes/default.recipes +++ b/src/main/resources/assets/opencomputers/recipes/default.recipes @@ -560,6 +560,14 @@ cable { ["", iron_nugget, ""]] output: 4 } +luaBios { + type: shapeless + input: ["oc:eeprom", "oc:manual"] +} +carpetedcapacitor { + type: shapeless + input: [carpet, "oc:capacitor"] +} capacitor { input: [[ingotIron, "oc:materialTransistor", ingotIron] [nuggetGold, paper, nuggetGold] diff --git a/src/main/resources/assets/opencomputers/recipes/gregtech.recipes b/src/main/resources/assets/opencomputers/recipes/gregtech.recipes index e4a45a627..1c3a45134 100644 --- a/src/main/resources/assets/opencomputers/recipes/gregtech.recipes +++ b/src/main/resources/assets/opencomputers/recipes/gregtech.recipes @@ -271,6 +271,10 @@ cable { time: 64 output: 8 } +carpetedcapacitor { + type: shapeless + input: [carpet, "oc:capacitor"] +} capacitor { # 7 = CESU input: [["", {item="ic2.blockElectric", subID=7}, ""] diff --git a/src/main/resources/assets/opencomputers/recipes/hardmode.recipes b/src/main/resources/assets/opencomputers/recipes/hardmode.recipes index 83db44f1c..14cc0646a 100644 --- a/src/main/resources/assets/opencomputers/recipes/hardmode.recipes +++ b/src/main/resources/assets/opencomputers/recipes/hardmode.recipes @@ -316,6 +316,10 @@ cable { ["", iron_nugget, ""]] output: 4 } +carpetedcapacitor { + type: shapeless + input: [carpet, "oc:capacitor"] +} capacitor { input: [[ingotIron, "oc:materialTransistor", ingotIron] [nuggetGold, paper, nuggetGold] diff --git a/src/main/resources/assets/opencomputers/textures/blocks/carpeted_capacitor_top.png b/src/main/resources/assets/opencomputers/textures/blocks/carpeted_capacitor_top.png new file mode 100644 index 000000000..8e868a1ce Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/carpeted_capacitor_top.png differ diff --git a/src/main/scala/li/cil/oc/Constants.scala b/src/main/scala/li/cil/oc/Constants.scala index 3bd93a7c8..1fca16de3 100644 --- a/src/main/scala/li/cil/oc/Constants.scala +++ b/src/main/scala/li/cil/oc/Constants.scala @@ -9,6 +9,7 @@ object Constants { final val Assembler = "assembler" final val Cable = "cable" final val Capacitor = "capacitor" + final val CarpetedCapacitor = "carpetedcapacitor" final val CaseCreative = "casecreative" final val CaseTier1 = "case1" final val CaseTier2 = "case2" diff --git a/src/main/scala/li/cil/oc/Localization.scala b/src/main/scala/li/cil/oc/Localization.scala index 93110c9f5..0bdd2a18d 100644 --- a/src/main/scala/li/cil/oc/Localization.scala +++ b/src/main/scala/li/cil/oc/Localization.scala @@ -88,8 +88,6 @@ object Localization { def WarningProjectRed: ITextComponent = new TextComponentString("§aOpenComputers§f: ").appendSibling(localizeLater("gui.Chat.WarningProjectRed")) - def WarningPower: ITextComponent = new TextComponentString("§aOpenComputers§f: ").appendSibling(localizeLater("gui.Chat.WarningPower")) - def WarningFingerprint(event: FMLFingerprintViolationEvent): ITextComponent = new TextComponentString("§aOpenComputers§f: ").appendSibling(localizeLater("gui.Chat.WarningFingerprint", event.getExpectedFingerprint, event.getFingerprints.toArray.mkString(", "))) def WarningRecipes: ITextComponent = new TextComponentString("§aOpenComputers§f: ").appendSibling(localizeLater("gui.Chat.WarningRecipes")) diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index f902b7ce5..484cfc632 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -153,6 +153,11 @@ class Settings(val config: Config) { val printerTickAmount = config.getDouble("power.printerTickAmount") max 1 val powerModBlacklist = config.getStringList("power.modBlacklist") + // power.carpetedCapacitors + val sheepPower = config.getDouble("power.carpetedCapacitors.sheepPower") max 0 + val ocelotPower = config.getDouble("power.carpetedCapacitors.ocelotPower") max 0 + val carpetDamageChance = config.getDouble("power.carpetedCapacitors.damageChance") max 0 min 1.0 + // power.buffer val bufferCapacitor = config.getDouble("power.buffer.capacitor") max 0 val bufferCapacitorAdjacencyBonus = config.getDouble("power.buffer.capacitorAdjacencyBonus") max 0 diff --git a/src/main/scala/li/cil/oc/common/block/CarpetedCapacitor.scala b/src/main/scala/li/cil/oc/common/block/CarpetedCapacitor.scala new file mode 100644 index 000000000..03108dce6 --- /dev/null +++ b/src/main/scala/li/cil/oc/common/block/CarpetedCapacitor.scala @@ -0,0 +1,8 @@ +package li.cil.oc.common.block + +import li.cil.oc.common.tileentity +import net.minecraft.world.World + +class CarpetedCapacitor extends Capacitor { + override def createNewTileEntity(world: World, metadata: Int) = new tileentity.CarpetedCapacitor() +} diff --git a/src/main/scala/li/cil/oc/common/init/Blocks.scala b/src/main/scala/li/cil/oc/common/init/Blocks.scala index 1359388c0..10c04648a 100644 --- a/src/main/scala/li/cil/oc/common/init/Blocks.scala +++ b/src/main/scala/li/cil/oc/common/init/Blocks.scala @@ -14,6 +14,7 @@ object Blocks { GameRegistry.registerTileEntity(classOf[tileentity.Assembler], Settings.namespace + "assembler") GameRegistry.registerTileEntity(classOf[tileentity.Cable], Settings.namespace + "cable") GameRegistry.registerTileEntity(classOf[tileentity.Capacitor], Settings.namespace + "capacitor") + GameRegistry.registerTileEntity(classOf[tileentity.CarpetedCapacitor], Settings.namespace + "carpetedCapacitor") GameRegistry.registerTileEntity(classOf[tileentity.Case], Settings.namespace + "case") GameRegistry.registerTileEntity(classOf[tileentity.Charger], Settings.namespace + "charger") GameRegistry.registerTileEntity(classOf[tileentity.DiskDrive], Settings.namespace + "diskDrive") @@ -79,5 +80,8 @@ object Blocks { // v1.5.16 Recipes.addBlock(new Transposer(), Constants.BlockName.Transposer, "oc:transposer") + + // v1.7.2 + Recipes.addBlock(new CarpetedCapacitor(), Constants.BlockName.CarpetedCapacitor, "oc:carpetedCapacitor") } } diff --git a/src/main/scala/li/cil/oc/common/inventory/ComponentInventory.scala b/src/main/scala/li/cil/oc/common/inventory/ComponentInventory.scala index 6e801639f..f79cd2d86 100644 --- a/src/main/scala/li/cil/oc/common/inventory/ComponentInventory.scala +++ b/src/main/scala/li/cil/oc/common/inventory/ComponentInventory.scala @@ -17,7 +17,16 @@ import scala.collection.convert.WrapAsScala._ import scala.collection.mutable trait ComponentInventory extends Inventory with network.Environment { - lazy val components = Array.fill[Option[ManagedEnvironment]](getSizeInventory)(None) + private var _components: Array[Option[ManagedEnvironment]] = _ + protected var isSizeInventoryReady: Boolean = true + + def components: Array[Option[ManagedEnvironment]] = { + if (_components == null && isSizeInventoryReady) { + _components = Array.fill[Option[ManagedEnvironment]](getSizeInventory)(None) + } + if (_components == null) Array[Option[ManagedEnvironment]]() else _components + } + protected val updatingComponents = mutable.ArrayBuffer.empty[ManagedEnvironment] // ----------------------------------------------------------------------- // @@ -99,11 +108,19 @@ trait ComponentInventory extends Inventory with network.Environment { for (slot <- 0 until getSizeInventory) { val stack = getStackInSlot(slot) if (!stack.isEmpty) { - components(slot) match { - case Some(component) => - // We're guaranteed to have a driver for entries. - save(component, Driver.driverFor(stack), stack) - case _ => // Nothing special to save. + if (slot >= components.length) { + // isSizeInventoryReady was added to resolve issues where an inventory was used before its + // nbt data had been parsed. See https://github.com/MightyPirates/OpenComputers/issues/2522 + // If this error is hit again, perhaps another subtype needs to handle nbt loading like Case does + OpenComputers.log.error(s"ComponentInventory components length ${components.length} does not accommodate inventory size ${getSizeInventory}") + return + } else { + components(slot) match { + case Some(component) => + // We're guaranteed to have a driver for entries. + save(component, Driver.driverFor(stack), stack) + case _ => // Nothing special to save. + } } } } 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 b7efddbae..31da0e1c2 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Capacitor.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Capacitor.scala @@ -76,5 +76,5 @@ class Capacitor extends traits.Environment with DeviceInfo { private def indirectNeighbors = EnumFacing.values.map(getPos.offset(_, 2)) - private def maxCapacity = Settings.get.bufferCapacitor + Settings.get.bufferCapacitorAdjacencyBonus * 9 + protected def maxCapacity = Settings.get.bufferCapacitor + Settings.get.bufferCapacitorAdjacencyBonus * 9 } diff --git a/src/main/scala/li/cil/oc/common/tileentity/CarpetedCapacitor.scala b/src/main/scala/li/cil/oc/common/tileentity/CarpetedCapacitor.scala new file mode 100644 index 000000000..b355dc9d9 --- /dev/null +++ b/src/main/scala/li/cil/oc/common/tileentity/CarpetedCapacitor.scala @@ -0,0 +1,69 @@ +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 net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.passive.{EntityOcelot, EntitySheep} +import net.minecraft.util.DamageSource +import net.minecraft.util.EnumFacing + +import scala.collection.convert.WrapAsJava._ +import scala.collection.convert.WrapAsScala._ +import li.cil.oc.common.tileentity.traits.Tickable + +class CarpetedCapacitor extends Capacitor with Tickable { + private final lazy val deviceInfo = Map( + DeviceAttribute.Class -> DeviceClass.Power, + DeviceAttribute.Description -> "Battery", + DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor, + DeviceAttribute.Product -> "CarpetedCapBank3x", + DeviceAttribute.Capacity -> maxCapacity.toString + ) + + override def getDeviceInfo: util.Map[String, String] = deviceInfo + + private def _world: net.minecraft.world.World = getWorld + private val rng = scala.util.Random + private val chance: Double = Settings.get.carpetDamageChance + private var nextChanceTime: Long = 0 + + private def energyFromGroup(entities: Set[EntityLivingBase], power: Double): Double = { + if (entities.size < 2) return 0 + def tryDamageOne(): Unit = { + for (ent <- entities) { + if (rng.nextDouble() < chance) { + ent.attackEntityFrom(DamageSource.GENERIC, 1) + ent.setRevengeTarget(ent) // panic + ent.knockBack(ent, 0, .25, 0) + // wait a minute before the next possible shock + nextChanceTime = _world.getTotalWorldTime + (20 * 60) + return + } + } + } + if (chance > 0 && nextChanceTime < _world.getTotalWorldTime) { + tryDamageOne() + } + power + } + + override def updateEntity() { + if (node != null && (_world.getTotalWorldTime + hashCode) % 20 == 0) { + val entities = _world.getEntitiesWithinAABB(classOf[EntityLivingBase], capacitorPowerBounds) + .filter(entity => entity.isEntityAlive) + .toSet + val sheepPower = energyFromGroup(entities.filter(_.isInstanceOf[EntitySheep]), Settings.get.sheepPower) + val ocelotPower = energyFromGroup(entities.filter(_.isInstanceOf[EntityOcelot]), Settings.get.ocelotPower) + val totalPower = sheepPower + ocelotPower + if (totalPower > 0) { + node.changeBuffer(totalPower) + } + } + } + + private def capacitorPowerBounds = position.offset(EnumFacing.UP).bounds +} 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 83ccbfab7..e1cf118d2 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Case.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Case.scala @@ -26,7 +26,12 @@ import net.minecraftforge.fml.relauncher.SideOnly 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) + def this() = { + this(0) + // If no tier was defined when constructing this case, then we don't yet know the inventory size + // this is set back to true when the nbt data is loaded + isSizeInventoryReady = false + } // Used on client side to check whether to render disk activity/network indicators. var lastFileSystemAccess = 0L @@ -87,6 +92,7 @@ class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with tier = nbt.getByte(TierTag) max 0 min 3 setColor(Color.rgbValues(Color.byTier(tier))) super.readFromNBTForServer(nbt) + isSizeInventoryReady = true } override def writeToNBTForServer(nbt: NBTTagCompound) { diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala index 72b082fab..70fd1efb5 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala @@ -212,6 +212,7 @@ object ModOpenComputers extends ModProxy { Constants.BlockName.Keyboard, Constants.BlockName.ScreenTier1, Constants.BlockName.Transposer, + Constants.BlockName.CarpetedCapacitor, Constants.ItemName.AngelUpgrade, Constants.ItemName.BatteryUpgradeTier1, Constants.ItemName.BatteryUpgradeTier2, @@ -234,6 +235,7 @@ object ModOpenComputers extends ModProxy { Constants.BlockName.Keyboard, Constants.BlockName.ScreenTier1, Constants.BlockName.Transposer, + Constants.BlockName.CarpetedCapacitor, Constants.ItemName.APUTier1, Constants.ItemName.APUTier2, Constants.ItemName.GraphicsCardTier1, @@ -248,6 +250,7 @@ object ModOpenComputers extends ModProxy { blacklistHost(classOf[internal.Microcontroller], Constants.BlockName.Keyboard, Constants.BlockName.ScreenTier1, + Constants.BlockName.CarpetedCapacitor, Constants.ItemName.APUTier1, Constants.ItemName.APUTier2, Constants.ItemName.GraphicsCardTier1, @@ -273,10 +276,12 @@ object ModOpenComputers extends ModProxy { Constants.ItemName.TradingUpgrade) blacklistHost(classOf[internal.Robot], Constants.BlockName.Transposer, + Constants.BlockName.CarpetedCapacitor, Constants.ItemName.LeashUpgrade) blacklistHost(classOf[internal.Tablet], Constants.BlockName.ScreenTier1, Constants.BlockName.Transposer, + Constants.BlockName.CarpetedCapacitor, Constants.ItemName.NetworkCard, Constants.ItemName.RedstoneCardTier1, Constants.ItemName.AngelUpgrade,