damage handling crap

This commit is contained in:
Boblet 2024-11-20 16:48:37 +01:00
parent b0a90d08f7
commit 4469efa601
3 changed files with 126 additions and 8 deletions

View File

@ -97,7 +97,7 @@ public class TileEntityMachineWoodBurner extends TileEntityMachineBase implement
this.maxBurnTime = this.burnTime = burn;
ItemStack container = slots[0].getItem().getContainerItem(slots[0]);
this.decrStackSize(0, 1);
if(slots[0] == null) slots[0] = container.copy();
if(slots[0] == null && container != null) slots[0] = container.copy();
this.markChanged();
}
}

View File

@ -65,6 +65,7 @@ public class CrucibleUtil {
}
for(MaterialStack stack : stacks) {
if(stack.material == null) continue;
int amountToPour = Math.min(stack.amount, quanta);
MaterialStack toPour = new MaterialStack(stack.material, amountToPour);

View File

@ -24,7 +24,7 @@ public class EntityDamageUtil {
* Attacks the given entity twice, based on a piecring percentage. The second hit sets the damage source to bypass armor.
* The damage source is modified, so you can't reuse damage source instances.
*/
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) {
if(src.isUnblockable() || piercing == 0) return victim.attackEntityFrom(src, damage);
@ -58,14 +58,14 @@ public class EntityDamageUtil {
}
}
public static float getDamageAfterTax(EntityLivingBase living, DamageSource source, float amount) {
@Deprecated public static float getDamageAfterTax(EntityLivingBase living, DamageSource source, float amount) {
amount = ForgeHooks.onLivingHurt(living, source, amount);
if(amount <= 0) return 0;
amount = applyArmorCalculations(living, source, amount);
return amount;
}
public static boolean attackArmorPiercing(EntityLivingBase living, DamageSource sourceDamageCalc, DamageSource sourceArmorPiercing, float amount, float piercing) {
@Deprecated public static boolean attackArmorPiercing(EntityLivingBase living, DamageSource sourceDamageCalc, DamageSource sourceArmorPiercing, float amount, float piercing) {
if(piercing <= 0) return living.attackEntityFrom(sourceDamageCalc, amount);
//damage intended to pass the armor
float afterTax = getDamageAfterTax(living, sourceDamageCalc, amount);
@ -73,11 +73,128 @@ public class EntityDamageUtil {
float reduced = Math.max(amount - afterTax, 0F);
//damage that would pass + damage tthat wouldn't pass * AP percentage
return attackEntityFromIgnoreIFrame(living, sourceArmorPiercing, Math.max(afterTax + (reduced * piercing), 0F));
}
public static boolean attackEntityFromNT(EntityLivingBase living, DamageSource source, float amount, boolean ignoreIFrame, boolean allowSpecialCancel, double knockbackMultiplier) {
if(ForgeHooks.onLivingAttack(living, source, amount) && allowSpecialCancel) return false;
if(living.isEntityInvulnerable()) return false;
if(living.worldObj.isRemote) return false;
living.entityAge = 0;
if(living.getHealth() <= 0.0F) return false;
if(source.isFireDamage() && living.isPotionActive(Potion.fireResistance)) return false;
living.limbSwingAmount = 1.5F;
boolean didAttackRegister = true;
if(living.hurtResistantTime > living.maxHurtResistantTime / 2.0F && !ignoreIFrame) {
if(amount <= living.lastDamage) { return false; }
damageEntityNT(living, source, amount - living.lastDamage); //TODO: override
living.lastDamage = amount;
didAttackRegister = false;
} else {
living.lastDamage = amount;
living.prevHealth = living.getHealth();
living.hurtResistantTime = living.maxHurtResistantTime;
damageEntityNT(living, source, amount); //TODO: override
living.hurtTime = living.maxHurtTime = 10;
}
living.attackedAtYaw = 0.0F;
Entity entity = source.getEntity();
if(entity != null) {
if(entity instanceof EntityLivingBase) {
living.setRevengeTarget((EntityLivingBase) entity);
}
if(entity instanceof EntityPlayer) {
living.recentlyHit = 100;
living.attackingPlayer = (EntityPlayer) entity;
} else if(entity instanceof EntityTameable) {
EntityTameable entitywolf = (EntityTameable) entity;
if(entitywolf.isTamed()) {
living.recentlyHit = 100;
living.attackingPlayer = null;
}
}
}
if(didAttackRegister) {
living.worldObj.setEntityState(living, (byte) 2);
if(source != DamageSource.drown) setBeenAttacked(living); //#
if(entity != null) {
double deltaX = entity.posX - living.posX;
double deltaZ;
for(deltaZ = entity.posZ - living.posZ; deltaX * deltaX + deltaZ * deltaZ < 1.0E-4D; deltaZ = (Math.random() - Math.random()) * 0.01D) {
deltaX = (Math.random() - Math.random()) * 0.01D;
}
living.attackedAtYaw = (float) (Math.atan2(deltaZ, deltaX) * 180.0D / Math.PI) - living.rotationYaw;
if(knockbackMultiplier > 0) living.knockBack(entity, amount, deltaX * knockbackMultiplier, deltaZ * knockbackMultiplier);
} else {
living.attackedAtYaw = (float) ((int) (Math.random() * 2.0D) * 180);
}
}
String sound;
if(living.getHealth() <= 0.0F) {
sound = getDeathSound(living);
if(didAttackRegister && sound != null) living.playSound(sound, getSoundVolume(living), getSoundPitch(living)); //#
living.onDeath(source);
} else {
sound = getHurtSound(living);
if(didAttackRegister && sound != null) living.playSound(sound, getSoundVolume(living), getSoundPitch(living)); //#
}
return true;
}
public static void damageEntityNT(EntityLivingBase living, DamageSource source, float amount) {
if(!living.isEntityInvulnerable()) {
amount = ForgeHooks.onLivingHurt(living, source, amount);
if(amount <= 0) return;
amount = applyArmorCalculationsNT(living, source, amount);
amount = applyPotionDamageCalculations(living, source, amount);
float originalAmount = amount;
amount = Math.max(amount - living.getAbsorptionAmount(), 0.0F);
living.setAbsorptionAmount(living.getAbsorptionAmount() - (originalAmount - amount));
if(amount != 0.0F) {
float health = living.getHealth();
living.setHealth(health - amount);
living.func_110142_aN().func_94547_a(source, health, amount);
living.setAbsorptionAmount(living.getAbsorptionAmount() - amount);
}
}
}
public static float applyArmorCalculationsNT(EntityLivingBase living, DamageSource source, float amount) {
if(!source.isUnblockable()) {
int i = 25 - living.getTotalArmorValue();
float armor = amount * (float) i;
damageArmorNT(living, amount);
amount = armor / 25.0F;
//TODO: special handling depending on armor stats
}
return amount;
}
public static void damageArmorNT(EntityLivingBase living, float amount) {
}
/** Currently just a copy of the vanilla damage code */
public static boolean attackEntityFromNT(EntityLivingBase living, DamageSource source, float amount) {
@Deprecated public static boolean attackEntityFromNT(EntityLivingBase living, DamageSource source, float amount) {
if(ForgeHooks.onLivingAttack(living, source, amount))
return false;
@ -204,7 +321,7 @@ public class EntityDamageUtil {
try { return (float) m.invoke(living); } catch(Exception e) { } return 1F;
}
public static void damageEntity(EntityLivingBase living, DamageSource source, float amount) {
@Deprecated public static void damageEntity(EntityLivingBase living, DamageSource source, float amount) {
if(!living.isEntityInvulnerable()) {
amount = ForgeHooks.onLivingHurt(living, source, amount);
if(amount <= 0)
@ -224,11 +341,11 @@ public class EntityDamageUtil {
}
}
public static float applyArmorCalculations(EntityLivingBase living, DamageSource source, float amount) {
@Deprecated public static float applyArmorCalculations(EntityLivingBase living, DamageSource source, float amount) {
if(!source.isUnblockable()) {
int i = 25 - living.getTotalArmorValue();
float armor = amount * (float) i;
//living.damageArmor(p_70655_2_); //unused
//living.damageArmor(amount); //unused
amount = armor / 25.0F;
}