Skip to content

Commit

Permalink
Update switch_face to attachment_face and add bells (#2512)
Browse files Browse the repository at this point in the history
* Bell `attachment` mechanism beginnings

* It worked the whole time! I was using the wrong `adjust` command :P

Thanks for letting me know Aya.

* Add `attachment` logic to `switch_face`

Also updates `MaterialSwitchFace` to new Property system

* Update mech to `attachment_face` and more optimizations

* Update meta and add value for `DOUBLE_WALL`
  • Loading branch information
BreadcrumbIsTaken committed Jul 30, 2023
1 parent ff0f280 commit 7341333
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 106 deletions.
Expand Up @@ -10,7 +10,7 @@
import com.denizenscript.denizen.objects.properties.material.MaterialDirectional;
import com.denizenscript.denizen.objects.properties.material.MaterialDistance;
import com.denizenscript.denizen.objects.properties.material.MaterialHalf;
import com.denizenscript.denizen.objects.properties.material.MaterialSwitchFace;
import com.denizenscript.denizen.objects.properties.material.MaterialAttachmentFace;
import com.denizenscript.denizen.scripts.commands.world.SwitchCommand;
import com.denizenscript.denizen.utilities.*;
import com.denizenscript.denizen.utilities.blocks.SpawnableHelper;
Expand Down Expand Up @@ -3902,8 +3902,8 @@ else if (PolygonTag.matches(attribute.getParam())) {
else if (material.getMaterial() == Material.WALL_TORCH || material.getMaterial() == Material.REDSTONE_WALL_TORCH || material.getMaterial() == Material.SOUL_WALL_TORCH) {
face = ((Directional) material.getModernData()).getFacing().getOppositeFace();
}
else if (MaterialSwitchFace.describes(material)) {
face = MaterialSwitchFace.getFrom(material).getAttachedTo();
else if (MaterialAttachmentFace.describes(material)) {
face = new MaterialAttachmentFace(material).getAttachedTo();
}
else if (material.hasModernData() && material.getModernData() instanceof org.bukkit.block.data.type.WallSign) {
face = ((org.bukkit.block.data.type.WallSign) material.getModernData()).getFacing().getOppositeFace();
Expand Down
Expand Up @@ -315,7 +315,7 @@ public static void register() {
});
tagProcessor.registerTag(ElementTag.class, "is_switch", (attribute, object) -> {
BukkitImplDeprecations.materialPropertyTags.warn(attribute.context);
return new ElementTag(MaterialSwitchFace.describes(object));
return new ElementTag(MaterialAttachmentFace.describes(object));
});
tagProcessor.registerTag(ElementTag.class, "is_waterloggable", (attribute, object) -> {
BukkitImplDeprecations.materialPropertyTags.warn(attribute.context);
Expand Down
Expand Up @@ -243,6 +243,7 @@ public static void registerMainProperties() {
// register core MaterialTag properties
PropertyParser.registerProperty(MaterialAge.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialAttached.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialAttachmentFace.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialBlockType.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialBrewingStand.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialCampfire.class, MaterialTag.class);
Expand All @@ -267,7 +268,6 @@ public static void registerMainProperties() {
PropertyParser.registerProperty(MaterialSides.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSnowable.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSwitchable.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSwitchFace.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialUnstable.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialWaterlogged.class, MaterialTag.class);

Expand Down
@@ -0,0 +1,91 @@
package com.denizenscript.denizen.objects.properties.material;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Mechanism;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.FaceAttachable;
import org.bukkit.block.data.type.Bell;

public class MaterialAttachmentFace extends MaterialProperty<ElementTag> {

// <--[property]
// @object MaterialTag
// @name attachment_face
// @input ElementTag
// @description
// Controls the current attach direction for attachable materials such as switches, grindstones, and bells.
// For bell values, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/Bell.Attachment.html>
// For all other supported type values, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/FaceAttachable.AttachedFace.html>
// -->

public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof FaceAttachable || data instanceof Bell;
}

public MaterialAttachmentFace(MaterialTag material) {
super(material);
}

@Override
public ElementTag getPropertyValue() {
if (getBlockData() instanceof FaceAttachable attachable) {
return new ElementTag(attachable.getAttachedFace());
}
else if (getBlockData() instanceof Bell bell) {
return new ElementTag(bell.getAttachment());
}
return null;
}

@Override
public String getPropertyId() {
return "attachment_face";
}

@Override
public void setPropertyValue(ElementTag attachment, Mechanism mechanism) {
if (getBlockData() instanceof FaceAttachable attachable) {
if (mechanism.requireEnum(FaceAttachable.AttachedFace.class)) {
attachable.setAttachedFace(FaceAttachable.AttachedFace.valueOf(attachment.asString().toUpperCase()));
}
}
else if (getBlockData() instanceof Bell bell) {
if (mechanism.requireEnum(Bell.Attachment.class)) {
bell.setAttachment(Bell.Attachment.valueOf(attachment.asString().toUpperCase()));
}
}
}

public BlockFace getAttachedTo() {
if (getBlockData() instanceof FaceAttachable attachable) {
return switch (attachable.getAttachedFace()) {
case WALL -> {
if (getBlockData() instanceof Directional) {
yield ((Directional) getBlockData()).getFacing().getOppositeFace();
}
yield BlockFace.SELF;
}
case FLOOR -> BlockFace.DOWN;
case CEILING -> BlockFace.UP;
};
}
else if (getBlockData() instanceof Bell bell) {
return switch (bell.getAttachment()) {
case SINGLE_WALL, DOUBLE_WALL -> ((Directional) getBlockData()).getFacing();
case FLOOR -> BlockFace.DOWN;
case CEILING -> BlockFace.UP;
};
}
return null;
}

public static void register() {
autoRegister("attachment_face", MaterialAttachmentFace.class, ElementTag.class, false, "switch_face");
}
}

This file was deleted.

0 comments on commit 7341333

Please sign in to comment.