@Override
 public void handleServer(EntityPlayerMP playerEntity) {
   if (moduleName != null && tweakName != null) {
     InventoryPlayer inventory = playerEntity.inventory;
     int entityId = playerEntity.entityId;
     NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
     if (MuseItemUtils.tagHasModule(itemTag, moduleName)) {
       NBTTagCompound moduleTag = itemTag.getCompoundTag(moduleName);
       tweakValue = Math.min(1, Math.max(0, tweakValue));
       moduleTag.setDouble(tweakName, tweakValue);
     }
   }
 }
  @Override
  public void tickEnd(EnumSet<TickType> type, Object... tickData) {
    EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;

    if (player != null) {
      if (slotSelected > -1) {
        player.inventory.currentItem = slotSelected;
        Minecraft.getMinecraft().playerController.updateController();
        ItemStack stack = player.inventory.getStackInSlot(slotSelected);
        if (stack != null && stack.getItem() instanceof IModularItem) {
          NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
          String mode = itemTag.getString("Mode");
          List<String> modes = MuseItemUtils.getModes(stack, player);
          if (mode.isEmpty() && modes.size() > 0) {
            mode = modes.get(0);
          }
          if (modes.size() > 0 && dWheel != 0) {
            int modeIndex = modes.indexOf(mode);
            String newMode = modes.get(clampMode(modeIndex + dWheel, modes.size()));
            itemTag.setString("Mode", newMode);
            RenderTickHandler.lastSwapTime = System.currentTimeMillis();
            RenderTickHandler.lastSwapDirection = (int) Math.signum(dWheel);
            MusePacket modeChangePacket =
                new MusePacketModeChangeRequest(
                    (Player) player, newMode, player.inventory.currentItem);
            player.sendQueue.addToSendQueue(modeChangePacket.getPacket250());
            dWheel = 0;
          }
        }
        slotSelected = -1;
      }
      PlayerInputMap inputmap = PlayerInputMap.getInputMapFor(player.username);
      inputmap.downKey =
          Keyboard.isKeyDown(Keyboard.KEY_Z) && Minecraft.getMinecraft().inGameHasFocus;
      inputmap.forwardKey = player.movementInput.moveForward;
      inputmap.strafeKey = player.movementInput.moveStrafe;
      inputmap.jumpKey = player.movementInput.jump;
      inputmap.sneakKey = player.movementInput.sneak;
      inputmap.motionX = player.motionX;
      inputmap.motionY = player.motionY;
      inputmap.motionZ = player.motionZ;

      MusePacket inputPacket = new MusePacketPlayerUpdate(player, inputmap);
      player.sendQueue.addToSendQueue(inputPacket.getPacket250());
    }
  }
 public LeafBlowerModule(List<IModularItem> validItems) {
   super(validItems);
   addInstallCost(new ItemStack(Item.ingotIron, 3));
   addInstallCost(MuseItemUtils.copyAndResize(ItemComponent.solenoid, 1));
   addBaseProperty(LEAF_BLOWER_ENERGY_CONSUMPTION, 100, "J");
   addBaseProperty(PLANT_RADIUS, 1, "m");
   addBaseProperty(LEAF_RADIUS, 1, "m");
   addIntTradeoffProperty(PLANT_RADIUS, PLANT_RADIUS, 2, "m", 1, 0);
   addIntTradeoffProperty(LEAF_RADIUS, LEAF_RADIUS, 2, "m", 1, 0);
 }
 public void toggleModules() {
   EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
   if (player == null) {
     return;
   }
   for (ClickableModule module : boundModules) {
     String valstring = toggleval ? " on" : " off";
     if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
       player.sendChatToPlayer("Toggled " + module.getModule().getName() + valstring);
     }
     MuseItemUtils.toggleModuleForPlayer(player, module.getModule().getName(), toggleval);
     MusePacketToggleRequest toggleRequest =
         new MusePacketToggleRequest((Player) player, module.getModule().getName(), toggleval);
     player.sendQueue.addToSendQueue(toggleRequest.getPacket250());
   }
   toggleval = !toggleval;
 }
  @Override
  public void tickEnd(EnumSet<TickType> type, Object... tickData) {
    EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
    if (player != null) {
      double currEnergy = ElectricItemUtils.getPlayerEnergy(player);
      double maxEnergy = ElectricItemUtils.getMaxEnergy(player);
      if (maxEnergy > 0) {
        String currStr = MuseStringUtils.formatNumberShort(currEnergy);
        String maxStr = MuseStringUtils.formatNumberShort(maxEnergy);
        MuseRenderer.drawString(currStr + '/' + maxStr + " J", 1, 1);
      }
    }
    if (Minecraft.getMinecraft().currentScreen == null) {
      Minecraft mc = Minecraft.getMinecraft();
      ScaledResolution screen =
          new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
      int i = player.inventory.currentItem;
      ItemStack stack = player.inventory.mainInventory[i];
      if (stack != null && stack.getItem() instanceof IModularItem) {
        MuseRenderer.blendingOn();
        NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
        int swapTime = (int) Math.min(System.currentTimeMillis() - lastSwapTime, SWAPTIME);
        Icon currentMode = null;
        Icon nextMode = null;
        Icon prevMode = null;
        List<String> modes = MuseItemUtils.getModes(stack, player);
        String mode = itemTag.getString("Mode");
        int modeIndex = modes.indexOf(mode);
        if (modeIndex > -1) {
          String prevModeName = modes.get((modeIndex + modes.size() - 1) % modes.size());
          String nextModeName = modes.get((modeIndex + 1) % modes.size());
          IPowerModule module = ModuleManager.getModule(mode);
          IPowerModule nextModule = ModuleManager.getModule(nextModeName);
          IPowerModule prevModule = ModuleManager.getModule(prevModeName);

          if (module != null) {
            currentMode = module.getIcon(stack);
            if (!nextModeName.equals(mode)) {
              nextMode = nextModule.getIcon(stack);
              prevMode = prevModule.getIcon(stack);
            }
          }
        }
        double prevX, prevY, currX, currY, nextX, nextY;
        double sw = screen.getScaledWidth_double();
        double baroffset = screen.getScaledHeight_double() - 40;
        if (!player.capabilities.isCreativeMode) {
          baroffset -= 16;
          if (ForgeHooks.getTotalArmorValue(player) > 0) {
            baroffset -= 8;
          }
        }
        // Root locations of the mode list
        prevX = sw / 2.0 - 105.0 + 20.0 * i;
        prevY = baroffset + 10;
        currX = sw / 2.0 - 89.0 + 20.0 * i;
        currY = baroffset;
        nextX = sw / 2.0 - 73.0 + 20.0 * i;
        nextY = baroffset + 10;
        if (swapTime == SWAPTIME || lastSwapDirection == 0) {
          drawIcon(prevX, prevY, prevMode, 0.4, 0, 0, 16, baroffset - prevY + 16);
          drawIcon(currX, currY, currentMode, 0.8, 0, 0, 16, baroffset - currY + 16);
          drawIcon(nextX, nextY, nextMode, 0.4, 0, 0, 16, baroffset - nextY + 16);
        } else {
          double r1 = 1 - swapTime / (double) SWAPTIME;
          double r2 = swapTime / (double) SWAPTIME;
          if (lastSwapDirection == -1) {
            nextX = (currX * r1 + nextX * r2);
            nextY = (currY * r1 + nextY * r2);
            currX = (prevX * r1 + currX * r2);
            currY = (prevY * r1 + currY * r2);
            drawIcon(currX, currY, currentMode, 0.8, 0, 0, 16, baroffset - currY + 16);
            drawIcon(nextX, nextY, nextMode, 0.8, 0, 0, 16, baroffset - nextY + 16);

          } else {
            prevX = (currX * r1 + prevX * r2);
            prevY = (currY * r1 + prevY * r2);
            currX = (nextX * r1 + currX * r2);
            currY = (nextY * r1 + currY * r2);
            // MuseRenderer
            drawIcon(prevX, prevY, prevMode, 0.8, 0, 0, 16, baroffset - prevY + 16);
            drawIcon(currX, currY, currentMode, 0.8, 0, 0, 16, baroffset - currY + 16);
          }
        }
        // MuseRenderer.blendingOff();
        GL11.glDisable(GL11.GL_LIGHTING);
        Colour.WHITE.doGL();
      }
    }
  }
 public InvisibilityModule(List<IModularItem> validItems) {
   super(validItems);
   addInstallCost(MuseItemUtils.copyAndResize(ItemComponent.laserHologram, 4));
   addInstallCost(MuseItemUtils.copyAndResize(ItemComponent.fieldEmitter, 2));
   addInstallCost(MuseItemUtils.copyAndResize(ItemComponent.controlCircuit, 2));
 }