// Advance the 'cur' index to the next block. Return false when done.
 // When done 'scanning' will be set to false as well.
 private boolean advanceCurrent() {
   Coordinate c = cur.getCoordinate();
   int cx = c.getX();
   int cy = c.getY();
   int cz = c.getZ();
   cx++;
   Coordinate lo = c1.getCoordinate();
   Coordinate up = c2.getCoordinate();
   if (cx > up.getX()) {
     cx = lo.getX();
     cy++;
     if (cy > up.getY()) {
       cy = lo.getY();
       cz++;
       if (cz > up.getZ()) {
         scanning.setValue(false);
         notifyBlockUpdate();
         return false;
       }
     }
   }
   cur.setCoordinate(new Coordinate(cx, cy, cz));
   notifyBlockUpdate();
   return true;
 }
  @Override
  protected void checkStateServer() {
    super.checkStateServer();
    if (scanning.getValue()) {
      int rf = StorageScannerConfiguration.rfPerOperation;
      rf = (int) (rf * (2.0f - getInfusedFactor()) / 2.0f);

      if (getEnergyStored(ForgeDirection.DOWN) < rf) {
        return;
      }
      consumeEnergy(rf);

      int scans = StorageScannerConfiguration.scansPerOperation;

      scans = scans * (int) (getInfusedFactor() + 1.01f);

      for (int i = 0; i < scans; i++) {
        Coordinate c = cur.getCoordinate();
        checkInventoryStatus(c.getX(), c.getY(), c.getZ());
        if (!advanceCurrent()) {
          return;
        }
      }
    }
  }
Esempio n. 3
0
  private void updateStorageList() {
    SyncedValueList<InvBlockInfo> inventories = tileEntity.getInventories();
    if (inventories.getClientVersion() != clientVersion) {
      clientVersion = inventories.getClientVersion();
      storageList.removeChildren();
      for (InvBlockInfo blockInfo : inventories) {
        Coordinate c = blockInfo.getCoordinate();
        Block block = mc.theWorld.getBlock(c.getX(), c.getY(), c.getZ());
        int meta = mc.theWorld.getBlockMetadata(c.getX(), c.getY(), c.getZ());
        String displayName;
        if (block == null || block.isAir(mc.theWorld, c.getX(), c.getY(), c.getZ())) {
          displayName = "[REMOVED]";
          block = null;
        } else {
          displayName = BlockInfo.getReadableName(block, meta);
        }

        Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout());
        panel.addChild(new BlockRender(mc, this).setRenderItem(block));
        panel.addChild(
            new Label(mc, this)
                .setText(displayName)
                .setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT)
                .setDesiredWidth(90));
        panel.addChild(new Label(mc, this).setDynamic(true).setText(c.toString()));
        storageList.addChild(panel);
      }
    }
    storageList.clearHilightedRows();
    Set<Coordinate> coordinates = fromServer_coordinates;
    int i = 0;
    for (InvBlockInfo blockInfo : inventories) {
      Coordinate c = blockInfo.getCoordinate();
      if (coordinates.contains(c)) {
        storageList.addHilightedRow(i);
      }
      i++;
    }
  }
Esempio n. 4
0
 private void getInventoryOnServer() {
   InvBlockInfo invBlockInfo = getSelectedContainer();
   if (invBlockInfo != null) {
     Coordinate c = invBlockInfo.getCoordinate();
     RFToolsMessages.INSTANCE.sendToServer(
         new PacketGetInventory(
             tileEntity.xCoord,
             tileEntity.yCoord,
             tileEntity.zCoord,
             c.getX(),
             c.getY(),
             c.getZ()));
   }
 }
 public List<Coordinate> startSearch(String search) {
   search = search.toLowerCase();
   List<Coordinate> output = new ArrayList<Coordinate>();
   for (InvBlockInfo invBlockInfo : inventories) {
     Coordinate c = invBlockInfo.getCoordinate();
     TileEntity tileEntity = worldObj.getTileEntity(c.getX(), c.getY(), c.getZ());
     if (tileEntity instanceof IInventory) {
       IInventory inventory = (IInventory) tileEntity;
       for (int i = 0; i < inventory.getSizeInventory(); i++) {
         ItemStack itemStack = inventory.getStackInSlot(i);
         if (itemStack != null) {
           String readableName = itemStack.getDisplayName();
           if (readableName.toLowerCase().contains(search)) {
             output.add(c);
             break;
           }
         }
       }
     }
   }
   return output;
 }
  public void createChamber(EntityPlayer player) {
    int x1 = xCoord;
    int y1 = yCoord;
    int z1 = zCoord;
    int x2 = x1;
    int y2 = y1;
    int z2 = z1;
    for (int i = 1; i < SpaceProjectorConfiguration.maxSpaceChamberDimension; i++) {
      if (x2 == x1) {
        if (worldObj.getBlock(x1 - i, y1, z1) == SpaceProjectorSetup.spaceChamberBlock) {
          x2 = x1 - i;
        } else if (worldObj.getBlock(x1 + i, y1, z1) == SpaceProjectorSetup.spaceChamberBlock) {
          x2 = x1 + i;
        }
      }
      if (z2 == z1) {
        if (worldObj.getBlock(x1, y1, z1 - i) == SpaceProjectorSetup.spaceChamberBlock) {
          z2 = z1 - i;
        } else if (worldObj.getBlock(x1, y1, z1 + i) == SpaceProjectorSetup.spaceChamberBlock) {
          z2 = z1 + i;
        }
      }
    }

    if (x1 == x2 || z2 == z1) {
      Logging.message(player, EnumChatFormatting.RED + "Not a valid chamber shape!");
      return;
    }

    if (worldObj.getBlock(x2, y1, z2) != SpaceProjectorSetup.spaceChamberBlock) {
      Logging.message(player, EnumChatFormatting.RED + "Not a valid chamber shape!");
      return;
    }

    for (int i = 1; i < SpaceProjectorConfiguration.maxSpaceChamberDimension; i++) {
      if (worldObj.getBlock(x1, y1 - i, z1) == SpaceProjectorSetup.spaceChamberBlock) {
        y2 = y1 - i;
        break;
      }
      if (worldObj.getBlock(x1, y1 + i, z1) == SpaceProjectorSetup.spaceChamberBlock) {
        y2 = y1 + i;
        break;
      }
    }

    if (y1 == y2) {
      Logging.message(player, EnumChatFormatting.RED + "Not a valid chamber shape!");
      return;
    }

    if (worldObj.getBlock(x2, y2, z2) != SpaceProjectorSetup.spaceChamberBlock) {
      Logging.message(player, EnumChatFormatting.RED + "Not a valid chamber shape!");
      return;
    }

    if (worldObj.getBlock(x1, y2, z2) != SpaceProjectorSetup.spaceChamberBlock) {
      Logging.message(player, EnumChatFormatting.RED + "Not a valid chamber shape!");
      return;
    }

    if (worldObj.getBlock(x2, y2, z1) != SpaceProjectorSetup.spaceChamberBlock) {
      Logging.message(player, EnumChatFormatting.RED + "Not a valid chamber shape!");
      return;
    }

    // We have a valid shape.
    minCorner = new Coordinate(Math.min(x1, x2) + 1, Math.min(y1, y2) + 1, Math.min(z1, z2) + 1);
    maxCorner = new Coordinate(Math.max(x1, x2) - 1, Math.max(y1, y2) - 1, Math.max(z1, z2) - 1);
    if (minCorner.getX() > maxCorner.getX()
        || minCorner.getY() > maxCorner.getY()
        || minCorner.getZ() > maxCorner.getZ()) {
      Logging.message(player, EnumChatFormatting.RED + "Chamber is too small!");
      minCorner = null;
      maxCorner = null;
      return;
    }

    Logging.message(player, EnumChatFormatting.WHITE + "Chamber succesfully created!");

    SpaceChamberRepository chamberRepository = SpaceChamberRepository.getChannels(worldObj);
    SpaceChamberRepository.SpaceChamberChannel chamberChannel =
        chamberRepository.getOrCreateChannel(channel);
    chamberChannel.setDimension(worldObj.provider.dimensionId);
    chamberChannel.setMinCorner(minCorner);
    chamberChannel.setMaxCorner(maxCorner);
    chamberRepository.save(worldObj);

    markDirty();
    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
  }