Beispiel #1
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
    }
  }
Beispiel #2
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();
    }
  }
  @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;
  }