@Override
 public boolean isSlotEnabled(final int idx) {
   if (idx == 1) {
     return Platform.isServer()
         ? !this.getPatternTerminal().isCraftingRecipe()
         : !this.isCraftingMode();
   } else if (idx == 2) {
     return Platform.isServer()
         ? this.getPatternTerminal().isCraftingRecipe()
         : this.isCraftingMode();
   } else {
     return false;
   }
 }
 @Override
 public IConfigManager getConfigManager() {
   if (Platform.isServer()) {
     return this.serverCM;
   }
   return this.clientCM;
 }
 private void addToENet() {
   if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.IC2)) {
     IIC2 ic2Integration = (IIC2) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.IC2);
     if (!this.isInIC2 && Platform.isServer() && ic2Integration != null) {
       ic2Integration.addToEnergyNet(this);
       this.isInIC2 = true;
     }
   }
 }
 private void removeFromENet() {
   if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.IC2)) {
     IIC2 ic2Integration = (IIC2) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.IC2);
     if (this.isInIC2 && Platform.isServer() && ic2Integration != null) {
       ic2Integration.removeFromEnergyNet(this);
       this.isInIC2 = false;
     }
   }
 }
  @Override
  public void detectAndSendChanges() {
    super.detectAndSendChanges();
    if (Platform.isServer()) {
      if (this.isCraftingMode() != this.getPatternTerminal().isCraftingRecipe()) {
        this.setCraftingMode(this.getPatternTerminal().isCraftingRecipe());
        this.updateOrderOfOutputSlots();
      }

      this.substitute = this.patternTerminal.isSubstitution();
    }
  }
  @Override
  public boolean onPartActivate(EntityPlayer p, Vec3 pos) {
    if (p.isSneaking()) {
      return false;
    }

    if (Platform.isServer()) {
      Platform.openGUI(p, this.getTileEntity(), this.side, GuiBridge.GUI_INTERFACE);
    }

    return true;
  }
  @Override
  public void detectAndSendChanges() {
    this.verifyPermissions(SecurityPermissions.BUILD, false);

    if (Platform.isServer()) {
      this.rsMode =
          (RedstoneMode)
              this.upgradeable.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
    }

    this.craftProgress = this.tma.getCraftingProgress();

    this.standardDetectAndSendChanges();
  }
  @Override
  public void detectAndSendChanges() {
    super.detectAndSendChanges();

    if (!this.wirelessTerminalGUIObject.rangeCheck()) {
      if (Platform.isServer() && this.isContainerValid) {
        this.getPlayerInv().player.addChatMessage(PlayerMessages.OutOfRange.get());
      }

      this.isContainerValid = false;
    } else {
      this.powerMultiplier =
          AEConfig.instance.wireless_getDrainRate(this.wirelessTerminalGUIObject.getRange());
    }
  }
  @Override
  public void onSlotChange(final Slot s) {
    if (s == this.patternSlotOUT && Platform.isServer()) {
      for (final Object crafter : this.crafters) {
        final ICrafting icrafting = (ICrafting) crafter;

        for (final Object g : this.inventorySlots) {
          if (g instanceof OptionalSlotFake || g instanceof SlotFakeCraftingMatrix) {
            final Slot sri = (Slot) g;
            icrafting.sendSlotContents(this, sri.slotNumber, sri.getStack());
          }
        }
        ((EntityPlayerMP) icrafting).isChangingQuantityOnly = false;
      }
      this.detectAndSendChanges();
    }
  }
  public void queueInventory(final ICrafting c) {
    if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
      try {
        PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
        final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();

        for (final IAEItemStack send : monitorCache) {
          try {
            piu.appendItem(send);
          } catch (final BufferOverflowException boe) {
            NetworkHandler.instance.sendTo(piu, (EntityPlayerMP) c);

            piu = new PacketMEInventoryUpdate();
            piu.appendItem(send);
          }
        }

        NetworkHandler.instance.sendTo(piu, (EntityPlayerMP) c);
      } catch (final IOException e) {
        AELog.error(e);
      }
    }
  }
  protected ContainerMEMonitorable(
      final InventoryPlayer ip, final ITerminalHost monitorable, final boolean bindInventory) {
    super(
        ip,
        monitorable instanceof TileEntity ? (TileEntity) monitorable : null,
        monitorable instanceof IPart ? (IPart) monitorable : null);

    this.host = monitorable;
    this.clientCM = new ConfigManager(this);

    this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
    this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
    this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);

    if (Platform.isServer()) {
      this.serverCM = monitorable.getConfigManager();

      this.monitor = monitorable.getItemInventory();
      if (this.monitor != null) {
        this.monitor.addListener(this, null);

        this.cellInv = this.monitor;

        if (monitorable instanceof IPortableCell) {
          this.powerSrc = (IEnergySource) monitorable;
        } else if (monitorable instanceof IMEChest) {
          this.powerSrc = (IEnergySource) monitorable;
        } else if (monitorable instanceof IGridHost) {
          final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN);
          if (node != null) {
            this.networkNode = node;
            final IGrid g = node.getGrid();
            if (g != null) {
              this.powerSrc =
                  new ChannelPowerSrc(
                      this.networkNode, (IEnergySource) g.getCache(IEnergyGrid.class));
            }
          }
        }
      } else {
        this.isContainerValid = false;
      }
    } else {
      this.monitor = null;
    }

    this.canAccessViewCells = false;
    if (monitorable instanceof IViewCellStorage) {
      for (int y = 0; y < 5; y++) {
        this.cellView[y] =
            new SlotRestrictedInput(
                SlotRestrictedInput.PlacableItemType.VIEW_CELL,
                ((IViewCellStorage) monitorable).getViewCellStorage(),
                y,
                206,
                y * 18 + 8,
                this.invPlayer);
        this.cellView[y].allowEdit = this.canAccessViewCells;
        this.addSlotToContainer(this.cellView[y]);
      }
    }

    if (bindInventory) {
      this.bindPlayerInventory(ip, 0, 0);
    }
  }
  @Override
  public void detectAndSendChanges() {
    if (Platform.isServer()) {
      if (this.monitor != this.host.getItemInventory()) {
        this.isContainerValid = false;
      }

      for (final Settings set : this.serverCM.getSettings()) {
        final Enum<?> sideLocal = this.serverCM.getSetting(set);
        final Enum<?> sideRemote = this.clientCM.getSetting(set);

        if (sideLocal != sideRemote) {
          this.clientCM.putSetting(set, sideLocal);
          for (final Object crafter : this.crafters) {
            try {
              NetworkHandler.instance.sendTo(
                  new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter);
            } catch (final IOException e) {
              AELog.error(e);
            }
          }
        }
      }

      if (!this.items.isEmpty()) {
        try {
          final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();

          final PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();

          for (final IAEItemStack is : this.items) {
            final IAEItemStack send = monitorCache.findPrecise(is);
            if (send == null) {
              is.setStackSize(0);
              piu.appendItem(is);
            } else {
              piu.appendItem(send);
            }
          }

          if (!piu.isEmpty()) {
            this.items.resetStatus();

            for (final Object c : this.crafters) {
              if (c instanceof EntityPlayer) {
                NetworkHandler.instance.sendTo(piu, (EntityPlayerMP) c);
              }
            }
          }
        } catch (final IOException e) {
          AELog.error(e);
        }
      }

      this.updatePowerStatus();

      final boolean oldAccessible = this.canAccessViewCells;
      this.canAccessViewCells = this.hasAccess(SecurityPermissions.BUILD, false);
      if (this.canAccessViewCells != oldAccessible) {
        for (int y = 0; y < 5; y++) {
          if (this.cellView[y] != null) {
            this.cellView[y].allowEdit = this.canAccessViewCells;
          }
        }
      }

      super.detectAndSendChanges();
    }
  }
 @Override
 public void fillWithRain(final World w, final int x, final int y, final int z) {
   if (Platform.isServer()) {
     w.setBlock(x, y, z, Platform.AIR_BLOCK, 0, 3);
   }
 }