use of org.bukkit.inventory.EntityEquipment 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 org.bukkit.inventory.EntityEquipment 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());
AttributeManager am = entity.getAttributeManager();
Map<String, Property> properties = am.getAllProperties();
if (!properties.isEmpty()) {
List<CompoundTag> attributes = new ArrayList<>();
for (Entry<String, Property> property : properties.entrySet()) {
CompoundTag attribute = new CompoundTag();
attribute.putString("Name", property.getKey());
Property p = property.getValue();
attribute.putDouble("Base", p.getValue());
if (p.getModifiers() != null && !p.getModifiers().isEmpty()) {
List<CompoundTag> modifiers = new ArrayList<>();
for (Modifier modifier : p.getModifiers()) {
CompoundTag modifierTag = new CompoundTag();
modifierTag.putDouble("Amount", modifier.getAmount());
modifierTag.putString("Name", modifier.getName());
modifierTag.putInt("Operation", modifier.getOperation());
modifierTag.putLong("UUIDLeast", modifier.getUuid().getLeastSignificantBits());
modifierTag.putLong("UUIDMost", modifier.getUuid().getMostSignificantBits());
modifiers.add(modifierTag);
}
attribute.putCompoundList("Modifiers", modifiers);
}
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("Equipment", Arrays.asList(NbtSerialization.writeItem(equip.getItemInHand(), -1), NbtSerialization.writeItem(equip.getBoots(), -1), NbtSerialization.writeItem(equip.getLeggings(), -1), NbtSerialization.writeItem(equip.getChestplate(), -1), NbtSerialization.writeItem(equip.getHelmet(), -1)));
tag.putList("DropChances", TagType.FLOAT, Arrays.asList(equip.getItemInHandDropChance(), equip.getBootsDropChance(), equip.getLeggingsDropChance(), equip.getChestplateDropChance(), equip.getHelmetDropChance()));
}
tag.putBool("CanPickUpLoot", entity.getCanPickupItems());
}
use of org.bukkit.inventory.EntityEquipment in project Glowstone by GlowstoneMC.
the class LivingEntityStore method load.
// these tags that apply to living entities only are documented as global:
// - short "Air"
// - string "CustomName"
// - bool "CustomNameVisible"
// todo: the following tags
// - float "AbsorptionAmount"
// - short "HurtTime"
// - int "HurtByTimestamp"
// - short "DeathTime"
// - bool "PersistenceRequired"
// - bool "Leashed"
// - compound "Leash"
// on ActiveEffects, bool "ShowParticles"
@Override
public void load(T entity, CompoundTag compound) {
super.load(entity, compound);
if (compound.isShort("Air")) {
entity.setRemainingAir(compound.getShort("Air"));
}
if (compound.isString("CustomName")) {
entity.setCustomName(compound.getString("CustomName"));
}
if (compound.isByte("CustomNameVisible")) {
entity.setCustomNameVisible(compound.getBool("CustomNameVisible"));
}
if (compound.isFloat("HealF")) {
entity.setHealth(compound.getFloat("HealF"));
} else if (compound.isShort("Health")) {
entity.setHealth(compound.getShort("Health"));
}
if (compound.isShort("AttackTime")) {
entity.setNoDamageTicks(compound.getShort("AttackTime"));
}
if (compound.isByte("FallFlying")) {
entity.setFallFlying(compound.getBool("FallFlying"));
}
if (compound.isList("ActiveEffects", TagType.COMPOUND)) {
for (CompoundTag effect : compound.getCompoundList("ActiveEffects")) {
// should really always have every field, but be forgiving if possible
if (!effect.isByte("Id") || !effect.isInt("Duration")) {
continue;
}
PotionEffectType type = PotionEffectType.getById(effect.getByte("Id"));
int duration = effect.getInt("Duration");
if (type == null || duration < 0) {
continue;
}
int amplifier = 0;
boolean ambient = false;
if (compound.isByte("Amplifier")) {
amplifier = compound.getByte("Amplifier");
}
if (compound.isByte("Ambient")) {
ambient = compound.getBool("Ambient");
}
// bool "ShowParticles"
entity.addPotionEffect(new PotionEffect(type, duration, amplifier, ambient), true);
}
}
EntityEquipment equip = entity.getEquipment();
if (equip != null) {
if (compound.isList("Equipment", TagType.COMPOUND)) {
List<CompoundTag> list = compound.getCompoundList("Equipment");
if (list.size() == 5) {
equip.setItemInHand(NbtSerialization.readItem(list.get(0)));
equip.setBoots(NbtSerialization.readItem(list.get(1)));
equip.setLeggings(NbtSerialization.readItem(list.get(2)));
equip.setChestplate(NbtSerialization.readItem(list.get(3)));
equip.setHelmet(NbtSerialization.readItem(list.get(4)));
}
}
if (compound.isList("DropChances", TagType.FLOAT)) {
List<Float> list = compound.getList("DropChances", TagType.FLOAT);
if (list.size() == 5) {
equip.setItemInHandDropChance(list.get(0));
equip.setBootsDropChance(list.get(1));
equip.setLeggingsDropChance(list.get(2));
equip.setChestplateDropChance(list.get(3));
equip.setHelmetDropChance(list.get(4));
}
}
}
if (compound.isByte("CanPickUpLoot")) {
entity.setCanPickupItems(compound.getBool("CanPickUpLoot"));
}
if (compound.isList("Attributes", TagType.COMPOUND)) {
List<CompoundTag> attributes = compound.getCompoundList("Attributes");
AttributeManager am = entity.getAttributeManager();
for (CompoundTag tag : attributes) {
if (tag.isString("Name") && tag.isDouble("Base")) {
List<Modifier> modifiers = null;
if (tag.isList("Modifiers", TagType.COMPOUND)) {
modifiers = new ArrayList<>();
List<CompoundTag> modifierTags = tag.getCompoundList("Modifiers");
for (CompoundTag modifierTag : modifierTags) {
if (modifierTag.isDouble("Amount") && modifierTag.isString("Name") && modifierTag.isInt("Operation") && modifierTag.isLong("UUIDLeast") && modifierTag.isLong("UUIDMost")) {
modifiers.add(new Modifier(modifierTag.getString("Name"), new UUID(modifierTag.getLong("UUIDLeast"), modifierTag.getLong("UUIDMost")), modifierTag.getDouble("Amount"), (byte) modifierTag.getInt("Operation")));
}
}
}
am.setProperty(tag.getString("Name"), tag.getDouble("Base"), modifiers);
}
}
}
}
use of org.bukkit.inventory.EntityEquipment in project Essentials by drtshock.
the class SpawnMob method changeMobData.
private static void changeMobData(final CommandSource sender, final EntityType type, final Entity spawned, final String inputData, final User target) throws Exception {
String data = inputData;
if (data.isEmpty()) {
sender.sendMessage(tl("mobDataList", StringUtil.joinList(MobData.getValidHelp(spawned))));
}
if (spawned instanceof Zombie) {
((Zombie) spawned).setBaby(false);
} else if (spawned instanceof Ageable) {
((Ageable) spawned).setAdult();
}
if (spawned instanceof Zombie || type == EntityType.SKELETON) {
if (inputData.contains("armor") || inputData.contains("armour")) {
final EntityEquipment invent = ((LivingEntity) spawned).getEquipment();
if (inputData.contains("noarmor") || inputData.contains("noarmour")) {
invent.clear();
} else if (inputData.contains("diamond")) {
invent.setBoots(new ItemStack(Material.DIAMOND_BOOTS, 1));
invent.setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS, 1));
invent.setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE, 1));
invent.setHelmet(new ItemStack(Material.DIAMOND_HELMET, 1));
} else if (inputData.contains("gold")) {
invent.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
invent.setLeggings(new ItemStack(Material.GOLD_LEGGINGS, 1));
invent.setChestplate(new ItemStack(Material.GOLD_CHESTPLATE, 1));
invent.setHelmet(new ItemStack(Material.GOLD_HELMET, 1));
} else if (inputData.contains("leather")) {
invent.setBoots(new ItemStack(Material.LEATHER_BOOTS, 1));
invent.setLeggings(new ItemStack(Material.LEATHER_LEGGINGS, 1));
invent.setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE, 1));
invent.setHelmet(new ItemStack(Material.LEATHER_HELMET, 1));
} else {
invent.setBoots(new ItemStack(Material.IRON_BOOTS, 1));
invent.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
invent.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
invent.setHelmet(new ItemStack(Material.IRON_HELMET, 1));
}
invent.setBootsDropChance(0f);
invent.setLeggingsDropChance(0f);
invent.setChestplateDropChance(0f);
invent.setHelmetDropChance(0f);
}
}
MobData newData = MobData.fromData(spawned, data);
while (newData != null) {
newData.setData(spawned, target.getBase(), data);
data = data.replace(newData.getMatched(), "");
newData = MobData.fromData(spawned, data);
}
}
use of org.bukkit.inventory.EntityEquipment in project Essentials by drtshock.
the class SpawnMob method defaultMobData.
private static void defaultMobData(final EntityType type, final Entity spawned) {
if (type == EntityType.SKELETON) {
final EntityEquipment invent = ((LivingEntity) spawned).getEquipment();
InventoryWorkaround.setItemInMainHand(invent, new ItemStack(Material.BOW, 1));
InventoryWorkaround.setItemInMainHandDropChance(invent, 0.1f);
invent.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
invent.setBootsDropChance(0.0f);
}
if (type == EntityType.PIG_ZOMBIE) {
final PigZombie zombie = ((PigZombie) spawned);
setVillager(zombie, false);
final EntityEquipment invent = zombie.getEquipment();
InventoryWorkaround.setItemInMainHand(invent, new ItemStack(Material.GOLD_SWORD, 1));
InventoryWorkaround.setItemInMainHandDropChance(invent, 0.1f);
invent.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
invent.setBootsDropChance(0.0f);
}
if (type == EntityType.ZOMBIE) {
final Zombie zombie = ((Zombie) spawned);
setVillager(zombie, false);
final EntityEquipment invent = zombie.getEquipment();
invent.setBoots(new ItemStack(Material.GOLD_BOOTS, 1));
invent.setBootsDropChance(0.0f);
}
if (type == EntityType.HORSE) {
((Horse) spawned).setJumpStrength(1.2);
}
}
Aggregations