-
Notifications
You must be signed in to change notification settings - Fork 1
Scripting
Scripting 1.7.x, 1.8.0 编写1.7.x, 1.8.0脚本
Starting 1.8.8 scripting changed because I hooked it into the modding api.
1.8.8开始, 脚本编写发生了变化. 因为我用钩子把它拉进了api里
By default java only supports javascript if you are on the latest version, but its possible to install other scripting languages by downloading their libraries and putting them in the mods folder. For example:
最新版Java默认只支持JavaScript. 但是一样可以加载其他的脚本语言通过下载他们的库并让Forge将其加载(Bukkit同理). 例如:
ECMAScript(more commenly know as javascript): Should be available if you are on the latest java version. (If you have java 8 and it’s not available, go to your java/jre/lib/ext folder and copy the nashorn.jar to the mods folder) Python: Download the standalone jar from the Jython website and put it in the mods folder. Lua: Download the luaj.zip from the Luaj website and put the lib/luaj-jse.jar into the mods folder. lua script example Ruby: Download the jruby.zip from the JRuby website and put the lib/jruby.jar into the mods folder. Php: Download the JavaBridge and php-script.jar from the php-java-bridge website and put them in the mods folder
- ECMAScript(一般叫做JavaScript): 最新版本的Java已经默认可用. 如果你安装了Jre1.8依旧不可用, 去"java/jre/lib/ext"目录复制"nashorn.jar"文件到你的"mods"文件夹
- Python: 从Jython官网下载库文件并将其放入"mods"文件夹.
- Lua: 从Luaj官网下载luaj.zip然后把压缩包里的"lib/luaj-jse.jar"放进"mods"文件夹.
- Ruby: 从JRuby下载jruby.zip然后把压缩包里的"lib/jruby.jar"放进"mods"文件夹
- Php: 从java-bridge官网下载JavaBridge和php-script.jar然后把它们丢进"mods"文件夹
就不能放入官方库里吗= =
There are probably more scripting languages available. These are just some examples. You can usually find them by googling: java scriptengine
应该大部分的脚本语言都可用. 这只是一个简单的示例. 你可以在google上面搜到他们: java scriptengine 语言名称. 渣度你们直接来个: 语言名称的Java实现?
If there is any extra functionality you would like feel free to ask for it on the forums.
如果你想实现任何其他功能的话请在论坛告诉作者
这里有个梨子:
var clicked = 0;
function interact(event){
clicked++;
event.npc.say(clicked);
}
function died(event){
clicked = 0;
}
下面的表格是从模组中用钩子拉出来的= =方便写脚本用.
功能 | 事件 | 说明 |
---|---|---|
init | NpcEvent.InitEvent | 当NPC被生成(创建或者复活) |
tick | NpcEvent.UpdateEvent | 当更新tick时(每10tick一循环. 建议操作在10tick内完成) |
interact | NpcEvent.InteractEvent | 当玩家与NPC互动 |
dialog | DialogEvent.OpenEvent | 当玩家打开与NPC的对话框时 |
dialog_option | DialogEvent.OptionEvent | 当玩家选择了对话选项或者关闭了对话框 |
damaged | NpcEvent.DamagedEvent | 当NPC被攻击时. 可取消 |
died | NpcEvent.DiedEvent | 当NPC被杀时 |
meleeAttack | NpcEvent.MeleeAttackEvent | 当NPC将要进行攻击 |
rangedLaunched | NpcEvent.RangedLaunchedEvent | 当NPC开火(发射东西吧) |
target | NpcEvent.TargetEvent | 当NPC选定目标时 |
targetLost | NpcEvent.TargetLostEvent | 当NPC丢失目标时 |
kill | NpcEvent.KilledEntityEvent | 当NPC杀掉了某个实体时 |
role | RoleEvent.* | 被某些NPC角色调用 |
collide | NpcEvent.CollideEvent | 当NPC与实体发生碰撞 |
timer | NpcEvent.TimerEvent | 当计时器结束(ICustomNpc.getTimers()) |