Esempio n. 1
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;
          }
        }
      }
    }
  }
Esempio n. 2
0
  public static boolean placePipe(
      Pipe pipe, World world, int i, int j, int k, int blockId, int meta) {
    if (world.isRemote) return true;

    boolean placed = world.setBlock(i, j, k, blockId, meta, 1);

    if (placed) {

      TileGenericPipe tile = (TileGenericPipe) world.getBlockTileEntity(i, j, k);
      tile.initialize(pipe);
    }

    return placed;
  }
Esempio n. 3
0
  private void updateSignalStateForColor(IPipe.WireColor color) {
    if (!wireSet[color.ordinal()]) return;

    // STEP 1: compute internal signal strength

    if (broadcastSignal[color.ordinal()]) {
      receiveSignal(255, color);
    } else {
      readNearbyPipesSignal(color);
    }

    // STEP 2: transmit signal in nearby blocks

    if (signalStrength[color.ordinal()] > 1) {
      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.wireSet[color.ordinal()])
            if (isWireConnectedTo(tile, color)) {
              tilePipe.pipe.receiveSignal(signalStrength[color.ordinal()] - 1, color);
            }
        }
      }
    }
  }
Esempio n. 4
0
  public int isPoweringTo(int l) {
    if (!broadcastRedstone) return 0;

    ForgeDirection o = ForgeDirection.values()[l].getOpposite();
    TileEntity tile = container.getTile(o);

    if (tile instanceof TileGenericPipe && Utils.checkPipesConnections(this.container, tile))
      return 0;

    return 15;
  }
Esempio n. 5
0
  @Override
  public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {

    if (BuildCraftCore.render == RenderMode.NoDynamic) return;

    TileGenericPipe pipe = (TileGenericPipe) tileentity;

    if (pipe.pipe == null) return;

    switch (pipe.getPipeType()) {
      case ITEM:
        renderSolids(pipe.pipe, x, y, z);
        break;
      case FLUID:
        renderFluids(pipe.pipe, x, y, z);
        break;
      case POWER:
        renderPower(pipe.pipe, x, y, z);
        break;
    }
  }
Esempio n. 6
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();
 }
Esempio n. 7
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
    }
  }
Esempio n. 8
0
  public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
    if (trigger instanceof ITriggerPipe)
      return ((ITriggerPipe) trigger).isTriggerActive(this, parameter);
    else if (trigger != null) {
      for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity tile = container.getTile(o);

        if (tile != null && !(tile instanceof TileGenericPipe)) {
          if (trigger.isTriggerActive(o.getOpposite(), tile, parameter)) return true;
        }
      }
    }

    return false;
  }
Esempio n. 9
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;
  }
Esempio n. 10
0
  /** If this pipe is open on one side, return it. */
  public ForgeDirection getOpenOrientation() {
    int Connections_num = 0;

    ForgeDirection target_orientation = ForgeDirection.UNKNOWN;

    for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS)
      if (Utils.checkPipesConnections(container.getTile(o), container)) {

        Connections_num++;

        if (Connections_num == 1) {
          target_orientation = o;
        }
      }

    if (Connections_num > 1 || Connections_num == 0) return ForgeDirection.UNKNOWN;

    return target_orientation.getOpposite();
  }
Esempio n. 11
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;
      }
  }
Esempio n. 12
0
  public RaytraceResult doRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
    float xMin = Utils.pipeMinPos,
        xMax = Utils.pipeMaxPos,
        yMin = Utils.pipeMinPos,
        yMax = Utils.pipeMaxPos,
        zMin = Utils.pipeMinPos,
        zMax = Utils.pipeMaxPos;

    TileEntity pipeTileEntity = world.getBlockTileEntity(x, y, z);

    TileGenericPipe tileG = null;
    if (pipeTileEntity instanceof TileGenericPipe) tileG = (TileGenericPipe) pipeTileEntity;

    if (tileG == null) return null;

    Pipe pipe = tileG.pipe;

    if (!isValid(pipe)) return null;

    /** pipe hits along x, y, and z axis, gate (all 6 sides) [and wires+facades] */
    MovingObjectPosition[] hits =
        new MovingObjectPosition[] {null, null, null, null, null, null, null, null, null};

    boolean needAxisCheck = false;
    boolean needCenterCheck = true;

    // check along the x axis

    if (tileG.isPipeConnected(ForgeDirection.WEST)) {
      xMin = 0.0F;
      needAxisCheck = true;
    }

    if (tileG.isPipeConnected(ForgeDirection.WEST)) {
      xMax = 1.0F;
      needAxisCheck = true;
    }

    if (needAxisCheck) {
      setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax);

      hits[0] = super.collisionRayTrace(world, x, y, z, origin, direction);
      xMin = Utils.pipeMinPos;
      xMax = Utils.pipeMaxPos;
      needAxisCheck = false;
      needCenterCheck = false; // center already checked through this axis
    }

    // check along the y axis

    if (tileG.isPipeConnected(ForgeDirection.DOWN)) {
      yMin = 0.0F;
      needAxisCheck = true;
    }

    if (tileG.isPipeConnected(ForgeDirection.UP)) {
      yMax = 1.0F;
      needAxisCheck = true;
    }

    if (needAxisCheck) {
      setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax);

      hits[1] = super.collisionRayTrace(world, x, y, z, origin, direction);
      yMin = Utils.pipeMinPos;
      yMax = Utils.pipeMaxPos;
      needAxisCheck = false;
      needCenterCheck = false; // center already checked through this axis
    }

    // check along the z axis

    if (tileG.isPipeConnected(ForgeDirection.NORTH)) {
      zMin = 0.0F;
      needAxisCheck = true;
    }

    if (tileG.isPipeConnected(ForgeDirection.SOUTH)) {
      zMax = 1.0F;
      needAxisCheck = true;
    }

    if (needAxisCheck) {
      setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax);

      hits[2] = super.collisionRayTrace(world, x, y, z, origin, direction);
      zMin = Utils.pipeMinPos;
      zMax = Utils.pipeMaxPos;
      needAxisCheck = false;
      needCenterCheck = false; // center already checked through this axis
    }

    // check center (only if no axis were checked/the pipe has no connections)

    if (needCenterCheck) {
      setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax);

      hits[0] = super.collisionRayTrace(world, x, y, z, origin, direction);
    }

    // gates

    if (pipe.hasGate()) {
      for (int side = 0; side < 6; side++) {
        setBlockBoundsToGate(ForgeDirection.VALID_DIRECTIONS[side]);

        hits[3 + side] = super.collisionRayTrace(world, x, y, z, origin, direction);
      }
    }

    // TODO: check wires, facades

    // get closest hit

    double minLengthSquared = Double.POSITIVE_INFINITY;
    int minIndex = -1;

    for (int i = 0; i < hits.length; i++) {
      MovingObjectPosition hit = hits[i];
      if (hit == null) continue;

      double lengthSquared = hit.hitVec.squareDistanceTo(origin);

      if (lengthSquared < minLengthSquared) {
        minLengthSquared = lengthSquared;
        minIndex = i;
      }
    }

    // reset bounds

    setBlockBounds(0, 0, 0, 1, 1, 1);

    if (minIndex == -1) {
      return null;
    } else {
      Part hitPart;

      if (minIndex < 3) {
        hitPart = Part.Pipe;
      } else {
        hitPart = Part.Gate;
      }

      return new RaytraceResult(hitPart, hits[minIndex]);
    }
  }
Esempio n. 13
0
  @Override
  public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k) {
    float xMin = Utils.pipeMinPos,
        xMax = Utils.pipeMaxPos,
        yMin = Utils.pipeMinPos,
        yMax = Utils.pipeMaxPos,
        zMin = Utils.pipeMinPos,
        zMax = Utils.pipeMaxPos;

    TileEntity tile1 = world.getBlockTileEntity(i, j, k);

    if (tile1 instanceof TileGenericPipe) {
      TileGenericPipe tileG = (TileGenericPipe) tile1;
      if (tileG.isPipeConnected(ForgeDirection.WEST) || tileG.hasFacade(ForgeDirection.WEST)) {
        xMin = 0.0F;
      }

      if (tileG.isPipeConnected(ForgeDirection.EAST) || tileG.hasFacade(ForgeDirection.EAST)) {
        xMax = 1.0F;
      }

      if (tileG.isPipeConnected(ForgeDirection.DOWN) || tileG.hasFacade(ForgeDirection.DOWN)) {
        yMin = 0.0F;
      }

      if (tileG.isPipeConnected(ForgeDirection.UP) || tileG.hasFacade(ForgeDirection.UP)) {
        yMax = 1.0F;
      }

      if (tileG.isPipeConnected(ForgeDirection.NORTH) || tileG.hasFacade(ForgeDirection.NORTH)) {
        zMin = 0.0F;
      }

      if (tileG.isPipeConnected(ForgeDirection.SOUTH) || tileG.hasFacade(ForgeDirection.SOUTH)) {
        zMax = 1.0F;
      }

      if (tileG.hasFacade(ForgeDirection.EAST) || tileG.hasFacade(ForgeDirection.WEST)) {
        yMin = 0.0F;
        yMax = 1.0F;
        zMin = 0.0F;
        zMax = 1.0F;
      }

      if (tileG.hasFacade(ForgeDirection.UP) || tileG.hasFacade(ForgeDirection.DOWN)) {
        xMin = 0.0F;
        xMax = 1.0F;
        zMin = 0.0F;
        zMax = 1.0F;
      }

      if (tileG.hasFacade(ForgeDirection.SOUTH) || tileG.hasFacade(ForgeDirection.NORTH)) {
        xMin = 0.0F;
        xMax = 1.0F;
        yMin = 0.0F;
        yMax = 1.0F;
      }
    }

    return AxisAlignedBB.getBoundingBox(
        (double) i + xMin,
        (double) j + yMin,
        (double) k + zMin,
        (double) i + xMax,
        (double) j + yMax,
        (double) k + zMax);
  }
Esempio n. 14
0
  @SuppressWarnings("rawtypes")
  @Override
  public void addCollisionBoxesToList(
      World world,
      int i,
      int j,
      int k,
      AxisAlignedBB axisalignedbb,
      List arraylist,
      Entity par7Entity) {
    setBlockBounds(
        Utils.pipeMinPos,
        Utils.pipeMinPos,
        Utils.pipeMinPos,
        Utils.pipeMaxPos,
        Utils.pipeMaxPos,
        Utils.pipeMaxPos);
    super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);

    TileEntity tile1 = world.getBlockTileEntity(i, j, k);
    TileGenericPipe tileG = (TileGenericPipe) tile1;

    if (tileG.isPipeConnected(ForgeDirection.WEST)) {
      setBlockBounds(
          0.0F,
          Utils.pipeMinPos,
          Utils.pipeMinPos,
          Utils.pipeMaxPos,
          Utils.pipeMaxPos,
          Utils.pipeMaxPos);
      super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
    }

    if (tileG.isPipeConnected(ForgeDirection.EAST)) {
      setBlockBounds(
          Utils.pipeMinPos,
          Utils.pipeMinPos,
          Utils.pipeMinPos,
          1.0F,
          Utils.pipeMaxPos,
          Utils.pipeMaxPos);
      super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
    }

    if (tileG.isPipeConnected(ForgeDirection.DOWN)) {
      setBlockBounds(
          Utils.pipeMinPos,
          0.0F,
          Utils.pipeMinPos,
          Utils.pipeMaxPos,
          Utils.pipeMaxPos,
          Utils.pipeMaxPos);
      super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
    }

    if (tileG.isPipeConnected(ForgeDirection.UP)) {
      setBlockBounds(
          Utils.pipeMinPos,
          Utils.pipeMinPos,
          Utils.pipeMinPos,
          Utils.pipeMaxPos,
          1.0F,
          Utils.pipeMaxPos);
      super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
    }

    if (tileG.isPipeConnected(ForgeDirection.NORTH)) {
      setBlockBounds(
          Utils.pipeMinPos,
          Utils.pipeMinPos,
          0.0F,
          Utils.pipeMaxPos,
          Utils.pipeMaxPos,
          Utils.pipeMaxPos);
      super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
    }

    if (tileG.isPipeConnected(ForgeDirection.SOUTH)) {
      setBlockBounds(
          Utils.pipeMinPos,
          Utils.pipeMinPos,
          Utils.pipeMinPos,
          Utils.pipeMaxPos,
          Utils.pipeMaxPos,
          1.0F);
      super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
    }

    if (tileG != null) {
      float facadeThickness = PipeWorldRenderer.facadeThickness;

      if (tileG.hasFacade(ForgeDirection.EAST)) {
        setBlockBounds(1 - facadeThickness, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
      }

      if (tileG.hasFacade(ForgeDirection.WEST)) {
        setBlockBounds(0.0F, 0.0F, 0.0F, facadeThickness, 1.0F, 1.0F);
        super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
      }

      if (tileG.hasFacade(ForgeDirection.UP)) {
        setBlockBounds(0.0F, 1 - facadeThickness, 0.0F, 1.0F, 1.0F, 1.0F);
        super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
      }

      if (tileG.hasFacade(ForgeDirection.DOWN)) {
        setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, facadeThickness, 1.0F);
        super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
      }

      if (tileG.hasFacade(ForgeDirection.SOUTH)) {
        setBlockBounds(0.0F, 0.0F, 1 - facadeThickness, 1.0F, 1.0F, 1.0F);
        super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
      }

      if (tileG.hasFacade(ForgeDirection.NORTH)) {
        setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, facadeThickness);
        super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
      }
    }

    setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  }