-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EntityTag.shot_at_angle for fireworks
- Loading branch information
1 parent
d65016e
commit 5f05abe
Showing
3 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
.../src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityShotAtAngle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |