예제 #1
0
  /* UPDATING */
  @Override
  public void updateEntity() {
    if (CoreProxy.proxy.isRenderWorld(worldObj)) return;

    // Have liquid flow down into tanks below if any.
    if (tank.getFluid() != null) {
      moveFluidBelow();
    }

    if (hasUpdate && tracker.markTimeIfDelay(worldObj, 2 * BuildCraftCore.updateFactor)) {
      sendNetworkUpdate();
      hasUpdate = false;
    }
  }
예제 #2
0
  public void updateEntity() {

    transport.updateEntity();
    logic.updateEntity();

    if (internalUpdateScheduled) {
      internalUpdate();
      internalUpdateScheduled = false;
    }

    // Do not try to update gates client side.
    if (worldObj.isRemote) return;

    if (actionTracker.markTimeIfDelay(worldObj, 10)) {
      resolveActions();
    }

    // Update the gate if we have any
    if (gate != null) {
      gate.update();
    }
  }
예제 #3
0
 @Override
 public void sendNetworkUpdate() {
   if (networkTracker.markTimeIfDelay(worldObj, nextNetworkUpdate)) {
     super.sendNetworkUpdate();
   }
 }
예제 #4
0
 protected boolean canUpdateLaser() {
   return laserTickTracker.markTimeIfDelay(worldObj, nextLaserUpdate);
 }
예제 #5
0
 protected boolean canFindTable() {
   return searchTracker.markTimeIfDelay(worldObj, nextLaserSearch);
 }
예제 #6
0
  @Override
  public void updateEntity() {
    if (CoreProxy.proxy.isRenderWorld(container.worldObj)) return;

    step();

    init();

    // Send the power to nearby pipes who requested it

    System.arraycopy(displayPower, 0, prevDisplayPower, 0, 6);
    Arrays.fill(displayPower, 0.0F);

    for (int i = 0; i < 6; ++i) {
      if (internalPower[i] > 0) {
        float totalPowerQuery = 0;

        for (int j = 0; j < 6; ++j) {
          if (j != i && powerQuery[j] > 0)
            if (tiles[j] instanceof TileGenericPipe || tiles[j] instanceof IPowerReceptor) {
              totalPowerQuery += powerQuery[j];
            }
        }

        for (int j = 0; j < 6; ++j) {
          if (j != i && powerQuery[j] > 0) {
            float watts = 0.0F;

            PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[j]);
            if (prov != null && prov.powerRequest() > 0) {
              watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
              watts =
                  prov.receiveEnergy(
                      Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
              internalPower[i] -= watts;
            } else if (tiles[j] instanceof TileGenericPipe) {
              watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
              TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j];

              PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport;

              watts =
                  nearbyTransport.receiveEnergy(
                      ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts);
              internalPower[i] -= watts;
            }

            displayPower[j] += watts;
            displayPower[i] += watts;
          }
        }
      }
    }

    double highestPower = 0;
    for (int i = 0; i < 6; i++) {
      displayPower[i] =
          (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0F) + displayPower[i]) / DISPLAY_SMOOTHING;
      if (displayPower[i] > highestPower) {
        highestPower = displayPower[i];
      }
    }

    overload += highestPower > maxPower * 0.95 ? 1 : -1;
    if (overload < 0) {
      overload = 0;
    }
    if (overload > OVERLOAD_TICKS) {
      overload = OVERLOAD_TICKS;
    }

    // Compute the tiles requesting energy that are not power pipes

    for (int i = 0; i < 6; ++i) {
      PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[i]);
      if (prov != null) {
        float request = prov.powerRequest();

        if (request > 0) {
          requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request);
        }
      }
    }

    // Sum the amount of energy requested on each side

    int[] transferQuery = new int[6];

    for (int i = 0; i < 6; ++i) {
      transferQuery[i] = 0;

      for (int j = 0; j < 6; ++j) {
        if (j != i) {
          transferQuery[i] += powerQuery[j];
        }
      }

      transferQuery[i] = Math.min(transferQuery[i], maxPower);
    }

    // Transfer the requested energy to nearby pipes

    for (int i = 0; i < 6; ++i) {
      if (transferQuery[i] != 0) {
        if (tiles[i] != null) {
          TileEntity entity = tiles[i];

          if (entity instanceof TileGenericPipe) {
            TileGenericPipe nearbyTile = (TileGenericPipe) entity;

            if (nearbyTile.pipe == null) {
              continue;
            }

            PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport;
            nearbyTransport.requestEnergy(
                ForgeDirection.VALID_DIRECTIONS[i].getOpposite(), transferQuery[i]);
          }
        }
      }
    }

    if (tracker.markTimeIfDelay(container.worldObj, 2 * BuildCraftCore.updateFactor)) {
      PacketPowerUpdate packet =
          new PacketPowerUpdate(container.xCoord, container.yCoord, container.zCoord);

      double displayFactor = MAX_DISPLAY / 1024.0;
      for (int i = 0; i < clientDisplayPower.length; i++) {
        clientDisplayPower[i] = (short) (displayPower[i] * displayFactor + .9999);
      }

      packet.displayPower = clientDisplayPower;
      packet.overload = isOverloaded();
      CoreProxy.proxy.sendToPlayers(
          packet.getPacket(),
          container.worldObj,
          container.xCoord,
          container.yCoord,
          container.zCoord,
          DefaultProps.PIPE_CONTENTS_RENDER_DIST);
    }
  }
  @Override
  public void updateEntity() {
    if (CoreProxy.proxy.isRenderWorld(worldObj)) return;

    step();

    init();

    // Send the power to nearby pipes who requested it

    Arrays.fill(displayPower, (short) 0);

    for (int i = 0; i < 6; ++i) {
      if (internalPower[i] > 0) {
        double div = 0;

        for (int j = 0; j < 6; ++j) {
          if (j != i && powerQuery[j] > 0)
            if (tiles[j] instanceof TileGenericPipe || tiles[j] instanceof IPowerReceptor) {
              div += powerQuery[j];
            }
        }

        double totalWatt = internalPower[i];

        for (int j = 0; j < 6; ++j) {
          if (j != i && powerQuery[j] > 0) {
            double watts = (totalWatt / div * powerQuery[j]);

            if (tiles[j] instanceof TileGenericPipe) {
              TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j];

              PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport;

              nearbyTransport.receiveEnergy(
                  ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts);

              displayPower[j] += (short) Math.ceil(watts * DISPLAY_POWER_FACTOR);
              displayPower[i] += (short) Math.ceil(watts * DISPLAY_POWER_FACTOR);

              internalPower[i] -= watts;
            } else if (tiles[j] instanceof IPowerReceptor) {
              IPowerReceptor pow = (IPowerReceptor) tiles[j];

              IPowerProvider prov = pow.getPowerProvider();

              if (prov != null) {
                prov.receiveEnergy((float) watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());

                displayPower[j] += (short) Math.ceil(watts * DISPLAY_POWER_FACTOR);
                displayPower[i] += (short) Math.ceil(watts * DISPLAY_POWER_FACTOR);

                internalPower[i] -= watts;
              }
            }
          }
        }
      }
    }

    double highestPower = 0;
    for (int i = 0; i < 6; i++) {
      if (internalPower[i] > highestPower) {
        highestPower = internalPower[i];
      }
      displayPower[i] =
          (short) Math.max(displayPower[i], Math.ceil(internalPower[i] * DISPLAY_POWER_FACTOR));
      displayPower[i] = (short) Math.min(displayPower[i], MAX_DISPLAY);
    }
    overload = highestPower > OVERLOAD_LIMIT;

    // Compute the tiles requesting energy that are not pipes

    for (int i = 0; i < 6; ++i) {
      if (tiles[i] instanceof IPowerReceptor && !(tiles[i] instanceof TileGenericPipe)) {
        IPowerReceptor receptor = (IPowerReceptor) tiles[i];
        int request = receptor.powerRequest();

        if (request > 0) {
          requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request);
        }
      }
    }

    // Sum the amount of energy requested on each side

    int transferQuery[] = {0, 0, 0, 0, 0, 0};

    for (int i = 0; i < 6; ++i) {
      transferQuery[i] = 0;

      for (int j = 0; j < 6; ++j) {
        if (j != i) {
          transferQuery[i] += powerQuery[j];
        }
      }
    }

    // Transfer the requested energy to nearby pipes

    for (int i = 0; i < 6; ++i) {
      if (transferQuery[i] != 0) {
        if (tiles[i] != null) {
          TileEntity entity = tiles[i];

          if (entity instanceof TileGenericPipe) {
            TileGenericPipe nearbyTile = (TileGenericPipe) entity;

            if (nearbyTile.pipe == null) {
              continue;
            }

            PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport;
            nearbyTransport.requestEnergy(
                ForgeDirection.VALID_DIRECTIONS[i].getOpposite(), transferQuery[i]);
          }
        }
      }
    }

    if (tracker.markTimeIfDelay(worldObj, 2 * BuildCraftCore.updateFactor)) {
      PacketPowerUpdate packet = new PacketPowerUpdate(xCoord, yCoord, zCoord);
      packet.displayPower = displayPower;
      packet.overload = overload;
      CoreProxy.proxy.sendToPlayers(
          packet.getPacket(),
          worldObj,
          xCoord,
          yCoord,
          zCoord,
          DefaultProps.PIPE_CONTENTS_RENDER_DIST);
    }
  }