use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.
the class GlowHumanEntity method processArmorChanges.
/**
* Process changes to the human enitity's armor, and update the entity's armor attributes accordingly.
*/
private void processArmorChanges() {
GlowPlayer player = null;
if (this instanceof GlowPlayer) {
player = ((GlowPlayer) this);
}
boolean armorUpdate = false;
List<EquipmentMonitor.Entry> armorChanges = getEquipmentMonitor().getArmorChanges();
if (armorChanges.size() > 0) {
for (EquipmentMonitor.Entry entry : armorChanges) {
if (player != null && needsArmorUpdate) {
player.getSession().send(new EntityEquipmentMessage(0, entry.slot, entry.item));
}
armorUpdate = true;
}
}
if (armorUpdate) {
getAttributeManager().setProperty(AttributeManager.Key.KEY_ARMOR, ArmorConstants.getDefense(getEquipment().getArmorContents()));
getAttributeManager().setProperty(AttributeManager.Key.KEY_ARMOR_TOUGHNESS, ArmorConstants.getToughness(getEquipment().getArmorContents()));
}
needsArmorUpdate = true;
}
use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method createUpdateMessage.
@Override
public List<Message> createUpdateMessage() {
List<Message> messages = super.createUpdateMessage();
messages.addAll(equipmentMonitor.getChanges().stream().map(change -> new EntityEquipmentMessage(id, change.slot, change.item)).collect(Collectors.toList()));
if (headRotated) {
messages.add(new EntityHeadRotationMessage(id, Position.getIntHeadYaw(headYaw)));
headRotated = false;
}
attributeManager.applyMessages(messages);
return messages;
}
use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.
the class GlowArmorStand method createSpawnMessage.
@Override
public List<Message> createSpawnMessage() {
double x = location.getX();
double y = location.getY();
double z = location.getZ();
int yaw = Position.getIntYaw(location);
int pitch = Position.getIntPitch(location);
return Arrays.asList(// TODO: once UUID is documented, actually use the appropriate ID here
new SpawnObjectMessage(id, UUID.randomUUID(), 78, x, y, z, pitch, yaw), new EntityMetadataMessage(id, metadata.getEntryList()), new EntityEquipmentMessage(id, EntityEquipmentMessage.HELD_ITEM, getItemInHand()), new EntityEquipmentMessage(id, EntityEquipmentMessage.BOOTS_SLOT, getBoots()), new EntityEquipmentMessage(id, EntityEquipmentMessage.LEGGINGS_SLOT, getLeggings()), new EntityEquipmentMessage(id, EntityEquipmentMessage.CHESTPLATE_SLOT, getChestplate()), new EntityEquipmentMessage(id, EntityEquipmentMessage.HELMET_SLOT, getHelmet()));
}
use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.
the class GlowHumanEntity method createSpawnMessage.
////////////////////////////////////////////////////////////////////////////
// Internals
@Override
public List<Message> createSpawnMessage() {
List<Message> result = new LinkedList<>();
// spawn player
double x = location.getX();
double y = location.getY();
double z = location.getZ();
int yaw = Position.getIntYaw(location);
int pitch = Position.getIntPitch(location);
result.add(new SpawnPlayerMessage(id, profile.getUniqueId(), x, y, z, yaw, pitch, metadata.getEntryList()));
// head facing
result.add(new EntityHeadRotationMessage(id, yaw));
// equipment
EntityEquipment equipment = getEquipment();
result.add(new EntityEquipmentMessage(id, 0, equipment.getItemInHand()));
for (int i = 0; i < 4; i++) {
result.add(new EntityEquipmentMessage(id, i + 1, equipment.getArmorContents()[i]));
}
return result;
}
use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.
the class EntityEquipmentCodec method decode.
@Override
public EntityEquipmentMessage decode(ByteBuf buf) throws IOException {
int id = ByteBufUtils.readVarInt(buf);
int slot = ByteBufUtils.readVarInt(buf);
ItemStack stack = GlowBufUtils.readSlot(buf);
return new EntityEquipmentMessage(id, slot, stack);
}
Aggregations