Skip to content

Commit 49a0655

Browse files
committed
Add get|set_entity_pose() functions
1 parent 0c1dcff commit 49a0655

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed

src/main/java/com/laytonsmith/abstraction/MCEntity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.laytonsmith.PureUtilities.Vector3D;
44
import com.laytonsmith.abstraction.enums.MCEntityEffect;
55
import com.laytonsmith.abstraction.enums.MCEntityType;
6+
import com.laytonsmith.abstraction.enums.MCPose;
67
import com.laytonsmith.abstraction.enums.MCTeleportCause;
78
import com.laytonsmith.abstraction.events.MCEntityDamageEvent;
89
import java.util.List;
@@ -122,4 +123,9 @@ public interface MCEntity extends MCMetadatable {
122123
boolean isVisibleByDefault();
123124

124125
void setVisibleByDefault(boolean visible);
126+
127+
MCPose getPose();
128+
129+
void setPose(MCPose pose);
130+
125131
}

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEntity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import com.laytonsmith.abstraction.bukkit.events.BukkitEntityEvents;
1616
import com.laytonsmith.abstraction.enums.MCEntityEffect;
1717
import com.laytonsmith.abstraction.enums.MCEntityType;
18+
import com.laytonsmith.abstraction.enums.MCPose;
1819
import com.laytonsmith.abstraction.enums.MCTeleportCause;
1920
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCEntityType;
21+
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPose;
2022
import com.laytonsmith.abstraction.events.MCEntityDamageEvent;
2123
import io.papermc.paper.entity.TeleportFlag;
2224
import org.bukkit.EntityEffect;
@@ -437,4 +439,14 @@ public void setVisibleByDefault(boolean visible) {
437439
// probably before 1.19.3
438440
}
439441
}
442+
443+
@Override
444+
public MCPose getPose() {
445+
return BukkitMCPose.getConvertor().getAbstractedEnum(e.getPose());
446+
}
447+
448+
@Override
449+
public void setPose(MCPose pose) {
450+
e.setPose(BukkitMCPose.getConvertor().getConcreteEnum(pose));
451+
}
440452
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.laytonsmith.abstraction.enums;
2+
3+
import com.laytonsmith.annotations.MEnum;
4+
5+
@MEnum("com.commandhelper.Pose")
6+
public enum MCPose {
7+
CROAKING,
8+
DIGGING,
9+
DYING,
10+
EMERGING,
11+
FALL_FLYING,
12+
INHALING,
13+
LONG_JUMPING,
14+
ROARING,
15+
SHOOTING,
16+
SITTING,
17+
SLEEPING,
18+
SLIDING,
19+
SNEAKING,
20+
SNIFFING,
21+
SPIN_ATTACK,
22+
STANDING,
23+
SWIMMING,
24+
USING_TONGUE
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.laytonsmith.abstraction.enums.bukkit;
2+
3+
import com.laytonsmith.abstraction.Implementation;
4+
import com.laytonsmith.abstraction.enums.EnumConvertor;
5+
import com.laytonsmith.abstraction.enums.MCPose;
6+
import com.laytonsmith.annotations.abstractionenum;
7+
import org.bukkit.entity.Pose;
8+
9+
@abstractionenum(
10+
implementation = Implementation.Type.BUKKIT,
11+
forAbstractEnum = MCPose.class,
12+
forConcreteEnum = Pose.class
13+
)
14+
public class BukkitMCPose extends EnumConvertor<MCPose, Pose> {
15+
16+
private static BukkitMCPose instance;
17+
18+
public static BukkitMCPose getConvertor() {
19+
if(instance == null) {
20+
instance = new BukkitMCPose();
21+
}
22+
return instance;
23+
}
24+
}

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
import com.laytonsmith.abstraction.enums.MCMushroomCowType;
114114
import com.laytonsmith.abstraction.enums.MCParrotType;
115115
import com.laytonsmith.abstraction.enums.MCParticle;
116+
import com.laytonsmith.abstraction.enums.MCPose;
116117
import com.laytonsmith.abstraction.enums.MCPotionType;
117118
import com.laytonsmith.abstraction.enums.MCProfession;
118119
import com.laytonsmith.abstraction.enums.MCRabbitType;
@@ -5784,4 +5785,107 @@ public Version since() {
57845785
return MSVersion.V3_3_5;
57855786
}
57865787
}
5788+
5789+
@api
5790+
@seealso(set_entity_pose.class)
5791+
public static class get_entity_pose extends EntityGetterFunction {
5792+
5793+
@Override
5794+
public String getName() {
5795+
return "get_entity_pose";
5796+
}
5797+
5798+
@Override
5799+
public String docs() {
5800+
return """
5801+
string {entityUUID} Returns the pose of an entity. Poses are desynchronized from entity state,
5802+
as the pose is set at the end of a tick and can be set to anything by a plugin.
5803+
----
5804+
Known poses:
5805+
{| class="wikitable"
5806+
|-
5807+
! scope="col" width="20%" | Entity Types
5808+
! scope="col" width="80%" | Poses
5809+
|-
5810+
! All Entities
5811+
| STANDING (default pose)
5812+
|-
5813+
! Living Entities
5814+
| DYING, SLEEPING
5815+
|-
5816+
! Most Humanoid Entities
5817+
| SNEAKING, SWIMMING, FALL_FLYING
5818+
|-
5819+
! Breeze
5820+
| INHALING, LONG_JUMPING, SHOOTING, SLIDING
5821+
|-
5822+
! Camel
5823+
| SITTING
5824+
|-
5825+
! Cat/Ocelot
5826+
| SNEAKING
5827+
|-
5828+
! Frog
5829+
| CROAKING, LONG_JUMPING, USING_TONGUE
5830+
|-
5831+
! Goat
5832+
| LONG_JUMPING
5833+
|-
5834+
! Player
5835+
| SPIN_ATTACK
5836+
|-
5837+
! Warden
5838+
| DIGGING, EMERGING, ROARING, SNIFFING
5839+
|}
5840+
""";
5841+
}
5842+
5843+
@Override
5844+
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
5845+
MCEntity entity = Static.getEntity(args[0], t);
5846+
return new CString(entity.getPose().name(), t);
5847+
}
5848+
5849+
@Override
5850+
public Version since() {
5851+
return MSVersion.V3_3_5;
5852+
}
5853+
}
5854+
5855+
@api
5856+
@seealso(get_entity_pose.class)
5857+
public static class set_entity_pose extends EntitySetterFunction {
5858+
5859+
@Override
5860+
public String getName() {
5861+
return "set_entity_pose";
5862+
}
5863+
5864+
@Override
5865+
public String docs() {
5866+
return """
5867+
void {entityUUID, pose} Sets an entity's pose. While you can set any pose to any entity, only
5868+
certain poses will result in a visual change for a particular entity type. Poses can affect entity
5869+
hitboxes but do not change entity state. See {{function|get_entity_pose}} for a list of poses.
5870+
""";
5871+
}
5872+
5873+
@Override
5874+
public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
5875+
MCEntity entity = Static.getEntity(args[0], t);
5876+
MCPose pose;
5877+
try {
5878+
pose = MCPose.valueOf(args[1].val().toUpperCase());
5879+
} catch(IllegalArgumentException ex) {
5880+
throw new CREFormatException("Invalid pose: " + args[1].val(), t);
5881+
}
5882+
entity.setPose(pose);
5883+
return CVoid.VOID;
5884+
}
5885+
5886+
@Override
5887+
public Version since() {
5888+
return MSVersion.V3_3_5;
5889+
}
5890+
}
57875891
}

0 commit comments

Comments
 (0)