示例#1
0
  private boolean stripEquipment(Pipe pipe) {

    // Try to strip wires first, starting with yellow.
    for (IPipe.WireColor color : IPipe.WireColor.values()) {
      if (pipe.wireSet[color.reverse().ordinal()]) {
        if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) {
          dropWire(color.reverse(), pipe);
        }
        pipe.wireSet[color.reverse().ordinal()] = false;
        // pipe.worldObj.markBlockNeedsUpdate(pipe.xCoord, pipe.yCoord, pipe.zCoord);
        pipe.container.scheduleRenderUpdate();
        return true;
      }
    }

    // Try to strip gate next
    if (pipe.hasGate()) {
      if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) {
        pipe.gate.dropGate();
      }
      pipe.resetGate();
      return true;
    }

    return false;
  }
示例#2
0
  @Override
  public LinkedList<ITrigger> getTriggers() {
    LinkedList<ITrigger> result = new LinkedList<ITrigger>();

    if (BlockGenericPipe.isFullyDefined(pipe) && pipe.hasGate()) {
      result.add(BuildCraftCore.triggerRedstoneActive);
      result.add(BuildCraftCore.triggerRedstoneInactive);
    }

    return result;
  }
示例#3
0
  // PRECONDITION: worldObj must not be null
  private void refreshRenderState() {

    // Only done on server/SSP
    if (worldObj.isRemote) return;

    // Pipe connections;
    for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
      renderState.pipeConnectionMatrix.setConnected(o, this.pipeConnectionsBuffer[o.ordinal()]);
    }

    // Pipe Textures
    renderState.setTextureFile(pipe.getTextureFile());
    for (ForgeDirection o : ForgeDirection.values()) {
      renderState.textureMatrix.setTextureIndex(o, pipe.getTextureIndex(o));
    }

    // WireState
    for (IPipe.WireColor color : IPipe.WireColor.values()) {
      renderState.wireMatrix.setWire(color, pipe.wireSet[color.ordinal()]);
      for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        renderState.wireMatrix.setWireConnected(
            color, direction, pipe.isWireConnectedTo(this.getTile(direction), color));
      }
    }

    // Wire Textures

    if (pipe.wireSet[IPipe.WireColor.Red.ordinal()]) {
      renderState.wireMatrix.setTextureIndex(
          WireColor.Red, pipe.signalStrength[IPipe.WireColor.Red.ordinal()] > 0 ? 6 : 5);
    } else {
      renderState.wireMatrix.setTextureIndex(WireColor.Red, 0);
    }

    if (pipe.wireSet[IPipe.WireColor.Blue.ordinal()]) {
      renderState.wireMatrix.setTextureIndex(
          WireColor.Blue, pipe.signalStrength[IPipe.WireColor.Blue.ordinal()] > 0 ? 8 : 7);
    } else {
      renderState.wireMatrix.setTextureIndex(WireColor.Blue, 0);
    }

    if (pipe.wireSet[IPipe.WireColor.Green.ordinal()]) {
      renderState.wireMatrix.setTextureIndex(
          WireColor.Green, pipe.signalStrength[IPipe.WireColor.Green.ordinal()] > 0 ? 10 : 9);
    } else {
      renderState.wireMatrix.setTextureIndex(WireColor.Green, 0);
    }

    if (pipe.wireSet[IPipe.WireColor.Yellow.ordinal()]) {
      renderState.wireMatrix.setTextureIndex(
          WireColor.Yellow, pipe.signalStrength[IPipe.WireColor.Yellow.ordinal()] > 0 ? 12 : 11);
    } else {
      renderState.wireMatrix.setTextureIndex(WireColor.Yellow, 0);
    }

    // Gate Textures
    renderState.setHasGate(pipe.hasGate());
    renderState.setGateTexture(!pipe.hasGate() ? 0 : pipe.gate.getTexture(pipe.isGateActive()));

    // Facades
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
      int blockId = this.facadeBlocks[direction.ordinal()];
      renderState.facadeMatrix.setConnected(
          direction, blockId != 0 && Block.blocksList[blockId] != null);
      if (Block.blocksList[blockId] != null) {
        Block block = Block.blocksList[blockId];
        renderState.facadeMatrix.setTextureFile(direction, block.getTextureFile());
        renderState.facadeMatrix.setTextureIndex(
            direction,
            block.getBlockTextureFromSideAndMetadata(
                direction.ordinal(), this.facadeMeta[direction.ordinal()]));
      }
    }

    if (renderState.isDirty()) {
      worldObj.markBlockNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);
      renderState.clean();
    }
  }
示例#4
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float xOffset,
      float yOffset,
      float zOffset) {
    super.onBlockActivated(world, x, y, z, player, side, xOffset, yOffset, zOffset);

    world.notifyBlocksOfNeighborChange(x, y, z, BuildCraftTransport.genericPipeBlock.blockID);

    Pipe pipe = getPipe(world, x, y, z);

    if (isValid(pipe)) {

      // / Right click while sneaking without wrench to strip equipment
      // from the pipe.
      if (player.isSneaking()
          && (player.getCurrentEquippedItem() == null
              || !(player.getCurrentEquippedItem().getItem() instanceof IToolWrench))) {

        if (pipe.hasGate() || pipe.isWired()) return stripEquipment(pipe);

      } else if (player.getCurrentEquippedItem() == null) {
        // Fall through the end of the test
      } else if (player.getCurrentEquippedItem().itemID == Item.sign.itemID)
        // Sign will be placed anyway, so lets show the sign gui
        return false;
      else if (player.getCurrentEquippedItem().getItem() instanceof ItemPipe) return false;
      else if (player.getCurrentEquippedItem().getItem() instanceof IToolWrench)
        // Only check the instance at this point. Call the IToolWrench
        // interface callbacks for the individual pipe/logic calls
        return pipe.blockActivated(player);
      else if (player.getCurrentEquippedItem().getItem() == BuildCraftTransport.redPipeWire) {
        if (!pipe.wireSet[IPipe.WireColor.Red.ordinal()]) {
          pipe.wireSet[IPipe.WireColor.Red.ordinal()] = true;
          if (!player.capabilities.isCreativeMode) {
            player.getCurrentEquippedItem().splitStack(1);
          }
          pipe.signalStrength[IPipe.WireColor.Red.ordinal()] = 0;
          pipe.container.scheduleNeighborChange();
          return true;
        }
      } else if (player.getCurrentEquippedItem().getItem() == BuildCraftTransport.bluePipeWire) {
        if (!pipe.wireSet[IPipe.WireColor.Blue.ordinal()]) {
          pipe.wireSet[IPipe.WireColor.Blue.ordinal()] = true;
          if (!player.capabilities.isCreativeMode) {
            player.getCurrentEquippedItem().splitStack(1);
          }
          pipe.signalStrength[IPipe.WireColor.Blue.ordinal()] = 0;
          pipe.container.scheduleNeighborChange();
          return true;
        }
      } else if (player.getCurrentEquippedItem().getItem() == BuildCraftTransport.greenPipeWire) {
        if (!pipe.wireSet[IPipe.WireColor.Green.ordinal()]) {
          pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true;
          if (!player.capabilities.isCreativeMode) {
            player.getCurrentEquippedItem().splitStack(1);
          }
          pipe.signalStrength[IPipe.WireColor.Green.ordinal()] = 0;
          pipe.container.scheduleNeighborChange();
          return true;
        }
      } else if (player.getCurrentEquippedItem().getItem() == BuildCraftTransport.yellowPipeWire) {
        if (!pipe.wireSet[IPipe.WireColor.Yellow.ordinal()]) {
          pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true;
          if (!player.capabilities.isCreativeMode) {
            player.getCurrentEquippedItem().splitStack(1);
          }
          pipe.signalStrength[IPipe.WireColor.Yellow.ordinal()] = 0;
          pipe.container.scheduleNeighborChange();
          return true;
        }
      } else if (player.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGate.itemID
          || player.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGateAutarchic.itemID)
        if (!pipe.hasGate()) {

          pipe.gate = Gate.makeGate(pipe, player.getCurrentEquippedItem());
          if (!player.capabilities.isCreativeMode) {
            player.getCurrentEquippedItem().splitStack(1);
          }
          pipe.container.scheduleRenderUpdate();
          return true;
        }

      boolean openGateGui = false;

      if (pipe.hasGate()) {
        RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);

        if (rayTraceResult != null && rayTraceResult.hitPart == Part.Gate) {
          openGateGui = true;
        }
      }

      if (openGateGui) {
        pipe.gate.openGui(player);

        return true;
      } else return pipe.blockActivated(player);
    }

    return false;
  }
示例#5
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]);
    }
  }