Search in sources :

Example 1 with ASoldierUpgrade

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

the class UpgradeHelperGlass method canBePickedUp.

@Override
public boolean canBePickedUp(EntityClayMan clayMan, ItemStack stack, ASoldierUpgrade upgrade) {
    ASoldierUpgrade mainUpgrade = SoldierUpgrades.getUpgrade(SoldierUpgrades.UPG_GLASS);
    if (clayMan.hasUpgrade(mainUpgrade)) {
        SoldierUpgradeInst upgInst = clayMan.getUpgrade(mainUpgrade);
        short rColor = upgInst.getNbtTag().getShort("rightColor");
        short dmg = (stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane) || stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass)) ? (short) stack.getItemDamage() : -1;
        return upgInst.getNbtTag().getShort("leftColor") == rColor && dmg != rColor;
    } else {
        return true;
    }
}
Also used : ASoldierUpgrade(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst)

Example 2 with ASoldierUpgrade

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

the class EntityClayMan method updateEntityActionState.

@Override
protected void updateEntityActionState() {
    // BUGFIX: fixes movement in blocks w/o collision box (snow layer, torches, tall grass, possibly cobweb?, etc.)
    if (!this.hasPath()) {
        if (this.entityToAttack != null) {
            this.setPathToEntity(BugfixHelper.getPathEntityToEntity(this.worldObj, this, this.entityToAttack, 16.0F, true, false, false, true));
        } else if (this.p_targetFollow != null) {
            this.setPathToEntity(BugfixHelper.getPathEntityToEntity(this.worldObj, this, this.p_targetFollow, 16.0F, true, false, false, true));
        } else if ((this.rand.nextInt(180) == 0 || this.rand.nextInt(120) == 0 || this.fleeingTick > 0) && this.entityAge < 100) {
            this.updateWanderPath();
        }
    }
    super.updateEntityActionState();
    if (!this.worldObj.isRemote) {
        this.p_entitiesInRange = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getTargetArea());
        if (this.entityToAttack == null) {
            if (rand.nextInt(4) != 0 && p_targetFollow == null) {
                Collection<EntityClayMan> claymen = this.getSoldiersInRange();
                for (EntityClayMan uberhaxornova : claymen) {
                    if (uberhaxornova.isDead || rand.nextInt(3) != 0) {
                        continue;
                    }
                    if (!this.checkIfValidTarget(uberhaxornova)) {
                        continue;
                    }
                    this.entityToAttack = uberhaxornova;
                    break;
                }
            } else {
                if (this.p_targetFollow == null) {
                    Collection<EntityItem> items = this.getItemsInRange();
                    items: for (EntityItem seamus : items) {
                        if (!this.canEntityBeSeen(seamus)) {
                            continue;
                        }
                        ASoldierUpgrade upgrade = SoldierUpgrades.getUpgrade(seamus.getEntityItem());
                        if (upgrade != null) {
                            if (this.hasUpgrade(upgrade) || !upgrade.canBePickedUp(this, seamus.getEntityItem(), null)) {
                                continue;
                            } else {
                                for (SoldierUpgradeInst upgradeInst : this.p_upgrades.values()) {
                                    if (upgrade == upgradeInst.getUpgrade() || !upgrade.canBePickedUp(this, seamus.getEntityItem(), upgradeInst.getUpgrade())) {
                                        continue items;
                                    }
                                }
                            }
                        } else {
                            continue;
                        }
                        this.p_targetFollow = seamus;
                        break;
                    }
                } else {
                    if (this.p_targetFollow.isDead) {
                        this.p_targetFollow = null;
                    } else if (!this.canEntityBeSeen(this.p_targetFollow)) {
                        this.p_targetFollow = null;
                    }
                    if (this.p_targetFollow instanceof EntityItem && this.p_targetFollow.getDistanceToEntity(this) < 0.5F) {
                        EntityItem itemEntity = (EntityItem) this.p_targetFollow;
                        ASoldierUpgrade upgrade = SoldierUpgrades.getUpgrade(itemEntity.getEntityItem());
                        if (upgrade != null) {
                            this.addUpgrade(upgrade, itemEntity.getEntityItem());
                            if (itemEntity.getEntityItem().stackSize <= 0) {
                                itemEntity.setDead();
                            }
                            this.p_targetFollow = null;
                        }
                    } else if (this.p_targetFollow instanceof IMount) {
                        if (this.p_targetFollow.riddenByEntity != null) {
                            this.p_targetFollow = null;
                        } else if (this.p_targetFollow.getDistanceToEntity(this) < 0.5D) {
                            this.mountEntity(this.p_targetFollow);
                            this.p_targetFollow = null;
                        }
                    }
                }
                if (this.p_targetFollow == null && this.ridingEntity == null) {
                    Collection<IMount> items = this.getMountsInRange();
                    for (IMount mount : items) {
                        EntityLivingBase slyfox = (EntityLivingBase) mount;
                        if (this.rand.nextInt(4) != 0 || !this.canEntityBeSeen(slyfox) || slyfox.riddenByEntity != null) {
                            continue;
                        }
                        this.p_targetFollow = slyfox;
                        break;
                    }
                }
            }
        } else {
            if (this.entityToAttack.isDead || !this.canEntityBeSeen(this.entityToAttack) || (this.entityToAttack instanceof EntityClayMan && !this.checkIfValidTarget((EntityClayMan) this.entityToAttack))) {
                this.entityToAttack = null;
            } else if (this.attackTime == 0) {
                this.attackTime = 5;
                MutableFloat atkRng = new MutableFloat(this.riddenByEntity != null ? 0.6F : 0.7F);
                for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                    upg.getUpgrade().getAttackRange(this, upg, this.entityToAttack, atkRng);
                }
                if (this.getDistanceToEntity(this.entityToAttack) < atkRng.floatValue() && this.entityToAttack instanceof EntityLivingBase && !this.entityToAttack.isEntityInvulnerable()) {
                    EntityLivingBase target = (EntityLivingBase) this.entityToAttack;
                    if (target.hurtTime == 0) {
                        MutableFloat damage = new MutableFloat(ModConfig.soldierBaseDamage);
                        if (target instanceof EntityClayMan) {
                            EntityClayMan soldierTarget = (EntityClayMan) target;
                            soldierTarget.knockBack = Triplet.with(0.8D, 0.8D, 0.8D);
                            for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                                upg.getUpgrade().onSoldierAttack(this, upg, soldierTarget, damage);
                            }
                        }
                        if (target.attackEntityFrom(DamageSource.causeMobDamage(this), damage.getValue()) && target instanceof EntityClayMan) {
                            for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                                upg.getUpgrade().onSoldierDamage(this, upg, (EntityClayMan) target);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) IMount(de.sanandrew.mods.claysoldiers.entity.mount.IMount) ASoldierUpgrade(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with ASoldierUpgrade

use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade 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 4 with ASoldierUpgrade

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

the class UpgradeDiamond method onConstruct.

@Override
public void onConstruct(EntityClayMan clayMan, SoldierUpgradeInst upgradeInst) {
    IAttributeInstance attrib = clayMan.getEntityAttribute(SharedMonsterAttributes.maxHealth);
    attrib.setBaseValue(attrib.getBaseValue() * 10.0D);
    clayMan.heal(clayMan.getMaxHealth());
    ASoldierUpgrade[] upgrades = clayMan.getAvailableUpgrades();
    for (ASoldierUpgrade upgrade : upgrades) {
        NBTTagCompound upgNbt = clayMan.getUpgrade(upgrade).getNbtTag();
        if (upgNbt.hasKey(NBT_USES, NBT.TAG_COMPOUND)) {
            upgNbt.setShort(NBT_USES, (short) (upgNbt.getShort(NBT_USES) * 2));
        }
    }
    clayMan.addUpgrade(SoldierUpgrades.getUpgrade(SoldierUpgrades.UPG_SUGAR));
}
Also used : ASoldierUpgrade(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 5 with ASoldierUpgrade

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

the class EntityClayMan method attackEntityFrom.

@Override
public boolean attackEntityFrom(DamageSource source, float damage) {
    if (!(source.getEntity() instanceof EntityPlayer) && source != IDisruptable.DISRUPT_DAMAGE) {
        if (this.ridingEntity != null && rand.nextInt(4) == 0) {
            this.ridingEntity.attackEntityFrom(source, damage);
            return false;
        }
    } else {
        damage = 10000.0F;
    }
    if (!this.worldObj.isRemote) {
        for (Entry<ASoldierUpgrade, SoldierUpgradeInst> upgrade : this.p_upgrades.entrySet()) {
            SoldierUpgradeInst upg = upgrade.getValue();
            MutableFloat newDamage = new MutableFloat(damage);
            if (upg.getUpgrade().onSoldierHurt(this, upg, source, newDamage)) {
                return false;
            } else {
                damage = newDamage.floatValue();
            }
        }
    }
    return super.attackEntityFrom(source, damage);
}
Also used : MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) ASoldierUpgrade(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst)

Aggregations

ASoldierUpgrade (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade)11 SoldierUpgradeInst (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 IThrowableUpgrade (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.IThrowableUpgrade)2 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)2 MutableFloat (org.apache.commons.lang3.mutable.MutableFloat)2 Pair (de.sanandrew.core.manpack.util.javatuples.Pair)1 EntityClayMan (de.sanandrew.mods.claysoldiers.entity.EntityClayMan)1 IMount (de.sanandrew.mods.claysoldiers.entity.mount.IMount)1 ASoldierEffect (de.sanandrew.mods.claysoldiers.util.soldier.effect.ASoldierEffect)1 SoldierEffectInst (de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst)1 AUpgradeLeftHanded (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.lefthand.AUpgradeLeftHanded)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1