BloodMagic/src/main/java/WayofTime/bloodmagic/livingArmour/tracker/StatTrackerArrowShot.java
Nicholas Ignoffo 4035d91151 Run migration mappings
Everything is still broken, but at least we reduced the amount of errors by hundreds, if not thousands.
2019-09-22 12:55:43 -07:00

104 lines
3.2 KiB
Java

package WayofTime.bloodmagic.livingArmour.tracker;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.livingArmour.StatTracker;
import WayofTime.bloodmagic.livingArmour.LivingArmour;
import WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeArrowShot;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class StatTrackerArrowShot extends StatTracker {
public static HashMap<LivingArmour, Integer> changeMap = new HashMap<>();
public static int[] shotsRequired = new int[]{50, 200, 700, 1500, 3000};
public int totalShots = 0;
@Override
public String getUniqueIdentifier() {
return BloodMagic.MODID + ".tracker.trickShot";
}
@Override
public void resetTracker() {
this.totalShots = 0;
}
@Override
public void readFromNBT(CompoundNBT tag) {
totalShots = tag.getInteger(BloodMagic.MODID + ".tracker.trickShot");
}
@Override
public void writeToNBT(CompoundNBT tag) {
tag.setInteger(BloodMagic.MODID + ".tracker.trickShot", totalShots);
}
@Override
public boolean onTick(World world, PlayerEntity player, LivingArmour livingArmour) {
if (changeMap.containsKey(livingArmour)) {
int change = Math.abs(changeMap.get(livingArmour));
if (change > 0) {
totalShots += Math.abs(changeMap.get(livingArmour));
changeMap.put(livingArmour, 0);
this.markDirty();
return true;
}
}
return false;
}
@Override
public void onDeactivatedTick(World world, PlayerEntity player, LivingArmour livingArmour) {
if (changeMap.containsKey(livingArmour)) {
changeMap.remove(livingArmour);
}
}
@Override
public List<LivingArmourUpgrade> getUpgrades() {
List<LivingArmourUpgrade> upgradeList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
if (totalShots >= shotsRequired[i]) {
upgradeList.add(new LivingArmourUpgradeArrowShot(i));
}
}
return upgradeList;
}
@Override
public double getProgress(LivingArmour livingArmour, int currentLevel) {
return Utils.calculateStandardProgress(totalShots, shotsRequired, currentLevel);
}
@Override
public boolean providesUpgrade(String key) {
return key.equals(BloodMagic.MODID + ".upgrade.arrowShot");
}
@Override
public void onArmourUpgradeAdded(LivingArmourUpgrade upgrade) {
if (upgrade instanceof LivingArmourUpgradeArrowShot) {
int level = upgrade.getUpgradeLevel();
if (level < shotsRequired.length) {
totalShots = Math.max(totalShots, shotsRequired[level]);
this.markDirty();
}
}
}
public static void incrementCounter(LivingArmour armour) {
changeMap.put(armour, changeMap.containsKey(armour) ? changeMap.get(armour) + 1 : 1);
}
}