Skip to content

Commit

Permalink
Merge pull request #1146 from IWareQ/add-animate-entity-packet
Browse files Browse the repository at this point in the history
Implements AnimateEntityPacket
  • Loading branch information
joserobjr authored Jun 23, 2021
2 parents a7a3b27 + 2a90481 commit 8bd5ce7
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/cn/nukkit/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,5 +473,6 @@ private void registerPackets() {
this.registerPacket(ProtocolInfo.REMOVE_VOLUME_ENTITY, RemoveVolumeEntityPacket.class);
this.registerPacket(ProtocolInfo.SYNC_ENTITY_PROPERTY, SyncEntityPropertyPacket.class);
this.registerPacket(ProtocolInfo.TICK_SYNC_PACKET, TickSyncPacket.class);
this.registerPacket(ProtocolInfo.ANIMATE_ENTITY_PACKET, AnimateEntityPacket.class);
}
}
129 changes: 129 additions & 0 deletions src/main/java/cn/nukkit/network/protocol/AnimateEntityPacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package cn.nukkit.network.protocol;

import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;

import java.util.ArrayList;
import java.util.List;

/**
* @author IWareQ
*/
@PowerNukkitOnly
@Since("FUTURE")
public class AnimateEntityPacket extends DataPacket {

@PowerNukkitOnly
@Since("FUTURE")
public static final byte NETWORK_ID = ProtocolInfo.ANIMATE_ENTITY_PACKET;

private String animation;
private String nextState;
private String stopExpression;
private String controller;
private float blendOutTime;
private List<Long> entityRuntimeIds = new ArrayList<>();

@Override
public void decode() {
this.animation = this.getString();
this.nextState = this.getString();
this.stopExpression = this.getString();
this.controller = this.getString();
this.blendOutTime = this.getLFloat();
for (int i = 0, len = (int) this.getUnsignedVarInt(); i < len; i++) {
this.entityRuntimeIds.add(this.getEntityRuntimeId());
}
}

@Override
public void encode() {
this.reset();
this.putString(this.animation);
this.putString(this.nextState);
this.putString(this.stopExpression);
this.putString(this.controller);
this.putLFloat(this.blendOutTime);
this.putUnsignedVarInt(this.entityRuntimeIds.size());
for (long entityRuntimeId : this.entityRuntimeIds){
this.putEntityRuntimeId(entityRuntimeId);
}
}

@Override
public byte pid() {
return NETWORK_ID;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public void setAnimation(String animation) {
this.animation = animation;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public String getAnimation() {
return this.animation;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public void setNextState(String nextState) {
this.nextState = nextState;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public String getNextState() {
return this.nextState;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public void setStopExpression(String stopExpression) {
this.stopExpression = stopExpression;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public String getStopExpression() {
return this.stopExpression;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public void setController(String controller) {
this.controller = controller;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public String getController() {
return this.controller;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public void setBlendOutTime(float blendOutTime) {
this.blendOutTime = blendOutTime;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public float getBlendOutTime() {
return this.blendOutTime;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public void setEntityRuntimeIds(List<Long> entityRuntimeIds) {
this.entityRuntimeIds = entityRuntimeIds;
}

@PowerNukkitOnly
@Since("1.5.0.0-PN")
public List<Long> getEntityRuntimeIds() {
return this.entityRuntimeIds;
}
}

0 comments on commit 8bd5ce7

Please sign in to comment.