package net.minecraft.src;

import libshapedraw.LibShapeDraw;
import libshapedraw.event.LSDEventListener;
import libshapedraw.event.LSDGameTickEvent;
import libshapedraw.event.LSDPreRenderEvent;
import libshapedraw.event.LSDRespawnEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.src.PlayerControllerHooks.PlayerControllerEventListener;

import com.bencvt.minecraft.client.buildregion.Controller;
import com.bencvt.minecraft.client.buildregion.ui.InputManager;

/**
 * Front-end class that handles events raised by various APIs:
 * LibShapeDraw, ModLoader, and PlayerControllerHooks.
 * <p>
 * Simply passes everything along to the Controller and InputManager.
 * 
 * @author bencvt
 */
public class mod_BuildRegion extends BaseMod implements LSDEventListener, PlayerControllerEventListener {
    private Controller controller;
    private InputManager inputManager;

    @Override
    public String getName() {
        return "BuildRegion";
    }

    @Override
    public String getVersion() {
        return "1.0.3-SNAPSHOT [1.3.2]";
    }

    @Override
    public void load() {
        controller = new Controller(
                new LibShapeDraw().addEventListener(this),
                this,
                ModLoader.getMinecraftInstance());
        inputManager = controller.getInputManager();

        ModLoader.setInGameHook(this, true, false); // include partial ticks

        PlayerControllerHooks.register(this);
    }

    // ========
    // ModLoader events
    // ========

    @Override
    public boolean onTickInGame(float partialTickTime, Minecraft minecraft) {
        inputManager.checkForMouseEvent();
        controller.render();
        return true;
    }

    @Override
    public void keyboardEvent(KeyBinding key) {
        inputManager.handleKeyboardEvent(key);
    }

    // ========
    // LibShapeDraw events
    // ========

    @Override
    public void onRespawn(LSDRespawnEvent event) {
        controller.cmdClear(event.isNewServer());
        PlayerControllerHooks.installHooks();
    }

    @Override
    public void onGameTick(LSDGameTickEvent event) {
        // do nothing
    }

    @Override
    public void onPreRender(LSDPreRenderEvent event) {
        controller.updatePlayerPosition(event.getPlayerCoords());
    }

    // ========
    // PlayerControllerHooks events
    // ========

    @Override
    public boolean onBlockClick(boolean isLeftClick, int blockX, int blockY, int blockZ, int direction) {
        return inputManager.handleBlockClick(
                isLeftClick, blockX, blockY, blockZ, direction);
    }

    @Override
    public boolean onBlockDamage(int blockX, int blockY, int blockZ, int direction) {
        return inputManager.handleBlockClick(
                true, blockX, blockY, blockZ, direction);
    }

    @Override
    public boolean onEntityClick(boolean isLeftClick, Entity entity) {
        return !inputManager.shouldConsumeClick(isLeftClick);
    }
}

@@ -404,24 +404,84 @@
 Controller;%0A
+import com.bencvt.minecraft.client.buildregion.UpdateCheck;%0A
 import com.b
@@ -937,16 +937,53 @@
 Manager;
+%0A    private UpdateCheck updateCheck;
 %0A%0A    @O
@@ -1049,32 +1049,108 @@
 Region%22;%0A    %7D%0A%0A
+    public String getModVersion() %7B%0A        return %221.0.3-SNAPSHOT%22;%0A    %7D%0A%0A
     @Override%0A  
@@ -1195,31 +1195,35 @@
  return 
-%221.0.3-SNAPSHOT
+getModVersion() + %22
  %5B1.3.2%5D
@@ -2219,99 +2219,511 @@
     
-%7D%0A%0A    @Override%0A    public void onGameTick(LSDGameTickEvent event) %7B%0A        // do nothing
+    if (updateCheck == null) %7B%0A            updateCheck = new UpdateCheck(getModVersion());%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void onGameTick(LSDGameTickEvent event) %7B%0A        if (updateCheck != null && updateCheck.getResult() != null) %7B%0A            GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI();%0A            for (String line : updateCheck.getResult().split(%22%5Cn%22)) %7B%0A                chat.printChatMessage(line);%0A            %7D%0A            updateCheck.setResult(null);%0A        %7D
 %0A   

add update check part 2