Skip to content

Commit

Permalink
Balance essence reaping
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jul 4, 2024
1 parent ece658e commit f6dab4a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 39 deletions.
65 changes: 40 additions & 25 deletions src/main/java/mod/emt/harkenscythe/events/HSLivingDeathEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
Expand All @@ -33,31 +34,25 @@ public static void onScytheReap(LivingDeathEvent event)
{
EntityLivingBase entity = event.getEntityLiving();
World world = entity.getEntityWorld();
DamageSource damageSource = event.getSource();
Entity trueSource = damageSource.getTrueSource();
if (trueSource instanceof EntityPlayer && isPlayerReap((EntityPlayer) trueSource, damageSource))
if (!world.isRemote)
{
spawnSoul(world, entity);
}
else if (trueSource instanceof HSEntityHarbinger)
{
spawnSpectralEntity(world, entity, entity.getPosition());
}
else if (!world.isRemote && entity.getEntityData().getBoolean("IsSpectral"))
{
entity.dropItem(HSItems.soul_essence, 1);
DamageSource damageSource = event.getSource();
Entity trueSource = damageSource.getTrueSource();
if (trueSource instanceof EntityPlayer && isSuccessfulReap((EntityPlayer) trueSource, damageSource))
{
spawnSoul(world, entity);
}
else if (trueSource instanceof HSEntityHarbinger)
{
spawnSpectralEntity(world, entity, entity.getPosition());
}
else if (entity.getEntityData().getBoolean("IsSpectral"))
{
entity.dropItem(HSItems.soul_essence, 1);
}
}
}

public static void spawnSoul(World world, EntityLivingBase entity)
{
if (entity.getEntityData().getBoolean("IsSpectral") || entity instanceof HSEntityGlobin) return;
HSEntitySoul soul = new HSEntitySoul(world, entity);
soul.setPosition(entity.posX, entity.posY, entity.posZ);
if (!world.isRemote) world.spawnEntity(soul);
world.playSound(null, entity.getPosition(), HSSoundEvents.ESSENCE_SOUL_SPAWN, SoundCategory.NEUTRAL, 1.0F, 1.5F / (world.rand.nextFloat() * 0.4F + 1.2F));
}

public static void spawnSpectralEntity(World world, EntityLivingBase entity, BlockPos pos)
{
if (entity != null)
Expand All @@ -77,7 +72,7 @@ public static void spawnSpectralEntity(World world, EntityLivingBase entity, Blo
entity = new HSEntityEctoglobin(world);
}
entity.setPosition(pos.getX(), pos.getY(), pos.getZ());
if (!world.isRemote) world.spawnEntity(entity);
world.spawnEntity(entity);
world.playSound(null, pos, HSSoundEvents.ESSENCE_SOUL_SPAWN, SoundCategory.NEUTRAL, 1.0F, 1.5F / (world.rand.nextFloat() * 0.4F + 1.2F));
//if (false && entity instanceof EntityCreature && !(entity instanceof EntityMob))
//{
Expand All @@ -88,12 +83,32 @@ public static void spawnSpectralEntity(World world, EntityLivingBase entity, Blo
}
}

private static boolean isPlayerReap(EntityPlayer player, DamageSource damageSource)
private static void spawnSoul(World world, EntityLivingBase entity)
{
if (entity.getEntityData().getBoolean("IsSpectral") || entity instanceof HSEntityGlobin) return;
HSEntitySoul soul = new HSEntitySoul(world, entity);
soul.setPosition(entity.posX, entity.posY, entity.posZ);
world.spawnEntity(soul);
world.playSound(null, entity.getPosition(), HSSoundEvents.ESSENCE_SOUL_SPAWN, SoundCategory.NEUTRAL, 1.0F, 1.5F / (world.rand.nextFloat() * 0.4F + 1.2F));
}

private static boolean isSuccessfulReap(EntityPlayer player, DamageSource damageSource)
{
return (player.getHeldItemMainhand().getItem() instanceof HSScythe && damageSource.getDamageType().equals("hs_reap")) || triggerEnchantment(HSEnchantments.SOULSTEAL, player);
return isRegularReap(player, damageSource, player.getHeldItemMainhand()) || isEnchantmentReap(HSEnchantments.SOULSTEAL, player);
}

private static boolean isRegularReap(EntityPlayer player, DamageSource damageSource, ItemStack stack)
{
if (player.getHeldItemMainhand().getItem() instanceof HSScythe && damageSource.getDamageType().equals("hs_reap"))
{
int damage = stack.getMaxDamage() - stack.getItemDamage();
double chance = Math.min(0.8D, Math.max(0.4D, (double) damage / 500));
return player.getRNG().nextDouble() < chance;
}
return false;
}

private static boolean triggerEnchantment(Enchantment enchantment, EntityPlayer player)
private static boolean isEnchantmentReap(Enchantment enchantment, EntityPlayer player)
{
int level = EnchantmentHelper.getMaxEnchantmentLevel(enchantment, player);
return (level > 0 && player.getRNG().nextFloat() < 0.15F * level);
Expand Down
44 changes: 32 additions & 12 deletions src/main/java/mod/emt/harkenscythe/events/HSLivingHurtEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import mod.emt.harkenscythe.items.tools.HSGlaive;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
Expand All @@ -29,29 +31,23 @@ public static void onGlaiveReap(LivingHurtEvent event)
if (!world.isRemote)
{
DamageSource damageSource = event.getSource();
if (damageSource.getTrueSource() instanceof EntityPlayer && damageSource.getDamageType().equals("hs_reap"))
Entity trueSource = damageSource.getTrueSource();
if (trueSource instanceof EntityPlayer && isSuccessfulReap((EntityPlayer) trueSource, damageSource))
{
EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
if (player.getHeldItemMainhand().getItem() instanceof HSGlaive)
{
HSEntityBlood blood = new HSEntityBlood(world);
blood.setPosition(entity.posX, entity.posY, entity.posZ);
world.spawnEntity(blood);
world.playSound(null, entity.getPosition(), HSSoundEvents.ESSENCE_BLOOD_SPAWN, SoundCategory.NEUTRAL, 1.0F, 1.5F / (world.rand.nextFloat() * 0.4F + 1.2F));
}
spawnBlood(world, entity);
}
if (entity instanceof EntityPlayer)
{
// Nourishment enchantment
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
if (player.getFoodStats().getFoodLevel() > 0 && triggerEnchantment(HSEnchantments.NOURISHMENT, player))
if (player.getFoodStats().getFoodLevel() > 0 && isEnchantmentReap(HSEnchantments.NOURISHMENT, player))
{
int damage = Math.min(player.getFoodStats().getFoodLevel(), Math.round(event.getAmount()));
player.getFoodStats().setFoodLevel(player.getFoodStats().getFoodLevel() - damage);
event.setAmount(0);
}
// Exude enchantment
if ((player.isPotionActive(MobEffects.POISON) || player.isPotionActive(MobEffects.WITHER) || player.isBurning()) && triggerEnchantment(HSEnchantments.EXUDE, player))
if ((player.isPotionActive(MobEffects.POISON) || player.isPotionActive(MobEffects.WITHER) || player.isBurning()) && isEnchantmentReap(HSEnchantments.EXUDE, player))
{
player.removePotionEffect(MobEffects.POISON);
player.removePotionEffect(MobEffects.WITHER);
Expand All @@ -63,7 +59,31 @@ public static void onGlaiveReap(LivingHurtEvent event)
}
}

private static boolean triggerEnchantment(Enchantment enchantment, EntityPlayer player)
private static void spawnBlood(World world, EntityLivingBase entity)
{
HSEntityBlood blood = new HSEntityBlood(world);
blood.setPosition(entity.posX, entity.posY, entity.posZ);
world.spawnEntity(blood);
world.playSound(null, entity.getPosition(), HSSoundEvents.ESSENCE_BLOOD_SPAWN, SoundCategory.NEUTRAL, 1.0F, 1.5F / (world.rand.nextFloat() * 0.4F + 1.2F));
}

private static boolean isSuccessfulReap(EntityPlayer player, DamageSource damageSource)
{
return isRegularReap(player, damageSource, player.getHeldItemMainhand()) || isEnchantmentReap(HSEnchantments.BLOODLETTING, player);
}

private static boolean isRegularReap(EntityPlayer player, DamageSource damageSource, ItemStack stack)
{
if (player.getHeldItemMainhand().getItem() instanceof HSGlaive && damageSource.getDamageType().equals("hs_reap"))
{
int damage = stack.getMaxDamage() - stack.getItemDamage();
double chance = Math.min(0.6D, Math.max(0.2D, (double) damage / 500));
return player.getRNG().nextDouble() < chance;
}
return false;
}

private static boolean isEnchantmentReap(Enchantment enchantment, EntityPlayer player)
{
int level = EnchantmentHelper.getMaxEnchantmentLevel(enchantment, player);
return (level > 0 && player.getRNG().nextFloat() < 0.05F * level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase
{
EntityPlayer player = (EntityPlayer) entityLiving;
RayTraceResult rayTraceResult = rayTrace(world, player, false);
if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
if (rayTraceResult != null && rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos creepPos = rayTraceResult.getBlockPos();
IBlockState creepState = world.getBlockState(creepPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase
if (!world.isRemote && entityLiving instanceof EntityPlayer)
{
RayTraceResult rayTraceResult = rayTrace(world, (EntityPlayer) entityLiving, false);
if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
if (rayTraceResult != null && rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
{
BlockPos cropPos = rayTraceResult.getBlockPos().up();
IBlockState cropState = world.getBlockState(cropPos);
Expand Down

0 comments on commit f6dab4a

Please sign in to comment.