@Override
  public ItemStack onItemRightClick(ItemStack essentiaCell, World world, EntityPlayer player) {
    // Ensure the player is sneaking(holding shift)
    if (!player.isSneaking()) {
      return essentiaCell;
    }

    // TODO: SaveProvider??
    // Get the handler
    IMEInventoryHandler<IAEFluidStack> handler =
        AEApi.instance()
            .registries()
            .cell()
            .getCellInventory(essentiaCell, null, StorageChannel.FLUIDS);

    // Is it the correct handler type?
    if (!(handler instanceof HandlerItemEssentiaCell)) {
      return essentiaCell;
    }

    // Cast
    HandlerItemEssentiaCell cellHandler = (HandlerItemEssentiaCell) handler;

    // If the cell is empty, and the player can hold the casing
    if ((cellHandler.usedBytes() == 0)
        && (player.inventory.addItemStackToInventory(
            ItemEnum.STORAGE_CASING.getItemStackWithSize(1)))) {
      // Return the storage component
      return ItemEnum.STORAGE_COMPONENT.getItemStackWithDamage(essentiaCell.getItemDamage());
    }

    // Can not remove storage component, return the current cell as is.
    return essentiaCell;
  }
  /** Creates the cell tooltip. */
  @Override
  public void addInformation(
      final ItemStack essentiaCell,
      final EntityPlayer player,
      final List displayList,
      final boolean advancedItemTooltips) {
    // Get the contents of the cell
    IMEInventoryHandler<IAEFluidStack> handler =
        AEApi.instance()
            .registries()
            .cell()
            .getCellInventory(essentiaCell, null, StorageChannel.FLUIDS);

    // Ensure we have a cell inventory handler
    if (!(handler instanceof HandlerItemEssentiaCell)) {
      return;
    }

    // Cast to cell inventory handler
    HandlerItemEssentiaCell cellHandler = (HandlerItemEssentiaCell) handler;

    // Create the bytes tooltip
    String bytesTip =
        String.format(
            ThEStrings.Tooltip_CellBytes.getLocalized(),
            cellHandler.getUsedBytes(),
            cellHandler.getTotalBytes());

    // Create the types tooltip
    String typesTip =
        String.format(
            ThEStrings.Tooltip_CellTypes.getLocalized(),
            cellHandler.getUsedTypes(),
            cellHandler.getTotalTypes());

    // Add the tooltips
    displayList.add(bytesTip);
    displayList.add(typesTip);

    // Is the cell pre-formated?
    if (cellHandler.isPartitioned()) {
      displayList.add(GuiText.Partitioned.getLocal());
    }

    // Does the cell have anything stored?
    if (cellHandler.getUsedTypes() > 0) {
      // Is shift being held?
      if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT))) {
        // Add information about the essentia types in the cell
        this.addContentsToCellDescription(cellHandler, displayList, player);
      } else {
        // Let the user know they can hold shift
        displayList.add(
            EnumChatFormatting.WHITE.toString()
                + EnumChatFormatting.ITALIC.toString()
                + ThEStrings.Tooltip_ItemStackDetails.getLocalized());
      }
    }
  }
  public ItemEssentiaCell() {
    AEApi.instance().registries().cell().addCellHandler(this);

    this.setMaxStackSize(1);

    this.setMaxDamage(0);

    this.setHasSubtypes(true);
  }
  public void encode() {
    ItemStack output = this.patternSlotOUT.getStack();

    final ItemStack[] in = this.getInputs();
    final ItemStack[] out = this.getOutputs();

    // if there is no input, this would be silly.
    if (in == null || out == null) {
      return;
    }

    // first check the output slots, should either be null, or a pattern
    if (output != null && !this.isPattern(output)) {
      return;
    } // if nothing is there we should snag a new pattern.
    else if (output == null) {
      output = this.patternSlotIN.getStack();
      if (output == null || !this.isPattern(output)) {
        return; // no blanks.
      }

      // remove one, and clear the input slot.
      output.stackSize--;
      if (output.stackSize == 0) {
        this.patternSlotIN.putStack(null);
      }

      // add a new encoded pattern.
      for (final ItemStack encodedPatternStack :
          AEApi.instance().definitions().items().encodedPattern().maybeStack(1).asSet()) {
        output = encodedPatternStack;
        this.patternSlotOUT.putStack(output);
      }
    }

    // encode the slot.
    final NBTTagCompound encodedValue = new NBTTagCompound();

    final NBTTagList tagIn = new NBTTagList();
    final NBTTagList tagOut = new NBTTagList();

    for (final ItemStack i : in) {
      tagIn.appendTag(this.createItemTag(i));
    }

    for (final ItemStack i : out) {
      tagOut.appendTag(this.createItemTag(i));
    }

    encodedValue.setTag("in", tagIn);
    encodedValue.setTag("out", tagOut);
    encodedValue.setBoolean("crafting", this.isCraftingMode());
    encodedValue.setBoolean("substitute", this.isSubstitute());

    output.setTagCompound(encodedValue);
  }
  public TileMolecularAssembler() {
    final ITileDefinition assembler = AEApi.instance().definitions().blocks().molecularAssembler();

    this.settings = new ConfigManager(this);
    this.settings.registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
    this.inv.setMaxStackSize(1);
    this.getProxy().setIdlePowerUsage(0.0);
    this.upgrades = new DefinitionUpgradeInventory(assembler, this, this.getUpgradeSlots());
    this.craftingInv = new InventoryCrafting(new ContainerNull(), 3, 3);
  }
  @Override
  public void addInformation(
      ItemStack essentiaCell, EntityPlayer player, List displayList, boolean advancedItemTooltips) {
    // TODO: Save provider??
    // Get the contents of the cell
    IMEInventoryHandler<IAEFluidStack> handler =
        AEApi.instance()
            .registries()
            .cell()
            .getCellInventory(essentiaCell, null, StorageChannel.FLUIDS);

    // Ensure we have a cell inventory handler
    if (!(handler instanceof HandlerItemEssentiaCell)) {
      return;
    }

    // Cast to cell inventory handler
    HandlerItemEssentiaCell cellHandler = (HandlerItemEssentiaCell) handler;

    // Create the bytes tooltip
    String bytesTip =
        String.format(
            StatCollector.translateToLocal(
                ThaumicEnergistics.MOD_ID + ".tooltip.essentia.cell.bytes"),
            new Object[] {
              cellHandler.usedBytes() / ItemEssentiaCell.CONVERSION_SIZE,
              cellHandler.totalBytes() / ItemEssentiaCell.CONVERSION_SIZE
            });

    // Create the types tooltip
    String typesTip =
        String.format(
            StatCollector.translateToLocal(
                ThaumicEnergistics.MOD_ID + ".tooltip.essentia.cell.types"),
            new Object[] {cellHandler.usedTypes(), cellHandler.totalTypes()});

    // Add the tooltips
    displayList.add(bytesTip);
    displayList.add(typesTip);

    // Is the cell pre-formated?
    if (cellHandler.isPreformatted()) {
      displayList.add(
          StatCollector.translateToLocal("Appeng.GuiITooltip.Partitioned")
              + " - "
              + StatCollector.translateToLocal("Appeng.GuiITooltip.Precise"));
    }

    // Is shift being held?
    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT))) {
      // Add information about the essentia types in the cell
      this.addContentsToCellDescription(cellHandler, displayList, player);
    }
  }
  private boolean isPattern(final ItemStack output) {
    if (output == null) {
      return false;
    }

    final IDefinitions definitions = AEApi.instance().definitions();

    boolean isPattern = definitions.items().encodedPattern().isSameAs(output);
    isPattern |= definitions.materials().blankPattern().isSameAs(output);

    return isPattern;
  }
  public ItemEssentiaCell() {
    // Add the handler to AE2
    AEApi.instance().registries().cell().addCellHandler(this);

    // Set max stack size to 1
    this.setMaxStackSize(1);

    // No damage
    this.setMaxDamage(0);

    // Has sub-types
    this.setHasSubtypes(true);
  }
 public void connectTo(int x, int y, int z) {
   TileEntity tileEntity = worldObj.getTileEntity(x, y, z);
   if (tileEntity instanceof TileMEWireConnector) {
     TileMEWireConnector connector = (TileMEWireConnector) tileEntity;
     try {
       gridConnections.add(
           AEApi.instance()
               .createGridConnection(
                   connector.getGridNode(ForgeDirection.UNKNOWN),
                   getGridNode(ForgeDirection.UNKNOWN)));
     } catch (FailedConnection failedConnection) {
       failedConnection.printStackTrace();
       ImmersiveIntegration.log.error("Something went wrong connecting the flux wire!");
     }
   }
 }
Ejemplo n.º 10
0
  @Override
  public ItemStack getIconItemStack() {
    final IDefinitions definitions = AEApi.instance().definitions();
    final IBlocks blocks = definitions.blocks();
    final IItems items = definitions.items();
    final IMaterials materials = definitions.materials();

    return this.findFirst(
        blocks.controller(),
        blocks.chest(),
        blocks.cellWorkbench(),
        blocks.fluix(),
        items.cell1k(),
        items.networkTool(),
        materials.fluixCrystal(),
        materials.certusQuartzCrystal());
  }
Ejemplo n.º 11
0
  @Override
  @Method(modid = "appliedenergistics2")
  public void updateEntity(World worldObj) {
    if (grid == null) {
      grid = new MEConduitGrid(this);
    }

    if (getNode() == null && !worldObj.isRemote) {
      IGridNode node = AEApi.instance().createGridNode(grid);
      if (node != null) {
        node.setPlayerID(playerID);
        getBundle().setGridNode(node);
        getNode().updateState();
      }
    }

    super.updateEntity(worldObj);
  }
 private void updateInternalState() {
   boolean intention = this.getIntention();
   if (intention == (this.connection == null)) {
     if (this.proxy.getNode() != null && this.outerProxy.getNode() != null) {
       if (intention) {
         try {
           this.connection =
               AEApi.instance()
                   .createGridConnection(this.proxy.getNode(), this.outerProxy.getNode());
         } catch (FailedConnection e) {
           // :(
         }
       } else {
         this.connection.destroy();
         this.connection = null;
       }
     }
   }
 }
  // api
  public PacketPatternSlot(IInventory pat, IAEItemStack slotItem, boolean shift)
      throws IOException {

    this.slotItem = slotItem;
    this.shift = shift;

    ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());

    data.writeBoolean(shift);

    this.writeItem(slotItem, data);
    for (int x = 0; x < 9; x++) {
      this.pattern[x] = AEApi.instance().storage().createItemStack(pat.getStackInSlot(x));
      this.writeItem(this.pattern[x], data);
    }

    this.configureWrite(data);
  }
  @Override
  public void updateEntity() {
    if (!loaded && hasWorldObj() && !worldObj.isRemote) {
      loaded = true;
      createAELink();
      for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity tileEntity =
            worldObj.getTileEntity(
                xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
        if (tileEntity instanceof IGridHost) {
          IGridNode node = ((IGridHost) tileEntity).getGridNode(direction);
          if (node != null) {
            node.updateState();
          }
        }

        for (ImmersiveNetHandler.Connection connection :
            ImmersiveNetHandler.INSTANCE.getConnections(worldObj, Utils.toCC(this))) {
          ChunkCoordinates opposite = connection.end;
          if (connection.end.equals(Utils.toCC(this))) {
            opposite = connection.start;
          }

          TileEntity teOpposite =
              worldObj.getTileEntity(opposite.posX, opposite.posY, opposite.posZ);
          if (teOpposite instanceof TileMEWireConnector) {
            GridNode nodeA =
                (GridNode) ((TileMEWireConnector) teOpposite).getGridNode(ForgeDirection.UNKNOWN);
            GridNode nodeB = (GridNode) getGridNode(ForgeDirection.UNKNOWN);
            if (!nodeA.hasConnection(nodeB) && !nodeB.hasConnection(nodeA)) {
              try {
                gridConnections.add(AEApi.instance().createGridConnection(nodeA, nodeB));
              } catch (FailedConnection failedConnection) {
                failedConnection.printStackTrace();
              }
            }
          }
        }
      }
    }
  }
  /** Attempts to remove the storage component. */
  @Override
  public ItemStack onItemRightClick(
      final ItemStack essentiaCell, final World world, final EntityPlayer player) {
    // Ensure the player is sneaking(holding shift)
    if (!player.isSneaking()) {
      return essentiaCell;
    }

    // Ensure this is not a creative cell
    if (essentiaCell.getItemDamage() == EnumEssentiaStorageTypes.Type_Creative.index) {
      return essentiaCell;
    }

    // Get the handler
    IMEInventoryHandler<IAEFluidStack> handler =
        AEApi.instance()
            .registries()
            .cell()
            .getCellInventory(essentiaCell, null, StorageChannel.FLUIDS);

    // Is it the correct handler type?
    if (!(handler instanceof HandlerItemEssentiaCell)) {
      return essentiaCell;
    }

    // Cast
    HandlerItemEssentiaCell cellHandler = (HandlerItemEssentiaCell) handler;

    // If the cell is empty, and the player can hold the casing
    if ((cellHandler.getUsedBytes() == 0)
        && (player.inventory.addItemStackToInventory(ItemEnum.STORAGE_CASING.getStack()))) {
      // Return the storage component
      return EnumEssentiaStorageTypes.fromIndex[essentiaCell.getItemDamage()].getComponent(1);
    }

    // Can not remove storage component, return the current cell as is.
    return essentiaCell;
  }
  public void updateEntity() {

    // Check for ghost TEs
    if (dead) return;
    // Make sure the relays haven't been broken
    verifyRelay();
    // Bounce
    if (linked
        && worldObj.getTotalWorldTime() % 100 == 0
        && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) {
      // Target coordinates to check
      int targetX = xCoord + movementDirection.offsetX;
      int targetZ = zCoord + movementDirection.offsetZ;
      // Switch direction if at end of track
      if (worldObj.getBlock(targetX, yCoord, targetZ) != Block.getBlockFromName("air")
          || worldObj.getBlock(targetX, yCoord + 1, targetZ) != Block.getBlockFromName("air")) {
        movementDirection = movementDirection.getOpposite();
      }
    }
    // Move
    if (linked
        && worldObj.getTotalWorldTime() % 100 == 1
        && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) {
      // Cache coordinated
      int targetX = xCoord + movementDirection.offsetX;
      int targetZ = zCoord + movementDirection.offsetZ;
      // Check for abandoned TEs
      if (worldObj.getBlock(xCoord, yCoord, zCoord)
          != ThaumicTinkerer.registry.getFirstBlockFromClass(BlockMobilizer.class)) {
        return;
      }
      // Check if the space the mobilizer will move into is empty
      if ((worldObj.isAirBlock(targetX, yCoord, targetZ)
          || worldObj.getBlock(targetX, yCoord, targetZ).isAir(worldObj, targetX, yCoord, targetZ)
              && (worldObj.isAirBlock(xCoord, yCoord + 1, zCoord)
                  || worldObj.isAirBlock(targetX, yCoord + 1, targetZ)
                  || worldObj
                      .getBlock(targetX, yCoord + 1, targetZ)
                      .isAir(worldObj, targetX, yCoord + 1, targetZ)))) {

        // Move Entities
        // List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class,
        // AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+3, zCoord+1));
        // System.out.print(entities);
        // for(Entity e: entities){
        //	e.setPosition(e.posX+movementDirection.offsetX, e.posY,
        // e.posZ+movementDirection.offsetZ);
        // }

        // Move the block on top of the mobilizer
        if (!worldObj.isRemote) {

          TileEntity passenger = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
          IAppEngApi api = AEApi.instance();

          // Prevent the passenger from popping off. Not sent to clients.
          worldObj.setBlock(targetX, yCoord, targetZ, Block.getBlockFromName("stone"), 0, 0);
          // Move non-TE blocks
          Block passengerId = worldObj.getBlock(xCoord, yCoord + 1, zCoord);

          if (worldObj.isAirBlock(xCoord, yCoord + 1, zCoord)
              || passengerId.canPlaceBlockAt(worldObj, targetX, yCoord + 1, targetZ)) {

            if (passenger == null) {
              if (passengerId != Block.getBlockFromName("bedrock")
                  && passengerId != Block.getBlockFromName("")) {
                worldObj.setBlock(
                    targetX,
                    yCoord + 1,
                    targetZ,
                    passengerId,
                    worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord),
                    3);
                if (passengerId != Block.getBlockFromName("air")
                    && passengerId != Block.getBlockFromName("piston_head")) {
                  worldObj.setBlock(
                      xCoord, yCoord + 1, zCoord, Block.getBlockFromName("air"), 0, 2);
                }
              }
              // If AE is installed, use its handler
            } else if (api != null) {
              if (api.registries().moveable().askToMove(passenger)) {
                worldObj.setBlock(
                    targetX,
                    yCoord + 1,
                    targetZ,
                    worldObj.getBlock(xCoord, yCoord + 1, zCoord),
                    worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord),
                    3);
                passenger.invalidate();
                worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord);
                api.registries()
                    .moveable()
                    .getHandler(passenger)
                    .moveTile(passenger, worldObj, targetX, yCoord + 1, targetZ);
                api.registries().moveable().doneMoving(passenger);
                passenger.validate();
              }

              // Handler IMovableTiles and vanilla TEs without AE
            } else if (passenger instanceof IMovableTile
                || passenger.getClass().getName().startsWith("net.minecraft.tileentity")) {
              boolean imovable = passenger instanceof IMovableTile;
              if (imovable) ((IMovableTile) passenger).prepareToMove();
              worldObj.setBlock(
                  targetX,
                  yCoord + 1,
                  targetZ,
                  worldObj.getBlock(xCoord, yCoord + 1, zCoord),
                  worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord),
                  3);
              passenger.invalidate();
              worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord);

              // IMovableHandler default code
              Chunk c = worldObj.getChunkFromBlockCoords(targetX, targetZ);

              c.func_150812_a(targetX & 0xF, yCoord + 1, targetZ & 0xF, passenger);

              if (c.isChunkLoaded) {
                worldObj.addTileEntity(passenger);
                worldObj.markBlockForUpdate(targetX, yCoord + 1, targetZ);
              }
              if (imovable) ((IMovableTile) passenger).doneMoving();
              passenger.validate();
            }
          }
          // Move self
          this.invalidate();
          worldObj.removeTileEntity(xCoord, yCoord, zCoord);
          worldObj.setBlock(xCoord, yCoord, zCoord, Block.getBlockFromName("air"), 0, 2);
          worldObj.setBlock(
              targetX,
              yCoord,
              targetZ,
              ThaumicTinkerer.registry.getFirstBlockFromClass(BlockMobilizer.class));

          int oldX = xCoord;
          int oldZ = zCoord;

          this.xCoord = targetX;
          this.zCoord = targetZ;
          this.validate();
          worldObj.addTileEntity(this);
          worldObj.removeTileEntity(oldX, yCoord, oldZ);

          worldObj.notifyBlockChange(oldX, yCoord, oldZ, Block.getBlockFromName("air"));
        }
      }
    }
  }
public class ContainerMEMonitorable extends AEBaseContainer
    implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack> {

  public final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
  final IMEMonitor<IAEItemStack> monitor;
  final IItemList<IAEItemStack> items = AEApi.instance().storage().createItemList();
  final IConfigManager clientCM;
  private final ITerminalHost host;

  @GuiSync(99)
  public boolean canAccessViewCells = false;

  @GuiSync(98)
  public boolean hasPower = false;

  public IConfigManagerHost gui;
  IConfigManager serverCM;
  private IGridNode networkNode;

  public ContainerMEMonitorable(final InventoryPlayer ip, final ITerminalHost monitorable) {
    this(ip, monitorable, true);
  }

  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);
    }
  }

  public IGridNode getNetworkNode() {
    return this.networkNode;
  }

  @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();
    }
  }

  protected void updatePowerStatus() {
    try {
      if (this.networkNode != null) {
        this.hasPower = this.networkNode.isActive();
      } else if (this.powerSrc instanceof IEnergyGrid) {
        this.hasPower = ((IEnergyGrid) this.powerSrc).isNetworkPowered();
      } else {
        this.hasPower =
            this.powerSrc.extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.8;
      }
    } catch (final Throwable t) {
      // :P
    }
  }

  @Override
  public void onUpdate(final String field, final Object oldValue, final Object newValue) {
    if (field.equals("canAccessViewCells")) {
      for (int y = 0; y < 5; y++) {
        if (this.cellView[y] != null) {
          this.cellView[y].allowEdit = this.canAccessViewCells;
        }
      }
    }

    super.onUpdate(field, oldValue, newValue);
  }

  @Override
  public void addCraftingToCrafters(final ICrafting c) {
    super.addCraftingToCrafters(c);
    this.queueInventory(c);
  }

  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);
      }
    }
  }

  @Override
  public void removeCraftingFromCrafters(final ICrafting c) {
    super.removeCraftingFromCrafters(c);

    if (this.crafters.isEmpty() && this.monitor != null) {
      this.monitor.removeListener(this);
    }
  }

  @Override
  public void onContainerClosed(final EntityPlayer player) {
    super.onContainerClosed(player);
    if (this.monitor != null) {
      this.monitor.removeListener(this);
    }
  }

  @Override
  public boolean isValid(final Object verificationToken) {
    return true;
  }

  @Override
  public void postChange(
      final IBaseMonitor<IAEItemStack> monitor,
      final Iterable<IAEItemStack> change,
      final BaseActionSource source) {
    for (final IAEItemStack is : change) {
      this.items.add(is);
    }
  }

  @Override
  public void onListUpdate() {
    for (final Object c : this.crafters) {
      if (c instanceof ICrafting) {
        final ICrafting cr = (ICrafting) c;
        this.queueInventory(cr);
      }
    }
  }

  @Override
  public void updateSetting(
      final IConfigManager manager, final Enum settingName, final Enum newValue) {
    if (this.gui != null) {
      this.gui.updateSetting(manager, settingName, newValue);
    }
  }

  @Override
  public IConfigManager getConfigManager() {
    if (Platform.isServer()) {
      return this.serverCM;
    }
    return this.clientCM;
  }

  public ItemStack[] getViewCells() {
    final ItemStack[] list = new ItemStack[this.cellView.length];

    for (int x = 0; x < this.cellView.length; x++) {
      list[x] = this.cellView[x].getStack();
    }

    return list;
  }
}
 public void createAELink() {
   if (!worldObj.isRemote) {
     if (theGridNode == null) theGridNode = AEApi.instance().createGridNode(this);
     theGridNode.updateState();
   }
 }