use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst 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;
}
}
use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst 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);
}
}
}
}
}
}
}
}
use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst 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()));
}
}
}
use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst 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();
}
}
use of de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst 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);
}
Aggregations