private Object[] setHomeImplementation(double x, double y, double z, double facing)
      throws Exception {
    if (golem == null) return new String[] {};

    golem.setHomeArea((int) x, (int) y, (int) z, 35);
    golem.homeFacing = (int) facing;
    return getHomeImplementation();
  }
 private Object[] deleteMarkerImplementation(double arguments) throws Exception {
   if (golem == null) return new String[] {};
   ArrayList<Marker> markers = golem.getMarkers();
   if (markers == null || markers.size() <= arguments)
     throw new Exception("marker " + (int) (double) arguments + " does not exist");
   markers.remove((int) (double) arguments);
   golem.setMarkers(markers);
   return new String[] {};
 }
 @SuppressWarnings("unchecked")
 private Object[] addMarkerImplementation(Map arguments) throws Exception {
   if (golem == null) return new String[] {};
   ArrayList<Marker> markers = golem.getMarkers();
   if (markers == null) markers = new ArrayList<Marker>();
   Marker mark = toMarkerImplementation(arguments);
   markers.add(mark);
   golem.setMarkers(markers);
   return getMarkerImplementation((double) (markers.size() - 1));
 }
 private Object[] saveMarkerImplementation(double markerNum, Map markerArg) throws Exception {
   if (golem == null) return new String[] {};
   ArrayList<Marker> markers = golem.getMarkers();
   if (markers == null || markers.size() <= markerNum)
     throw new Exception("marker " + (int) (double) markerNum + " does not exist");
   Marker mark = toMarkerImplementation(markerArg);
   markers.set((int) (double) markerNum, mark);
   golem.setMarkers(markers);
   return getMarkerImplementation(markerNum);
 }
  public String[] getGolemCoreImplementation() throws Exception {
    if (golem == null) return new String[] {};
    if (golem.getCore() == -1)
      return new String[] {StatCollector.translateToLocal("item.ItemGolemCore.100.name")};
    String[] decorations = new String[1];
    EnumGolemCores golemCore = EnumGolemCores.getFromByte(golem.getCore());
    if (golemCore == null) throw new Exception("Golem has Unknown core: " + golem.getCore());
    decorations[0] = StatCollector.translateToLocal(golemCore.getName());

    return decorations;
  }
  public void verifyGolem() {
    if (golemConnected == null) return;
    List list =
        this.worldObj.getEntitiesWithinAABB(
            EntityGolemBase.class,
            AxisAlignedBB.getBoundingBox(
                xCoord - 30, yCoord - 30, zCoord - 30, xCoord + 30, yCoord + 30, zCoord + 30));
    Iterator iterator = list.iterator();

    while (iterator.hasNext()) {
      EntityGolemBase entityGolem = (EntityGolemBase) iterator.next();

      if (entityGolem.getUniqueID().equals(golemConnected)) {
        this.golem = entityGolem;
        break;
      }
    }
  }
  private Object[] getMarkerImplementation(Double arguments) throws Exception {
    if (golem == null) return new String[] {};
    ArrayList<Marker> markers = golem.getMarkers();
    if (markers == null || markers.size() <= arguments)
      throw new Exception("marker " + (int) (double) arguments + " does not exist");
    Marker mark = markers.get((int) (double) arguments);

    return new Object[] {fromMarkerImplementation(mark)};
  }
 private Object[] getMarkersImplementation() {
   if (golem == null) return new String[] {};
   ArrayList<Marker> markers = golem.getMarkers();
   HashMap<Integer, HashMap<String, Object>> luaMarkers =
       new HashMap<Integer, HashMap<String, Object>>();
   int i = 1;
   for (Marker mark : markers) {
     HashMap<String, Object> luaMarker = fromMarkerImplementation(mark);
     luaMarkers.put(i++, luaMarker);
   }
   return new Object[] {luaMarkers};
 }
 @Override
 @Optional.Method(modid = "ComputerCraft")
 public Object[] callMethod(
     IComputerAccess computer, ILuaContext context, int method, Object[] arguments)
     throws Exception {
   switch (method) {
     case 0:
       return getGolemDecorationsImplementation();
     case 1:
       if (golem == null) return new Integer[] {};
       return new Integer[] {(int) golem.posX, (int) golem.posY, (int) golem.posZ};
     case 2:
       return getGolemTypeImplementation();
     case 3:
       if (golem == null) return new Float[] {};
       return new Float[] {golem.getHealth()};
     case 4:
       return getGolemCoreImplementation();
     case 5:
       return getHomeImplementation();
     case 6:
       if (arguments.length != 4) throw new Exception("Invalid arguments");
       double x = (Double) arguments[0];
       double y = (Double) arguments[0];
       double z = (Double) arguments[0];
       double facing = (Double) arguments[0];
       return setHomeImplementation(x, y, z, facing);
     case 7:
       return getMarkersImplementation();
     case 8:
       if (arguments.length != 1) throw new Exception("setMarkers takes 1 argument");
       return setMarkersImplementation((HashMap<Double, HashMap<String, Object>>) arguments[0]);
     case 9:
       return newMarkerImplementation();
     case 10:
       if (arguments.length != 1) throw new Exception("addMarker must have 1 argument");
       return addMarkerImplementation((Map) arguments[0]);
     case 11:
       if (arguments.length != 2) throw new Exception("saveMarker must have 2 arguments");
       return saveMarkerImplementation((Double) arguments[0], (Map) arguments[1]);
     case 12:
       if (arguments.length != 1) throw new Exception("deleteMarker must have 1 argument");
       return deleteMarkerImplementation((Double) arguments[0]);
     case 13:
       if (arguments.length != 1) throw new Exception("getMarker must have 1 argument");
       return getMarkerImplementation((Double) arguments[0]);
     case 14:
       return getMarkerCountImplementation();
   }
   return null;
 }
 private String[] getGolemTypeImplementation() throws Exception {
   if (golem == null) return new String[] {};
   switch (golem.getGolemType()) {
     case CLAY:
       return new String[] {"Clay"};
     case FLESH:
       return new String[] {"Flesh"};
     case IRON:
       return new String[] {"Iron"};
     case STONE:
       return new String[] {"Stone"};
     case STRAW:
       return new String[] {"Straw"};
     case TALLOW:
       return new String[] {"Tallow"};
     case THAUMIUM:
       return new String[] {"Thaumium"};
     case WOOD:
       return new String[] {"Wood"};
     default:
       throw new Exception("Unknown Golem Type: " + golem.getGolemType());
   }
 }
  @SuppressWarnings("unchecked")
  private Object[] setMarkersImplementation(Map arguments) throws Exception {
    if (golem == null) return new String[] {};

    ArrayList<Marker> arrList = new ArrayList<Marker>();

    for (Object map : arguments.values()) {
      Marker mark = toMarkerImplementation((Map) map);

      arrList.add(mark);
    }
    golem.setMarkers(arrList);
    return getMarkersImplementation();
  }
 @Callback(doc = "function():number -- Returns The golems health")
 @Optional.Method(modid = "OpenComputers")
 public Object[] getHealth(Context context, Arguments args) throws Exception {
   return new Float[] {golem.getHealth()};
 }
 private Object[] getHomeImplementation() {
   if (golem == null) return new String[] {};
   ChunkCoordinates home = golem.getHomePosition();
   return new Integer[] {home.posX, home.posY, home.posZ, golem.homeFacing};
 }
 private Object[] getMarkerCountImplementation() {
   if (golem == null) return new String[] {};
   ArrayList<Marker> markers = golem.getMarkers();
   if (markers == null) return new Object[] {0};
   return new Object[] {(double) markers.size()};
 }