Skip to content

Commit

Permalink
initial usages of mech registration
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 28, 2022
1 parent e7eedae commit c4cba4a
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 71 deletions.
Expand Up @@ -333,5 +333,6 @@ public void adjust(Mechanism mechanism) {
biome.setPrecipitation(BiomeNMS.DownfallType.valueOf(mechanism.getValue().asString().toUpperCase()));
}

tagProcessor.processMechanism(this, mechanism);
}
}
Expand Up @@ -694,8 +694,6 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

// <--[mechanism]
// @object ChunkTag
// @name inhabited_time
Expand Down Expand Up @@ -832,6 +830,5 @@ public void adjust(Mechanism mechanism) {
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);
}
}
Expand Up @@ -1495,8 +1495,6 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

// <--[mechanism]
// @object CuboidTag
// @name set_member
Expand Down Expand Up @@ -1603,7 +1601,6 @@ public void adjust(Mechanism mechanism) {
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);
}

@Override
Expand Down
Expand Up @@ -623,8 +623,7 @@ public void applyProperty(Mechanism mechanism) {

@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);
tagProcessor.processMechanism(this, mechanism);
}

@Override
Expand Down
Expand Up @@ -2938,8 +2938,6 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

if (isGeneric()) {
mechanisms.add(mechanism);
mechanism.fulfill();
Expand Down Expand Up @@ -4066,7 +4064,6 @@ else if (getBukkitEntity() instanceof Creeper) {
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);
}

public static HashSet<String> specialEntityMatchables = new HashSet<>(Arrays.asList("entity", "npc", "player", "living", "vehicle", "fish", "projectile", "hanging", "monster", "mob", "animal"));
Expand Down
Expand Up @@ -2368,9 +2368,7 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);
tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);

// <--[mechanism]
// @object InventoryTag
Expand Down
35 changes: 15 additions & 20 deletions plugin/src/main/java/com/denizenscript/denizen/objects/ItemTag.java
Expand Up @@ -496,7 +496,6 @@ public boolean isTruthy() {

public static void registerTags() {

AbstractFlagTracker.registerFlagHandlers(tagProcessor);
PropertyParser.registerPropertyTagHandlers(ItemTag.class, tagProcessor);

// <--[tag]
Expand Down Expand Up @@ -719,6 +718,21 @@ else if (container != null) {
tagProcessor.registerTag(ElementTag.class, "formatted", (attribute, object) -> {
return new ElementTag(object.formattedName());
});

// <--[mechanism]
// @object ItemTag
// @name material
// @input MaterialTag
// @description
// Changes the item's material to the given material.
// Only copies the base material type, not any advanced block-data material properties.
// Note that this may cause some properties of the item to be lost.
// @tags
// <ItemTag.material>
// -->
tagProcessor.registerMechanism("material", true, MaterialTag.class, (object, mechanism, material) -> {
object.item.setType(material.getMaterial());
});
}

public String formattedName() {
Expand Down Expand Up @@ -785,26 +799,7 @@ public void applyProperty(Mechanism mechanism) {

@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

// <--[mechanism]
// @object ItemTag
// @name material
// @input MaterialTag
// @description
// Changes the item's material to the given material.
// Only copies the base material type, not any advanced block-data material properties.
// Note that this may cause some properties of the item to be lost.
// @tags
// <ItemTag.material>
// -->
if (mechanism.matches("material") && mechanism.requireObject(MaterialTag.class)) {
item.setType(mechanism.valueAsType(MaterialTag.class).getMaterial());
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);
}

public static class ItemPropertyMatchHelper {
Expand Down
Expand Up @@ -4376,8 +4376,6 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

// <--[mechanism]
// @object LocationTag
// @name block_facing
Expand Down Expand Up @@ -5428,7 +5426,6 @@ else if (state instanceof Dropper) {
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);
}

@Override
Expand Down
Expand Up @@ -714,7 +714,6 @@ public void adjust(Mechanism mechanism) {
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);
}

public static boolean advancedMatchesInternal(Material mat, String comparedto, boolean allowByMaterialName) {
Expand Down
Expand Up @@ -1303,8 +1303,6 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

// TODO: For all the mechanism tags, add the @Mechanism link!

// <--[mechanism]
Expand Down Expand Up @@ -1877,7 +1875,6 @@ else if ((wp.getCurrentProvider() instanceof WanderWaypointProvider)) {
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);

// Pass along to EntityTag mechanism handler if not already handled.
if (!mechanism.fulfilled()) {
Expand Down
Expand Up @@ -2506,8 +2506,6 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

// <--[mechanism]
// @object PlayerTag
// @name send_climbable_materials
Expand Down Expand Up @@ -3928,7 +3926,6 @@ else if (bal > goal) {
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);

// Pass along to EntityTag mechanism handler if not already handled.
if (!mechanism.fulfilled()) {
Expand Down
Expand Up @@ -716,6 +716,27 @@ public static void registerTags() {
tagProcessor.registerTag(ListTag.class, "outline", (attribute, polygon) -> {
return polygon.getOutline();
});

// <--[mechanism]
// @object PolygonTag
// @name add_corner
// @input LocationTag
// @description
// Adds a corner to the end of the polygon's corner list.
// @tags
// <PolygonTag.with_corner[<location>]>
// -->
tagProcessor.registerMechanism("add_corner", false, LocationTag.class, (object, mechanism, location) -> {
if (object.noteName != null) {
NotedAreaTracker.remove(object);
}
Corner newCorner = new Corner(location.getX(), location.getZ());
object.corners.add(newCorner);
object.recalculateToFit(newCorner);
if (object.noteName != null) {
NotedAreaTracker.add(object);
}
});
}

public static ObjectTagProcessor<PolygonTag> tagProcessor = new ObjectTagProcessor<>();
Expand All @@ -735,30 +756,7 @@ public void applyProperty(Mechanism mechanism) {

@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

// <--[mechanism]
// @object PolygonTag
// @name add_corner
// @input LocationTag
// @description
// Adds a corner to the end of the polygon's corner list.
// @tags
// <PolygonTag.with_corner[<location>]>
// -->
if (mechanism.matches("add_corner") && mechanism.requireObject(LocationTag.class)) {
if (noteName != null) {
NotedAreaTracker.remove(this);
}
LocationTag loc = mechanism.valueAsType(LocationTag.class);
Corner newCorner = new Corner(loc.getX(), loc.getZ());
corners.add(newCorner);
recalculateToFit(newCorner);
if (noteName != null) {
NotedAreaTracker.add(this);
}
}
tagProcessor.processMechanism(this, mechanism);
}

@Override
Expand Down
Expand Up @@ -166,6 +166,5 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {
tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);
}
}
Expand Up @@ -1058,8 +1058,6 @@ public void applyProperty(Mechanism mechanism) {
@Override
public void adjust(Mechanism mechanism) {

AbstractFlagTracker.tryFlagAdjusts(this, mechanism);

// <--[mechanism]
// @object WorldTag
// @name ambient_spawn_limit
Expand Down Expand Up @@ -1405,7 +1403,6 @@ public void adjust(Mechanism mechanism) {
}

tagProcessor.processMechanism(this, mechanism);
CoreUtilities.autoPropertyMechanism(this, mechanism);
}

public void unloadWorldClean(Mechanism mechanism, boolean doSave) {
Expand Down

0 comments on commit c4cba4a

Please sign in to comment.