diff --git a/src/main/java/com/hbm/main/MainRegistry.java b/src/main/java/com/hbm/main/MainRegistry.java index 3058b4ea8..f1ec80bfc 100644 --- a/src/main/java/com/hbm/main/MainRegistry.java +++ b/src/main/java/com/hbm/main/MainRegistry.java @@ -865,6 +865,7 @@ public class MainRegistry { TileEntityNukeCustom.registerBombItems(); ArmorUtil.register(); HazmatRegistry.registerHazmats(); + DamageResistanceHandler.init(); FluidContainerRegistry.register(); BlockToolConversion.registerRecipes(); AchievementHandler.register(); diff --git a/src/main/java/com/hbm/util/DamageResistanceHandler.java b/src/main/java/com/hbm/util/DamageResistanceHandler.java new file mode 100644 index 000000000..cc16fd0f0 --- /dev/null +++ b/src/main/java/com/hbm/util/DamageResistanceHandler.java @@ -0,0 +1,79 @@ +package com.hbm.util; + +import java.util.HashMap; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; + +public class DamageResistanceHandler { + + public static HashMap itemStats = new HashMap(); + public static HashMap, ResistanceStats> entityStats = new HashMap(); + + public static void init() { + + } + + public static float calculateDamage(EntityLivingBase entity, DamageSource damage, float amount, float pierceDT, float pierce) { + if(damage.isDamageAbsolute() || damage.isUnblockable()) return amount; + + String key = damage.damageType; + float dt = 0; + float dr = 0; + + //TODO add category resistance stats + + for(int i = 1; i <= 4; i++) { + ItemStack armor = entity.getEquipmentInSlot(i); + if(armor == null) continue; + ResistanceStats stats = itemStats.get(armor.getItem()); + if(stats == null) continue; + Resistance res = stats.resistances.get(key); + if(res == null) continue; + dt += res.threshold; + dr += res.resistance; + } + + ResistanceStats inateResistance = entityStats.get(entity.getClass()); + if(inateResistance != null) { + Resistance res = inateResistance.resistances.get(key); + if(res != null) { + dt += res.threshold; + dr += res.resistance; + } + } + + dt = Math.max(0F, dt - pierceDT); + if(dt <= amount) return 0F; + + amount -= dt; + dr *= MathHelper.clamp_float(1F - pierce, 0F, 1F); + + return amount *= (1F - dr); + } + + public static class ResistanceStats { + + public HashMap resistances = new HashMap(); + + public ResistanceStats add(String type, float threshold, float resistance) { + resistances.put(type, new Resistance(threshold, resistance)); + return this; + } + } + + public static class Resistance { + + public float threshold; + public float resistance; + + public Resistance(float threshold, float resistance) { + this.threshold = threshold; + this.resistance = resistance; + } + } +} diff --git a/src/main/java/com/hbm/util/EntityDamageUtil.java b/src/main/java/com/hbm/util/EntityDamageUtil.java index 8c7e5161a..4e8a1b58d 100644 --- a/src/main/java/com/hbm/util/EntityDamageUtil.java +++ b/src/main/java/com/hbm/util/EntityDamageUtil.java @@ -21,7 +21,7 @@ import net.minecraftforge.common.ForgeHooks; public class EntityDamageUtil { /** - * Attacks the given entity twice, based on a piecring percentage. The second hit sets the damage source to bypass armor. + * Attacks the given entity twice, based on a piercing percentage. The second hit sets the damage source to bypass armor. * The damage source is modified, so you can't reuse damage source instances. */ @Deprecated public static boolean attackEntityFromArmorPiercing(Entity victim, DamageSource src, float damage, float piercing) { diff --git a/src/main/resources/assets/hbm/my_hecking_realism.png b/src/main/resources/assets/hbm/my_hecking_realism.png new file mode 100644 index 000000000..dab8b86bc Binary files /dev/null and b/src/main/resources/assets/hbm/my_hecking_realism.png differ