Implemented Custom Model Data

issue #246
This commit is contained in:
Sn0wStorm
2020-04-12 22:21:17 +02:00
parent ef868fc7eb
commit 8f7696cdb5
14 changed files with 172 additions and 19 deletions
+4
View File
@@ -130,6 +130,7 @@ public class BIngredients {
cookedName = cookRecipe.getName(quality);
cookRecipe.getColor().colorBrew(potionMeta, potion, false);
brew.updateCustomModelData(potionMeta);
} else {
// new base potion
@@ -149,6 +150,9 @@ public class BIngredients {
lore.write();
}
cauldronRecipe.getColor().colorBrew(potionMeta, potion, true);
if (P.use1_14 && cauldronRecipe.getCmData() != 0) {
potionMeta.setCustomModelData(cauldronRecipe.getCmData());
}
}
}
}
+24
View File
@@ -409,6 +409,27 @@ public class Brew implements Cloneable {
}
}
public void updateCustomModelData(ItemMeta meta) {
if (!P.use1_14) return;
if (currentRecipe != null && currentRecipe.getCmData() != null) {
int cm;
if (quality > 7) {
cm = currentRecipe.getCmData()[2];
} else if (quality > 3) {
cm = currentRecipe.getCmData()[1];
} else {
cm = currentRecipe.getCmData()[0];
}
if (cm == 0) {
meta.setCustomModelData(null);
} else {
meta.setCustomModelData(cm);
}
} else {
meta.setCustomModelData(null);
}
}
/**
* Get Special Drink Effects
*/
@@ -621,6 +642,7 @@ public class Brew implements Cloneable {
PotionColor.GREY.colorBrew(potionMeta, slotItem, canDistill());
}
alc = calcAlcohol();
updateCustomModelData(potionMeta);
// Distill Lore
if (currentRecipe != null && BConfig.colorInBrewer != BrewLore.hasColorLore(potionMeta)) {
@@ -695,6 +717,7 @@ public class Brew implements Cloneable {
}
}
alc = calcAlcohol();
updateCustomModelData(potionMeta);
// Lore
if (currentRecipe != null && BConfig.colorInBarrels != BrewLore.hasColorLore(potionMeta)) {
@@ -779,6 +802,7 @@ public class Brew implements Cloneable {
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
recipe.getColor().colorBrew(potionMeta, potion, false);
updateCustomModelData(potionMeta);
potionMeta.setDisplayName(P.p.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
+2 -1
View File
@@ -58,7 +58,7 @@ public class BConfig {
// Barrel
public static boolean openEverywhere;
public static boolean loadDataAsync = true;
public static boolean loadDataAsync;
// Cauldron
public static boolean useOffhandForCauldron;
@@ -242,6 +242,7 @@ public class BConfig {
openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
MCBarrel.maxBrews = config.getInt("maxBrewsInMCBarrels", 6);
useOffhandForCauldron = config.getBoolean("useOffhandForCauldron", false);
loadDataAsync = config.getBoolean("loadDataAsync", true);
Brew.loadSeed(config, new File(P.p.getDataFolder(), "config.yml"));
@@ -31,6 +31,7 @@ public class BCauldronRecipe {
//private List<String> particles
private PotionColor color;
private List<String> lore;
private int cmData; // Custom Model Data
private boolean saveInData; // If this recipe should be saved in data and loaded again when the server restarts. Applicable to non-config recipes
@@ -83,6 +84,8 @@ public class BCauldronRecipe {
recipe.lore = lore.stream().map(Tuple::second).collect(Collectors.toList());
}
recipe.cmData = cfg.getInt(id + ".customModelData", 0);
return recipe;
}
@@ -131,6 +134,13 @@ public class BCauldronRecipe {
this.lore = lore;
}
/**
* Get the Custom Model Data
*/
public int getCmData() {
return cmData;
}
public void setSaveInData(boolean saveInData) {
this.saveInData = saveInData;
}
+33
View File
@@ -45,6 +45,7 @@ public class BRecipe {
private PotionColor color; // color of the distilled/finished potion
private int alcohol; // Alcohol in perfect potion
private List<Tuple<Integer, String>> lore; // Custom Lore on the Potion. The int is for Quality Lore, 0 = any, 1,2,3 = Bad,Middle,Good
private int[] cmData; // Custom Model Data[3] for each quality
// drinking
private List<BEffect> effects = new ArrayList<>(); // Special Effects when drinking
@@ -150,6 +151,23 @@ public class BRecipe {
recipe.drinkMsg = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinkmessage"));
recipe.drinkTitle = P.p.color(BUtil.loadCfgString(configSectionRecipes, recipeId + ".drinktitle"));
if (configSectionRecipes.isString(recipeId + ".customModelData")) {
String[] cmdParts = configSectionRecipes.getString(recipeId + ".customModelData", "").split("/");
if (cmdParts.length == 3) {
recipe.cmData = new int[]{P.p.parseInt(cmdParts[0]), P.p.parseInt(cmdParts[1]), P.p.parseInt(cmdParts[2])};
if (recipe.cmData[0] == 0 && recipe.cmData[1] == 0 && recipe.cmData[2] == 0) {
P.p.errorLog("Invalid customModelData in Recipe: " + recipe.getRecipeName());
recipe.cmData = null;
}
} else {
P.p.errorLog("Invalid customModelData in Recipe: " + recipe.getRecipeName());
}
} else {
int cmd = configSectionRecipes.getInt(recipeId + ".customModelData", 0);
if (cmd != 0) {
recipe.cmData = new int[]{cmd, cmd, cmd};
}
}
List<String> effectStringList = configSectionRecipes.getStringList(recipeId + ".effects");
if (effectStringList != null) {
@@ -628,6 +646,13 @@ public class BRecipe {
return list;
}
/**
* Get the Custom Model Data array for bad, normal, good quality
*/
public int[] getCmData() {
return cmData;
}
public List<String> getPlayercmds() {
return playercmds;
}
@@ -889,6 +914,14 @@ public class BRecipe {
return this;
}
/**
* Add Custom Model Data for each Quality
*/
public Builder addCustomModelData(int bad, int normal, int good) {
recipe.cmData = new int[] {bad, normal, good};
return this;
}
public Builder addEffects(BEffect... effects) {
Collections.addAll(recipe.effects, effects);
return this;