use of de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst 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.upgrade.ISoldierUpgradeInst in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method pickupUpgrade.
public void pickupUpgrade(EntityItem item) {
ItemStack stack = item.getItem();
if (stack.getCount() < 1) {
return;
}
ISoldierUpgrade upg = UpgradeRegistry.INSTANCE.getUpgrade(stack);
if (upg == null || this.hasUpgrade(upg, upg.getType(this))) {
return;
}
ISoldierUpgradeInst upgInst = this.addUpgrade(upg, upg.getType(this), stack);
if (upgInst != null) {
if (Arrays.asList(UpgradeRegistry.getFuncCalls(upg)).contains(EnumUpgFunctions.ON_PICKUP)) {
upg.onPickup(this, item, upgInst);
}
}
}
use of de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method addUpgradeInternal.
private void addUpgradeInternal(ISoldierUpgradeInst instance) {
ISoldierUpgrade upgrade = instance.getUpgrade();
UpgradeEntry entry = new UpgradeEntry(upgrade, upgrade.getType(this));
this.upgradeMap.put(entry, instance);
if (upgrade.syncData()) {
this.upgradeSyncList.add(instance);
}
Arrays.asList(UpgradeRegistry.getFuncCalls(upgrade)).forEach(func -> {
Queue<ISoldierUpgradeInst> upgList = this.upgradeFuncMap.get(func).computeIfAbsent(upgrade.getPriority(), k -> new ConcurrentLinkedQueue<>());
upgList.add(instance);
});
switch(upgrade.getType(this)) {
case MAIN_HAND:
this.setMainhandUpg(true);
break;
case OFF_HAND:
this.setOffhandUpg(true);
break;
case BEHAVIOR:
this.setBehaviorUpg(true);
break;
}
}
use of de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst in project ClaySoldiersMod by SanAndreasP.
the class UpgradeCoal method onAdded.
@Override
public void onAdded(ISoldier<?> soldier, ItemStack stack, ISoldierUpgradeInst upgradeInst) {
if (!soldier.getEntity().world.isRemote) {
soldier.getEntity().playSound(SoundEvents.ENTITY_ITEM_PICKUP, 0.2F, ((MiscUtils.RNG.randomFloat() - MiscUtils.RNG.randomFloat()) * 0.7F + 1.0F) * 2.0F);
stack.shrink(1);
}
ISoldierUpgradeInst bPowderInst = soldier.getUpgradeInstance(Upgrades.MC_BLAZEPOWDER, EnumUpgradeType.MISC);
if (bPowderInst != null) {
bPowderInst.getNbtData().setShort("uses", (short) (bPowderInst.getNbtData().getShort("uses") + 1));
}
}
Aggregations