Exemplo 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;
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  public boolean isPipeConnected(TileEntity with) {
    Pipe pipe1 = pipe;
    Pipe pipe2 = null;

    if (with instanceof TileGenericPipe) pipe2 = ((TileGenericPipe) with).pipe;

    if (!BlockGenericPipe.isValid(pipe1)) return false;

    if (BlockGenericPipe.isValid(pipe2)
        && !pipe1.transport.getClass().isAssignableFrom(pipe2.transport.getClass())
        && !pipe1.transport.allowsConnect(pipe2.transport)) return false;

    if (pipe2 != null && !(pipe2.isPipeConnected(this))) return false;

    return pipe1 != null ? pipe1.isPipeConnected(with) : false;
  }
Exemplo 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);
            }
        }
      }
    }
  }
Exemplo n.º 4
0
  @Override
  public void updateEntity() {

    if (pipe == null) return;

    if (!initialized) initialize(pipe);

    if (!BlockGenericPipe.isValid(pipe)) return;

    if (blockNeighborChange) {

      computeConnections();
      pipe.onNeighborBlockChange(0);
      blockNeighborChange = false;
      refreshRenderState = true;
    }

    if (refreshRenderState) {
      refreshRenderState();
      refreshRenderState = false;
    }

    IPowerProvider provider = getPowerProvider();

    if (provider != null) provider.update(this);

    if (pipe != null) pipe.updateEntity();
  }
Exemplo n.º 5
0
 /* SMP */
 public void handleDescriptionPacket(PipeRenderStatePacket packet) {
   if (worldObj.isRemote) {
     if (pipe == null && packet.getPipeId() != 0) {
       initialize(BlockGenericPipe.createPipe(packet.getPipeId()));
     }
     renderState = packet.getRenderState();
     worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
   }
   return;
 }
Exemplo n.º 6
0
  @Override
  public boolean tryPlaceIntoWorld(
      ItemStack itemstack,
      EntityPlayer entityplayer,
      World world,
      int i,
      int j,
      int k,
      int l,
      float par8,
      float par9,
      float par10) {
    int blockID = BuildCraftTransport.genericPipeBlock.blockID;

    if (world.getBlockId(i, j, k) == Block.snow.blockID) l = 0;
    else {
      if (l == 0) j--;
      if (l == 1) j++;
      if (l == 2) k--;
      if (l == 3) k++;
      if (l == 4) i--;
      if (l == 5) i++;
    }

    if (itemstack.stackSize == 0) return false;
    if (entityplayer.canPlayerEdit(i, j, k)) {
      //		if (world.canBlockBePlacedAt(blockID, i, j, k, false, l)) {

      Pipe pipe = BlockGenericPipe.createPipe(shiftedIndex);
      if (BlockGenericPipe.placePipe(pipe, world, i, j, k, blockID, 0)) {

        // Block.blocksList[blockID].onBlockPlaced(world, i, j, k, l);
        Block.blocksList[blockID].onBlockPlacedBy(world, i, j, k, entityplayer);
        // To move to a proxt
        // world.playSoundEffect((float)i + 0.5F, (float)j + 0.5F,
        // (float)k + 0.5F, block.stepSound.func_1145_d(),
        // (block.stepSound.getVolume() + 1.0F) / 2.0F,
        // block.stepSound.getPitch() * 0.8F);
        itemstack.stackSize--;
      }
      return true;
    } else return false;
  }
Exemplo n.º 7
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;
  }
Exemplo n.º 8
0
 private boolean passToNextPipe(TravelingItem item, TileEntity tile) {
   if (tile instanceof TileGenericPipe) {
     TileGenericPipe pipe = (TileGenericPipe) tile;
     if (BlockGenericPipe.isValid(pipe.pipe)
         && pipe.pipe.transport instanceof PipeTransportItems) {
       ((PipeTransportItems) pipe.pipe.transport).injectItem(item, item.output);
       return true;
     }
   }
   return false;
 }
Exemplo n.º 9
0
  @Override
  public boolean isWireConnectedTo(TileEntity tile, WireColor color) {
    if (!(tile instanceof TileGenericPipe)) return false;

    TileGenericPipe tilePipe = (TileGenericPipe) tile;

    if (!BlockGenericPipe.isFullyDefined(tilePipe.pipe)) return false;

    if (!tilePipe.pipe.wireSet[color.ordinal()]) return false;

    return (tilePipe.pipe.transport instanceof PipeTransportStructure
        || transport instanceof PipeTransportStructure
        || Utils.checkPipesConnections(container, tile));
  }
  private static ItemPipe createPipe(int defaultID, Class<? extends Pipe> clazz, String descr) {
    String name =
        Character.toLowerCase(clazz.getSimpleName().charAt(0)) + clazz.getSimpleName().substring(1);

    Property prop = aboConfiguration.getItem(name + ".id", defaultID);

    int id = prop.getInt(defaultID);

    try {
      // search for free id
      while (BlockGenericPipe.isPipeRegistered(id)) ++id;

      prop.set(id);
    } catch (NoSuchMethodError e) {
      // e.printStackTrace();
    }

    ItemPipe pipe = BlockGenericPipe.registerPipe(id, clazz);
    pipe.setUnlocalizedName(clazz.getSimpleName());
    LanguageRegistry.addName(pipe, descr);
    GameRegistry.registerItem(pipe, pipe.getUnlocalizedName().replace("item.", ""));

    return pipe;
  }
Exemplo n.º 11
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);

    coreState.pipeId = nbttagcompound.getInteger("pipeId");
    pipe = BlockGenericPipe.createPipe(coreState.pipeId);

    if (pipe != null) {
      pipe.readFromNBT(nbttagcompound);
    }

    for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
      facadeBlocks[i] = nbttagcompound.getInteger("facadeBlocks[" + i + "]");
      facadeMeta[i] = nbttagcompound.getInteger("facadeMeta[" + i + "]");
    }
  }
Exemplo n.º 12
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);

    key = nbttagcompound.getInteger("pipeId");
    pipe = BlockGenericPipe.createPipe(key);

    if (pipe != null) {
      pipe.readFromNBT(nbttagcompound);
    }

    for (int i = 0; i < Orientations.dirs().length; i++) {
      facadeBlocks[i] = nbttagcompound.getInteger("facadeBlocks[" + i + "]");
      facadeMeta[i] = nbttagcompound.getInteger("facadeMeta[" + i + "]");
    }
  }
Exemplo n.º 13
0
  public static Item createPipe(
      int defaultID,
      Class<? extends Pipe> clas,
      String descr,
      Object ingredient1,
      Object ingredient2,
      Object ingredient3) {
    String name =
        Character.toLowerCase(clas.getSimpleName().charAt(0)) + clas.getSimpleName().substring(1);

    Property prop = BuildCraftCore.mainConfiguration.getItem(name + ".id", defaultID);

    int id = prop.getInt(defaultID);
    ItemPipe res = BlockGenericPipe.registerPipe(id, clas);
    res.setItemName(clas.getSimpleName());
    LanguageRegistry.addName(res, descr);

    // Add appropriate recipe to temporary list
    PipeRecipe recipe = new PipeRecipe();

    if (ingredient1 != null && ingredient2 != null && ingredient3 != null) {
      recipe.result = new ItemStack(res, 8);
      recipe.input =
          new Object[] {
            "ABC",
            Character.valueOf('A'),
            ingredient1,
            Character.valueOf('B'),
            ingredient2,
            Character.valueOf('C'),
            ingredient3
          };

      pipeRecipes.add(recipe);
    } else if (ingredient1 != null && ingredient2 != null) {
      recipe.isShapeless = true;
      recipe.result = new ItemStack(res, 1);
      recipe.input = new Object[] {ingredient1, ingredient2};

      pipeRecipes.add(recipe);
    }

    return res;
  }
Exemplo n.º 14
0
  @Override
  public boolean canPipeConnect(TileEntity tile, ForgeDirection side) {
    if (tile instanceof TileGenericPipe) {
      Pipe pipe2 = ((TileGenericPipe) tile).pipe;
      if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportItems))
        return false;
    }

    if (tile instanceof ISidedInventory) {
      int[] slots =
          ((ISidedInventory) tile).getAccessibleSlotsFromSide(side.getOpposite().ordinal());
      return slots != null && slots.length > 0;
    }

    return tile instanceof TileGenericPipe
        || tile instanceof ISpecialInventory
        || (tile instanceof IInventory && ((IInventory) tile).getSizeInventory() > 0)
        || (tile instanceof IMachine && ((IMachine) tile).manageSolids());
  }
Exemplo n.º 15
0
  @Override
  public void afterStateUpdated(byte stateId) {
    if (!worldObj.isRemote) return;

    switch (stateId) {
      case 0:
        if (pipe == null && coreState.pipeId != 0) {
          initialize(BlockGenericPipe.createPipe(coreState.pipeId));
        }
        if (pipe != null) {
          if (pipe.gate == null) {
            pipe.gate = new GateVanilla(pipe);
          }
          pipe.gate.kind = GateKind.values()[coreState.gateKind];
        }
        break;
    }
    worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
  }
Exemplo n.º 16
0
  @Override
  public boolean canPipeConnect(TileEntity tile, ForgeDirection side) {
    if (tile instanceof TileGenericPipe) {
      Pipe pipe2 = ((TileGenericPipe) tile).pipe;
      if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportPower))
        return false;
      return true;
    }

    if (tile instanceof IPowerReceptor) {
      IPowerReceptor receptor = (IPowerReceptor) tile;
      PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite());
      if (receiver != null && receiver.getType().canReceiveFromPipes()) return true;
    }

    if (container.pipe instanceof PipePowerWood && tile instanceof IPowerEmitter) {
      IPowerEmitter emitter = (IPowerEmitter) tile;
      if (emitter.canEmitPowerFrom(side.getOpposite())) return true;
    }

    return false;
  }
Exemplo n.º 17
0
 @Override
 public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) {
   if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
     return ((ITankContainer) pipe.transport).drain(tankIndex, maxDrain, doDrain);
   else return null;
 }
Exemplo n.º 18
0
 @Override
 public boolean doDrop() {
   if (BlockGenericPipe.isValid(pipe)) return pipe.doDrop();
   else return false;
 }
Exemplo n.º 19
0
 @Override
 public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
   if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
     return ((ITankContainer) pipe.transport).fill(tankIndex, resource, doFill);
   else return 0;
 }
 private static Item createPipe(Class<? extends Pipe<?>> clas) {
   Item res = BlockGenericPipe.registerPipe(clas, CreativeTabBuildCraft.PIPES);
   res.setUnlocalizedName(clas.getSimpleName());
   proxy.registerPipeRendering(res);
   return res;
 }
Exemplo n.º 21
0
 @Override
 public ILiquidTank[] getTanks() {
   if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
     return ((ITankContainer) pipe.transport).getTanks();
   else return null;
 }
Exemplo n.º 22
0
 @Override
 public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) {
   if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof ITankContainer)
     return ((ITankContainer) pipe.transport).getTank(direction, type);
   else return null;
 }
Exemplo n.º 23
0
 @Override
 public boolean acceptItems() {
   if (BlockGenericPipe.isValid(pipe)) return pipe.transport.acceptItems();
   else return false;
 }
Exemplo n.º 24
0
 /* IPIPEENTRY */
 @Override
 public void entityEntering(IPipedItem item, ForgeDirection orientation) {
   if (BlockGenericPipe.isValid(pipe)) pipe.transport.entityEntering(item, orientation);
 }
Exemplo n.º 25
0
 @Override
 public void doWork() {
   if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor)
     ((IPowerReceptor) pipe).doWork();
 }
Exemplo n.º 26
0
 @Override
 public IPowerProvider getPowerProvider() {
   if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor)
     return ((IPowerReceptor) pipe).getPowerProvider();
   else return null;
 }
Exemplo n.º 27
0
 @Override
 public void setPowerProvider(IPowerProvider provider) {
   if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor)
     ((IPowerReceptor) pipe).setPowerProvider(provider);
 }
Exemplo n.º 28
0
  @Override
  public boolean onItemUse(
      ItemStack itemstack,
      EntityPlayer entityplayer,
      World world,
      int i,
      int j,
      int k,
      int side,
      float par8,
      float par9,
      float par10) {
    int blockID = BuildCraftTransport.genericPipeBlock.blockID;
    Block block = BuildCraftTransport.genericPipeBlock;

    int id = world.getBlockId(i, j, k);

    if (id == Block.snow.blockID) {
      side = 1;
    } else if (id != Block.vine.blockID
        && id != Block.tallGrass.blockID
        && id != Block.deadBush.blockID
        && (Block.blocksList[id] == null
            || !Block.blocksList[id].isBlockReplaceable(world, i, j, k))) {
      if (side == 0) {
        j--;
      }
      if (side == 1) {
        j++;
      }
      if (side == 2) {
        k--;
      }
      if (side == 3) {
        k++;
      }
      if (side == 4) {
        i--;
      }
      if (side == 5) {
        i++;
      }
    }

    if (itemstack.stackSize == 0) return false;
    if (entityplayer.canCurrentToolHarvestBlock(i, j, k)
        && world.canPlaceEntityOnSide(blockID, i, j, k, false, side, entityplayer, itemstack)) {

      Pipe pipe = BlockGenericPipe.createPipe(itemID);
      if (pipe == null) {
        BuildCraftCore.bcLog.log(
            Level.WARNING,
            "Pipe failed to create during placement at {0},{1},{2}",
            new Object[] {i, j, k});
        return true;
      }
      if (BlockGenericPipe.placePipe(pipe, world, i, j, k, blockID, 0)) {

        Block.blocksList[blockID].onBlockPlacedBy(world, i, j, k, entityplayer, itemstack);
        world.playSoundEffect(
            i + 0.5F,
            j + 0.5F,
            k + 0.5F,
            block.stepSound.getPlaceSound(),
            (block.stepSound.getVolume() + 1.0F) / 2.0F,
            block.stepSound.getPitch() * 0.8F);
        itemstack.stackSize--;
      }
      return true;
    } else return false;
  }