Added output-item and silent-craft options for crafting station recipes.

Examples (Under the options: tab in a recipe.):
output-item: false > This makes it so only the triggers activate for an item craft, still requires an item under the output tab to display as an icon.
silent-craft: true > Whenever a craft is completed it will not make a noise to the player, good for the sound trigger.
This commit is contained in:
Ethan 2020-07-30 00:01:53 -04:00
parent a963dde0a0
commit e1817e8863
2 changed files with 26 additions and 6 deletions

View File

@ -17,6 +17,8 @@ import net.mmogroup.mmolib.api.util.SmartGive;
public class CraftingRecipe extends Recipe {
private final ConfigMMOItem output;
private final ConfigurationSection config;
/*
* there can't be any crafting time for upgrading recipes since there is no
* way to save an MMOItem in the config file TODO save as ItemStack
@ -25,6 +27,7 @@ public class CraftingRecipe extends Recipe {
public CraftingRecipe(ConfigurationSection config) {
super(config);
this.config = config;
craftingTime = config.getDouble("crafting-time");
@ -42,6 +45,18 @@ public class CraftingRecipe extends Recipe {
return craftingTime <= 0;
}
/*
* this determines whether or not to give an item whenever an item is crafted
* yaml format is 'output-item: false' under options
*/
public boolean isItemRecipe() {
return config.getConfigurationSection("options").getBoolean("output-item", true);
}
public boolean isSilent() {
return config.getConfigurationSection("options").getBoolean("silent-craft", false);
}
public ConfigMMOItem getOutput() {
return output;
}
@ -53,9 +68,11 @@ public class CraftingRecipe extends Recipe {
* directly add the ingredients to the player inventory
*/
if (isInstant()) {
new SmartGive(data.getPlayer()).give(getOutput().generate());
if (isItemRecipe())
new SmartGive(data.getPlayer()).give(getOutput().generate());
recipe.getRecipe().getTriggers().forEach(trigger -> trigger.whenCrafting(data));
if (!isSilent())
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
/*
* if recipe not instant, add item to crafting queue, either way
* RELOAD inventory data and reopen inventory!
@ -63,7 +80,8 @@ public class CraftingRecipe extends Recipe {
} else
data.getCrafting().getQueue(station).add(this);
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
if (!isInstant())
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
}
@Override

View File

@ -178,8 +178,6 @@ public class CraftingStationView extends PluginInventory {
if (!(tag = item.getString("queueId")).equals("")) {
UUID uuid = UUID.fromString(tag);
CraftingInfo craft = data.getCrafting().getQueue(station).getCraft(uuid);
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
data.getCrafting().getQueue(station).remove(craft);
if (craft.isReady()) {
@ -187,8 +185,12 @@ public class CraftingStationView extends PluginInventory {
recipe.getTriggers().forEach(trigger -> trigger.whenCrafting(data));
ItemStack craftedItem = recipe.getOutput().generate();
CustomSoundListener.stationCrafting(craftedItem, data.getPlayer());
new SmartGive(data.getPlayer()).give(craftedItem);
if (!recipe.isSilent())
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
if (recipe.isItemRecipe())
new SmartGive(data.getPlayer()).give(craftedItem);
} else
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
for (Ingredient ingredient : craft.getRecipe().getIngredients())
new SmartGive(data.getPlayer()).give(ingredient.generateItemStack());