Пример #1
0
  private void mineStack(ItemStack s) {
    boolean added = false;

    // First, try to add to a nearby chest

    StackUtil stackUtils = new StackUtil(s);

    added = stackUtils.addToRandomInventory(this, Orientations.Unknown);

    if (!added || stackUtils.items.stackSize > 0) {
      added = Utils.addToRandomPipeEntry(this, Orientations.Unknown, stackUtils.items);
    }

    // Last, throw the object away

    if (!added) {
      float f = worldObj.rand.nextFloat() * 0.8F + 0.1F;
      float f1 = worldObj.rand.nextFloat() * 0.8F + 0.1F;
      float f2 = worldObj.rand.nextFloat() * 0.8F + 0.1F;

      EntityItem entityitem =
          new EntityItem(worldObj, xCoord + f, yCoord + f1 + 0.5F, zCoord + f2, stackUtils.items);

      float f3 = 0.05F;
      entityitem.motionX = (float) worldObj.rand.nextGaussian() * f3;
      entityitem.motionY = (float) worldObj.rand.nextGaussian() * f3 + 1.0F;
      entityitem.motionZ = (float) worldObj.rand.nextGaussian() * f3;
      worldObj.spawnEntityInWorld(entityitem);
    }
  }
Пример #2
0
 public void dropFacade(Orientations direction) {
   if (this.worldObj.isRemote) return;
   if (!hasFacade(direction)) return;
   Utils.dropItems(
       worldObj,
       new ItemStack(
           BuildCraftTransport.facadeItem,
           1,
           ItemFacade.encode(
               this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()])),
       this.xCoord,
       this.yCoord,
       this.zCoord);
   this.facadeBlocks[direction.ordinal()] = 0;
   this.facadeMeta[direction.ordinal()] = 0;
   scheduleRenderUpdate();
   // refreshRenderState();
 }
Пример #3
0
  @Override
  public void doWork() {
    if (powerProvider.getEnergyStored() <= 0) return;

    World w = worldObj;

    int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);

    if (meta > 5) return;

    Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[meta]);
    pos.moveForwards(1);
    TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);

    if (tile instanceof IInventory) {
      if (!PipeManager.canExtractItems(this, w, (int) pos.x, (int) pos.y, (int) pos.z)) return;

      IInventory inventory = (IInventory) tile;

      ItemStack[] extracted = checkExtract(inventory, true, pos.orientation.reverse());
      if (extracted == null) return;

      for (ItemStack stack : extracted) {
        if (stack == null || stack.stackSize == 0) {
          powerProvider.useEnergy(1, 1, false);
          continue;
        }

        Position entityPos =
            new Position(
                pos.x + 0.5,
                pos.y + Utils.getPipeFloorOf(stack),
                pos.z + 0.5,
                pos.orientation.reverse());

        entityPos.moveForwards(0.5);

        IPipedItem entity = new EntityPassiveItem(w, entityPos.x, entityPos.y, entityPos.z, stack);

        ((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation);
      }
    }
  }
Пример #4
0
  /**
   * Return the itemstack that can be if something can be extracted from this inventory, null if
   * none. On certain cases, the extractable slot depends on the position of the pipe.
   */
  public ItemStack[] checkExtract(IInventory inventory, boolean doRemove, Orientations from) {

    /// ISPECIALINVENTORY
    if (inventory instanceof ISpecialInventory)
      return ((ISpecialInventory) inventory).extractItem(doRemove, from, 1);

    if (inventory instanceof ISidedInventory) {
      ISidedInventory sidedInv = (ISidedInventory) inventory;

      int first = sidedInv.getStartInventorySide(from.toDirection());
      int last = first + sidedInv.getSizeInventorySide(from.toDirection()) - 1;

      IInventory inv = Utils.getInventory(inventory);

      ItemStack result = checkExtractGeneric(inv, doRemove, from, first, last);

      if (result != null) return new ItemStack[] {result};
    } else if (inventory.getSizeInventory() == 2) {
      // This is an input-output inventory

      int slotIndex = 0;

      if (from == Orientations.YNeg || from == Orientations.YPos) slotIndex = 0;
      else slotIndex = 1;

      ItemStack slot = inventory.getStackInSlot(slotIndex);

      if (slot != null && slot.stackSize > 0)
        if (doRemove)
          return new ItemStack[] {
            inventory.decrStackSize(
                slotIndex, (int) powerProvider.useEnergy(1, slot.stackSize, true))
          };
        else return new ItemStack[] {slot};
    } else if (inventory.getSizeInventory() == 3) {
      // This is a furnace-like inventory

      int slotIndex = 0;

      if (from == Orientations.YPos) slotIndex = 0;
      else if (from == Orientations.YNeg) slotIndex = 1;
      else slotIndex = 2;

      ItemStack slot = inventory.getStackInSlot(slotIndex);

      if (slot != null && slot.stackSize > 0)
        if (doRemove)
          return new ItemStack[] {
            inventory.decrStackSize(
                slotIndex, (int) powerProvider.useEnergy(1, slot.stackSize, true))
          };
        else return new ItemStack[] {slot};
    } else {
      // This is a generic inventory
      IInventory inv = Utils.getInventory(inventory);

      ItemStack result = checkExtractGeneric(inv, doRemove, from, 0, inv.getSizeInventory() - 1);

      if (result != null) return new ItemStack[] {result};
    }

    return null;
  }
Пример #5
0
  private void setBoundaries(boolean useDefault) {

    IAreaProvider a = null;

    if (!useDefault) {
      a = Utils.getNearbyAreaProvider(worldObj, xCoord, yCoord, zCoord);
    }

    if (a == null) {
      a = new DefaultAreaProvider(xCoord, yCoord, zCoord, xCoord + 10, yCoord + 4, zCoord + 10);

      useDefault = true;
    }

    int xSize = a.xMax() - a.xMin() + 1;
    int ySize = a.yMax() - a.yMin() + 1;
    int zSize = a.zMax() - a.zMin() + 1;

    if (xSize < 3 || zSize < 3) {
      a = new DefaultAreaProvider(xCoord, yCoord, zCoord, xCoord + 10, yCoord + 4, zCoord + 10);

      useDefault = true;
    }

    xSize = a.xMax() - a.xMin() + 1;
    ySize = a.yMax() - a.yMin() + 1;
    zSize = a.zMax() - a.zMin() + 1;

    box.initialize(a);

    if (ySize < 5) {
      ySize = 5;
      box.yMax = box.yMin + ySize - 1;
    }

    if (useDefault) {
      int xMin = 0, zMin = 0;

      Orientations o =
          Orientations.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)].reverse();

      switch (o) {
        case XPos:
          xMin = xCoord + 1;
          zMin = zCoord - 4 - 1;
          break;
        case XNeg:
          xMin = xCoord - 9 - 2;
          zMin = zCoord - 4 - 1;
          break;
        case ZPos:
          xMin = xCoord - 4 - 1;
          zMin = zCoord + 1;
          break;
        case ZNeg:
        default:
          xMin = xCoord - 4 - 1;
          zMin = zCoord - 9 - 2;
          break;
      }

      box.initialize(xMin, yCoord, zMin, xMin + xSize - 1, yCoord + ySize - 1, zMin + zSize - 1);
    }

    a.removeFromWorld();
  }