Search in sources :

Example 6 with SoldierUpgradeInst

use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method onDeath.

@Override
public void onDeath(DamageSource damageSource) {
    super.onDeath(damageSource);
    if (!this.worldObj.isRemote) {
        if (damageSource.isFireDamage() && this.dollItem != null) {
            ItemStack brickItem = new ItemStack(RegistryItems.dollBrick, this.dollItem.stackSize);
            brickItem.setTagCompound(this.dollItem.getTagCompound());
            this.dollItem = brickItem;
        }
        ArrayList<ItemStack> drops = new ArrayList<>();
        if (!this.nexusSpawn) {
            if (this.dollItem != null) {
                drops.add(this.dollItem.copy());
            }
            for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                upg.getUpgrade().onItemDrop(this, upg, drops);
            }
            drops.removeAll(Collections.singleton(null));
            for (ItemStack drop : drops) {
                this.entityDropItem(drop, 0.0F);
            }
        }
        for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
            upg.getUpgrade().onSoldierDeath(this, upg, damageSource);
        }
        for (SoldierEffectInst eff : this.p_effects.values()) {
            eff.getEffect().onSoldierDeath(this, eff, damageSource);
        }
    }
}
Also used : SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst) SoldierEffectInst(de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst) ItemStack(net.minecraft.item.ItemStack)

Example 7 with SoldierUpgradeInst

use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method writeEntityToNBT.

@Override
public void writeEntityToNBT(NBTTagCompound nbt) {
    super.writeEntityToNBT(nbt);
    nbt.setString("team", this.getClayTeam());
    nbt.setByte("miscColor", this.dataWatcher.getWatchableObjectByte(DW_MISC_COLOR));
    nbt.setByte("isRareOrUnique", this.dataWatcher.getWatchableObjectByte(DW_IS_TEXTURE_RARE_OR_UNIQUE));
    nbt.setInteger("textureIndex", this.dataWatcher.getWatchableObjectInt(DW_TEXTURE_INDEX));
    nbt.setBoolean("canMove", this.canMove);
    nbt.setBoolean("nexusSpawned", this.nexusSpawn);
    if (this.dollItem != null) {
        NBTTagCompound stackNbt = new NBTTagCompound();
        this.dollItem.writeToNBT(stackNbt);
        nbt.setTag("dollItem", stackNbt);
    }
    NBTTagList upgNbtList = new NBTTagList();
    for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
        NBTTagCompound savedUpg = new NBTTagCompound();
        savedUpg.setString("name", SoldierUpgrades.getName(upg.getUpgrade()));
        savedUpg.setTag("data", upg.getNbtTag());
        NBTTagCompound upgItem = upg.saveStoredItemToNBT();
        if (upgItem != null) {
            savedUpg.setTag("item", upgItem);
        }
        upgNbtList.appendTag(savedUpg);
    }
    nbt.setTag("upgrade", upgNbtList);
    NBTTagList effNbtList = new NBTTagList();
    for (SoldierEffectInst eff : this.p_effects.values()) {
        NBTTagCompound savedEff = new NBTTagCompound();
        savedEff.setString("name", SoldierEffects.getEffectName(eff.getEffect()));
        savedEff.setTag("data", eff.getNbtTag());
        effNbtList.appendTag(savedEff);
    }
    nbt.setTag("effect", effNbtList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst) SoldierEffectInst(de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst)

Example 8 with SoldierUpgradeInst

use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method readEntityFromNBT.

@Override
public void readEntityFromNBT(NBTTagCompound nbt) {
    super.readEntityFromNBT(nbt);
    this.dataWatcher.updateObject(DW_TEAM, nbt.getString("team"));
    this.dataWatcher.updateObject(DW_MISC_COLOR, nbt.getByte("miscColor"));
    this.dataWatcher.updateObject(DW_IS_TEXTURE_RARE_OR_UNIQUE, nbt.getByte("isRareOrUnique"));
    this.dataWatcher.updateObject(DW_TEXTURE_INDEX, nbt.getInteger("textureIndex"));
    this.canMove = nbt.getBoolean("canMove");
    this.nexusSpawn = nbt.getBoolean("nexusSpawned");
    if (nbt.hasKey("dollItem")) {
        this.dollItem = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("dollItem"));
    }
    NBTTagList upgNbtList = nbt.getTagList("upgrade", NBT.TAG_COMPOUND);
    for (int i = 0; i < upgNbtList.tagCount(); i++) {
        NBTTagCompound savedUpg = upgNbtList.getCompoundTagAt(i);
        SoldierUpgradeInst upgInst = new SoldierUpgradeInst(SoldierUpgrades.getUpgrade(savedUpg.getString("name")));
        upgInst.setNbtTag(savedUpg.getCompoundTag("data"));
        if (savedUpg.hasKey("item")) {
            upgInst.readStoredItemFromNBT(savedUpg.getCompoundTag("item"));
        }
        this.p_upgrades.put(upgInst.getUpgrade(), upgInst);
    }
    NBTTagList effNbtList = nbt.getTagList("effect", NBT.TAG_COMPOUND);
    for (int i = 0; i < effNbtList.tagCount(); i++) {
        NBTTagCompound savedEff = effNbtList.getCompoundTagAt(i);
        SoldierEffectInst effInst = new SoldierEffectInst(SoldierEffects.getEffect(savedEff.getString("name")));
        effInst.setNbtTag(savedEff.getCompoundTag("data"));
        this.p_effects.put(effInst.getEffect(), effInst);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst) SoldierEffectInst(de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst)

Example 9 with SoldierUpgradeInst

use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method addUpgrade.

public SoldierUpgradeInst addUpgrade(ASoldierUpgrade upgrade, ItemStack stack) {
    if (!this.hasUpgrade(upgrade)) {
        SoldierUpgradeInst upgradeInst = new SoldierUpgradeInst(upgrade);
        upgrade.onConstruct(this, upgradeInst);
        if (stack != null) {
            upgrade.onPickup(this, upgradeInst, stack);
        }
        for (SoldierUpgradeInst inst : this.p_upgrades.values()) {
            inst.getUpgrade().onUpgradeAdded(this, inst, upgradeInst);
        }
        this.p_upgrades.put(upgrade, upgradeInst);
        return upgradeInst;
    } else {
        return null;
    }
}
Also used : SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst)

Example 10 with SoldierUpgradeInst

use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst in project ClaySoldiersMod by SanAndreasP.

the class UpgradeHelperShearBlade method onPickup.

@Override
public void onPickup(EntityClayMan clayMan, SoldierUpgradeInst upgradeInst, ItemStack stack) {
    ASoldierUpgrade upgrade = null;
    ItemStack savedItem = null;
    if (stack.getItem() == RegistryItems.shearBlade) {
        if (!clayMan.hasUpgrade(AUpgradeLeftHanded.class)) {
            upgrade = SoldierUpgrades.getUpgrade(SoldierUpgrades.UPG_SHEARLEFT);
            savedItem = stack;
        } else if (!clayMan.hasUpgrade(AUpgradeRightHanded.class)) {
            upgrade = SoldierUpgrades.getUpgrade(SoldierUpgrades.UPG_SHEARRIGHT);
            savedItem = stack;
        }
    } else {
        if (!clayMan.hasUpgrade(AUpgradeLeftHanded.class)) {
            clayMan.entityDropItem(new ItemStack(RegistryItems.shearBlade, 1), 0.0F);
            upgrade = SoldierUpgrades.getUpgrade(SoldierUpgrades.UPG_SHEARLEFT);
            savedItem = new ItemStack(RegistryItems.shearBlade, 1);
        } else if (!clayMan.hasUpgrade(AUpgradeRightHanded.class)) {
            clayMan.entityDropItem(new ItemStack(RegistryItems.shearBlade, 1), 0.0F);
            upgrade = SoldierUpgrades.getUpgrade(SoldierUpgrades.UPG_SHEARRIGHT);
            savedItem = new ItemStack(RegistryItems.shearBlade, 1);
        }
    }
    if (upgrade != null) {
        if (savedItem != stack) {
            stack.setCount(stack.getCount() - 1);
        }
        SoldierUpgradeInst newUpgrade = clayMan.addUpgrade(upgrade);
        this.consumeItem(savedItem, newUpgrade);
        clayMan.playSound("random.pop", 1.0F, 1.0F);
    }
}
Also used : AUpgradeLeftHanded(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.lefthand.AUpgradeLeftHanded) ASoldierUpgrade(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SoldierUpgradeInst (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst)12 ASoldierUpgrade (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade)6 SoldierEffectInst (de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ItemStack (net.minecraft.item.ItemStack)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 MutableFloat (org.apache.commons.lang3.mutable.MutableFloat)2 Pair (de.sanandrew.core.manpack.util.javatuples.Pair)1 IMount (de.sanandrew.mods.claysoldiers.entity.mount.IMount)1 ASoldierEffect (de.sanandrew.mods.claysoldiers.util.soldier.effect.ASoldierEffect)1 AUpgradeLeftHanded (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.lefthand.AUpgradeLeftHanded)1 Entry (java.util.Map.Entry)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1