Ejemplo n.º 1
0
  private void computeConnections() {
    if (tileBuffer != null) {
      boolean[] oldConnections = pipeConnectionsBuffer;
      pipeConnectionsBuffer = new boolean[6];

      for (int i = 0; i < tileBuffer.length; ++i) {
        TileBuffer t = tileBuffer[i];
        t.refresh();

        if (t.getTile() != null) {
          pipeConnectionsBuffer[i] = isPipeConnected(t.getTile());

          if (t.getTile() instanceof TileGenericPipe) {
            TileGenericPipe pipe = (TileGenericPipe) t.getTile();
            pipe.pipeConnectionsBuffer[ForgeDirection.values()[i].getOpposite().ordinal()] =
                pipeConnectionsBuffer[i];
          }
        }
      }

      for (int i = 0; i < tileBuffer.length; ++i)
        if (oldConnections[i] != pipeConnectionsBuffer[i]) {
          Position pos = new Position(xCoord, yCoord, zCoord, ForgeDirection.values()[i]);
          pos.moveForwards(1.0);
          scheduleRenderUpdate();
        }
    }
  }
Ejemplo n.º 2
0
  public void initialize(Pipe pipe) {

    this.pipe = pipe;

    tileBuffer = new TileBuffer[6];

    for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
      Position pos = new Position(xCoord, yCoord, zCoord, o);
      pos.moveForwards(1.0);

      tileBuffer[o.ordinal()] = new TileBuffer();
      tileBuffer[o.ordinal()].initialize(worldObj, (int) pos.x, (int) pos.y, (int) pos.z);
    }

    for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
      TileEntity tile = getTile(o);

      if (tile instanceof ITileBufferHolder)
        ((ITileBufferHolder) tile)
            .blockCreated(o, BuildCraftTransport.genericPipeBlock.blockID, this);
    }

    bindPipe();

    computeConnections();
    scheduleRenderUpdate();

    if (pipe != null) pipe.initialize();

    initialized = true;
  }
Ejemplo n.º 3
0
  private void readNearbyPipesSignal(WireColor color) {
    boolean foundBiggerSignal = false;

    for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
      TileEntity tile = container.getTile(o);

      if (tile instanceof TileGenericPipe) {
        TileGenericPipe tilePipe = (TileGenericPipe) tile;

        if (BlockGenericPipe.isFullyDefined(tilePipe.pipe))
          if (isWireConnectedTo(tile, color)) {
            foundBiggerSignal |=
                receiveSignal(tilePipe.pipe.signalStrength[color.ordinal()] - 1, color);
          }
      }
    }

    if (!foundBiggerSignal && signalStrength[color.ordinal()] != 0) {
      signalStrength[color.ordinal()] = 0;
      // worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
      container.scheduleRenderUpdate();

      for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity tile = container.getTile(o);

        if (tile instanceof TileGenericPipe) {
          TileGenericPipe tilePipe = (TileGenericPipe) tile;

          if (BlockGenericPipe.isFullyDefined(tilePipe.pipe)) {
            tilePipe.pipe.internalUpdateScheduled = true;
          }
        }
      }
    }
  }
Ejemplo n.º 4
0
  public boolean addFacade(ForgeDirection direction, int blockid, int meta) {
    if (this.worldObj.isRemote) return false;
    if (this.facadeBlocks[direction.ordinal()] == blockid) return false;

    if (hasFacade(direction)) {
      dropFacade(direction);
    }

    this.facadeBlocks[direction.ordinal()] = blockid;
    this.facadeMeta[direction.ordinal()] = meta;
    scheduleRenderUpdate();
    return true;
  }
Ejemplo n.º 5
0
 public void resetGate() {
   gate = null;
   activatedTriggers = new ITrigger[activatedTriggers.length];
   triggerParameters = new ITriggerParameter[triggerParameters.length];
   activatedActions = new IAction[activatedActions.length];
   broadcastSignal = new boolean[] {false, false, false, false};
   if (broadcastRedstone) {
     updateNeighbors(true);
   }
   broadcastRedstone = false;
   // worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
   container.scheduleRenderUpdate();
 }
Ejemplo n.º 6
0
 public void dropFacade(ForgeDirection direction) {
   if (this.worldObj.isRemote) return;
   if (!hasFacade(direction)) return;
   Utils.dropItems(
       worldObj,
       new ItemStack(
           BuildCraftTransport.facadeItem,
           1,
           ItemFacade.encode(
               this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()])),
       this.xCoord,
       this.yCoord,
       this.zCoord);
   this.facadeBlocks[direction.ordinal()] = 0;
   this.facadeMeta[direction.ordinal()] = 0;
   scheduleRenderUpdate();
 }
Ejemplo n.º 7
0
  private boolean receiveSignal(int signal, IPipe.WireColor color) {
    if (worldObj == null) return false;

    int oldSignal = signalStrength[color.ordinal()];

    if (signal >= signalStrength[color.ordinal()] && signal != 0) {
      signalStrength[color.ordinal()] = signal;
      internalUpdateScheduled = true;

      if (oldSignal == 0) {
        // worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
        container.scheduleRenderUpdate();
      }

      return true;
    } else return false;
  }
Ejemplo n.º 8
0
  private void resolveActions() {
    if (!hasGate()) return;

    boolean oldBroadcastRedstone = broadcastRedstone;
    boolean[] oldBroadcastSignal = broadcastSignal;

    broadcastRedstone = false;
    broadcastSignal = new boolean[] {false, false, false, false};

    // Tell the gate to prepare for resolving actions. (Disable pulser)
    gate.startResolution();

    HashMap<Integer, Boolean> actions = new HashMap<Integer, Boolean>();
    Multiset<Integer> actionCount = HashMultiset.create();

    // Computes the actions depending on the triggers
    for (int it = 0; it < 8; ++it) {
      ITrigger trigger = activatedTriggers[it];
      IAction action = activatedActions[it];
      ITriggerParameter parameter = triggerParameters[it];

      if (trigger != null && action != null) {
        actionCount.add(action.getId());
        if (!actions.containsKey(action.getId())) {
          actions.put(action.getId(), isNearbyTriggerActive(trigger, parameter));
        } else if (gate.getConditional() == GateConditional.AND) {
          actions.put(
              action.getId(),
              actions.get(action.getId()) && isNearbyTriggerActive(trigger, parameter));
        } else {
          actions.put(
              action.getId(),
              actions.get(action.getId()) || isNearbyTriggerActive(trigger, parameter));
        }
      }
    }

    // Activate the actions
    for (Integer i : actions.keySet())
      if (actions.get(i)) {

        // Custom gate actions take precedence over defaults.
        if (gate.resolveAction(ActionManager.actions[i], actionCount.count(i))) {
          continue;
        }

        if (ActionManager.actions[i] instanceof ActionRedstoneOutput) {
          broadcastRedstone = true;
        } else if (ActionManager.actions[i] instanceof ActionSignalOutput) {
          broadcastSignal[((ActionSignalOutput) ActionManager.actions[i]).color.ordinal()] = true;
        } else {
          for (int a = 0; a < container.tileBuffer.length; ++a)
            if (container.tileBuffer[a].getTile() instanceof IActionReceptor) {
              IActionReceptor recept = (IActionReceptor) container.tileBuffer[a].getTile();
              recept.actionActivated(ActionManager.actions[i]);
            }
        }
      }

    actionsActivated(actions);

    if (oldBroadcastRedstone != broadcastRedstone) {
      container.scheduleRenderUpdate();
      updateNeighbors(true);
    }

    for (int i = 0; i < oldBroadcastSignal.length; ++i)
      if (oldBroadcastSignal[i] != broadcastSignal[i]) {
        // worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
        container.scheduleRenderUpdate();
        updateSignalState();
        break;
      }
  }