Tweaks to damage. It now uses the DamageSource correctly

This commit is contained in:
Nick 2015-12-01 23:35:09 -08:00
parent 305b5e165f
commit 437dc1b96e
4 changed files with 70 additions and 101 deletions

View file

@ -1,6 +1,10 @@
package WayofTime.bloodmagic.api;
import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IChatComponent;
public class DamageSourceBloodMagic extends DamageSource {
@ -8,5 +12,11 @@ public class DamageSourceBloodMagic extends DamageSource {
super("bloodMagic");
setDamageBypassesArmor();
setDamageIsAbsolute();
}
@Override
public IChatComponent getDeathMessage(EntityLivingBase livingBase) {
return new ChatComponentText(TextHelper.localizeEffect("chat.BloodMagic.damageSource", livingBase.getName()));
}
}

View file

@ -100,46 +100,47 @@ public class SoulNetwork extends WorldSavedData {
* @return - Whether the action should be performed.
*/
public boolean syphonAndDamage(int toSyphon) {
if (getPlayer().worldObj.isRemote)
return false;
if (!Strings.isNullOrEmpty(mapName)) {
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(player, mapName, getPlayer().getHeldItem(), toSyphon);
if (MinecraftForge.EVENT_BUS.post(event))
if (getPlayer() != null) {
if (getPlayer().worldObj.isRemote)
return false;
int drainAmount = syphon(event.syphon);
if (!Strings.isNullOrEmpty(mapName)) {
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(player, mapName, getPlayer().getHeldItem(), toSyphon);
if (drainAmount == 0 || event.shouldDamage)
hurtPlayer(event.syphon);
if (MinecraftForge.EVENT_BUS.post(event))
return false;
return event.getResult() != Event.Result.DENY;
int drainAmount = syphon(event.syphon);
if (drainAmount == 0 || event.shouldDamage)
hurtPlayer(event.syphon);
return event.getResult() != Event.Result.DENY;
}
int amount = syphon(toSyphon);
hurtPlayer(toSyphon - amount);
return true;
}
int amount = syphon(toSyphon);
hurtPlayer(toSyphon - amount);
return true;
return false;
}
public void hurtPlayer(int syphon) {
getPlayer().addPotionEffect(new PotionEffect(Potion.confusion.getId(), 20));
if (syphon < 100 && syphon > 0) {
if (!getPlayer().capabilities.isCreativeMode) {
getPlayer().setHealth((getPlayer().getHealth() - 1));
public void hurtPlayer(float syphon) {
if (getPlayer() != null) {
getPlayer().addPotionEffect(new PotionEffect(Potion.confusion.getId(), 20));
if (syphon < 100 && syphon > 0) {
if (!getPlayer().capabilities.isCreativeMode) {
getPlayer().hurtResistantTime = 0;
getPlayer().attackEntityFrom(BloodMagicAPI.getDamageSource(), 1.0F);
}
if (getPlayer().getHealth() <= 0.0005f)
getPlayer().onDeath(BloodMagicAPI.getDamageSource());
}
} else if (syphon >= 100) {
if (!getPlayer().capabilities.isCreativeMode) {
for (int i = 0; i < ((syphon + 99) / 100); i++) {
getPlayer().setHealth((getPlayer().getHealth() - 1));
if (getPlayer().getHealth() <= 0.0005f) {
getPlayer().onDeath(BloodMagicAPI.getDamageSource());
break;
} else if (syphon >= 100) {
if (!getPlayer().capabilities.isCreativeMode) {
for (int i = 0; i < ((syphon + 99) / 100); i++) {
getPlayer().hurtResistantTime = 0;
getPlayer().attackEntityFrom(BloodMagicAPI.getDamageSource(), 1.0F);
}
}
}