package fyresmodjam; import java.util.Random; import fyresmodjam.blessings.BlessingUtils; import fyresmodjam.misc.EntityStat; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.monster.EntityCreeper; public final class EntityLevelStat extends EntityStat { public EntityLevelStat(String name, String value) { super(name, value); } @Override public Object getNewValue(Random r) { for (int i = 1;; i++) { if (ModjamMod.r.nextInt( 5 * (Math.max(1, i / 5))) < 3) { return i; } } } @Override public String getAlteredEntityName(EntityLiving entity) { int level = 1; try { level = Integer.parseInt(entity.getEntityData() .getString(name)); } catch (Exception e) { e.printStackTrace(); } String baseName = ""; if (BlessingUtils.hasDisadvantage("Organized Foes")) { baseName += "Level " + level + " "; switch (level) { case 2: baseName = "Private"; break; case 3: baseName = "Corporal"; break; case 4: baseName = "Sergeant"; break; case 5: baseName = "Lieutenant"; break; case 6: baseName = "Captain"; break; case 7: baseName = "Major"; break; case 8: baseName = "Colonel"; break; case 9: baseName = "General"; default: if (level > 9) { baseName = "Field Marshal"; } else { baseName = "Unelisted"; } } if (!baseName.equals("Unelisted")) { baseName += " "; } baseName += entity.getName(); } else { baseName = (level == 5 ? "\u00A7c" : "") + entity.getName() + ", Level " + level; } return baseName; } @Override public void modifyEntity(Entity entity) { int level = 1; try { level = Integer.parseInt(entity.getEntityData() .getString(name)); } catch (Exception e) { e.printStackTrace(); } int healthGain = calculateMobHealthGain(entity, level); if (healthGain != 0) { ((EntityLivingBase) entity).getEntityAttribute( SharedMonsterAttributes.MAX_HEALTH) .setBaseValue(((EntityLivingBase) entity) .getMaxHealth() + healthGain); ((EntityLivingBase) entity).setHealth( ((EntityLivingBase) entity) .getMaxHealth() + healthGain); } if (level >= 5) { blessMob(entity); } else if (BlessingUtils.hasDisadvantage("Diabolic") && ModjamMod.r.nextInt(20) == 0) { blessMob(entity); } if (BlessingUtils.hasDisadvantage("Organized Mobs")) { equipMob((EntityLivingBase) entity, level); } } private void equipMob(EntityLivingBase entity, int level) { if (level < 2) { return; } float regionalDifficulty = entity.world .getDifficultyForLocation( entity.getPosition()).getClampedAdditionalDifficulty(); int adjustedDifficulty = (int) Math .ceil(level + regionalDifficulty); if (ModjamMod.r.nextInt(10) == 0 || adjustedDifficulty > 5) { } // TODO actually implement this } private int calculateMobHealthGain(Entity entity, int level) { int levelBase = level - 1; float adjustedMaxHealth = ((EntityLivingBase) entity) .getMaxHealth() / 4; float bonusLevel5Health; if (level >= 5) { bonusLevel5Health = ((EntityLivingBase) entity) .getMaxHealth() / 4; bonusLevel5Health *= Math.max(1, level / 5); } else { bonusLevel5Health = 0; } return (int) ((levelBase * adjustedMaxHealth) + bonusLevel5Health); } private void blessMob(Entity entity) { String chosenBlessing = BlessingUtils.getMobBlessing(); entity.getEntityData().setString("Blessing", chosenBlessing); BlessingUtils.getBlessingInstance(chosenBlessing) .correctBlessing(entity); if (entity instanceof EntityCreeper) { // TODO is it fine to comment this out? //((EntityCreeper) entity).getDataWatcher() // .updateObject(17, (byte) 1); ((EntityCreeper) entity).getEntityData() .setBoolean("powered", true); } } }