Search in sources :

Example 1 with SoldierEffectInst

use of de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method addEffect.

public SoldierEffectInst addEffect(ASoldierEffect effect) {
    if (!this.hasEffect(effect)) {
        SoldierEffectInst effectInst = new SoldierEffectInst(effect);
        effect.onConstruct(this, effectInst);
        for (SoldierEffectInst existEffect : this.p_effects.values()) {
            if (!effect.isCompatibleWith(this, effectInst, existEffect)) {
                return null;
            }
        }
        this.p_effects.put(effect, effectInst);
        return effectInst;
    } else {
        return null;
    }
}
Also used : SoldierEffectInst(de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst)

Example 2 with SoldierEffectInst

use of de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method updateUpgradeEffectRenders.

public void updateUpgradeEffectRenders() {
    if (this.worldObj.isRemote) {
        for (Byte renderId : SoldierUpgrades.getRegisteredRenderIds()) {
            long renderFlag = 1L << (renderId % 64);
            int renderStorageDw = (renderId / 64);
            long dwValue = this.p_upgradeRenderFlags[renderStorageDw];
            ASoldierUpgrade upgrade = SoldierUpgrades.getUpgrade(renderId);
            if ((dwValue & renderFlag) == renderFlag) {
                if (!this.p_upgrades.containsKey(upgrade)) {
                    this.p_upgrades.put(upgrade, new SoldierUpgradeInst(upgrade));
                }
            } else {
                this.p_upgrades.remove(upgrade);
            }
        }
        for (byte renderId : SoldierEffects.getRegisteredRenderIds()) {
            long renderFlag = 1L << (renderId % 64);
            int renderStorageDw = (renderId / 64);
            long dwValue = this.p_effectRenderFlags[renderStorageDw];
            ASoldierEffect effect = SoldierEffects.getEffect(renderId);
            if ((dwValue & renderFlag) == renderFlag) {
                if (!this.p_effects.containsKey(effect)) {
                    SoldierEffectInst effectInst = new SoldierEffectInst(effect);
                    this.p_effects.put(effect, effectInst);
                    effect.onConstruct(this, effectInst);
                }
            } else {
                this.p_effects.remove(effect);
            }
        }
    } else {
        this.p_upgradeRenderFlags[0] = 0;
        this.p_upgradeRenderFlags[1] = 0;
        this.p_effectRenderFlags[0] = 0;
        this.p_effectRenderFlags[1] = 0;
        for (SoldierUpgradeInst upgInst : this.p_upgrades.values()) {
            byte renderId = SoldierUpgrades.getRenderId(upgInst.getUpgrade());
            if (renderId >= 0) {
                long renderFlag = 1L << (renderId % 64);
                int renderStorageDw = renderId / 64;
                long prevDwValue = p_upgradeRenderFlags[renderStorageDw];
                p_upgradeRenderFlags[renderStorageDw] = prevDwValue | renderFlag;
            }
        }
        List<Pair<Byte, NBTTagCompound>> effectNbtToClt = new ArrayList<>();
        for (SoldierEffectInst effInst : this.p_effects.values()) {
            byte renderId = SoldierEffects.getRenderId(effInst.getEffect());
            if (renderId >= 0) {
                long renderFlag = 1L << (renderId % 64);
                int renderStorageDw = renderId / 64;
                long prevDwValue = this.p_effectRenderFlags[renderStorageDw];
                this.p_effectRenderFlags[renderStorageDw] = prevDwValue | renderFlag;
                if (effInst.getEffect().shouldNbtSyncToClient(this, effInst)) {
                    effectNbtToClt.add(Pair.with(renderId, effInst.getNbtTag()));
                }
            }
        }
        List<Pair<Byte, NBTTagCompound>> upgradeNbtToClt = new ArrayList<>();
        for (SoldierUpgradeInst upgInst : this.p_upgrades.values()) {
            byte renderId = SoldierUpgrades.getRenderId(upgInst.getUpgrade());
            if (renderId >= 0) {
                long renderFlag = 1L << (renderId % 64);
                int renderStorageDw = renderId / 64;
                long prevDwValue = this.p_upgradeRenderFlags[renderStorageDw];
                this.p_upgradeRenderFlags[renderStorageDw] = prevDwValue | renderFlag;
                if (upgInst.getUpgrade().shouldNbtSyncToClient(this, upgInst)) {
                    upgradeNbtToClt.add(Pair.with(renderId, upgInst.getNbtTag()));
                }
            }
        }
        PacketManager.sendToAllAround(PacketManager.PKG_SOLDIER_RENDERS, this.dimension, this.posX, this.posY, this.posZ, 64.0D, Triplet.with(this.getEntityId(), this.p_upgradeRenderFlags, this.p_effectRenderFlags));
        for (Pair<Byte, NBTTagCompound> effNbt : effectNbtToClt) {
            PacketManager.sendToAllAround(PacketManager.PKG_SOLDIER_EFFECT_NBT, this.dimension, this.posX, this.posY, this.posZ, 64.0D, Triplet.with(this.getEntityId(), effNbt.getValue0(), effNbt.getValue1()));
        }
        for (Pair<Byte, NBTTagCompound> upgNbt : upgradeNbtToClt) {
            PacketManager.sendToAllAround(PacketManager.PKG_SOLDIER_UPGRADE_NBT, this.dimension, this.posX, this.posY, this.posZ, 64.0D, Triplet.with(this.getEntityId(), upgNbt.getValue0(), upgNbt.getValue1()));
        }
    }
}
Also used : ASoldierEffect(de.sanandrew.mods.claysoldiers.util.soldier.effect.ASoldierEffect) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst) ASoldierUpgrade(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade) SoldierEffectInst(de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst) Pair(de.sanandrew.core.manpack.util.javatuples.Pair)

Example 3 with SoldierEffectInst

use of de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    this.cloakHelper.onUpdate(this.posX, this.posY, this.posZ);
    if (!this.canMove) {
        this.motionX = 0.0F;
        this.motionZ = 0.0F;
        this.isJumping = false;
    }
    this.canMove = true;
    Iterator<Map.Entry<ASoldierUpgrade, SoldierUpgradeInst>> iterUpgrades = p_upgrades.entrySet().iterator();
    while (iterUpgrades.hasNext()) {
        if (!this.worldObj.isRemote) {
            SoldierUpgradeInst upg = iterUpgrades.next().getValue();
            if (upg.getUpgrade().onUpdate(this, upg)) {
                iterUpgrades.remove();
            }
        } else {
            SoldierUpgradeInst upg = iterUpgrades.next().getValue();
            upg.getUpgrade().onClientUpdate(this, upg);
        }
    }
    Iterator<Map.Entry<ASoldierEffect, SoldierEffectInst>> iterEffects = p_effects.entrySet().iterator();
    while (iterEffects.hasNext()) {
        if (!this.worldObj.isRemote) {
            SoldierEffectInst upg = iterEffects.next().getValue();
            if (upg.getEffect().onUpdate(this, upg)) {
                iterEffects.remove();
            }
        } else {
            SoldierEffectInst upg = iterEffects.next().getValue();
            upg.getEffect().onClientUpdate(this, upg);
        }
    }
    if ((ticksExisted % 5) == 0) {
        this.updateUpgradeEffectRenders();
    }
}
Also used : Entry(java.util.Map.Entry) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst) SoldierEffectInst(de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst)

Example 4 with SoldierEffectInst

use of de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst 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 5 with SoldierEffectInst

use of de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst 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)

Aggregations

SoldierEffectInst (de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst)7 SoldierUpgradeInst (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)2 Pair (de.sanandrew.core.manpack.util.javatuples.Pair)1 EntityClayMan (de.sanandrew.mods.claysoldiers.entity.EntityClayMan)1 ASoldierEffect (de.sanandrew.mods.claysoldiers.util.soldier.effect.ASoldierEffect)1 ASoldierUpgrade (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade)1 Entry (java.util.Map.Entry)1 ItemStack (net.minecraft.item.ItemStack)1 DamageSource (net.minecraft.util.DamageSource)1