Esempio n. 1
0
 // This is called client side.
 public List<ClientScreenModule> getClientScreenModules() {
   if (clientScreenModules == null) {
     needsServerData = false;
     clientScreenModules = new ArrayList<ClientScreenModule>();
     for (int i = 0; i < inventoryHelper.getCount(); i++) {
       ItemStack itemStack = inventoryHelper.getStackInSlot(i);
       if (itemStack != null && itemStack.getItem() instanceof ModuleProvider) {
         ModuleProvider moduleProvider = (ModuleProvider) itemStack.getItem();
         ClientScreenModule clientScreenModule;
         try {
           clientScreenModule = moduleProvider.getClientScreenModule().newInstance();
         } catch (InstantiationException e) {
           e.printStackTrace();
           continue;
         } catch (IllegalAccessException e) {
           e.printStackTrace();
           continue;
         }
         clientScreenModule.setupFromNBT(
             itemStack.getTagCompound(), worldObj.provider.dimensionId, xCoord, yCoord, zCoord);
         clientScreenModules.add(clientScreenModule);
         if (clientScreenModule.needsServerData()) {
           needsServerData = true;
         }
       } else {
         clientScreenModules.add(
             null); // To keep the indexing correct so that the modules correspond with there slot
                    // number.
       }
     }
   }
   return clientScreenModules;
 }
Esempio n. 2
0
  public void hitScreenClient(double hitX, double hitY, double hitZ, int side) {
    float factor = large ? 2.0f : 1.0f;
    float dx = 0;
    float dy = (float) ((-hitY + 1.0) / factor);
    switch (side) {
      case 2:
        dx = (float) ((1.0 - hitX) / factor);
        break;
      case 3:
        dx = (float) (hitX / factor);
        break;
      case 4:
        dx = (float) (hitZ / factor);
        break;
      case 5:
        dx = (float) ((1.0 - hitZ) / factor);
        break;
    }
    int x = (int) (dx * 128);
    int y = (int) (dy * 128);
    int currenty = 7;

    int moduleIndex = 0;
    List<ClientScreenModule> clientScreenModules = getClientScreenModules();
    for (ClientScreenModule module : clientScreenModules) {
      if (module != null) {
        int height = module.getHeight();
        // Check if this module has enough room
        if (currenty + height <= 124) {
          if (currenty <= y && y < (currenty + height)) {
            break;
          }
          currenty += height;
        }
      }
      moduleIndex++;
    }
    if (moduleIndex >= clientScreenModules.size()) {
      return;
    }

    clientScreenModules.get(moduleIndex).mouseClick(worldObj, x, y - currenty, true);
    clickedModules.add(new ActivatedModule(moduleIndex, 5, x, y));

    PacketHandler.INSTANCE.sendToServer(
        new PacketServerCommand(
            xCoord,
            yCoord,
            zCoord,
            CMD_CLICK,
            new Argument("x", x),
            new Argument("y", y - currenty),
            new Argument("module", moduleIndex)));
  }