mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
damage resistance handler crap
This commit is contained in:
parent
4469efa601
commit
d791e7e8e4
@ -865,6 +865,7 @@ public class MainRegistry {
|
|||||||
TileEntityNukeCustom.registerBombItems();
|
TileEntityNukeCustom.registerBombItems();
|
||||||
ArmorUtil.register();
|
ArmorUtil.register();
|
||||||
HazmatRegistry.registerHazmats();
|
HazmatRegistry.registerHazmats();
|
||||||
|
DamageResistanceHandler.init();
|
||||||
FluidContainerRegistry.register();
|
FluidContainerRegistry.register();
|
||||||
BlockToolConversion.registerRecipes();
|
BlockToolConversion.registerRecipes();
|
||||||
AchievementHandler.register();
|
AchievementHandler.register();
|
||||||
|
|||||||
79
src/main/java/com/hbm/util/DamageResistanceHandler.java
Normal file
79
src/main/java/com/hbm/util/DamageResistanceHandler.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,7 +21,7 @@ import net.minecraftforge.common.ForgeHooks;
|
|||||||
public class EntityDamageUtil {
|
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.
|
* 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) {
|
@Deprecated public static boolean attackEntityFromArmorPiercing(Entity victim, DamageSource src, float damage, float piercing) {
|
||||||
|
|||||||
BIN
src/main/resources/assets/hbm/my_hecking_realism.png
Normal file
BIN
src/main/resources/assets/hbm/my_hecking_realism.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
Loading…
x
Reference in New Issue
Block a user