-
-
Notifications
You must be signed in to change notification settings - Fork 113
Added Dried Ghast Hydration Level #2779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
32b2b3f
d81e4c1
89f869b
47f5d16
e7296e7
cc95035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,10 +9,7 @@ | |
| import org.bukkit.block.data.BlockData; | ||
| import org.bukkit.block.data.Brushable; | ||
| import org.bukkit.block.data.Levelled; | ||
| import org.bukkit.block.data.type.Beehive; | ||
| import org.bukkit.block.data.type.Cake; | ||
| import org.bukkit.block.data.type.Farmland; | ||
| import org.bukkit.block.data.type.Snow; | ||
| import org.bukkit.block.data.type.*; | ||
|
|
||
| public class MaterialLevel extends MaterialProperty<ElementTag> { | ||
|
|
||
|
|
@@ -32,6 +29,7 @@ public class MaterialLevel extends MaterialProperty<ElementTag> { | |
| // For farmland, this is the moisture level. | ||
| // For composters, this is the amount of compost. | ||
| // For brushable blocks (also referred to as "suspicious blocks"), this is the level of dusting. 1.20+ only. | ||
| // For dried ghasts, this is the level of hydration. 1.21+ only. | ||
| // See also <@link tag MaterialTag.maximum_level> and <@link tag MaterialTag.minimum_level>. | ||
| // --> | ||
|
|
||
|
|
@@ -42,12 +40,34 @@ public static boolean describes(MaterialTag material) { | |
| || data instanceof Snow | ||
| || data instanceof Farmland | ||
| || data instanceof Beehive | ||
| || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && data instanceof Brushable); | ||
| || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && data instanceof Brushable) | ||
| || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && data instanceof DriedGhast); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| return new ElementTag(getCurrent()); | ||
| if (getBlockData() instanceof Cake cake) { | ||
| return new ElementTag(cake.getBites()); | ||
| } | ||
| else if (getBlockData() instanceof Snow snow) { | ||
| return new ElementTag(snow.getLayers()); | ||
| } | ||
| else if (getBlockData() instanceof Beehive beehive) { | ||
| return new ElementTag(beehive.getHoneyLevel()); | ||
| } | ||
| else if (getBlockData() instanceof Farmland farmland) { | ||
| return new ElementTag(farmland.getMoisture()); | ||
| } | ||
| else if (getBlockData() instanceof Levelled levelled) { | ||
| return new ElementTag(levelled.getLevel()); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && getBlockData() instanceof Brushable brushable) { | ||
| return new ElementTag(brushable.getDusted()); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof DriedGhast driedGhast) { | ||
| return new ElementTag(driedGhast.getHydration()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -61,11 +81,31 @@ public void setPropertyValue(ElementTag value, Mechanism mechanism) { | |
| return; | ||
| } | ||
| int level = value.asInt(); | ||
| if (level < getMin() || level > getMax()) { | ||
| mechanism.echoError("Level value '" + level + "' is not valid. Must be between " + getMin() + " and " + getMax() + " for material '" + getBlockData().getMaterial().name() + "'."); | ||
| if (level < (getBlockData() instanceof Snow snow ? snow.getMinimumLayers() : 0) || level > getMax()) { | ||
| mechanism.echoError("Level value '" + level + "' is not valid. Must be between " + (getBlockData() instanceof Snow snow ? snow.getMinimumLayers() : 0) + " and " + getMax() + " for material '" + getBlockData().getMaterial().name() + "'."); | ||
|
||
| return; | ||
| } | ||
| setCurrent(level); | ||
| if (getBlockData() instanceof Cake cake) { | ||
| cake.setBites(level); | ||
| } | ||
| else if (getBlockData() instanceof Snow snow) { | ||
| snow.setLayers(level); | ||
| } | ||
| else if (getBlockData() instanceof Beehive beehive) { | ||
| beehive.setHoneyLevel(level); | ||
| } | ||
| else if (getBlockData() instanceof Farmland farmland) { | ||
| farmland.setMoisture(level); | ||
| } | ||
| else if (getBlockData() instanceof Levelled levelled) { | ||
| levelled.setLevel(level); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && getBlockData() instanceof Brushable brushable) { | ||
| brushable.setDusted(level); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof DriedGhast driedGhast) { | ||
| driedGhast.setHydration(level); | ||
| } | ||
| } | ||
|
|
||
| public static void register() { | ||
|
|
@@ -90,118 +130,34 @@ public static void register() { | |
| // This will return 0 for all valid materials aside from snow. | ||
| // --> | ||
| PropertyParser.registerStaticTag(MaterialLevel.class, ElementTag.class, "minimum_level", (attribute, material) -> { | ||
| return new ElementTag(material.getMin()); | ||
| return new ElementTag(material.getBlockData() instanceof Snow snow ? snow.getMinimumLayers() : 0); | ||
|
||
| }); | ||
|
|
||
| autoRegister("level", MaterialLevel.class, ElementTag.class, false); | ||
| } | ||
|
|
||
| public Levelled getLevelled() { | ||
| return (Levelled) getBlockData(); | ||
| } | ||
|
|
||
| public boolean isCake() { | ||
| return getBlockData() instanceof Cake; | ||
| } | ||
|
|
||
| public Cake getCake() { | ||
| return (Cake) getBlockData(); | ||
| } | ||
|
|
||
| public boolean isSnow() { | ||
| return getBlockData() instanceof Snow; | ||
| } | ||
|
|
||
| public Snow getSnow() { | ||
| return (Snow) getBlockData(); | ||
| } | ||
|
|
||
| public boolean isHive() { | ||
| return getBlockData() instanceof Beehive; | ||
| } | ||
|
|
||
| public Beehive getHive() { | ||
| return (Beehive) getBlockData(); | ||
| } | ||
|
|
||
| public boolean isFarmland() { | ||
| return getBlockData() instanceof Farmland; | ||
| } | ||
|
|
||
| public Farmland getFarmland() { | ||
| return (Farmland) getBlockData(); | ||
| } | ||
|
|
||
| public boolean isBrushable() { | ||
| return NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && getBlockData() instanceof Brushable; | ||
| } | ||
|
|
||
| public int getCurrent() { | ||
| if (isCake()) { | ||
| return getCake().getBites(); | ||
| } | ||
| else if (isSnow()) { | ||
| return getSnow().getLayers(); | ||
| } | ||
| else if (isHive()) { | ||
| return getHive().getHoneyLevel(); | ||
| } | ||
| else if (isFarmland()) { | ||
| return getFarmland().getMoisture(); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && isBrushable()) { | ||
| return ((Brushable) getBlockData()).getDusted(); | ||
| } | ||
| return getLevelled().getLevel(); | ||
| } | ||
|
|
||
| public int getMax() { | ||
| if (isCake()) { | ||
| return getCake().getMaximumBites(); | ||
| if (getBlockData() instanceof Cake cake) { | ||
| return cake.getMaximumBites(); | ||
| } | ||
| else if (isSnow()) { | ||
| return getSnow().getMaximumLayers(); | ||
| else if (getBlockData() instanceof Snow snow) { | ||
| return snow.getMaximumLayers(); | ||
| } | ||
| else if (isHive()) { | ||
| return getHive().getMaximumHoneyLevel(); | ||
| else if (getBlockData() instanceof Beehive beehive) { | ||
| return beehive.getMaximumHoneyLevel(); | ||
| } | ||
| else if (isFarmland()) { | ||
| return getFarmland().getMaximumMoisture(); | ||
| else if (getBlockData() instanceof Farmland farmland) { | ||
| return farmland.getMaximumMoisture(); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && isBrushable()) { | ||
| return ((Brushable) getBlockData()).getMaximumDusted(); | ||
| else if (getBlockData() instanceof Levelled levelled) { | ||
| return levelled.getMaximumLevel(); | ||
| } | ||
| return getLevelled().getMaximumLevel(); | ||
| } | ||
|
|
||
| public int getMin() { | ||
| if (isSnow()) { | ||
| return getSnow().getMinimumLayers(); | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && getBlockData() instanceof Brushable brushable) { | ||
| return brushable.getMaximumDusted(); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| public void setCurrent(int level) { | ||
| if (isCake()) { | ||
| getCake().setBites(level); | ||
| return; | ||
| } | ||
| else if (isSnow()) { | ||
| getSnow().setLayers(level); | ||
| return; | ||
| } | ||
| else if (isHive()) { | ||
| getHive().setHoneyLevel(level); | ||
| return; | ||
| } | ||
| else if (isFarmland()) { | ||
| getFarmland().setMoisture(level); | ||
| return; | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20) && isBrushable()) { | ||
| ((Brushable) getBlockData()).setDusted(level); | ||
| return; | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof DriedGhast driedGhast) { | ||
| return driedGhast.getMaximumHydration(); | ||
| } | ||
| getLevelled().setLevel(level); | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to use
getMinas well I believe?