damage resistance handler crap

This commit is contained in:
Boblet 2024-11-21 16:45:59 +01:00
parent 4469efa601
commit d791e7e8e4
4 changed files with 81 additions and 1 deletions

View File

@ -865,6 +865,7 @@ public class MainRegistry {
TileEntityNukeCustom.registerBombItems();
ArmorUtil.register();
HazmatRegistry.registerHazmats();
DamageResistanceHandler.init();
FluidContainerRegistry.register();
BlockToolConversion.registerRecipes();
AchievementHandler.register();

View File

@ -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<Item, ResistanceStats> itemStats = new HashMap();
public static HashMap<Class<? extends Entity>, 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<String, Resistance> 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;
}
}
}

View File

@ -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) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB