From fc9adf902eef02e63b992245ca4b771a01126a2c Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 3 Mar 2016 12:07:18 +0100 Subject: [PATCH] Add sample script with world access See #123 --- .../config/sample-script-with-world-access.cs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 MinecraftClient/config/sample-script-with-world-access.cs diff --git a/MinecraftClient/config/sample-script-with-world-access.cs b/MinecraftClient/config/sample-script-with-world-access.cs new file mode 100644 index 00000000..cfa5f915 --- /dev/null +++ b/MinecraftClient/config/sample-script-with-world-access.cs @@ -0,0 +1,61 @@ +//MCCScript 1.0 + +MCC.LoadBot(new WatchLamp()); + +//MCCScript Extensions + +/* The ChatBot will access the world on a regular basis to watch for a lamp. + * This is an example of how the world around the player can be accessed from a C# script. */ + +class WatchLamp : ChatBot +{ + /* == CONFIG == */ + + int lampX = 0; + int lampY = 64; + int lampZ = 0; + + /* == CODE == */ + + int checkCount = 0; + Location lampLoc; + + public WatchLamp() + { + if (!Settings.TerrainAndMovements) + { + LogToConsole("WARNING: Terrain handling is disabled in INI file."); + LogToConsole("WARNING: This means this bot cannot watch for lamps."); + UnloadBot(); + } + else + { + lampLoc = new Location(lampX, lampY, lampZ); + LogToConsole("Watching lamp at " + lampLoc); + } + } + + public override void Update() + { + if (checkCount > 10) + { + checkCount = 0; + Material blockType = GetWorld().GetBlock(lampLoc).Type; + switch (blockType) + { + case Material.RedstoneLampOn: + //Lamp is on. All right. Nothing to say here. + break; + case Material.RedstoneLampOff: + LogToConsole("Lamp at " + lampLoc + " is currently turned OFF !!!"); + for (int i = 0; i < 3; i++) + Console.Beep(); + break; + default: + LogToConsole("Block at " + lampLoc + " is not a lamp: " + blockType + "..."); + break; + } + } + else checkCount++; + } +} \ No newline at end of file