Skip to content

Commit

Permalink
Add brew glint #617
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsinco committed Apr 5, 2024
1 parent 66c8201 commit 3f51fe2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
2 changes: 2 additions & 0 deletions resources/config/v13/en/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ cauldron:
# Specific Commands for quality possible, using + bad, ++ normal, +++ good, added to the front of the line.
# drinkmessage: Chat-message to the Player when drinking the Brew
# drinktitle: Title on Screen to the Player when drinking the Brew
# glint: Boolean if the item should have a glint (enchant glint)
# customModelData: Custom Model Data Tag. This is a number that can be used to add custom textures to the item.
# Can specify one for all, or one for each quality, separated by /
# effects: List of effect/level/duration Special potion-effect when drinking, duration in sek.
Expand Down Expand Up @@ -478,6 +479,7 @@ recipes:
- homes
drinkmessage: Tastes good
drinktitle: Warms you from inside
glint: true
customModelData: 556/557/557
effects:
- FIRE_RESISTANCE/20
Expand Down
6 changes: 6 additions & 0 deletions src/com/dre/brewery/BIngredients.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.dre.brewery.recipe.PotionColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -133,6 +135,10 @@ public ItemStack cook(int state, String brewer) {
cookRecipe.getColor().colorBrew(potionMeta, potion, false);
brew.updateCustomModelData(potionMeta);

if (cookRecipe.hasGlint()) {
potionMeta.addEnchant(Enchantment.LUCK, 1, true);
potionMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
} else {
// new base potion
brew = new Brew(this);
Expand Down
19 changes: 19 additions & 0 deletions src/com/dre/brewery/Brew.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import com.dre.brewery.utility.BUtil;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
Expand Down Expand Up @@ -53,6 +55,7 @@ public class Brew implements Cloneable {
private boolean stripped; // Most Brewing information removed, only drinking and rough quality information available. Brew should not change anymore
private int lastUpdate; // last update in hours after install time
private boolean needsSave; // There was a change that has not yet been saved
private boolean hasGlint; // The Brew has a glint effect

/**
* A new Brew with only ingredients
Expand Down Expand Up @@ -572,6 +575,10 @@ public boolean needsSave() {
return needsSave;
}

public boolean hasGlint() {
return hasGlint;
}

public void setNeedsSave(boolean needsSave) {
this.needsSave = needsSave;
}
Expand Down Expand Up @@ -708,6 +715,11 @@ public void age(ItemStack item, float time, byte woodType) {
lore.addOrReplaceEffects(getEffects(), quality);
potionMeta.setDisplayName(BreweryPlugin.getInstance().color("&f" + recipe.getName(quality)));
recipe.getColor().colorBrew(potionMeta, item, canDistill());

if (recipe.hasGlint()) {
potionMeta.addEnchant(Enchantment.LUCK, 1, true);
potionMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
} else {
quality = 0;
lore.convertLore(false);
Expand Down Expand Up @@ -804,6 +816,13 @@ public ItemStack createItem(@Nullable BRecipe recipe, boolean event) {

recipe.getColor().colorBrew(potionMeta, potion, false);
updateCustomModelData(potionMeta);


if (recipe.hasGlint()) {
potionMeta.addEnchant(Enchantment.LUCK, 1, true);
potionMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}

potionMeta.setDisplayName(BreweryPlugin.getInstance().color("&f" + recipe.getName(quality)));
//if (!P.use1_14) {
// Before 1.14 the effects duration would strangely be only a quarter of what we tell it to be
Expand Down
37 changes: 25 additions & 12 deletions src/com/dre/brewery/recipe/BRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class BRecipe {
private @Nullable List<Tuple<Integer, String>> servercmds; // Commands executed as the server when drinking
private String drinkMsg; // Message when drinking
private String drinkTitle; // Title to show when drinking
private boolean glint; // If the potion should have a glint effect

private BRecipe() {
}
Expand Down Expand Up @@ -101,7 +102,7 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri
BreweryPlugin.getInstance().errorLog(recipeId + ": Recipe Name missing or invalid!");
return null;
}
if (recipe.getRecipeName() == null || recipe.getRecipeName().length() < 1) {
if (recipe.getRecipeName() == null || recipe.getRecipeName().isEmpty()) {
BreweryPlugin.getInstance().errorLog(recipeId + ": Recipe Name invalid");
return null;
}
Expand Down Expand Up @@ -138,6 +139,8 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri

recipe.drinkMsg = BreweryPlugin.getInstance().color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinkmessage"));
recipe.drinkTitle = BreweryPlugin.getInstance().color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinktitle"));
recipe.glint = configSectionRecipes.getBoolean(recipeId + ".glint", false);

if (configSectionRecipes.isString(recipeId + ".customModelData")) {
String[] cmdParts = configSectionRecipes.getString(recipeId + ".customModelData", "").split("/");
if (cmdParts.length == 3) {
Expand All @@ -157,17 +160,15 @@ public static BRecipe fromConfig(ConfigurationSection configSectionRecipes, Stri
}

List<String> effectStringList = configSectionRecipes.getStringList(recipeId + ".effects");
if (effectStringList != null) {
for (String effectString : effectStringList) {
BEffect effect = new BEffect(effectString);
if (effect.isValid()) {
recipe.effects.add(effect);
} else {
BreweryPlugin.getInstance().errorLog("Error adding Effect to Recipe: " + recipe.getRecipeName());
}
}
}
return recipe;
for (String effectString : effectStringList) {
BEffect effect = new BEffect(effectString);
if (effect.isValid()) {
recipe.effects.add(effect);
} else {
BreweryPlugin.getInstance().errorLog("Error adding Effect to Recipe: " + recipe.getRecipeName());
}
}
return recipe;
}

public static List<RecipeItem> loadIngredients(ConfigurationSection cfg, String recipeId) {
Expand Down Expand Up @@ -660,6 +661,10 @@ public String getDrinkTitle() {
return drinkTitle;
}

public boolean hasGlint() {
return glint;
}

public List<BEffect> getEffects() {
return effects;
}
Expand Down Expand Up @@ -945,6 +950,14 @@ public Builder drinkTitle(String title) {
return this;
}

/**
* Add a Glint to the Potion
*/
public Builder glint(boolean glint) {
recipe.glint = glint;
return this;
}

/**
* Set the Optional ID of this recipe
*/
Expand Down

0 comments on commit 3f51fe2

Please sign in to comment.