Skip to content

Commit

Permalink
EntityTag.shot_at_angle for fireworks
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 7, 2022
1 parent d65016e commit 5f05abe
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static void registerMainProperties() {
PropertyParser.registerProperty(EntityScoreboardTags.class, EntityTag.class);
PropertyParser.registerProperty(EntitySmall.class, EntityTag.class);
PropertyParser.registerProperty(EntityShivering.class, EntityTag.class);
PropertyParser.registerProperty(EntityShotAtAngle.class, EntityTag.class);
PropertyParser.registerProperty(EntityShulkerPeek.class, EntityTag.class);
PropertyParser.registerProperty(EntitySilent.class, EntityTag.class);
PropertyParser.registerProperty(EntitySitting.class, EntityTag.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name firework_lifetime
// @input ElementTag(Boolean)
// @input DurationTag
// @description
// Sets the duration that a firework will live for (before detonating).
// @tags
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.entity.Firework;

public class EntityShotAtAngle implements Property {

public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Firework;
}

public static EntityShotAtAngle getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityShotAtAngle((EntityTag) entity);
}
}

public static final String[] handledMechs = new String[] {
"shot_at_angle"
};

private EntityShotAtAngle(EntityTag entity) {
this.entity = entity;
}

EntityTag entity;

public Firework getFirework() {
return (Firework) entity.getBukkitEntity();
}

@Override
public String getPropertyString() {
return getFirework().isShotAtAngle() ? "true" : "false";
}

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

public static void registerTags() {

// <--[tag]
// @attribute <EntityTag.shot_at_angle>
// @returns ElementTag(Boolean)
// @mechanism EntityTag.shot_at_angle
// @group properties
// @description
// Returns true if the Firework entity is 'shot at angle', meaning it should render facing the direction it's moving. If false, will be angled straight up.
// -->
PropertyParser.<EntityShotAtAngle, ElementTag>registerTag(ElementTag.class, "shot_at_angle", (attribute, object) -> {
return new ElementTag(object.getFirework().isShotAtAngle());
});
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object EntityTag
// @name shot_at_angle
// @input ElementTag(Boolean)
// @description
// Set to true if the Firework entity should be 'shot at angle', meaning it should render facing the direction it's moving. If false, will be angled straight up.
// @tags
// <EntityTag.shot_at_angle>
// -->
if (mechanism.matches("shot_at_angle") && mechanism.requireBoolean()) {
getFirework().setShotAtAngle(mechanism.getValue().asBoolean());
}
}
}

0 comments on commit 5f05abe

Please sign in to comment.