Search in sources :

Example 6 with FairyData

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());
}
Also used : FairyData(com.teamwizardry.wizardry.api.entity.fairy.FairyData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) Vec3d(net.minecraft.util.math.Vec3d)

Example 7 with FairyData

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));
}
Also used : FairyData(com.teamwizardry.wizardry.api.entity.fairy.FairyData) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 8 with FairyData

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);
}
Also used : Entity(net.minecraft.entity.Entity) IMiscCapability(com.teamwizardry.wizardry.api.capability.player.miscdata.IMiscCapability) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityFairy(com.teamwizardry.wizardry.common.entity.EntityFairy) FairyData(com.teamwizardry.wizardry.api.entity.fairy.FairyData) List(java.util.List) UUID(java.util.UUID)

Example 9 with FairyData

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);
}
Also used : FairyData(com.teamwizardry.wizardry.api.entity.fairy.FairyData) IManaCapability(com.teamwizardry.wizardry.api.capability.player.mana.IManaCapability)

Example 10 with FairyData

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileJar(com.teamwizardry.wizardry.common.tile.TileJar) FairyData(com.teamwizardry.wizardry.api.entity.fairy.FairyData) EntityFairy(com.teamwizardry.wizardry.common.entity.EntityFairy) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FairyData (com.teamwizardry.wizardry.api.entity.fairy.FairyData)14 ItemStack (net.minecraft.item.ItemStack)6 EntityFairy (com.teamwizardry.wizardry.common.entity.EntityFairy)5 BlockPos (net.minecraft.util.math.BlockPos)5 Vec3d (net.minecraft.util.math.Vec3d)5 UUID (java.util.UUID)4 IMiscCapability (com.teamwizardry.wizardry.api.capability.player.miscdata.IMiscCapability)3 Entity (net.minecraft.entity.Entity)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 InterpBezier3D (com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D)2 IManaCapability (com.teamwizardry.wizardry.api.capability.player.mana.IManaCapability)2 List (java.util.List)2 Minecraft (net.minecraft.client.Minecraft)2 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 GlStateManager (net.minecraft.client.renderer.GlStateManager)2 Tessellator (net.minecraft.client.renderer.Tessellator)2 Path (net.minecraft.pathfinding.Path)2 PathNavigate (net.minecraft.pathfinding.PathNavigate)2 ResourceLocation (net.minecraft.util.ResourceLocation)2