From 9f7cc25ef5abc7527c11445cb6405932f3e3306c Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 24 Aug 2021 19:01:34 +0700 Subject: [PATCH] Stats! --- .../mc/otm/OverdriveThatMatters.java | 1 + .../java/ru/dbotthepony/mc/otm/Registry.java | 22 +++++++++++++++++++ .../android/feature/AndroidNanobotsArmor.java | 10 ++++++++- .../feature/AndroidNanobotsRegeneration.java | 10 ++++++++- .../mc/otm/capability/AndroidCapability.java | 4 ++++ .../overdrive_that_matters/lang/en_us.json | 4 ++++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 561d8d6d5..70f2e1e14 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -56,6 +56,7 @@ public class OverdriveThatMatters { FMLJavaModLoadingContext.get().getModEventBus().register(Registry.Menus.class); FMLJavaModLoadingContext.get().getModEventBus().register(Registry.AndroidFeatures.class); FMLJavaModLoadingContext.get().getModEventBus().register(Registry.AndroidResearch.class); + FMLJavaModLoadingContext.get().getModEventBus().register(Registry.Stats.class); FMLJavaModLoadingContext.get().getModEventBus().addListener(AndroidCapability::registerEffects); diff --git a/src/main/java/ru/dbotthepony/mc/otm/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/Registry.java index 09e61bb4c..5d05cc08a 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/Registry.java @@ -4,6 +4,9 @@ import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.stats.StatFormatter; +import net.minecraft.stats.StatType; +import net.minecraft.stats.Stats; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.food.FoodProperties; import net.minecraft.world.inventory.MenuType; @@ -14,6 +17,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.registries.ForgeRegistry; import net.minecraftforge.registries.RegistryBuilder; import ru.dbotthepony.mc.otm.android.AndroidFeature; @@ -153,6 +157,11 @@ public class Registry { public static final ResourceLocation HYDRAULICS_OVERLOAD_1 = new ResourceLocation(OverdriveThatMatters.MOD_ID, "hydraulics_overload_1"); public static final ResourceLocation HYDRAULICS_OVERLOAD_2 = new ResourceLocation(OverdriveThatMatters.MOD_ID, "hydraulics_overload_2"); public static final ResourceLocation HYDRAULICS_OVERLOAD_3 = new ResourceLocation(OverdriveThatMatters.MOD_ID, "hydraulics_overload_3"); + + // stats + public static final ResourceLocation DAMAGE_ABSORBED = new ResourceLocation(OverdriveThatMatters.MOD_ID, "damage_absorbed"); + public static final ResourceLocation HEALTH_REGENERATED = new ResourceLocation(OverdriveThatMatters.MOD_ID, "health_regenerated"); + public static final ResourceLocation POWER_CONSUMED = new ResourceLocation(OverdriveThatMatters.MOD_ID, "power_consumed"); } public static class Blocks { @@ -606,4 +615,17 @@ public class Registry { // OverdriveThatMatters.LOGGER.info("Registered screens"); } } + + public static class Stats { + @SubscribeEvent + public static void registerVanilla(final FMLCommonSetupEvent event) { + net.minecraft.core.Registry.register(net.minecraft.core.Registry.CUSTOM_STAT, Names.DAMAGE_ABSORBED, Names.DAMAGE_ABSORBED); + net.minecraft.core.Registry.register(net.minecraft.core.Registry.CUSTOM_STAT, Names.HEALTH_REGENERATED, Names.HEALTH_REGENERATED); + net.minecraft.core.Registry.register(net.minecraft.core.Registry.CUSTOM_STAT, Names.POWER_CONSUMED, Names.POWER_CONSUMED); + + net.minecraft.stats.Stats.CUSTOM.get(Names.DAMAGE_ABSORBED, StatFormatter.DIVIDE_BY_TEN); + net.minecraft.stats.Stats.CUSTOM.get(Names.HEALTH_REGENERATED, StatFormatter.DIVIDE_BY_TEN); + net.minecraft.stats.Stats.CUSTOM.get(Names.POWER_CONSUMED, StatFormatter.DIVIDE_BY_TEN); + } + } } diff --git a/src/main/java/ru/dbotthepony/mc/otm/android/feature/AndroidNanobotsArmor.java b/src/main/java/ru/dbotthepony/mc/otm/android/feature/AndroidNanobotsArmor.java index 492e3c52d..e369c9628 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/android/feature/AndroidNanobotsArmor.java +++ b/src/main/java/ru/dbotthepony/mc/otm/android/feature/AndroidNanobotsArmor.java @@ -1,8 +1,10 @@ package ru.dbotthepony.mc.otm.android.feature; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.event.entity.living.LivingHurtEvent; import ru.dbotthepony.mc.otm.OverdriveThatMatters; +import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.android.AndroidFeature; import ru.dbotthepony.mc.otm.android.AndroidFeatureType; import ru.dbotthepony.mc.otm.capability.IAndroidCapability; @@ -78,7 +80,13 @@ public class AndroidNanobotsArmor extends AndroidFeature { if (absorbed > 0.1f) { var required = ENERGY_PER_HITPOINT.multiply(new BigDecimal(Float.toString(absorbed))); var extracted = capability.extractEnergyInner(required, false); - event.setAmount(event.getAmount() - absorbed * extracted.divide(required, MatteryCapability.ROUND_RULES).floatValue()); + var real_absorbed = absorbed * extracted.divide(required, MatteryCapability.ROUND_RULES).floatValue(); + event.setAmount(event.getAmount() - real_absorbed); + + if (capability.getEntity() instanceof ServerPlayer ply) { + ply.awardStat(Registry.Names.DAMAGE_ABSORBED, Math.round(real_absorbed * 10f)); + } + layers--; } } diff --git a/src/main/java/ru/dbotthepony/mc/otm/android/feature/AndroidNanobotsRegeneration.java b/src/main/java/ru/dbotthepony/mc/otm/android/feature/AndroidNanobotsRegeneration.java index fba62657d..7c5d19d99 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/android/feature/AndroidNanobotsRegeneration.java +++ b/src/main/java/ru/dbotthepony/mc/otm/android/feature/AndroidNanobotsRegeneration.java @@ -1,7 +1,9 @@ package ru.dbotthepony.mc.otm.android.feature; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.event.entity.living.LivingHurtEvent; +import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.android.AndroidFeature; import ru.dbotthepony.mc.otm.android.AndroidFeatureType; import ru.dbotthepony.mc.otm.capability.IAndroidCapability; @@ -41,7 +43,13 @@ public class AndroidNanobotsRegeneration extends AndroidFeature { if (extract.compareTo(BigDecimal.ZERO) > 0) { heal_ticks = Math.min(heal_ticks + 1, level); - ent.heal(missing * extract.divide(ENERGY_PER_HITPOINT, MatteryCapability.ROUND_RULES).floatValue()); + var heal = missing * extract.divide(ENERGY_PER_HITPOINT, MatteryCapability.ROUND_RULES).floatValue(); + ent.heal(heal); + + if (capability.getEntity() instanceof ServerPlayer ply) { + ply.awardStat(Registry.Names.HEALTH_REGENERATED, Math.round(heal * 10f)); + } + ticks_passed = 0; } } diff --git a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapability.java b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapability.java index 7594b3be8..7d58f724a 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapability.java +++ b/src/main/java/ru/dbotthepony/mc/otm/capability/AndroidCapability.java @@ -417,6 +417,10 @@ public class AndroidCapability implements ICapabilityProvider, IAndroidCapabilit if (!simulate) { energy_stored = new_energy; + + if (ent instanceof ServerPlayer ply) { + ply.awardStat(Registry.Names.POWER_CONSUMED, drained.intValue() * 10); + } } return drained; diff --git a/src/main/resources/assets/overdrive_that_matters/lang/en_us.json b/src/main/resources/assets/overdrive_that_matters/lang/en_us.json index 7765c5ea6..140826152 100644 --- a/src/main/resources/assets/overdrive_that_matters/lang/en_us.json +++ b/src/main/resources/assets/overdrive_that_matters/lang/en_us.json @@ -76,6 +76,10 @@ "android_research.overdrive_that_matters.nanobots_armor_strength": "Nanobots armor build speed %s", "android_research.overdrive_that_matters.nanobots_armor_strength.description": "Increases impact absorption strength of nanobots", + "stat.overdrive_that_matters.health_regenerated": "Damage regenerated by nanobots", + "stat.overdrive_that_matters.damage_absorbed": "Damage absorbed by nanobots", + "stat.overdrive_that_matters.power_consumed": "MtE burnt as Android", + "otm.suffix.merge": "%s %s", "otm.suffix.kilo": "%s k%s",