Exemplo n.º 1
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();
 }
Exemplo n.º 2
0
  public void onBlockRemoval() {
    if (wireSet[IPipe.WireColor.Red.ordinal()]) {
      Utils.dropItems(
          worldObj, new ItemStack(BuildCraftTransport.redPipeWire), xCoord, yCoord, zCoord);
    }

    if (wireSet[IPipe.WireColor.Blue.ordinal()]) {
      Utils.dropItems(
          worldObj, new ItemStack(BuildCraftTransport.bluePipeWire), xCoord, yCoord, zCoord);
    }

    if (wireSet[IPipe.WireColor.Green.ordinal()]) {
      Utils.dropItems(
          worldObj, new ItemStack(BuildCraftTransport.greenPipeWire), xCoord, yCoord, zCoord);
    }

    if (wireSet[IPipe.WireColor.Yellow.ordinal()]) {
      Utils.dropItems(
          worldObj, new ItemStack(BuildCraftTransport.yellowPipeWire), xCoord, yCoord, zCoord);
    }

    if (hasGate()) {
      gate.dropGate(worldObj, xCoord, yCoord, zCoord);
    }

    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
      if (container.hasFacade(direction)) {
        container.dropFacade(direction);
      }
      if (container.hasPlug(direction)) {
        container.removeAndDropPlug(direction);
      }
    }

    if (broadcastRedstone) {
      updateNeighbors(false); // self will update due to block id changing
    }
  }
Exemplo n.º 3
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;
      }
  }