Skip to content

Commit

Permalink
Material properties - acikek's part (#2295)
Browse files Browse the repository at this point in the history
* cave vines berries in `type`

* farmland in `level`

* hopper in `switched`

* remove scaffolding - aya did that

* revert getDripstone

* formatting and newlines

* nms version check for cave vines

* more special handling for cave vines
  • Loading branch information
acikek committed Jan 19, 2022
1 parent 4ef5985 commit fc357ea
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
Expand Up @@ -11,10 +11,7 @@
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Campfire;
import org.bukkit.block.data.type.PointedDripstone;
import org.bukkit.block.data.type.Slab;
import org.bukkit.block.data.type.TechnicalPiston;
import org.bukkit.block.data.type.*;

public class MaterialBlockType implements Property {

Expand All @@ -30,7 +27,8 @@ public static boolean describes(ObjectTag material) {
return data instanceof Slab
|| data instanceof TechnicalPiston
|| data instanceof Campfire
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && data instanceof PointedDripstone);
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && data instanceof PointedDripstone)
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && data instanceof CaveVinesPlant);
}

public static MaterialBlockType getFrom(ObjectTag _material) {
Expand Down Expand Up @@ -65,6 +63,7 @@ public static void registerTags() {
// For piston_heads, output is NORMAL or STICKY.
// For campfires, output is NORMAL or SIGNAL.
// For pointed dripstone, output is BASE, FRUSTUM, MIDDLE, TIP, or TIP_MERGE.
// For cave vines, output is NORMAL or BERRIES.
// -->
PropertyParser.<MaterialBlockType, ElementTag>registerStaticTag(ElementTag.class, "type", (attribute, material) -> {
return new ElementTag(material.getPropertyString());
Expand All @@ -87,6 +86,10 @@ public boolean isDripstone() {
return NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && material.getModernData() instanceof PointedDripstone;
}

public boolean isCaveVines() {
return NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && material.getModernData() instanceof CaveVinesPlant;
}

public Slab getSlab() {
return (Slab) material.getModernData();
}
Expand All @@ -103,6 +106,10 @@ public Campfire getCampfire() {
return (PointedDripstone) material.getModernData();
}*/

/*public CaveVinesPlant getCaveVines() { // TODO: 1.17
return (CaveVinesPlant) material.getModernData();
}*/

@Override
public String getPropertyString() {
if (isSlab()) {
Expand All @@ -117,6 +124,9 @@ else if (isPistonHead()) {
else if (isDripstone()) {
return ((PointedDripstone) material.getModernData()).getThickness().name(); // TODO: 1.17
}
else if (isCaveVines()) {
return ((CaveVinesPlant) material.getModernData()).isBerries() ? "BERRIES" : "NORMAL"; // TODO: 1.17
}
return null; // Unreachable.
}

Expand All @@ -138,6 +148,7 @@ public void adjust(Mechanism mechanism) {
// For piston_heads, input is NORMAL or STICKY.
// For campfires, input is NORMAL or SIGNAL.
// For pointed dripstone, input is BASE, FRUSTUM, MIDDLE, TIP, or TIP_MERGE.
// For cave vines, input is NORMAL or BERRIES.
// @tags
// <MaterialTag.type>
// -->
Expand All @@ -151,7 +162,7 @@ else if (isCampfire()) {
else if (isPistonHead() && mechanism.requireEnum(false, TechnicalPiston.Type.values())) {
getPistonHead().setType(TechnicalPiston.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else {
else if (isDripstone() || isCaveVines()) {
MultiVersionHelper1_17.materialBlockTypeRunMech(mechanism, this);
}
}
Expand Down
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.type.Cake;
import org.bukkit.block.data.type.Beehive;
import org.bukkit.block.data.type.Farmland;
import org.bukkit.block.data.type.Snow;

public class MaterialLevel implements Property {
Expand All @@ -21,6 +22,7 @@ public static boolean describes(ObjectTag material) {
&& (((MaterialTag) material).getModernData() instanceof Levelled
|| ((MaterialTag) material).getModernData() instanceof Cake
|| ((MaterialTag) material).getModernData() instanceof Snow
|| ((MaterialTag) material).getModernData() instanceof Farmland
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_15) && ((MaterialTag) material).getModernData() instanceof Beehive));
}

Expand Down Expand Up @@ -50,7 +52,7 @@ public static void registerTags() {
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the maximum level for a Levelled material (like water, lava, and cauldrons), cake, beehives, and snow.
// Returns the maximum level for a Levelled material (like water, lava, and cauldrons), cake, beehives, snow, and farmland.
// -->
PropertyParser.<MaterialLevel, ElementTag>registerStaticTag(ElementTag.class, "maximum_level", (attribute, material) -> {
return new ElementTag(material.getMax());
Expand All @@ -61,7 +63,7 @@ public static void registerTags() {
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the minimum level for a Levelled material (like water, lava, and cauldrons), cake, beehives, and snow.
// Returns the minimum level for a Levelled material (like water, lava, and cauldrons), cake, beehives, snow, and farmland.
// This will return 0 for all valid materials aside from snow.
// -->
PropertyParser.<MaterialLevel, ElementTag>registerStaticTag(ElementTag.class, "minimum_level", (attribute, material) -> {
Expand All @@ -74,7 +76,7 @@ public static void registerTags() {
// @mechanism MaterialTag.level
// @group properties
// @description
// Returns the current level for a Levelled material (like water, lava, and cauldrons), cake, beehives, and snow.
// Returns the current level for a Levelled material (like water, lava, and cauldrons), cake, beehives, snow, and farmland.
// -->
PropertyParser.<MaterialLevel, ElementTag>registerStaticTag(ElementTag.class, "level", (attribute, material) -> {
return new ElementTag(material.getCurrent());
Expand Down Expand Up @@ -117,6 +119,14 @@ public void setHoneyLevel(int level) {
((Beehive) material.getModernData()).setHoneyLevel(level);
}

public boolean isFarmland() {
return material.getModernData() instanceof Farmland;
}

public Farmland getFarmland() {
return (Farmland) material.getModernData();
}

public int getCurrent() {
if (isCake()) {
return getCake().getBites();
Expand All @@ -127,6 +137,9 @@ else if (isSnow()) {
else if (isHive()) {
return getHoneyLevel();
}
else if (isFarmland()) {
return getFarmland().getMoisture();
}
return getLevelled().getLevel();
}

Expand All @@ -140,6 +153,9 @@ else if (isSnow()) {
else if (isHive()) {
return getMaxHoneyLevel();
}
else if (isFarmland()) {
return getFarmland().getMaximumMoisture();
}
return getLevelled().getMaximumLevel();
}

Expand All @@ -163,6 +179,10 @@ else if (isHive()) {
setHoneyLevel(level);
return;
}
else if (isFarmland()) {
getFarmland().setMoisture(level);
return;
}
getLevelled().setLevel(level);
}

Expand All @@ -184,7 +204,7 @@ public void adjust(Mechanism mechanism) {
// @name level
// @input ElementTag(Number)
// @description
// Sets the current level for a Levelled material (like water, lava, and cauldrons), cake, beehives, and snow.
// Sets the current level for a Levelled material (like water, lava, and cauldrons), cake, beehives, snow, and farmland.
// @tags
// <MaterialTag.level>
// <MaterialTag.maximum_level>
Expand Down
Expand Up @@ -10,10 +10,7 @@
import org.bukkit.block.data.Lightable;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.type.DaylightDetector;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.block.data.type.Piston;
import org.bukkit.block.data.type.EndPortalFrame;
import org.bukkit.block.data.type.*;

public class MaterialSwitchable implements Property {

Expand All @@ -32,7 +29,8 @@ public static boolean describes(ObjectTag material) {
|| data instanceof DaylightDetector
|| data instanceof Piston
|| data instanceof Lightable
|| data instanceof EndPortalFrame;
|| data instanceof EndPortalFrame
|| data instanceof Hopper;
}

public static MaterialSwitchable getFrom(ObjectTag _material) {
Expand Down Expand Up @@ -72,6 +70,7 @@ public static void registerTags() {
// - a lightable block is lit
// - a piston block is extended
// - an end portal frame has an ender eye in it
// - a hopper is NOT being powered by redstone
// -->
PropertyParser.<MaterialSwitchable, ElementTag>registerStaticTag(ElementTag.class, "switched", (attribute, material) -> {
return new ElementTag(material.getState());
Expand Down Expand Up @@ -110,6 +109,10 @@ public boolean isEndFrame() {
return material.getModernData() instanceof EndPortalFrame;
}

public boolean isHopper() {
return material.getModernData() instanceof Hopper;
}

public Openable getOpenable() {
return (Openable) material.getModernData();
}
Expand All @@ -134,6 +137,10 @@ public EndPortalFrame getEndFrame() {
return (EndPortalFrame) material.getModernData();
}

public Hopper getHopper() {
return (Hopper) material.getModernData();
}

public boolean getState() {
if (isOpenable()) {
return getOpenable().isOpen();
Expand All @@ -156,6 +163,9 @@ else if (isPiston()) {
else if (isEndFrame()) {
return getEndFrame().hasEye();
}
else if (isHopper()) {
return getHopper().isEnabled();
}
return false; // Unreachable
}

Expand All @@ -181,6 +191,9 @@ else if (isPiston()) {
else if (isEndFrame()) {
getEndFrame().setEye(state);
}
else if (isHopper()) {
getHopper().setEnabled(state);
}
}

@Override
Expand Down
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.block.data.type.CaveVinesPlant;
import org.bukkit.block.data.type.PointedDripstone;
import org.bukkit.entity.Axolotl;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -53,5 +54,8 @@ public static void materialBlockTypeRunMech(Mechanism mechanism, MaterialBlockTy
if (object.isDripstone() && mechanism.requireEnum(false, PointedDripstone.Thickness.values())) {
((PointedDripstone) object.material.getModernData()).setThickness(PointedDripstone.Thickness.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (object.isCaveVines()) {
((CaveVinesPlant) object.material.getModernData()).setBerries(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "berries"));
}
}
}

0 comments on commit fc357ea

Please sign in to comment.