Java Code Examples for net.minecraft.tileentity.TileEntityFurnace#getItemBurnTime()

The following examples show how to use net.minecraft.tileentity.TileEntityFurnace#getItemBurnTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpgradeFueled.java    From BetterChests with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void update(IUpgradableBlock chest, ItemStack stack) {
	if (UpgradeHelper.INSTANCE.getFrequencyTick(chest, stack, 64) != 0) {
		return;
	}
	IEnergyStorage storage = chest.getEnergyStorage();
	if (storage.getEnergyStored() >= storage.getMaxEnergyStored()) {
		return;
	}

	IBetterChest inv = (IBetterChest) chest;
	IFilter filter = inv.getFilterFor(stack);

	int slot = InvUtil.findInInvInternal(inv, null, test -> TileEntityFurnace.getItemBurnTime(test) > 0 && filter.matchesStack(test));
	if (slot != -1) {
		ItemStack current = inv.getStackInSlot(slot);
		int provided = TileEntityFurnace.getItemBurnTime(current) * Config.INSTANCE.energyFueled;
		if (storage.receiveEnergy(provided, true) == provided) {
			storage.receiveEnergy(provided, false);
			current.setCount(current.getCount() - 1);
			inv.markDirty();
		}
	}
}
 
Example 2
Source File: TileEntityEngine.java    From archimedes-ships with MIT License 6 votes vote down vote up
public boolean consumeFuel(int f)
{
	if (burnTime >= f)
	{
		burnTime -= f;
		return true;
	}
	
	for (int i = 0; i < getSizeInventory(); i++)
	{
		ItemStack is = decrStackSize(i, 1);
		if (is != null && is.stackSize > 0)
		{
			burnTime += TileEntityFurnace.getItemBurnTime(is);
			return consumeFuel(f);
		}
	}
	return false;
}
 
Example 3
Source File: FurnaceRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
private static void findFuels() {
    afuels = new ArrayList<>();
    Set<Item> efuels = excludedFuels();
    for (ItemStack item : ItemList.items) {
        Block block = Block.getBlockFromItem(item.getItem());
        if (block instanceof BlockDoor) {
            continue;
        }
        if (efuels.contains(item.getItem())) {
            continue;
        }

        int burnTime = TileEntityFurnace.getItemBurnTime(item);
        if (burnTime > 0) {
            afuels.add(new FuelPair(item.copy(), burnTime));
        }
    }
}
 
Example 4
Source File: MachineManager.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
public static MachineFuel findMatchingFuel(ResourceLocation list, NonNullList<ItemStack> input)
{
    if (list.toString().equals("minecraft:vanilla"))
    {
        if (input.size() == 1 && !input.get(0).isEmpty())
        {
            ItemStack stack = input.get(0);
            int burnTime = TileEntityFurnace.getItemBurnTime(stack);
            if (burnTime > 0)
                return new VanillaFurnaceFuel(stack, burnTime);
        }

        return MachineFuel.EMPTY;
    }

    return findMatchingFuel(getInstance(list).fuels, input);
}
 
Example 5
Source File: MachineManager.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isPartOfFuel(ResourceLocation list, ItemStack stack)
{
    if (stack.isEmpty())
        return false;

    if (list.toString().equals("minecraft:vanilla"))
    {
        return TileEntityFurnace.getItemBurnTime(stack) > 0;
    }

    for (MachineFuel fuel : getInstance(list).fuels)
    {
        if (fuel.getFuelInput().stream()
                .anyMatch(input -> ItemHelper.stackMatchesRecipeInput(stack, input, false)))
            return true;
    }

    return false;
}
 
Example 6
Source File: CraftingHelper.java    From malmo with MIT License 5 votes vote down vote up
/**
 * Go through player's inventory and see how much fuel they have.
 *
 * @param player
 * @return the amount of fuel available in ticks
 */
public static int totalBurnTimeInInventory(EntityPlayerMP player) {
    Integer fromCache = fuelCaches.get(player);
    int total = (fromCache != null) ? fromCache : 0;
    for (int i = 0; i < player.inventory.mainInventory.size(); i++) {
        ItemStack is = player.inventory.mainInventory.get(i);
        total += is.getCount() * TileEntityFurnace.getItemBurnTime(is);
    }
    return total;
}
 
Example 7
Source File: TileEntityAirCompressor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateEntity(){
    if(!worldObj.isRemote) {
        if(burnTime < curFuelUsage && inventory[0] != null && TileEntityFurnace.isItemFuel(inventory[0]) && redstoneAllows()) {
            burnTime += TileEntityFurnace.getItemBurnTime(inventory[0]);
            maxBurnTime = burnTime;

            inventory[0].stackSize--;
            if(inventory[0].stackSize == 0) {
                inventory[0] = inventory[0].getItem().getContainerItem(inventory[0]);
            }

        }

        curFuelUsage = (int)(getBaseProduction() * getSpeedUsageMultiplierFromUpgrades(getUpgradeSlots()) / 10);
        if(burnTime >= curFuelUsage) {
            burnTime -= curFuelUsage;
            if(!worldObj.isRemote) {
                addAir((int)(getBaseProduction() * getSpeedMultiplierFromUpgrades(getUpgradeSlots()) * getEfficiency() / 100D), ForgeDirection.UNKNOWN);
                onFuelBurn(curFuelUsage);
            }
        }
        isActive = burnTime > curFuelUsage;
    } else if(isActive) spawnBurningParticle();

    super.updateEntity();

}
 
Example 8
Source File: FurnaceRecipeHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private static void findFuels() {
    afuels = new ArrayList<FuelPair>();
    Set<Item> efuels = excludedFuels();
    for (ItemStack item : ItemList.items) {
        Block block = Block.getBlockFromItem(item.getItem());
        if (block instanceof BlockDoor)
            continue;
        if (efuels.contains(item.getItem()))
            continue;

        int burnTime = TileEntityFurnace.getItemBurnTime(item);
        if (burnTime > 0)
            afuels.add(new FuelPair(item.copy(), burnTime));
    }
}
 
Example 9
Source File: CapabilityMinecartDestination.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tries to use fuel and returns true if succeeded.
 * @return
 */
public boolean useFuel(EntityMinecart cart){
    if(motorized) {
        if(fuelLeft == 0) {
            for(int i = 0; i < fuelInv.getSizeInventory(); i++) {
                ItemStack fuel = fuelInv.getStackInSlot(i);
                if(!fuel.isEmpty()) {
                    int fuelValue = TileEntityFurnace.getItemBurnTime(fuel);
                    if(fuelValue > 0) {
                        fuel.shrink(1);
                        if(fuel.isEmpty()) {
                            fuelInv.setInventorySlotContents(i, fuel.getItem().getContainerItem(fuel));
                        }
                        fuelLeft += fuelValue;
                        totalBurnTime = fuelValue;
                        break;
                    }
                }
            }
        }
        if(fuelLeft > 0) {
            fuelLeft--;
            double randX = cart.getPositionVector().x + (cart.world.rand.nextDouble() - 0.5) * 0.5;
            double randY = cart.getPositionVector().y + (cart.world.rand.nextDouble() - 0.5) * 0.5;
            double randZ = cart.getPositionVector().z + (cart.world.rand.nextDouble() - 0.5) * 0.5;
            NetworkHandler.sendToAllAround(new PacketSpawnParticle(EnumParticleTypes.SMOKE_LARGE, randX, randY, randZ, 0, 0, 0), cart.world);
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: CraftingHelper.java    From malmo with MIT License 5 votes vote down vote up
/**
 * Consume fuel from the player's inventory.<br>
 * Take it first from their cache, if present, and then from their inventory, starting
 * at the first slot and working upwards.
 *
 * @param player
 * @param burnAmount amount of fuel to burn, in ticks.
 */
public static void burnInventory(EntityPlayerMP player, int burnAmount, ItemStack input) {
    if (!fuelCaches.containsKey(player))
        fuelCaches.put(player, -burnAmount);
    else
        fuelCaches.put(player, fuelCaches.get(player) - burnAmount);
    int index = 0;
    while (fuelCaches.get(player) < 0 && index < player.inventory.mainInventory.size()) {
        ItemStack is = player.inventory.mainInventory.get(index);
        if (is != null) {
            int burnTime = TileEntityFurnace.getItemBurnTime(is);
            if (burnTime != 0) {
                // Consume item:
                if (is.getCount() > 1)
                    is.setCount(is.getCount() - 1);
                else {
                    // If this is a bucket of lava, we need to consume the lava but leave the bucket.
                    if (is.getItem() == Items.LAVA_BUCKET) {
                        // And if we're cooking wet sponge, we need to leave the bucket filled with water.
                        if (input.getItem() == Item.getItemFromBlock(Blocks.SPONGE) && input.getMetadata() == 1)
                            player.inventory.mainInventory.set(index, new ItemStack(Items.WATER_BUCKET));
                        else
                            player.inventory.mainInventory.set(index, new ItemStack(Items.BUCKET));
                    } else
                        player.inventory.mainInventory.get(index).setCount(0);
                    index++;
                }
                fuelCaches.put(player, fuelCaches.get(player) + burnTime);
            } else
                index++;
        } else
            index++;
    }
}
 
Example 11
Source File: BW_TileEntity_HeatedWaterPump.java    From bartworks with MIT License 5 votes vote down vote up
private void handleRefuel() {
    if (this.fuelstack != null && this.fuel == 0) {
        this.fuel = this.maxfuel = TileEntityFurnace.getItemBurnTime(this.fuelstack);
        --this.fuelstack.stackSize;
        if (this.fuelstack.stackSize <= 0)
            this.fuelstack = null;
    }
}
 
Example 12
Source File: SteamCoalBoiler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IItemHandlerModifiable createImportItemHandler() {
    return new ItemStackHandler(1) {
        @Nonnull
        @Override
        public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
            if (TileEntityFurnace.getItemBurnTime(stack) <= 0)
                return stack;
            return super.insertItem(slot, stack, simulate);
        }
    };
}
 
Example 13
Source File: SteamCoalBoiler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void tryConsumeNewFuel() {
    ItemStack fuelInSlot = importItems.extractItem(0, 1, true);
    if (fuelInSlot.isEmpty()) return;
    int burnTime = TileEntityFurnace.getItemBurnTime(fuelInSlot);
    if (burnTime <= 0) return;
    importItems.extractItem(0, 1, false);
    ItemStack remainderAsh = ModHandler.getBurningFuelRemainder(getWorld().rand, fuelInSlot);
    if (!remainderAsh.isEmpty()) { //we don't care if we can't insert ash - it's chanced anyway
        exportItems.insertItem(0, remainderAsh, false);
    }
    setFuelMaxBurnTime(burnTime);
}
 
Example 14
Source File: TileEntitySaltFurnace.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * Like the old updateEntity(), except more generic.
 */
@Override
public void update() {

    boolean wasBurning = isBurning();
    if (isBurning()) furnaceBurnTime--;

    int cauldron = this.getCauldronStatus();
    boolean isDirty = false;
    if (!world.isRemote) {
        if (furnaceBurnTime == 0 && this.canBoil(cauldron)) {
            ItemStack fuel = furnaceItemStacks.get(0);
            furnaceBurnTime = TileEntityFurnace.getItemBurnTime(fuel);
            if (furnaceBurnTime > 0) {
                isDirty = true;
                fuel.shrink(1);
                if (fuel.getCount() == 0) {
                    furnaceItemStacks.set(0, fuel.getItem().getContainerItem(fuel));
                }
            }
        }

        if (isBurning() && canBoil(cauldron) && cauldron >= 1) {
            cookTime++;
            if (cookTime == 200) {
                cookTime = 0;
                boilDown();
                isDirty = true;
            }
        } else cookTime = 0;

        if (wasBurning != isBurning()) {
            isDirty = true;
            BlockSaltFurnace.setState(isBurning(), world, pos);
        }

        if (this.isBurning()) {
            if (cauldron == -1) {
                this.world.setBlockState(this.pos.up(), Blocks.FIRE.getDefaultState().withProperty(BlockFire.AGE, 0));
            } else if (cauldron == -2) {
                if (this.world.rand.nextInt(200) == 0) {
                    this.world.setBlockState(this.pos.up(2), Blocks.FIRE.getDefaultState().withProperty(BlockFire.AGE, 0));
                }
            }
        }

        // Output nigari
        this.outputNigari();
    }

    updateCauldronStatus();
    if (isDirty) markDirty();
}
 
Example 15
Source File: BW_TileEntity_HeatedWaterPump.java    From bartworks with MIT License 4 votes vote down vote up
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
    return TileEntityFurnace.getItemBurnTime(p_94041_2_) > 0 && p_94041_1_ == BW_TileEntity_HeatedWaterPump.FUELSLOT;
}
 
Example 16
Source File: BW_TileEntity_HeatedWaterPump.java    From bartworks with MIT License 4 votes vote down vote up
@Override
public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) {
    return TileEntityFurnace.getItemBurnTime(p_102007_2_) > 0;
}
 
Example 17
Source File: BurnTimeMetaProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Object getMeta(Item target, ItemStack stack) {
	int time = TileEntityFurnace.getItemBurnTime(stack);
	return time > 0? time : null;
}
 
Example 18
Source File: BurnTimeMetaProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public boolean canApply(Item target, ItemStack stack) {
	return TileEntityFurnace.getItemBurnTime(stack) > 0;
}
 
Example 19
Source File: BW_FuelSlot.java    From bartworks with MIT License 4 votes vote down vote up
@Override
public boolean isItemValid(ItemStack itemStack) {
    return TileEntityFurnace.getItemBurnTime(itemStack) > 0;
}