use of net.glowstone.entity.AttributeManager.Property in project Glowstone by GlowstoneMC.
the class EntityPropertyCodec method encode.
@Override
public ByteBuf encode(ByteBuf buf, EntityPropertyMessage message) throws IOException {
ByteBufUtils.writeVarInt(buf, message.getId());
Map<String, Property> props = message.getProperties();
buf.writeInt(props.size());
for (Entry<String, Property> property : props.entrySet()) {
ByteBufUtils.writeUTF8(buf, property.getKey());
buf.writeDouble(property.getValue().getValue());
Collection<AttributeModifier> modifiers = property.getValue().getModifiers();
if (modifiers == null) {
ByteBufUtils.writeVarInt(buf, 0);
} else {
ByteBufUtils.writeVarInt(buf, modifiers.size());
for (AttributeModifier modifier : modifiers) {
GlowBufUtils.writeUuid(buf, modifier.getUniqueId());
buf.writeDouble(modifier.getAmount());
buf.writeByte(modifier.getOperation().ordinal());
}
}
}
return buf;
}
use of net.glowstone.entity.AttributeManager.Property in project Glowstone by GlowstoneMC.
the class LivingEntityStore method save.
@Override
public void save(T entity, CompoundTag tag) {
super.save(entity, tag);
tag.putShort("Air", entity.getRemainingAir());
if (entity.getCustomName() != null && !entity.getCustomName().isEmpty()) {
tag.putString("CustomName", entity.getCustomName());
tag.putBool("CustomNameVisible", entity.isCustomNameVisible());
}
tag.putFloat("HealF", entity.getHealth());
tag.putShort("Health", (int) entity.getHealth());
tag.putShort("AttackTime", entity.getNoDamageTicks());
tag.putBool("FallFlying", entity.isFallFlying());
Map<String, Property> properties = entity.getAttributeManager().getAllProperties();
if (!properties.isEmpty()) {
List<CompoundTag> attributes = new ArrayList<>(properties.size());
properties.forEach((key, property) -> {
CompoundTag attribute = new CompoundTag();
attribute.putString("Name", key);
attribute.putDouble("Base", property.getValue());
Collection<AttributeModifier> modifiers = property.getModifiers();
if (modifiers != null && !modifiers.isEmpty()) {
List<CompoundTag> modifierTags = modifiers.stream().map(modifier -> {
CompoundTag modifierTag = new CompoundTag();
modifierTag.putDouble("Amount", modifier.getAmount());
modifierTag.putString("Name", modifier.getName());
modifierTag.putInt("Operation", modifier.getOperation().ordinal());
UUID uuid = modifier.getUniqueId();
modifierTag.putLong("UUIDLeast", uuid.getLeastSignificantBits());
modifierTag.putLong("UUIDMost", uuid.getMostSignificantBits());
return modifierTag;
}).collect(Collectors.toList());
attribute.putCompoundList("Modifiers", modifierTags);
}
attributes.add(attribute);
});
tag.putCompoundList("Attributes", attributes);
}
List<CompoundTag> effects = new LinkedList<>();
for (PotionEffect effect : entity.getActivePotionEffects()) {
CompoundTag effectTag = new CompoundTag();
effectTag.putByte("Id", effect.getType().getId());
effectTag.putByte("Amplifier", effect.getAmplifier());
effectTag.putInt("Duration", effect.getDuration());
effectTag.putBool("Ambient", effect.isAmbient());
effectTag.putBool("ShowParticles", true);
effects.add(effectTag);
}
tag.putCompoundList("ActiveEffects", effects);
EntityEquipment equip = entity.getEquipment();
if (equip != null) {
tag.putCompoundList("HandItems", Arrays.asList(NbtSerialization.writeItem(equip.getItemInMainHand(), -1), NbtSerialization.writeItem(equip.getItemInOffHand(), -1)));
tag.putCompoundList("ArmorItems", Arrays.asList(NbtSerialization.writeItem(equip.getBoots(), -1), NbtSerialization.writeItem(equip.getLeggings(), -1), NbtSerialization.writeItem(equip.getChestplate(), -1), NbtSerialization.writeItem(equip.getHelmet(), -1)));
tag.putFloatList("HandDropChances", Arrays.asList(equip.getItemInMainHandDropChance(), equip.getItemInOffHandDropChance()));
tag.putFloatList("ArmorDropChances", Arrays.asList(equip.getBootsDropChance(), equip.getLeggingsDropChance(), equip.getChestplateDropChance(), equip.getHelmetDropChance()));
}
tag.putBool("CanPickUpLoot", entity.getCanPickupItems());
tag.putBool("Leashed", entity.isLeashed());
if (entity.isLeashed()) {
Entity leashHolder = entity.getLeashHolder();
CompoundTag leash = new CompoundTag();
// The empty Leash tag is still persisted tough
if (leashHolder instanceof LeashHitch) {
Location location = leashHolder.getLocation();
leash.putInt("X", location.getBlockX());
leash.putInt("Y", location.getBlockY());
leash.putInt("Z", location.getBlockZ());
} else if (leashHolder instanceof LivingEntity) {
leash.putLong("UUIDMost", entity.getUniqueId().getMostSignificantBits());
leash.putLong("UUIDLeast", entity.getUniqueId().getLeastSignificantBits());
}
tag.putCompound("Leash", leash);
}
}
Aggregations