finish integrating ObjectData
This commit is contained in:
parent
a7d7fd2748
commit
1b7ef9a4cd
1 changed files with 33 additions and 2 deletions
|
@ -3,6 +3,8 @@ package me.tofaa.entitylib.entity;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
||||||
import com.github.retrooper.packetevents.protocol.player.User;
|
import com.github.retrooper.packetevents.protocol.player.User;
|
||||||
import com.github.retrooper.packetevents.protocol.world.Location;
|
import com.github.retrooper.packetevents.protocol.world.Location;
|
||||||
|
import com.github.retrooper.packetevents.util.Vector3d;
|
||||||
|
import com.github.retrooper.packetevents.util.Vector3f;
|
||||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||||
import com.github.retrooper.packetevents.wrapper.play.server.*;
|
import com.github.retrooper.packetevents.wrapper.play.server.*;
|
||||||
import me.tofaa.entitylib.EntityLib;
|
import me.tofaa.entitylib.EntityLib;
|
||||||
|
@ -24,6 +26,7 @@ public class WrapperEntity {
|
||||||
private Location location;
|
private Location location;
|
||||||
private boolean onGround;
|
private boolean onGround;
|
||||||
private boolean spawned;
|
private boolean spawned;
|
||||||
|
private Vector3d velocity = Vector3d.zero();
|
||||||
|
|
||||||
public WrapperEntity(@NotNull UUID uuid, EntityType entityType, EntityMeta meta) {
|
public WrapperEntity(@NotNull UUID uuid, EntityType entityType, EntityMeta meta) {
|
||||||
this.uuid = Optional.of(uuid);
|
this.uuid = Optional.of(uuid);
|
||||||
|
@ -43,8 +46,23 @@ public class WrapperEntity {
|
||||||
this.spawned = true;
|
this.spawned = true;
|
||||||
|
|
||||||
int data = 0;
|
int data = 0;
|
||||||
|
Optional<Vector3d> velocity;
|
||||||
|
double veloX = 0, veloY = 0, veloZ = 0;
|
||||||
if (meta instanceof ObjectData) {
|
if (meta instanceof ObjectData) {
|
||||||
data = ((ObjectData) meta).getObjectData();
|
ObjectData od = (ObjectData) meta;
|
||||||
|
|
||||||
|
data = od.getObjectData();
|
||||||
|
if (od.requiresVelocityPacketAtSpawn()) {
|
||||||
|
final WrapperPlayServerEntityVelocity veloPacket = getVelocityPacket();
|
||||||
|
veloX = veloPacket.getVelocity().getX();
|
||||||
|
veloY = veloPacket.getVelocity().getY();
|
||||||
|
veloZ = veloPacket.getVelocity().getZ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (veloX == 0 && veloY == 0 && veloZ == 0) {
|
||||||
|
velocity = Optional.empty();
|
||||||
|
} else {
|
||||||
|
velocity = Optional.of(new Vector3d(veloX, veloY, veloZ));
|
||||||
}
|
}
|
||||||
sendPacketToViewers(
|
sendPacketToViewers(
|
||||||
new WrapperPlayServerSpawnEntity(
|
new WrapperPlayServerSpawnEntity(
|
||||||
|
@ -56,7 +74,7 @@ public class WrapperEntity {
|
||||||
location.getYaw(),
|
location.getYaw(),
|
||||||
location.getYaw(),
|
location.getYaw(),
|
||||||
data,
|
data,
|
||||||
Optional.empty()
|
velocity
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
sendPacketToViewers(meta.createPacket());
|
sendPacketToViewers(meta.createPacket());
|
||||||
|
@ -161,4 +179,17 @@ public class WrapperEntity {
|
||||||
return spawned;
|
return spawned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3d getVelocity() {
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVelocity(Vector3d velocity) {
|
||||||
|
this.velocity = velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WrapperPlayServerEntityVelocity getVelocityPacket() {
|
||||||
|
Vector3d velocity = this.velocity.multiply(8000.0f / 20.0f);
|
||||||
|
return new WrapperPlayServerEntityVelocity(entityId, velocity);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue