use of de.sanandrew.mods.claysoldiers.api.soldier.effect.ISoldierEffectInst in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method addEffect.
@Override
public ISoldierEffectInst addEffect(ISoldierEffect effect, int duration) {
if (effect == null) {
return null;
}
ISoldierEffectInst effInst = new SoldierEffect(effect, duration);
this.addEffectInternal(effInst);
effect.onAdded(this, effInst);
if (effect.syncData() && !this.world.isRemote) {
this.sendSyncEffects(true, effInst);
}
return effInst;
}
use of de.sanandrew.mods.claysoldiers.api.soldier.effect.ISoldierEffectInst in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method expireEffect.
// endregion
// region effects
@Override
public void expireEffect(ISoldierEffect effect) {
ISoldierEffectInst inst = this.effectMap.get(effect);
this.effectMap.remove(effect);
this.effectSyncList.remove(inst);
effect.onExpired(this, inst);
if (!this.world.isRemote) {
if (effect.syncData()) {
this.sendSyncEffects(false, inst);
}
}
}
use of de.sanandrew.mods.claysoldiers.api.soldier.effect.ISoldierEffectInst in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method readEntityFromNBT.
@Override
public void readEntityFromNBT(NBTTagCompound compound) {
super.readEntityFromNBT(compound);
String teamId = compound.getString(NBTConstants.E_SOLDIER_TEAM);
this.dataManager.set(TEAM_PARAM, UuidUtils.isStringUuid(teamId) ? UUID.fromString(teamId) : UuidUtils.EMPTY_UUID);
this.dataManager.set(TEXTURE_TYPE_PARAM, compound.getByte(NBTConstants.E_SOLDIER_TEXTYPE));
this.dataManager.set(TEXTURE_ID_PARAM, compound.getByte(NBTConstants.E_SOLDIER_TEXID));
if (compound.hasKey(NBTConstants.E_SOLDIER_DOLL, Constants.NBT.TAG_COMPOUND)) {
this.doll = new ItemStack(compound.getCompoundTag(NBTConstants.E_SOLDIER_DOLL));
}
NBTTagList upgrades = compound.getTagList(NBTConstants.E_SOLDIER_UPGRADES, Constants.NBT.TAG_COMPOUND);
for (int i = 0, max = upgrades.tagCount(); i < max; i++) {
NBTTagCompound upgNbt = upgrades.getCompoundTagAt(i);
String idStr = upgNbt.getString(NBTConstants.N_UPGRADE_ID);
byte type = upgNbt.getByte(NBTConstants.N_UPGRADE_TYPE);
if (UuidUtils.isStringUuid(idStr)) {
ItemStack upgStack = new ItemStack(upgNbt.getCompoundTag(NBTConstants.N_UPGRADE_ITEM));
ISoldierUpgrade upgrade = UpgradeRegistry.INSTANCE.getUpgrade(UUID.fromString(idStr));
if (upgrade != null) {
ISoldierUpgradeInst upgInst = new SoldierUpgrade(upgrade, EnumUpgradeType.VALUES[type], upgStack);
upgInst.setNbtData(upgNbt.getCompoundTag(NBTConstants.N_UPGRADE_NBT));
upgrade.onLoad(this, upgInst, upgNbt);
this.addUpgradeInternal(upgInst);
}
}
}
NBTTagList effects = compound.getTagList(NBTConstants.E_SOLDIER_EFFECTS, Constants.NBT.TAG_COMPOUND);
for (int i = 0, max = effects.tagCount(); i < max; i++) {
NBTTagCompound effectNbt = effects.getCompoundTagAt(i);
String idStr = effectNbt.getString(NBTConstants.N_EFFECT_ID);
if (UuidUtils.isStringUuid(idStr)) {
ISoldierEffect effect = EffectRegistry.INSTANCE.getEffect(UUID.fromString(idStr));
if (effect != null) {
ISoldierEffectInst effInst = new SoldierEffect(effect, effectNbt.getInteger(NBTConstants.N_EFFECT_DURATION));
effInst.setNbtData(effectNbt.getCompoundTag(NBTConstants.N_EFFECT_NBT));
effect.onLoad(this, effInst, effectNbt);
this.addEffectInternal(effInst);
}
}
}
this.dwBooleans.readFromNbt(compound);
}
use of de.sanandrew.mods.claysoldiers.api.soldier.effect.ISoldierEffectInst in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method writeSpawnData.
@Override
public void writeSpawnData(ByteBuf buffer) {
PacketSyncUpgrades pktu = new PacketSyncUpgrades(this, true, this.upgradeSyncList.stream().map(entry -> new UpgradeEntry(entry.getUpgrade(), entry.getUpgradeType())).toArray(UpgradeEntry[]::new));
pktu.toBytes(buffer);
PacketSyncEffects pkte = new PacketSyncEffects(this, true, this.effectSyncList.toArray(new ISoldierEffectInst[0]));
pkte.toBytes(buffer);
}
use of de.sanandrew.mods.claysoldiers.api.soldier.effect.ISoldierEffectInst in project ClaySoldiersMod by SanAndreasP.
the class PacketSyncEffects method applyEffects.
public void applyEffects(EntityClaySoldier soldier) {
for (int i = 0, max = this.effects.length; i < max; i++) {
ISoldierEffect eff = this.effects[i];
int duration = this.durations[i];
if (eff != null && this.add) {
ISoldierEffectInst inst = soldier.addEffect(eff, duration);
if (this.effectNBT.containsKey(eff)) {
inst.setNbtData(this.effectNBT.get(eff));
}
} else {
soldier.expireEffect(eff);
}
}
}
Aggregations