mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-01 03:55:28 +02:00
Refactor ricochet code, don't reflect shallow angles
This commit is contained in:
@@ -161,16 +161,10 @@ public final class CombatUtils {
|
||||
|
||||
//Make sure the profiles been loaded
|
||||
if(mcMMOPlayer == null) {
|
||||
cleanupArrowMetadata(arrow);
|
||||
ProjectileUtils.cleanupProjectileMetadata(arrow);
|
||||
return;
|
||||
}
|
||||
|
||||
// CrossbowsManager crossbowsManager = mcMMOPlayer.getCrossbowsManager();
|
||||
|
||||
// if (crossbowsManager.canActivateAbility()) {
|
||||
// mcMMOPlayer.checkAbilityActivation(PrimarySkillType.CROSSBOWS);
|
||||
// }
|
||||
|
||||
double boostedDamage = event.getDamage();
|
||||
|
||||
if(canUseLimitBreak(player, target, SubSkillType.CROSSBOWS_CROSSBOWS_LIMIT_BREAK)) {
|
||||
@@ -190,7 +184,7 @@ public final class CombatUtils {
|
||||
"Final Damage: "+boostedDamage);
|
||||
|
||||
//Clean data
|
||||
cleanupArrowMetadata(arrow);
|
||||
ProjectileUtils.cleanupProjectileMetadata(arrow);
|
||||
}
|
||||
|
||||
private static void processAxeCombat(@NotNull LivingEntity target, @NotNull Player player, @NotNull EntityDamageByEntityEvent event) {
|
||||
@@ -327,7 +321,7 @@ public final class CombatUtils {
|
||||
|
||||
//Make sure the profiles been loaded
|
||||
if(mcMMOPlayer == null) {
|
||||
cleanupArrowMetadata(arrow);
|
||||
ProjectileUtils.cleanupProjectileMetadata(arrow);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -368,7 +362,7 @@ public final class CombatUtils {
|
||||
"Initial Damage: "+initialDamage,
|
||||
"Final Damage: "+boostedDamage);
|
||||
//Clean data
|
||||
cleanupArrowMetadata(arrow);
|
||||
ProjectileUtils.cleanupProjectileMetadata(arrow);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -500,7 +494,7 @@ public final class CombatUtils {
|
||||
}
|
||||
} else {
|
||||
//Cleanup Arrow
|
||||
cleanupArrowMetadata(arrow);
|
||||
ProjectileUtils.cleanupProjectileMetadata(arrow);
|
||||
}
|
||||
|
||||
if (target.getType() != EntityType.CREEPER
|
||||
@@ -733,35 +727,6 @@ public final class CombatUtils {
|
||||
}
|
||||
|
||||
dealNoInvulnerabilityTickDamage(target, damage, attacker);
|
||||
|
||||
// //IFrame storage
|
||||
//// int noDamageTicks = target.getNoDamageTicks();
|
||||
//
|
||||
//// String debug = "BLEED DMG RESULT: INC DMG:"+damage+", HP-Before:"+target.getHealth()+", HP-After:";
|
||||
//
|
||||
//// double incDmg = getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, damage);
|
||||
//
|
||||
//// double newHealth = Math.max(0, target.getHealth() - incDmg);
|
||||
//
|
||||
// //Don't kill things with a stone or wooden weapon
|
||||
//// if(toolTier < 3 && newHealth == 0)
|
||||
//// return;
|
||||
//
|
||||
// target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue);
|
||||
//
|
||||
// if(newHealth == 0 && !(target instanceof Player))
|
||||
// {
|
||||
// target.damage(99999, attacker);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
//// Vector beforeRuptureVec = new Vector(target.getVelocity().getX(), target.getVelocity().getY(), target.getVelocity().getZ()); ;
|
||||
// target.damage(damage, attacker);
|
||||
//// debug+=target.getHealth();
|
||||
// Bukkit.broadcastMessage(debug);
|
||||
//// target.setNoDamageTicks(noDamageTicks); //Do not add additional IFrames
|
||||
//// target.setVelocity(beforeRuptureVec);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1062,31 +1027,12 @@ public final class CombatUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up metadata from a projectile
|
||||
*
|
||||
* @param entity projectile
|
||||
*/
|
||||
public static void cleanupArrowMetadata(@NotNull Projectile entity) {
|
||||
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_INF_ARROW)) {
|
||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_INF_ARROW, mcMMO.p);
|
||||
}
|
||||
|
||||
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_BOW_FORCE)) {
|
||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_BOW_FORCE, mcMMO.p);
|
||||
}
|
||||
|
||||
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_ARROW_DISTANCE)) {
|
||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_ARROW_DISTANCE, mcMMO.p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up metadata from a projectile after a minute has passed
|
||||
*
|
||||
* @param entity the projectile
|
||||
*/
|
||||
public static void delayArrowMetaCleanup(@NotNull Projectile entity) {
|
||||
mcMMO.p.getFoliaLib().getImpl().runLater(() -> cleanupArrowMetadata(entity), 20*60);
|
||||
mcMMO.p.getFoliaLib().getImpl().runLater(() -> ProjectileUtils.cleanupProjectileMetadata(entity), 20*60);
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,11 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.MetadataConstants;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ProjectileUtils {
|
||||
public static Vector getNormal(BlockFace blockFace) {
|
||||
@@ -22,21 +20,31 @@ public class ProjectileUtils {
|
||||
};
|
||||
}
|
||||
|
||||
public static void spawnReflectedArrow(Plugin pluginRef, Arrow originalArrow, Location origin, Vector normal) {
|
||||
// TODO: Add an event for this for plugins to hook into
|
||||
ProjectileSource originalArrowShooter = originalArrow.getShooter();
|
||||
Vector incomingDirection = originalArrow.getVelocity();
|
||||
Vector reflectedDirection = incomingDirection.subtract(normal.multiply(2 * incomingDirection.dot(normal)));
|
||||
/**
|
||||
* Clean up all possible mcMMO related metadata for a projectile
|
||||
*
|
||||
* @param entity projectile
|
||||
*/
|
||||
// TODO: Add test
|
||||
public static void cleanupProjectileMetadata(@NotNull Projectile entity) {
|
||||
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_INF_ARROW)) {
|
||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_INF_ARROW, mcMMO.p);
|
||||
}
|
||||
|
||||
// Spawn new arrow with the reflected direction
|
||||
Arrow arrow = originalArrow.getWorld().spawnArrow(origin,
|
||||
reflectedDirection, 1, 1);
|
||||
arrow.setShooter(originalArrowShooter);
|
||||
arrow.setMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW,
|
||||
new FixedMetadataValue(pluginRef, originalArrowShooter));
|
||||
// TODO: This metadata needs to get cleaned up at some point
|
||||
arrow.setMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE,
|
||||
new FixedMetadataValue(pluginRef, originalArrow.getMetadata(
|
||||
MetadataConstants.METADATA_KEY_BOW_TYPE).get(0)));
|
||||
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_BOW_FORCE)) {
|
||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_BOW_FORCE, mcMMO.p);
|
||||
}
|
||||
|
||||
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_ARROW_DISTANCE)) {
|
||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_ARROW_DISTANCE, mcMMO.p);
|
||||
}
|
||||
|
||||
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE)) {
|
||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE, mcMMO.p);
|
||||
}
|
||||
|
||||
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW)) {
|
||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW, mcMMO.p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user