Skip to content

Creating Furnaces

Shane Bee edited this page Apr 4, 2020 · 1 revision

Time to create some furnaces

There are two different methods for creating a furnace. You could simply create a new furnace object or use the provided methods in the furnace manager class to create a simple furnace.

Let's go over both methods.

Furnace Class Constructor

When creating a furnace object using the Furnace class's constructor, the furnace itself will not be registered to the server, saved to file, nor will it tick. This could be good if you simply want to manager how your furnaces are saved/ticked yourself.

Let's take a look at how we do this:

// Instantiate a new furnace object
Furnace furnace = new Furnace("My Furnace");

Yep, pretty simple. But keep in mind, this newly created furnace won't do a darn thing.

The furnace class has a build in serializer that will work with Bukkit's YAML system. So you can easily save/retrieve your furnaces from a YAML file.

To tick a furnace, simply use the furnace's tick method:

furnace.tick();

Furnace Manager

The furnace manager has a couple of methods for creating furnaces. When you create a new furnace via this method, it is automatically saved to file, and ticked automatically. The current furnaces will also save to file every 5 minutes to prevent loss of data.

Create an instance of the furnace manager

First we're going to want to get an instance of the FurnaceManager, just like we previously did with the recipe manager

// Let's create an instance of the FurnaceManager
private FurnaceManager furnaceManager;

@Override
public void onEnable() {
    this.virtualFurnaceAPI = new VirtualFurnaceAPI(this);

    // Now let's instantiate our furnace manager
    this.furnaceManager = virtualFurnaceAPI.getFurnaceManager();
}

Now that we have our furnace manager, let's look at both methods for creating a new furnace.

Simple Method

This method will simply create a new furnace, name it, add it to the server's VirtualFurnaceMap, save it to file, and start ticking it.
The name here will be the name see in the GUI of the furnace.

// Create a new furnace using the furnace manager's create method
Furnace furnace = furnaceManager.createFurnace("&3Virtual Furnace");

Consumer Method

The consumer method is basically the same, but it allows you to modify your furnace before it saves to file and starts ticking.
Like in the above method, we're going to create a new furnace, but this time we are going to use the consumer method and modify the new furnace's fuel and input items.

// Create a new furnace with a name and consumer function
Furnace furnace = furnaceManager.createFurnace("&3Virtual Furnace", furnace1 -> {
    // Set the furnace's fuel and input
    furnace1.setFuel(new ItemStack(Material.COAL, 64));
    furnace1.setInput(new ItemStack(Material.CHICKEN, 64));
});

Dinner has started :)

Clone this wiki locally