Skip to content

Commit

Permalink
add potion color, fixes #1760
Browse files Browse the repository at this point in the history
1.12 only for the moment, version lock can be lowered if older versions are confirmed to support it
  • Loading branch information
mcmonkey4eva committed Jun 28, 2018
1 parent 5dcc6b9 commit 33f82ad
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public String getPropertyString() {
}
PotionMeta meta = (PotionMeta) item.getItemStack().getItemMeta();
dList effects = new dList();
effects.add(meta.getBasePotionData().getType() + "," + meta.getBasePotionData().isUpgraded() + "," + meta.getBasePotionData().isExtended());
effects.add(meta.getBasePotionData().getType()
+ "," + meta.getBasePotionData().isUpgraded()
+ "," + meta.getBasePotionData().isExtended()
+ (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && meta.hasColor() ? "," + new dColor(meta.getColor()).identify() : "")
);
for (PotionEffect pot : meta.getCustomEffects()) {
StringBuilder sb = new StringBuilder();
sb.append(pot.getType().getName()).append(",")
Expand Down Expand Up @@ -89,13 +93,14 @@ public String getAttribute(Attribute attribute) {
// @group properties
// @description
// Returns the potion effect on this item.
// In the format Effect,Level,Extended,Splash
// In the format Effect,Level,Extended,Splash,Color
// -->
if (attribute.startsWith("potion_base") && item.getItemStack().hasItemMeta() && item.getItemStack().getItemMeta() instanceof PotionMeta) {
PotionMeta meta = ((PotionMeta) item.getItemStack().getItemMeta());
return new Element(meta.getBasePotionData().getType().name() + "," + (meta.getBasePotionData().isUpgraded() ? 2 : 1)
+ "," + meta.getBasePotionData().isExtended() + "," + (item.getItemStack().getType() == Material.SPLASH_POTION))
.getAttribute(attribute.fulfill(1));
+ "," + meta.getBasePotionData().isExtended() + "," + (item.getItemStack().getType() == Material.SPLASH_POTION)
+ (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && meta.hasColor() ? "," + new dColor(meta.getColor()).identify() : "")
).getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand Down Expand Up @@ -272,7 +277,7 @@ public void adjust(Mechanism mechanism) {
// @input dList
// @description
// Sets the potion's potion effect(s).
// Input is a formed like: Effect,Upgraded,Extended|Type,Amplifier,Duration,Ambient,Particles(,Color)|...
// Input is a formed like: Effect,Upgraded,Extended(,Color)|Type,Amplifier,Duration,Ambient,Particles(,Color)|...
// For example: SPEED,true,false|SPEED,2,200,false,true,red
// @tags
// <i@item.potion_effect[<#>]>
Expand All @@ -290,6 +295,9 @@ public void adjust(Mechanism mechanism) {
meta.setBasePotionData(new PotionData(PotionType.valueOf(d1[0].toUpperCase()),
CoreUtilities.toLowerCase(d1[2]).equals("true"),
CoreUtilities.toLowerCase(d1[1]).equals("true")));
if (d1.length > 3) {
meta.setColor(dColor.valueOf(d1[3]).getColor());
}
meta.clearCustomEffects();
for (int i = 1; i < data.size(); i++) {
String[] d2 = data.get(i).split(",");
Expand Down

0 comments on commit 33f82ad

Please sign in to comment.