From edea97f9a2a39dcfd0c84b152257db3b6c9c8258 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 5 Mar 2019 20:55:52 +0100 Subject: [PATCH 1/2] Add RGB colored potions --- src/com/dre/brewery/BIngredients.java | 2 +- src/com/dre/brewery/BRecipe.java | 4 +- src/com/dre/brewery/Brew.java | 67 ++++++++++++++----- .../brewery/listeners/InventoryListener.java | 2 +- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index a1524d5..765439f 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -80,7 +80,7 @@ public class BIngredients { Brew.addOrReplaceEffects(potionMeta, brew.getEffects(), brew.getQuality()); cookedName = cookRecipe.getName(quality); - Brew.PotionColor.valueOf(cookRecipe.getColor()).colorBrew(potionMeta, potion, false); + Brew.PotionColor.fromString(cookRecipe.getColor()).colorBrew(potionMeta, potion, false); } else { // new base potion diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index 836acfd..b0e1984 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -146,7 +146,7 @@ public class BRecipe { return false; } try { - Brew.PotionColor.valueOf(getColor()); + Brew.PotionColor.fromString(getColor()); } catch (IllegalArgumentException e) { P.p.errorLog("Invalid Color '" + color + "' in Recipe: " + getName(5)); return false; @@ -263,7 +263,7 @@ public class BRecipe { Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true, 0); - Brew.PotionColor.valueOf(getColor()).colorBrew(potionMeta, potion, false); + Brew.PotionColor.fromString(getColor()).colorBrew(potionMeta, potion, false); potionMeta.setDisplayName(P.p.color("&f" + getName(quality))); // This effect stores the UID in its Duration potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true); diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 4bc312a..56fe7ee 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -315,9 +315,9 @@ public class Brew { this.stat = stat; if (currentRecipe != null && canDistill()) { if (stat) { - PotionColor.valueOf(currentRecipe.getColor()).colorBrew(((PotionMeta) potion.getItemMeta()), potion, false); + PotionColor.fromString(currentRecipe.getColor()).colorBrew(((PotionMeta) potion.getItemMeta()), potion, false); } else { - PotionColor.valueOf(currentRecipe.getColor()).colorBrew(((PotionMeta) potion.getItemMeta()), potion, true); + PotionColor.fromString(currentRecipe.getColor()).colorBrew(((PotionMeta) potion.getItemMeta()), potion, true); } } } @@ -354,7 +354,7 @@ public class Brew { addOrReplaceEffects(potionMeta, getEffects(), quality); potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); - PotionColor.valueOf(recipe.getColor()).colorBrew(potionMeta, slotItem, canDistill()); + PotionColor.fromString(recipe.getColor()).colorBrew(potionMeta, slotItem, canDistill()); } else { quality = 0; @@ -419,7 +419,7 @@ public class Brew { addOrReplaceEffects(potionMeta, getEffects(), quality); potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); - PotionColor.valueOf(recipe.getColor()).colorBrew(potionMeta, item, canDistill()); + PotionColor.fromString(recipe.getColor()).colorBrew(potionMeta, item, canDistill()); } else { quality = 0; removeEffects(potionMeta); @@ -684,19 +684,19 @@ public class Brew { } } - public enum PotionColor { - PINK(1, PotionType.REGEN, Color.FUCHSIA), - CYAN(2, PotionType.SPEED, Color.AQUA), - ORANGE(3, PotionType.FIRE_RESISTANCE, Color.ORANGE), - GREEN(4, PotionType.POISON, Color.GREEN), - BRIGHT_RED(5, PotionType.INSTANT_HEAL, Color.fromRGB(255,0,0)), - BLUE(6, PotionType.NIGHT_VISION, Color.NAVY), - BLACK(8, PotionType.WEAKNESS, Color.BLACK), - RED(9, PotionType.STRENGTH, Color.fromRGB(196,0,0)), - GREY(10, PotionType.SLOWNESS, Color.GRAY), - WATER(11, P.use1_9 ? PotionType.WATER_BREATHING : null, Color.BLUE), - DARK_RED(12, PotionType.INSTANT_DAMAGE, Color.fromRGB(128,0,0)), - BRIGHT_GREY(14, PotionType.INVISIBILITY, Color.SILVER); + public static class PotionColor { + public static final PotionColor PINK = new PotionColor(1, PotionType.REGEN, Color.FUCHSIA); + public static final PotionColor CYAN = new PotionColor(2, PotionType.SPEED, Color.AQUA); + public static final PotionColor ORANGE = new PotionColor(3, PotionType.FIRE_RESISTANCE, Color.ORANGE); + public static final PotionColor GREEN = new PotionColor(4, PotionType.POISON, Color.GREEN); + public static final PotionColor BRIGHT_RED = new PotionColor(5, PotionType.INSTANT_HEAL, Color.fromRGB(255,0,0)); + public static final PotionColor BLUE = new PotionColor(6, PotionType.NIGHT_VISION, Color.NAVY); + public static final PotionColor BLACK = new PotionColor(8, PotionType.WEAKNESS, Color.BLACK); + public static final PotionColor RED = new PotionColor(9, PotionType.STRENGTH, Color.fromRGB(196,0,0)); + public static final PotionColor GREY = new PotionColor(10, PotionType.SLOWNESS, Color.GRAY); + public static final PotionColor WATER = new PotionColor(11, P.use1_9 ? PotionType.WATER_BREATHING : null, Color.BLUE); + public static final PotionColor DARK_RED = new PotionColor(12, PotionType.INSTANT_DAMAGE, Color.fromRGB(128,0,0)); + public static final PotionColor BRIGHT_GREY = new PotionColor(14, PotionType.INVISIBILITY, Color.SILVER); private final int colorId; private final PotionType type; @@ -708,6 +708,12 @@ public class Brew { this.color = color; } + public PotionColor(Color color) { + colorId = -1; + type = null; + this.color = color; + } + // gets the Damage Value, that sets a color on the potion // offset +32 is not accepted by brewer, so not further destillable public short getColorId(boolean destillable) { @@ -739,6 +745,33 @@ public class Brew { } } + public static PotionColor fromString(String string) { + switch (string) { + case "PINK": return PINK; + case "CYAN": return CYAN; + case "ORANGE": return ORANGE; + case "GREEN": return GREEN; + case "BRIGHT_RED": return BRIGHT_RED; + case "BLUE": return BLUE; + case "BLACK": return BLACK; + case "RED": return RED; + case "GREY": return GREY; + case "WATER": return WATER; + case "DARK_RED": return DARK_RED; + case "BRIGHT_GREY": return BRIGHT_GREY; + default: + try{ + return new PotionColor(Color.fromRGB( + Integer.parseInt(string.substring( 1, 3 ), 16 ), + Integer.parseInt(string.substring( 3, 5 ), 16 ), + Integer.parseInt(string.substring( 5, 7 ), 16 ) + )); + } catch (Exception e) { + return WATER; + } + } + } + } } diff --git a/src/com/dre/brewery/listeners/InventoryListener.java b/src/com/dre/brewery/listeners/InventoryListener.java index 3a9a051..410f02b 100644 --- a/src/com/dre/brewery/listeners/InventoryListener.java +++ b/src/com/dre/brewery/listeners/InventoryListener.java @@ -277,7 +277,7 @@ public class InventoryListener implements Listener { BRecipe recipe = brew.getCurrentRecipe(); if (recipe != null) { Brew.removeEffects(potion); - Brew.PotionColor.valueOf(recipe.getColor()).colorBrew(potion, item, brew.canDistill()); + Brew.PotionColor.fromString(recipe.getColor()).colorBrew(potion, item, brew.canDistill()); item.setItemMeta(potion); } } From 314889be8992432cc022e160878b2293caa120f5 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 7 Mar 2019 18:41:45 +0100 Subject: [PATCH 2/2] Use dynamic placeholder potion type instead of null for custom potion colors --- src/com/dre/brewery/Brew.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 56fe7ee..83a9739 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -710,7 +710,7 @@ public class Brew { public PotionColor(Color color) { colorId = -1; - type = null; + type = WATER.getType(); this.color = color; }