First stab at Living Armour reimplementation.
Added a lot of the upgrades, but there's still more testing/upgrades to be done/reimplemented.
This commit is contained in:
parent
06faa916c3
commit
2075fa5be3
42 changed files with 2352 additions and 2 deletions
|
@ -623,4 +623,112 @@ public class Utils
|
|||
|
||||
return added;
|
||||
}
|
||||
|
||||
// public static float getModifiedDamage(LivingEntity attackedEntity, DamageSource source, float amount)
|
||||
// {
|
||||
// if (!attackedEntity.isInvulnerableTo(source))
|
||||
// {
|
||||
// if (amount <= 0)
|
||||
// return 0;
|
||||
//
|
||||
// amount = applyArmor(attackedEntity, Iterables.toArray(attackedEntity.getEquipmentAndArmor(), ItemStack.class), source, amount);
|
||||
// if (amount <= 0)
|
||||
// return 0;
|
||||
// amount = applyPotionDamageCalculations(attackedEntity, source, amount);
|
||||
//
|
||||
// return amount;
|
||||
// }
|
||||
//
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// public static float applyArmor(LivingEntity entity, ItemStack[] inventory, DamageSource source, double damage)
|
||||
// {
|
||||
// damage *= 25;
|
||||
// ArrayList<ArmorProperties> dmgVals = new ArrayList<>();
|
||||
// for (int x = 0; x < inventory.length; x++)
|
||||
// {
|
||||
// ItemStack stack = inventory[x];
|
||||
// if (stack.isEmpty())
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// ArmorProperties prop = null;
|
||||
// if (stack.getItem() instanceof ISpecialArmor)
|
||||
// {
|
||||
// ISpecialArmor armor = (ISpecialArmor) stack.getItem();
|
||||
// prop = armor.getProperties(entity, stack, source, damage / 25D, x).copy();
|
||||
// } else if (stack.getItem() instanceof ArmorItem && !source.isUnblockable())
|
||||
// {
|
||||
// ArmorItem armor = (ArmorItem) stack.getItem();
|
||||
// prop = new ArmorProperties(0, armor.damageReduceAmount / 25D, Integer.MAX_VALUE);
|
||||
// }
|
||||
// if (prop != null)
|
||||
// {
|
||||
// prop.Slot = x;
|
||||
// dmgVals.add(prop);
|
||||
// }
|
||||
// }
|
||||
// if (dmgVals.size() > 0)
|
||||
// {
|
||||
// ArmorProperties[] props = dmgVals.toArray(new ArmorProperties[dmgVals.size()]);
|
||||
// int level = props[0].Priority;
|
||||
// double ratio = 0;
|
||||
// for (ArmorProperties prop : props)
|
||||
// {
|
||||
// if (level != prop.Priority)
|
||||
// {
|
||||
// damage -= (damage * ratio);
|
||||
// ratio = 0;
|
||||
// level = prop.Priority;
|
||||
// }
|
||||
// ratio += prop.AbsorbRatio;
|
||||
//
|
||||
// }
|
||||
// damage -= (damage * ratio);
|
||||
// }
|
||||
//
|
||||
// return (float) (damage / 25.0F);
|
||||
// }
|
||||
//
|
||||
// public static float applyPotionDamageCalculations(LivingEntity attackedEntity, DamageSource source, float damage)
|
||||
// {
|
||||
// Effect resistance = Effects.RESISTANCE;
|
||||
//
|
||||
// if (source.isDamageAbsolute())
|
||||
// {
|
||||
// return damage;
|
||||
// } else
|
||||
// {
|
||||
// if (attackedEntity.isPotionActive(resistance) && source != DamageSource.OUT_OF_WORLD)
|
||||
// {
|
||||
// int i = (attackedEntity.getActivePotionEffect(resistance).getAmplifier() + 1) * 5;
|
||||
// int j = 25 - i;
|
||||
// float f = damage * (float) j;
|
||||
// damage = f / 25.0F;
|
||||
// }
|
||||
//
|
||||
// if (damage <= 0.0F)
|
||||
// {
|
||||
// return 0.0F;
|
||||
// } else
|
||||
// {
|
||||
// int k = EnchantmentHelper.getEnchantmentModifierDamage(attackedEntity.getArmorInventoryList(), source);
|
||||
//
|
||||
// if (k > 20)
|
||||
// {
|
||||
// k = 20;
|
||||
// }
|
||||
//
|
||||
// if (k > 0 && k <= 20)
|
||||
// {
|
||||
// int l = 25 - k;
|
||||
// float f1 = damage * (float) l;
|
||||
// damage = f1 / 25.0F;
|
||||
// }
|
||||
//
|
||||
// return damage;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,19 +1,30 @@
|
|||
package wayoftime.bloodmagic.util.handler.event;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.event.entity.living.LivingDamageEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHealEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerXpEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent.BlockToolInteractEvent;
|
||||
|
@ -26,10 +37,14 @@ import wayoftime.bloodmagic.common.item.BloodOrb;
|
|||
import wayoftime.bloodmagic.common.item.IBindable;
|
||||
import wayoftime.bloodmagic.common.item.IBloodOrb;
|
||||
import wayoftime.bloodmagic.common.item.ItemExperienceBook;
|
||||
import wayoftime.bloodmagic.core.LivingArmorRegistrar;
|
||||
import wayoftime.bloodmagic.core.data.Binding;
|
||||
import wayoftime.bloodmagic.core.data.SoulNetwork;
|
||||
import wayoftime.bloodmagic.core.living.LivingStats;
|
||||
import wayoftime.bloodmagic.core.living.LivingUtil;
|
||||
import wayoftime.bloodmagic.demonaura.WorldDemonWillHandler;
|
||||
import wayoftime.bloodmagic.event.ItemBindEvent;
|
||||
import wayoftime.bloodmagic.event.SacrificeKnifeUsedEvent;
|
||||
import wayoftime.bloodmagic.network.DemonAuraClientPacket;
|
||||
import wayoftime.bloodmagic.potion.BMPotionUtils;
|
||||
import wayoftime.bloodmagic.potion.BloodMagicPotions;
|
||||
|
@ -100,6 +115,95 @@ public class GenericHandler
|
|||
// }
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
// Called when an entity is set to be hurt. Called before vanilla armour
|
||||
// calculations.
|
||||
public void onLivingHurt(LivingHurtEvent event)
|
||||
{
|
||||
Entity sourceEntity = event.getSource().getTrueSource();
|
||||
LivingEntity living = event.getEntityLiving();
|
||||
|
||||
if (sourceEntity instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity sourcePlayer = (PlayerEntity) sourceEntity;
|
||||
if (LivingUtil.hasFullSet(sourcePlayer))
|
||||
{
|
||||
ItemStack mainWeapon = sourcePlayer.getActiveItemStack();
|
||||
double additionalDamage = LivingUtil.getAdditionalDamage(sourcePlayer, mainWeapon, living, event.getAmount());
|
||||
event.setAmount((float) (event.getAmount() + additionalDamage));
|
||||
}
|
||||
}
|
||||
|
||||
if (living instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) living;
|
||||
if (LivingUtil.hasFullSet(player))
|
||||
{
|
||||
event.setAmount((float) LivingUtil.getDamageReceivedForArmour(player, event.getSource(), event.getAmount()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
// Called after armour calculations (including LivingHurtEvent) are parsed.
|
||||
// Damage that the player should receive after armour/absorption hearts.
|
||||
public void onLivingDamage(LivingDamageEvent event)
|
||||
{
|
||||
Entity sourceEntity = event.getSource().getTrueSource();
|
||||
LivingEntity living = event.getEntityLiving();
|
||||
|
||||
if (sourceEntity instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity sourcePlayer = (PlayerEntity) sourceEntity;
|
||||
if (LivingUtil.hasFullSet(sourcePlayer))
|
||||
{
|
||||
if (sourcePlayer.isSprinting())
|
||||
{
|
||||
LivingUtil.applyNewExperience(sourcePlayer, LivingArmorRegistrar.UPGRADE_SPRINT_ATTACK.get(), event.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (living instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) living;
|
||||
if (LivingUtil.hasFullSet(player))
|
||||
{
|
||||
if (event.getSource().isProjectile())
|
||||
{
|
||||
// LivingStats stats = LivingStats.fromPlayer(player);
|
||||
// stats.addExperience(LivingArmorRegistrar.TEST_UPGRADE.get().getKey(), 10);
|
||||
LivingUtil.applyNewExperience(player, LivingArmorRegistrar.UPGRADE_ARROW_PROTECT.get(), event.getAmount());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onExperiencePickupHighest(PlayerXpEvent.PickupXp event)
|
||||
{
|
||||
LivingEntity living = event.getEntityLiving();
|
||||
if (living instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) living;
|
||||
if (LivingUtil.hasFullSet(player))
|
||||
{
|
||||
LivingStats stats = LivingStats.fromPlayer(player);
|
||||
double expModifier = 1 + LivingArmorRegistrar.UPGRADE_EXPERIENCE.get().getBonusValue("exp", stats.getLevel(LivingArmorRegistrar.UPGRADE_EXPERIENCE.get().getKey())).doubleValue();
|
||||
System.out.println("Experience modifier: " + expModifier);
|
||||
|
||||
int xp = event.getOrb().xpValue;
|
||||
|
||||
event.getOrb().xpValue = ((int) Math.floor(xp * expModifier) + (player.world.rand.nextDouble() < (xp * expModifier) % 1
|
||||
? 1
|
||||
: 0));
|
||||
|
||||
LivingUtil.applyNewExperience(player, LivingArmorRegistrar.UPGRADE_EXPERIENCE.get(), event.getOrb().getXpValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onHoe(BlockToolInteractEvent event)
|
||||
{
|
||||
|
@ -185,4 +289,85 @@ public class GenericHandler
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onHeal(LivingHealEvent event)
|
||||
{
|
||||
LivingEntity living = event.getEntityLiving();
|
||||
if (living instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) living;
|
||||
if (LivingUtil.hasFullSet(player))
|
||||
{
|
||||
LivingUtil.applyNewExperience(player, LivingArmorRegistrar.UPGRADE_HEALTH.get(), event.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSelfSacrifice(SacrificeKnifeUsedEvent event)
|
||||
{
|
||||
if (LivingUtil.hasFullSet(event.player))
|
||||
{
|
||||
LivingStats stats = LivingStats.fromPlayer(event.player);
|
||||
double bonus = LivingArmorRegistrar.UPGRADE_SELF_SACRIFICE.get().getBonusValue("self_mod", stats.getLevel(LivingArmorRegistrar.UPGRADE_SELF_SACRIFICE.get().getKey())).doubleValue();
|
||||
event.lpAdded = (int) Math.round(event.lpAdded * (1 + bonus));
|
||||
LivingUtil.applyNewExperience(event.player, LivingArmorRegistrar.UPGRADE_SELF_SACRIFICE.get(), event.healthDrained);
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<UUID, Double> posXMap = new HashMap<>();
|
||||
public static Map<UUID, Double> posZMap = new HashMap<>();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onEntityUpdate(LivingEvent.LivingUpdateEvent event)
|
||||
{
|
||||
if (event.getEntity().world.isRemote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getEntityLiving() instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
|
||||
float percentIncrease = 0;
|
||||
|
||||
if (LivingUtil.hasFullSet(player))
|
||||
{
|
||||
LivingStats stats = LivingStats.fromPlayer(player);
|
||||
percentIncrease += LivingArmorRegistrar.UPGRADE_SPEED.get().getBonusValue("speed_modifier", stats.getLevel(LivingArmorRegistrar.UPGRADE_SPEED.get().getKey())).doubleValue();
|
||||
if (player.isSprinting())
|
||||
{
|
||||
int speedTime = LivingArmorRegistrar.UPGRADE_SPEED.get().getBonusValue("speed_time", stats.getLevel(LivingArmorRegistrar.UPGRADE_SPEED.get().getKey())).intValue();
|
||||
if (speedTime > 0)
|
||||
{
|
||||
int speedLevel = LivingArmorRegistrar.UPGRADE_SPEED.get().getBonusValue("speed_level", stats.getLevel(LivingArmorRegistrar.UPGRADE_SPEED.get().getKey())).intValue();
|
||||
player.addPotionEffect(new EffectInstance(Effects.SPEED, speedTime, speedLevel, true, false));
|
||||
}
|
||||
}
|
||||
|
||||
double distance = 0;
|
||||
|
||||
if (posXMap.containsKey(player.getUniqueID()))
|
||||
{
|
||||
distance = Math.sqrt((player.getPosX() - posXMap.get(player.getUniqueID())) * (player.getPosX() - posXMap.get(player.getUniqueID())) + (player.getPosZ() - posZMap.get(player.getUniqueID())) * (player.getPosZ() - posZMap.get(player.getUniqueID())));
|
||||
}
|
||||
|
||||
// System.out.println("Distance travelled: " + distance);
|
||||
if (player.isOnGround() && distance > 0 && distance < 50)
|
||||
{
|
||||
distance *= (1 + percentIncrease);
|
||||
LivingUtil.applyNewExperience(player, LivingArmorRegistrar.UPGRADE_SPEED.get(), distance);
|
||||
}
|
||||
}
|
||||
|
||||
if (percentIncrease > 0 && (player.isOnGround()) && (Math.abs(player.moveForward) > 0 || Math.abs(player.moveStrafing) > 0))
|
||||
{
|
||||
player.travel(new Vector3d(player.moveStrafing * percentIncrease, 0, player.moveForward * percentIncrease));
|
||||
}
|
||||
|
||||
posXMap.put(player.getUniqueID(), player.getPosX());
|
||||
posZMap.put(player.getUniqueID(), player.getPosZ());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue