mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 20:39:13 +00:00
Velocity for balloons
This commit is contained in:
@@ -12,6 +12,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEntityMove;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -342,6 +343,14 @@ public class PacketManager extends BasePacket {
|
||||
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
||||
}
|
||||
|
||||
public static void sendLeashPacket(
|
||||
final int leashedEntity,
|
||||
final int entityId,
|
||||
final Location location
|
||||
) {
|
||||
sendLeashPacket(leashedEntity, entityId, getViewers(location));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a leash packet, useful for balloons!
|
||||
* @param leashedEntity Entity being leashed (ex. a horse)
|
||||
@@ -353,10 +362,10 @@ public class PacketManager extends BasePacket {
|
||||
final int entityId,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
|
||||
packet.getIntegers().write(0, leashedEntity);
|
||||
packet.getIntegers().write(1, entityId);
|
||||
for (final Player p : sendTo) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
|
||||
packet.getIntegers().write(0, leashedEntity);
|
||||
packet.getIntegers().write(1, entityId);
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
}
|
||||
@@ -387,6 +396,42 @@ public class PacketManager extends BasePacket {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a movement packet from one location to another
|
||||
* @param entityId Entity this will affect
|
||||
* @param from Previous location
|
||||
* @param to New location
|
||||
* @param onGround If the movement is on the ground
|
||||
* @param sendTo Whom to send the packet to
|
||||
*/
|
||||
public static void sendMovePacket(
|
||||
final int entityId,
|
||||
final Location from,
|
||||
final Location to,
|
||||
final boolean onGround,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
|
||||
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
|
||||
wrapper.setEntityID(entityId);
|
||||
wrapper.setDx(to.getX() - from.getX());
|
||||
wrapper.setDy(to.getY() - from.getY());
|
||||
wrapper.setDz(to.getZ() - from.getZ());
|
||||
wrapper.setOnGround(onGround);
|
||||
for (final Player p : sendTo) {
|
||||
sendPacket(p, wrapper.getHandle());
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMovePacket(
|
||||
final int entityId,
|
||||
final Location from,
|
||||
final Location to,
|
||||
final boolean onGround
|
||||
) {
|
||||
sendMovePacket(entityId, from, to, onGround, getViewers(to));
|
||||
}
|
||||
|
||||
private static List<Player> getViewers(Location location) {
|
||||
ArrayList<Player> viewers = new ArrayList();
|
||||
if (Settings.getViewDistance() <= 0) {
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
|
||||
public static final PacketType TYPE =
|
||||
PacketType.Play.Server.REL_ENTITY_MOVE;
|
||||
|
||||
public WrapperPlayServerRelEntityMove() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerRelEntityMove(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Entity ID.
|
||||
* <p>
|
||||
* Notes: entity's ID
|
||||
*
|
||||
* @return The current Entity ID
|
||||
*/
|
||||
public int getEntityID() {
|
||||
return handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Entity ID.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setEntityID(int value) {
|
||||
handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the entity of the painting that will be spawned.
|
||||
*
|
||||
* @param world - the current world of the entity.
|
||||
* @return The spawned entity.
|
||||
*/
|
||||
public Entity getEntity(World world) {
|
||||
return handle.getEntityModifier(world).read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the entity of the painting that will be spawned.
|
||||
*
|
||||
* @param event - the packet event.
|
||||
* @return The spawned entity.
|
||||
*/
|
||||
public Entity getEntity(PacketEvent event) {
|
||||
return getEntity(event.getPlayer().getWorld());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve DX.
|
||||
*
|
||||
* @return The current DX
|
||||
*/
|
||||
public double getDx() {
|
||||
return handle.getShorts().read(0) / 4096D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set DX.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setDx(double value) {
|
||||
handle.getShorts().write(0, (short) (value * 4096));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve DY.
|
||||
*
|
||||
* @return The current DY
|
||||
*/
|
||||
public double getDy() {
|
||||
return handle.getShorts().read(1) / 4096D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set DY.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setDy(double value) {
|
||||
handle.getShorts().write(1, (short) (value * 4096));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve DZ.
|
||||
*
|
||||
* @return The current DZ
|
||||
*/
|
||||
public double getDz() {
|
||||
return handle.getShorts().read(2) / 4096D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set DZ.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setDz(double value) {
|
||||
handle.getShorts().write(2, (short) (value * 4096));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the yaw of the current entity.
|
||||
*
|
||||
* @return The current Yaw
|
||||
*/
|
||||
public float getYaw() {
|
||||
return (handle.getBytes().read(0) * 360.F) / 256.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the yaw of the current entity.
|
||||
*
|
||||
* @param value - new yaw.
|
||||
*/
|
||||
public void setYaw(float value) {
|
||||
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the pitch of the current entity.
|
||||
*
|
||||
* @return The current pitch
|
||||
*/
|
||||
public float getPitch() {
|
||||
return (handle.getBytes().read(1) * 360.F) / 256.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pitch of the current entity.
|
||||
*
|
||||
* @param value - new pitch.
|
||||
*/
|
||||
public void setPitch(float value) {
|
||||
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve On Ground.
|
||||
*
|
||||
* @return The current On Ground
|
||||
*/
|
||||
public boolean getOnGround() {
|
||||
return handle.getBooleans().read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set On Ground.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setOnGround(boolean value) {
|
||||
handle.getBooleans().write(0, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user