Пример #1
0
  protected boolean isValidTable() {

    if (laserTarget == null || laserTarget.isInvalidTarget() || !laserTarget.requiresLaserEnergy())
      return false;

    return true;
  }
Пример #2
0
  protected void findTable() {
    int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);

    int minX = xCoord - 5;
    int minY = yCoord - 5;
    int minZ = zCoord - 5;
    int maxX = xCoord + 5;
    int maxY = yCoord + 5;
    int maxZ = zCoord + 5;

    switch (ForgeDirection.values()[meta]) {
      case WEST:
        maxX = xCoord;
        break;
      case EAST:
        minX = xCoord;
        break;
      case DOWN:
        maxY = yCoord;
        break;
      case UP:
        minY = yCoord;
        break;
      case NORTH:
        maxZ = zCoord;
        break;
      default:
      case SOUTH:
        minZ = zCoord;
        break;
    }

    List<ILaserTarget> targets = new LinkedList<ILaserTarget>();

    for (int x = minX; x <= maxX; ++x) {
      for (int y = minY; y <= maxY; ++y) {
        for (int z = minZ; z <= maxZ; ++z) {

          TileEntity tile = worldObj.getBlockTileEntity(x, y, z);
          if (tile instanceof ILaserTarget) {

            ILaserTarget table = (ILaserTarget) tile;
            if (table.requiresLaserEnergy()) {
              targets.add(table);
            }
          }
        }
      }
    }

    if (targets.isEmpty()) return;

    laserTarget = targets.get(worldObj.rand.nextInt(targets.size()));
  }
Пример #3
0
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (!CoreProxy.proxy.isSimulating(worldObj)) return;

    // If a gate disabled us, remove laser and do nothing.
    if (lastMode == ActionMachineControl.Mode.Off) {
      removeLaser();
      return;
    }

    // Check for available tables if none is linked to this laser.
    if (!isValidTable())
      if (canFindTable()) {
        findTable();
      }

    // If we still don't have a valid table or the existing has
    // become invalid, we disable the laser and do nothing.
    if (!isValidTable()) {
      removeLaser();
      return;
    }

    // Disable the laser and do nothing if no energy is available.
    if (powerHandler.getEnergyStored() == 0) {
      removeLaser();
      return;
    }

    // We have a table and can work, so we create a laser if
    // necessary.
    if (laser == null) {
      createLaser();
    }

    // We have a laser and may update it
    if (laser != null && canUpdateLaser()) {
      updateLaser();
    }

    // Consume power and transfer it to the table.
    float power = powerHandler.useEnergy(0, getMaxPowerSent(), true);
    laserTarget.receiveLaserEnergy(power);

    if (laser != null) {
      laser.pushPower(power);
    }

    onPowerSent(power);

    sendNetworkUpdate();
  }
Пример #4
0
  protected void updateLaser() {

    int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
    double px = 0, py = 0, pz = 0;

    switch (ForgeDirection.values()[meta]) {
      case WEST:
        px = -0.3;
        break;
      case EAST:
        px = 0.3;
        break;
      case DOWN:
        py = -0.3;
        break;
      case UP:
        py = 0.3;
        break;
      case NORTH:
        pz = -0.3;
        break;
      case SOUTH:
      default:
        pz = 0.3;
        break;
    }

    Position head = new Position(xCoord + 0.5 + px, yCoord + 0.5 + py, zCoord + 0.5 + pz);
    Position tail =
        new Position(
            laserTarget.getXCoord() + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F,
            laserTarget.getYCoord() + 9F / 16F,
            laserTarget.getZCoord() + 0.475 + (worldObj.rand.nextFloat() - 0.5) / 5F);

    laser.setPositions(head, tail);

    if (!laser.isVisible()) {
      laser.show();
    }
  }