Esempio n. 1
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (getRunning()) run();
    else postRun();

    if (Config.useFuel && !worldObj.isRemote) {
      if (inventory.getStackInSlot(0) != null
          && TileEntityFurnace.isItemFuel(inventory.getStackInSlot(0))
          && (fuel.get() + TileEntityFurnace.getItemBurnTime(inventory.getStackInSlot(0)))
              <= Config.maxFuelLevel)
        if (inventory.getStackInSlot(0).getItem().equals(Items.lava_bucket)) {
          fuel.modify(TileEntityFurnace.getItemBurnTime(inventory.decrStackSize(0, 1)));
          inventory.setInventorySlotContents(0, new ItemStack(Items.bucket));
        } else {
          fuel.modify(TileEntityFurnace.getItemBurnTime(inventory.decrStackSize(0, 1)));
        }

      if (fuel.isDirty()) sync();
    }

    lastTickPosX = posX;
    lastTickPosY = posY;
    lastTickPosZ = posZ;

    posX += motionX;
    posY += motionY;
    posZ += motionZ;

    setPosition(posX, posY, posZ);

    if (getTimeSinceHit() > 0) setTimeSinceHit(getTimeSinceHit() - 1);
    if (getDamageTaken() > 0) setDamageTaken(getDamageTaken() - 1);
  }
  public void updateEntity() {
    ItemStack log = getStackInSlot(0);
    ItemStack output = getStackInSlot(1);

    boolean powered = burning > 0;

    if (log != null && powered) {
      if (progress != loggingTime) {
        progress++;
      } else {
        if (output == null) {
          decrStackSize(0, 1);
          setInventorySlotContents(1, new ItemStack(Block.planks, 6, log.getItemDamage()));
          progress = 0;
        } else {
          if (output.isItemEqual(new ItemStack(Block.planks, 6, log.getItemDamage()))
              && output.stackSize < getInventoryStackLimit()) {
            decrStackSize(0, 1);
            output.stackSize = output.stackSize + 6;
            progress = 0;
          } else {
            progress = 0;
          }
        }
      }
    } else {
      progress = 0;
    }

    if (powered) {
      burning--;
    }

    ItemStack fuel = getStackInSlot(2);

    if (fuel != null) {
      if (TileEntityFurnace.getItemBurnTime(fuel) > 0) {
        if (!powered) {
          decrStackSize(2, 1);
          burning = TileEntityFurnace.getItemBurnTime(fuel);
        }
      }
    }

    if (powered != burning > 0) {
      this.onInventoryChanged();
      // BlockLogger.updateState(burning > 0, worldObj, xCoord, yCoord, zCoord);
    }
  }
  public int getFuel(ItemStack itemstack) {
    if (itemstack.getItem() == Items.lava_bucket) {
      return 1000;
    }

    return TileEntityFurnace.getItemBurnTime(itemstack) / 2;
  }
 @Override
 public void loadUsageRecipes(ItemStack ingredient) {
   int redstone = RedstoneExtractorRecipes.discharge().value(ingredient);
   if (redstone > 0) arecipes.add(new StarchPair(ingredient, redstone));
   int fuel = TileEntityFurnace.getItemBurnTime(ingredient);
   if (fuel > 0) afuels.add(new FuelPair(ingredient, fuel));
 }
Esempio n. 5
0
  private static int findFuelValue(ItemStack stack) {
    try {
      Item item = stack.getItem();

      if (item instanceof ItemBlock) {
        Block block = InvTools.getBlockFromStack(stack);

        String name = block.getUnlocalizedName();
        if (name != null && name.contains("blockScaffold")) return 0;
      }

      //            if (itemID == Item.coal.itemID && stack.getItemDamage() == 0)
      //                return 1600;

      if (item == Items.blaze_rod) return 1000;

      FluidStack liquid = FluidItemHelper.getFluidStackInContainer(stack);
      if (liquid != null && Fluids.LAVA.get() == liquid.getFluid()) return liquid.amount;

      String name = stack.getItem().getUnlocalizedName();
      if (name != null && name.contains("itemScrap")) return 0;

      return TileEntityFurnace.getItemBurnTime(stack);
    } catch (Exception ex) {
      Game.logThrowable(
          "Error in Fuel Handler! Is some mod creating items that are not compliant with standards?",
          ex);
    }
    return 0;
  }
  @Override
  public void readFromNBT(NBTTagCompound tagCompound) {
    super.readFromNBT(tagCompound);

    facing = ForgeDirection.getOrientation(tagCompound.getInteger("direction"));

    isValidMultiblock = tagCompound.getBoolean("isValidMultiblock");

    NBTTagList itemsTag = (NBTTagList) tagCompound.getTag("Items");
    furnaceItems = new ItemStack[getSizeInventory()];

    for (int i = 0; i < itemsTag.tagCount(); i++) {
      NBTTagCompound slotTag = (NBTTagCompound) itemsTag.getCompoundTagAt(i);
      byte slot = slotTag.getByte("Slot");

      if (slot >= 0 && slot < furnaceItems.length)
        furnaceItems[slot] = ItemStack.loadItemStackFromNBT(slotTag);
    }

    furnaceBurnTime = tagCompound.getShort("BurnTime");
    furnaceCookTime = tagCompound.getShort("CookTime");
    currentItemBurnTime = TileEntityFurnace.getItemBurnTime(furnaceItems[1]);
    cooking = tagCompound.getBoolean("active");
    type = tagCompound.getInteger("type");
    if (type == 1) partBlocks = stonebrick;
    hole = hole.readFromNBT(tagCompound, "hole");
  }
 private static void findFuels() {
   afuels = new ArrayList<FuelPair>();
   Set<Item> efuels = excludedFuels();
   for (ItemStack item : ItemList.items)
     if (!efuels.contains(item.getItem())) {
       int burnTime = TileEntityFurnace.getItemBurnTime(item);
       if (burnTime > 0) afuels.add(new FuelPair(item.copy(), burnTime));
     }
 }
  public void updateEntity() {
    boolean flag = burnTime > 0;
    boolean flag1 = false;

    if (burnTime > 0) {
      burnTime--;
    }

    if (!worldObj.isRemote) {
      if (burnTime != 0 || contents[1] != null && contents[0] != null) {
        if (burnTime == 0 && canSmelt()) {
          currentItemBurnTime = burnTime = TileEntityFurnace.getItemBurnTime(contents[1]);

          if (burnTime > 0) {
            flag1 = true;

            if (contents[1] != null) {
              contents[1].stackSize--;

              if (contents[1].stackSize == 0) {
                contents[1] = contents[1].getItem().getContainerItem(contents[1]);
              }
            }
          }
        }

        if (isBurning() && canSmelt()) {
          progress++;

          if (progress == 200) {
            progress = 0;
            smeltItem();
            flag1 = true;
          }
        } else {
          progress = 0;
        }
      }

      if (flag != burnTime > 0) {
        flag1 = true;
        // BlockFurnace.updateFurnaceBlockState(burnTime > 0, worldObj, xCoord, yCoord, zCoord);
      }
    }

    if (flag1) {
      markDirty();
    }
  }
  private boolean getFuelFromInventory() {
    for (int i = 0; i < owner.getInventory().getSizeInventory(); i++) {
      ItemStack stack = owner.getInventory().getStackInSlot(i);

      if (stack != null) {
        try {
          final boolean isFuel = TileEntityFurnace.isItemFuel(stack);
          int fuelValue =
              TileEntityFurnace.getItemBurnTime(stack) == 0
                  ? GameRegistry.getFuelValue(stack)
                  : TileEntityFurnace.getItemBurnTime(stack);
          fuelValue = fuelValue / Time.SECOND / 10;

          if (fuelValue == 0 && isFuel) {
            fuelValue = 1;
          }

          if (fuelValue > 0) {
            hasFuel = true;
            fuelUsesRemaining = fuelValue;

            owner
                .getInventory()
                .decrStackSize(owner.getInventory().getFirstSlotContainingItem(stack.getItem()), 1);
          }
        } catch (
            ClassCastException
                e) // Known problem with earlier versions of MCA, not sure why this happened.
        {
          continue;
        }
      }
    }

    return hasFuel;
  }
Esempio n. 10
0
 private int getItemBurnTime(ItemStack stack) {
   int val = TileEntityFurnace.getItemBurnTime(stack);
   return (val * ticksBeforeSmelt) / 200 * efficiencyBonus;
 }
  @Override
  public void updateEntity() {
    if (first && isValidMultiblock) {
      first = false;
      convertDummies();
    }
    if (!isValidMultiblock) return;
    boolean flag = furnaceBurnTime > 0;
    boolean flag1 = false;

    int metadata = getBlockMetadata();
    int isActive = (metadata >> 3);

    if (furnaceBurnTime > 0) furnaceBurnTime--;
    if (furnaceBurnTime == 0 && metadata != 0) {
      worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 3);
    }

    if (!this.worldObj.isRemote) {
      boolean canSmelt = false;

      for (int i = 0; i < 8; i++) {
        canSmelt = canSmelt || canSmelt(i);
      }
      if (furnaceBurnTime == 0 && canSmelt) {
        currentItemBurnTime = furnaceBurnTime = TileEntityFurnace.getItemBurnTime(furnaceItems[8]);

        if (furnaceBurnTime > 0) {
          flag1 = true;

          if (furnaceItems[8] != null) {
            furnaceItems[8].stackSize--;

            if (furnaceItems[8].stackSize == 0)
              furnaceItems[8] = furnaceItems[8].getItem().getContainerItem(furnaceItems[8]);
          }
        }
      }
      canSmelt = false;
      for (int i = 0; i < 8; i++) {
        canSmelt = canSmelt || canSmelt(i);
      }
      if (isBurning() && canSmelt) {
        furnaceCookTime++;

        if (furnaceCookTime == getCookTime()) {
          furnaceCookTime = 0;
          for (int i = 0; i < 8; i++) smeltItem(i);
          flag1 = true;
        }
      } else {
        furnaceCookTime = 0;
      }

      if (isActive == 0 && furnaceBurnTime > 0) {
        flag1 = true;
        isActive = 1;
        metadata = 1;
        setInside();
        if (metadata != 1) worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 3);
      }
    }

    if (flag1) closeInventory();
  }
 // returns the number of ticks the given item will burn. Returns 0 if the given item is not a
 // valid fuel
 public static short getItemBurnTime(ItemStack stack) {
   int burntime = TileEntityFurnace.getItemBurnTime(stack); // just use the vanilla values
   return (short) MathHelper.clamp_int(burntime, 0, Short.MAX_VALUE);
 }
Esempio n. 13
0
public class VanillaSmeltingRecipe implements IMachineRecipe {

  // We will use the same energy as per a standard furnace.
  // To do the conversion between fuel burning and RF, use the Stirling Gen
  // which produces ten RF per tick of burn time
  private static int RF_PER_ITEM =
      TileEntityFurnace.getItemBurnTime(new ItemStack(Items.coal, 1, 0)) * 10 / 8;

  private boolean enabled = true;

  private List<RecipeInput> excludes = new ArrayList<RecipeInput>();

  @Override
  public String getUid() {
    return "VanillaSmeltingRecipe";
  }

  public void setEnabled(boolean enabled) {
    this.enabled = enabled;
  }

  public void addExclude(RecipeInput ri) {
    excludes.add(ri);
  }

  @Override
  public int getEnergyRequired(MachineRecipeInput... inputs) {
    int numInputs = getNumInputs(inputs);
    return numInputs * RF_PER_ITEM;
  }

  @Override
  public RecipeBonusType getBonusType(MachineRecipeInput... inputs) {
    return RecipeBonusType.NONE;
  }

  private int getNumInputs(MachineRecipeInput[] inputs) {
    int numInputs = 0;
    for (MachineRecipeInput input : inputs) {
      if (input != null && isValidInput(input)) {
        numInputs += input.item.stackSize;
      }
    }
    return Math.min(numInputs, 3);
  }

  @Override
  public boolean isRecipe(MachineRecipeInput... inputs) {
    if (!enabled) {
      return false;
    }
    ItemStack output = null;
    for (MachineRecipeInput ri : inputs) {
      if (ri != null && ri.item != null && !isExcluded(ri.item)) {
        if (output == null) {
          output = FurnaceRecipes.smelting().getSmeltingResult(ri.item);
          if (output == null) {
            return false;
          }
        } else {
          ItemStack newOutput = FurnaceRecipes.smelting().getSmeltingResult(ri.item);
          if (newOutput == null || !newOutput.isItemEqual(output)) {
            return false;
          }
        }
      }
    }
    return output != null;
  }

  private boolean isExcluded(ItemStack item) {
    for (RecipeInput ri : excludes) {
      if (ri != null && ri.isInput(item)) {
        return true;
      }
    }
    return false;
  }

  @Override
  public ResultStack[] getCompletedResult(float chance, MachineRecipeInput... inputs) {
    ItemStack output = null;
    int inputCount = 0;
    for (MachineRecipeInput ri : inputs) {
      if (ri != null && ri.item != null && output == null) {
        output = FurnaceRecipes.smelting().getSmeltingResult(ri.item);
      }
    }
    if (output == null) {
      return new ResultStack[0];
    }
    int stackSize = output.stackSize;
    output = OreDictionaryPreferences.instance.getPreferred(output);
    ItemStack result = output.copy();
    result.stackSize = stackSize;
    result.stackSize = result.stackSize * getNumInputs(inputs);
    return new ResultStack[] {new ResultStack(result)};
  }

  @Override
  public float getExperienceForOutput(ItemStack output) {
    if (output == null) {
      return 0;
    }
    float result = FurnaceRecipes.smelting().func_151398_b(output);
    return result * output.stackSize;
  }

  @Override
  public boolean isValidInput(MachineRecipeInput input) {
    if (!enabled) {
      return false;
    }
    if (input == null || input.item == null) {
      return false;
    }
    if (isExcluded(input.item)) {
      return false;
    }
    ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(input.item);
    return itemstack != null;
  }

  @Override
  public String getMachineName() {
    return ModObject.blockAlloySmelter.unlocalisedName;
  }

  @Override
  public List<MachineRecipeInput> getQuantitiesConsumed(MachineRecipeInput[] inputs) {
    int consumed = 0;
    List<MachineRecipeInput> result = new ArrayList<MachineRecipeInput>();
    for (MachineRecipeInput ri : inputs) {
      if (isValidInput(new MachineRecipeInput(ri.slotNumber, ri.item))
          && consumed < 3
          && ri != null
          && ri.item != null) {
        int available = ri.item.stackSize;
        int canUse = 3 - consumed;
        int use = Math.min(canUse, available);
        if (use > 0) {
          ItemStack st = ri.item.copy();
          st.stackSize = use;
          result.add(new MachineRecipeInput(ri.slotNumber, st));
          consumed += use;
        }
      }
    }
    return result;
  }

  public List<IRecipe> getAllRecipes() {
    if (!enabled) {
      return Collections.emptyList();
    }
    List<IRecipe> result = new ArrayList<IRecipe>();
    Map<ItemStack, ItemStack> metaList = FurnaceRecipes.smelting().getSmeltingList();
    for (Entry<ItemStack, ItemStack> entry : metaList.entrySet()) {
      ItemStack output = entry.getValue();
      output = OreDictionaryPreferences.instance.getPreferred(output).copy();
      result.add(
          new Recipe(
              new RecipeInput(entry.getKey()),
              RF_PER_ITEM,
              RecipeBonusType.NONE,
              new RecipeOutput(output)));
    }
    return result;
  }
}