Internet Explorer is not supported. Please upgrade to a more modern browser.
Hi!
This is the third devlog! In this thread I will talk about our crafting system and how it has been improved.
Introduction
I didn't plan on writing a devlog about our crafting system, however many people have complained about it in the past, many things have been improved just now and the mechanics behind it are actually quite interesting.
Crafting System
As you probably could've guessed, our crafting system is completely custom. We don't rely on the vanilla crafting table and it's abilities and all recipes are self-made.
Why don't we use the vanilla crafting system? Minecraft is a little bit weird when it comes to crafting. Can you think of a vanilla recipe that requires more than just one single item on a slot? Like there is no recipe that requires putting multiple of the same item on a single slot to craft an item. And plugins don't allow us to do that either!
There are ways of creating custom recipes, however you cannot make it so players must put more than one item in a slot - and this would become an issue in terms of item cost and recipe possibilities.
Therefore we haven't had any other choice but making our own crafting system!
Our custom crafting system is made out of 5 core parts.
All of these systems must work without any flaws, otherwise it may lead into you being able to dupe items while crafting!
Registered Recipes
As already mentioned, our custom recipes are registered in seperate objects containing all the data required for crafting and displaying the recipe.
This is what a recipe looks like:
EXOTIC_AXE(new RecipeItemStack[]{item1, item2, item3,
item4, item5, item6,
item7, item8, item9},
false, new RecipeLock(RecipeTypes.EXOTIC_AXE, -1), true, Items.EXOTIC_AXE, 1),
Item1-9 are sets of data containing the item, the amount and if it should have the modifier priority or not. They may also be "null" in case an empty slot should be in that recipe.
The bottom row contains data such as if the recipe should be unlocked by default, if not what the requirement should be, if the item should receive a modifier update when being crafted (only necessary for items that may actually have modifiers), what item the output item should be and how many of them you receive.
Pretty simple right?
Inventory and Item Updater
The inventory updater doesn't do anything special.
As already said it iterates through all registered recipes and compares them with the 9 slots of your current crafting gui. If it found a matching recipe it creates an output item using the item updater, adds some additional data to it and repeats the entire process.
The Item Updater receives the default output item (without anything on it) and then applies all modifiers of either the item with the modifier priority on it or the first item in the crafting grid.
If - for whatever reason! - there isn't an item in the grid, it just returns the default item.
This is what the updater basically looks like:
private ItemStack updateModifiers(ItemStack outputItem, CraftingRecipes recipe, Inventory inventory){
int[] slots = new int[]{10, 11, 12, 19, 20, 21, 28, 29, 30};
for(int i = 1; i 9; i++){
if(recipe.getItemOnSlot(i).isHighestModifierPriorityOnCraft()){
return new ItemUtils().createItemByOriginal(inventory.getItem(slots[i-1]), outputItem);
}
}
for(int slot : slots) {
if(inventory.getItem(slot) != null && inventory.getItem(slot).getType() != Material.AIR){
return new ItemUtils().createItemByOriginal(inventory.getItem(slot), outputItem);
}
}
return outputItem;
}
Crafting Listener
The Crafting Listener is probably one of the most important systems. Not only does it allow you to actually craft items, but it also blocks any kinds of item dupes regarding crafting.
It checks the type of inventory click you're performing (e.g. leftclick, rightclick, shiftclick), it checks what item you have on your cursor, it checks clicked slots and it checks other inventory actions such as if you're trying to collect items to your cursor (basically when you double click with an item on your cursor and it merges all identical items of the entire inventory with the ones on your cursor).
Upon crafting an item it checks wether you shift-clicked or not, then removes all unnecessary data from the output item and either gives you one set of items or as many as you may craft.
After that it simply just removes the used items from the crafting grid and that's it!
Improvements
So as you could probably guess, if there's one thing that goes wrong, this entire system may lead into massive issues with dupes or performance. However I have made some improvements to it!
Over the past few months, one of STN's biggest flaws was probably the crafting system. You could only craft one set of items at a time, then you'd have to wait for like .5 seconds, then you can craft another set. I've received a lot of feedback, what I could add in addition to make crafting less painful and how this system needs a change and here are the changes:
Conclusion
The crafting system may look simple for you guys but in reality it isn't! In fact this might be one of STN's most complex systems as basically nothing relies on the default minecraft crafting mechanics!
The crafting system is still not 100% done just yet, however it's looking promising!
Systems that must still be reworked
This is more like a checklist with systems that will probably receive their own devlog once they're done.