From 437dc1b96e501639cbcb66afc506027fe8ad435e Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 1 Dec 2015 23:35:09 -0800 Subject: [PATCH] Tweaks to damage. It now uses the DamageSource correctly --- .../api/DamageSourceBloodMagic.java | 10 ++ .../bloodmagic/api/network/SoulNetwork.java | 63 ++++++------ .../item/ItemSacrificialDagger.java | 95 +++++-------------- .../assets/bloodmagic/lang/en_US.lang | 3 + 4 files changed, 70 insertions(+), 101 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/api/DamageSourceBloodMagic.java b/src/main/java/WayofTime/bloodmagic/api/DamageSourceBloodMagic.java index e67cd442..60b46a9d 100644 --- a/src/main/java/WayofTime/bloodmagic/api/DamageSourceBloodMagic.java +++ b/src/main/java/WayofTime/bloodmagic/api/DamageSourceBloodMagic.java @@ -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())); } } diff --git a/src/main/java/WayofTime/bloodmagic/api/network/SoulNetwork.java b/src/main/java/WayofTime/bloodmagic/api/network/SoulNetwork.java index d28b1a0a..b06cdb46 100644 --- a/src/main/java/WayofTime/bloodmagic/api/network/SoulNetwork.java +++ b/src/main/java/WayofTime/bloodmagic/api/network/SoulNetwork.java @@ -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); } } } diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemSacrificialDagger.java b/src/main/java/WayofTime/bloodmagic/item/ItemSacrificialDagger.java index 1c63c9c0..eea0c7af 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemSacrificialDagger.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemSacrificialDagger.java @@ -1,12 +1,15 @@ package WayofTime.bloodmagic.item; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.api.BloodMagicAPI; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.DamageSourceBloodMagic; import WayofTime.bloodmagic.api.altar.IBloodAltar; import WayofTime.bloodmagic.api.event.SacrificeKnifeUsedEvent; +import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.api.util.helper.PlayerHelper; import WayofTime.bloodmagic.api.util.helper.PlayerSacrificeHelper; +import WayofTime.bloodmagic.util.helper.TextHelper; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -23,6 +26,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import java.util.Arrays; import java.util.List; public class ItemSacrificialDagger extends Item { @@ -52,28 +56,12 @@ public class ItemSacrificialDagger extends Item { } @Override - public void addInformation(ItemStack stack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { -// if (AlchemicalWizardry.wimpySettings) - { -// par3List.add(StatCollector.translateToLocal("tooltip.sacrificialdagger.desc1")); - } -// else - { - par3List.add(StatCollector.translateToLocal("tooltip.sacrificialdagger.desc2")); - par3List.add(StatCollector.translateToLocal("tooltip.sacrificialdagger.desc3")); - } + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) { + list.addAll(Arrays.asList(TextHelper.cutLongString(TextHelper.localizeEffect("tooltip.BloodMagic.sacrificialDagger.desc")))); } - /** - * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount - */ @Override public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int itemInUseCount) { -// if(itemInUseCount < 32) -// { -// return; -// } - PlayerSacrificeHelper.sacrificePlayerHealth(player); } @@ -82,9 +70,6 @@ public class ItemSacrificialDagger extends Item { return 72000; } - /** - * returns the action that specifies what animation to play when the items is being used - */ @Override public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.BOW; @@ -92,6 +77,10 @@ public class ItemSacrificialDagger extends Item { @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + + if (PlayerHelper.isFakePlayer(player)) + return stack; + if (this.canUseForSacrifice(stack)) { player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); return stack; @@ -99,21 +88,16 @@ public class ItemSacrificialDagger extends Item { if (!player.capabilities.isCreativeMode) { SacrificeKnifeUsedEvent evt = new SacrificeKnifeUsedEvent(player, true, true, 2); - if (MinecraftForge.EVENT_BUS.post(evt)) { + if (MinecraftForge.EVENT_BUS.post(evt)) return stack; - } if (evt.shouldDrainHealth) { - player.setHealth(player.getHealth() - 2); + player.hurtResistantTime = 0; + player.attackEntityFrom(BloodMagicAPI.getDamageSource(), 2.0F); } - if (!evt.shouldFillAltar) { + if (!evt.shouldFillAltar) return stack; - } - } - - if (PlayerHelper.isFakePlayer(player)) { - return stack; } double posX = player.posX; @@ -125,37 +109,24 @@ public class ItemSacrificialDagger extends Item { float f2 = f * f * 0.7F - 0.5F; float f3 = f * f * 0.6F - 0.7F; - for (int l = 0; l < 8; ++l) { + for (int l = 0; l < 8; ++l) world.spawnParticle(EnumParticleTypes.REDSTONE, posX + Math.random() - Math.random(), posY + Math.random() - Math.random(), posZ + Math.random() - Math.random(), f1, f2, f3); - } - if (!world.isRemote && PlayerHelper.isFakePlayer(player)) { + if (!world.isRemote && PlayerHelper.isFakePlayer(player)) return stack; - } -// if (player.isPotionActive(AlchemicalWizardry.customPotionSoulFray)) - { -// findAndFillAltar(world, player, 20); - } -// else - { - findAndFillAltar(world, player, 200); - } - - if (player.getHealth() <= 0.001f) { - player.onDeath(new DamageSourceBloodMagic()); - } + // TODO - Check if SoulFray is active + findAndFillAltar(world, player, 200); return stack; } - public void findAndFillAltar(World world, EntityPlayer player, int amount) { + private void findAndFillAltar(World world, EntityPlayer player, int amount) { BlockPos pos = player.getPosition(); IBloodAltar altarEntity = getAltar(world, pos); - if (altarEntity == null) { + if (altarEntity == null) return; - } altarEntity.sacrificialDaggerCall(amount, false); altarEntity.startCycle(); @@ -182,18 +153,8 @@ public class ItemSacrificialDagger extends Item { @Override public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { - if (!world.isRemote && entity instanceof EntityPlayer) { + if (!world.isRemote && entity instanceof EntityPlayer) this.setUseForSacrifice(stack, this.isPlayerPreparedForSacrifice(world, (EntityPlayer) entity)); - } - } - - @Override - public String getItemStackDisplayName(ItemStack stack) { -// if (AlchemicalWizardry.wimpySettings) - { -// return "Sacrificial Orb"; - } - return super.getItemStackDisplayName(stack); } public boolean isPlayerPreparedForSacrifice(World world, EntityPlayer player) { @@ -201,19 +162,13 @@ public class ItemSacrificialDagger extends Item { } public boolean canUseForSacrifice(ItemStack stack) { - NBTTagCompound tag = stack.getTagCompound(); - - return tag != null && tag.getBoolean("sacrifice"); + stack = NBTHelper.checkNBT(stack); + return stack.getTagCompound().getBoolean(Constants.NBT.SACRIFICE); } public void setUseForSacrifice(ItemStack stack, boolean sacrifice) { - NBTTagCompound tag = stack.getTagCompound(); - if (tag == null) { - tag = new NBTTagCompound(); - stack.setTagCompound(tag); - } - - tag.setBoolean("sacrifice", sacrifice); + stack = NBTHelper.checkNBT(stack); + stack.getTagCompound().setBoolean(Constants.NBT.SACRIFICE, sacrifice); } @Override diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index c5539752..1fbbaef7 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -117,6 +117,8 @@ tooltip.BloodMagic.sigil.water.desc=&oInfinite water, anyone? tooltip.BloodMagic.sigil.lava.desc=&oHOT! DO NOT EAT tooltip.BloodMagic.sigil.void.desc=&oBetter than a Swiffer®! +tooltip.BloodMagic.sacrificialDagger.desc=Just a prick of the finger will suffice... + tooltip.BloodMagic.pack.selfSacrifice.desc=This pack really chafes... tooltip.BloodMagic.pack.sacrifice.desc=Description tooltip.BloodMagic.pack.stored=Stored: %d LP @@ -129,6 +131,7 @@ tooltip.BloodMagic.activationCrystal.creative=Creative Only - Activates any ritu chat.BloodMagic.altarMaker.setTier=Set Tier to: %d chat.BloodMagic.altarMaker.building=Building a Tier %d Altar chat.BloodMagic.altarMaker.destroy=Destroyed a Tier %d Altar +chat.BloodMagic.damageSource=%s's soul became too weak # JustEnoughItems jei.BloodMagic.recipe.altar=Blood Altar