use of com.teamwizardry.wizardry.api.entity.fairy.FairyData in project Wizardry by TeamWizardry.
the class EntityFairy method writeEntityToNBT.
@Override
public void writeEntityToNBT(NBTTagCompound compound) {
super.writeEntityToNBT(compound);
FairyData dataFairy = getDataFairy();
if (dataFairy != null)
NBTHelper.setCompoundTag(compound, "fairy", dataFairy.serializeNBT());
NBTTagCompound stackCompound = new NBTTagCompound();
getDataHeldItem().writeToNBT(stackCompound);
NBTHelper.setCompoundTag(compound, "held_item", stackCompound);
UUID uuid = getChainedFairy();
if (uuid != null) {
NBTHelper.setUniqueId(compound, "chained_fairy", uuid);
}
Vec3d targetLook = getLookTarget();
if (targetLook != null) {
compound.setDouble("look_target_x", targetLook.x);
compound.setDouble("look_target_y", targetLook.y);
compound.setDouble("look_target_z", targetLook.z);
}
if (currentTarget != null) {
compound.setDouble("current_target_x", currentTarget.x);
compound.setDouble("current_target_y", currentTarget.y);
compound.setDouble("current_target_z", currentTarget.z);
}
BlockPos origin = originPos;
if (origin != null) {
compound.setInteger("origin_x", origin.getX());
compound.setInteger("origin_y", origin.getY());
compound.setInteger("origin_z", origin.getZ());
}
BlockPos target = targetPos;
if (target != null) {
compound.setInteger("target_x", target.getX());
compound.setInteger("target_y", target.getY());
compound.setInteger("target_z", target.getZ());
}
compound.setBoolean("moving", moving);
compound.setBoolean("stunned", stunned);
NBTHelper.setString(compound, "fairy_task", fairyTaskController.getLocation().toString());
}
use of com.teamwizardry.wizardry.api.entity.fairy.FairyData in project Wizardry by TeamWizardry.
the class EntityFairy method setupTamedAI.
@Override
protected void setupTamedAI() {
FairyData dataFairy = getDataFairy();
if (dataFairy != null && dataFairy.isDepressed)
return;
if (this.avoidEntity == null) {
this.avoidEntity = new EntityAIAvoidEntity<>(this, EntityPlayer.class, 16.0F, 2, 3);
}
this.tasks.removeTask(this.avoidEntity);
if (!this.isTamed()) {
this.tasks.addTask(0, this.avoidEntity);
}
this.tasks.addTask(0, new EntityAIAvoidEntity<>(this, EntityUnicorn.class, 16, 2, 3));
this.tasks.addTask(0, new EntityAIAvoidEntity<>(this, EntitySpiritWight.class, 16, 2, 3));
}
use of com.teamwizardry.wizardry.api.entity.fairy.FairyData in project Wizardry by TeamWizardry.
the class ItemFairyBell method itemInteractionForEntity.
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand) {
if (playerIn.world.isRemote || playerIn.isSneaking())
return super.itemInteractionForEntity(stack, playerIn, target, hand);
if (target instanceof EntityFairy) {
EntityFairy targetFairy = (EntityFairy) target;
FairyData targetData = targetFairy.getDataFairy();
if (targetData == null)
return super.itemInteractionForEntity(stack, playerIn, target, hand);
if (targetData.isDepressed) {
IMiscCapability cap = MiscCapabilityProvider.getCap(playerIn);
if (cap != null) {
UUID selected = cap.getSelectedFairyUUID();
if (selected != null && selected.equals(targetFairy.getUniqueID())) {
cap.setSelectedFairy(null);
playerIn.world.playSound(null, playerIn.getPosition(), ModSounds.TINY_BELL, SoundCategory.NEUTRAL, 1, 0.25f);
playerIn.sendStatusMessage(new TextComponentTranslation("item.wizardry:fairy_bell.status.deselected"), true);
} else if (selected != null && !selected.equals(targetFairy.getUniqueID())) {
List<Entity> list = playerIn.world.loadedEntityList;
for (Entity entity : list) {
if (entity instanceof EntityFairy && entity.getUniqueID().equals(selected)) {
if (entity.isDead)
continue;
((EntityFairy) entity).setChainedFairy(targetFairy.getUniqueID());
targetFairy.setChainedFairy(selected);
playerIn.sendStatusMessage(new TextComponentTranslation("item.wizardry:fairy_bell.status.linked_to_fairy"), true);
break;
}
}
} else {
cap.setSelectedFairy(targetFairy.getUniqueID());
boolean movingMode = NBTHelper.getBoolean(stack, "moving_mode", true);
if (!movingMode) {
playerIn.world.playSound(null, playerIn.getPosition(), ModSounds.TINY_BELL, SoundCategory.NEUTRAL, 1, 0.75f);
} else {
playerIn.world.playSound(null, playerIn.getPosition(), ModSounds.TINY_BELL, SoundCategory.NEUTRAL, 1, 1.25f);
}
playerIn.sendStatusMessage(new TextComponentTranslation(movingMode ? "item.wizardry:fairy_bell.status.fairy_moving" : "item.wizardry:fairy_bell.status.fairy_aiming"), true);
}
cap.dataChanged(playerIn);
}
}
}
return super.itemInteractionForEntity(stack, playerIn, target, hand);
}
use of com.teamwizardry.wizardry.api.entity.fairy.FairyData in project Wizardry by TeamWizardry.
the class ItemJar method getItemStackDisplayName.
@Override
public String getItemStackDisplayName(ItemStack stack) {
if (stack.getItemDamage() == 2) {
FairyData fairy = FairyData.deserialize(NBTHelper.getCompound(stack, "fairy"));
if (fairy == null)
return super.getItemStackDisplayName(stack);
IManaCapability cap = fairy.handler;
double mana = ManaManager.getMana(cap) / ManaManager.getMaxMana(cap);
boolean dulled = fairy.isDepressed;
if (dulled) {
return I18n.translateToLocal("item.wizardry.fairy_jar.dulled.name").trim();
} else if (mana > 0.25 && mana < 0.5) {
return I18n.translateToLocal("item.wizardry.fairy_jar.barely_excited.name").trim();
} else if (mana >= 0.5 && mana < 0.75) {
return I18n.translateToLocal("item.wizardry.fairy_jar.moderately_excited.name").trim();
} else if (mana > 0.75 && mana < 1) {
return I18n.translateToLocal("item.wizardry.fairy_jar.very_excited.name").trim();
} else if (mana >= 1) {
return I18n.translateToLocal("item.wizardry.fairy_jar.overloaded.name").trim();
} else
return super.getItemStackDisplayName(stack);
} else
return super.getItemStackDisplayName(stack);
}
use of com.teamwizardry.wizardry.api.entity.fairy.FairyData in project Wizardry by TeamWizardry.
the class ItemFairy method onItemUse.
@NotNull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (stack.isEmpty())
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
if (worldIn.isRemote)
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
FairyData object = FairyData.deserialize(NBTHelper.getCompound(stack, "fairy"));
if (object == null)
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof TileJar) {
TileJar jar = (TileJar) tileEntity;
if (jar.fairy != null)
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
jar.fairy = object;
jar.markDirty();
worldIn.checkLight(pos);
} else {
BlockPos offsetpos = pos.offset(facing);
EntityFairy entity = new EntityFairy(worldIn, object);
entity.setPosition(offsetpos.getX() + 0.5, offsetpos.getY() + 0.5, offsetpos.getZ() + 0.5);
entity.originPos = offsetpos;
worldIn.spawnEntity(entity);
}
stack.shrink(1);
worldIn.playSound(pos.getX(), pos.getY(), pos.getZ(), ModSounds.FAIRY, SoundCategory.BLOCKS, 1, 1, false);
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
Aggregations