Added Rebounding

This commit is contained in:
Auxilor 2021-04-08 00:18:46 +01:00
parent 39f4353f44
commit 7efbe8220f
3 changed files with 92 additions and 0 deletions

View File

@ -161,6 +161,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Radiance;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rage;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rapid;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reaper;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rebounding;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reel;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reinforcement;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rejuvenation;
@ -489,6 +490,7 @@ public class EcoEnchants {
public static final EcoEnchant SWEEP_ARTIFACT = new SweepArtifact();
public static final EcoEnchant REAPER = new Reaper();
public static final EcoEnchant WOOD_SWITCHER = new WoodSwitcher();
public static final EcoEnchant REBOUNDING = new Rebounding();
/**
* Get all registered {@link EcoEnchant}s.

View File

@ -0,0 +1,63 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.eco.util.VectorUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
public class Rebounding extends EcoEnchant {
public Rebounding() {
super(
"rebounding", EnchantmentType.NORMAL
);
}
@EventHandler
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof LivingEntity)) {
return;
}
if (!(event.getDamager() instanceof LivingEntity)) {
return;
}
if (event.isCancelled()) {
return;
}
LivingEntity victim = (LivingEntity) event.getEntity();
LivingEntity attacker = (LivingEntity) event.getDamager();
int level = EnchantChecks.getArmorPoints(attacker, this);
if (level == 0) {
return;
}
if (this.getDisabledWorlds().contains(attacker.getWorld())) {
return;
}
Vector vector = attacker.getLocation().toVector().clone().subtract(victim.getLocation().toVector()).normalize()
.multiply((-level * (this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity-multiplier") - 1)) + 1);
if (!VectorUtils.isFinite(vector)) {
return;
}
vector.setY(0.2);
if (!VectorUtils.isFinite(vector)) {
return;
}
attacker.setVelocity(vector);
}
}

View File

@ -0,0 +1,27 @@
#
# Rebounding EcoEnchant
#
name: "Rebounding"
description: Deal knockback to entities that attack you.
enabled: true
obtaining:
table: true
villager: true
loot: true
rarity: epic
general-config:
targets:
- helmet
- chestplate
- leggings
- boots
grindstoneable: true
disabled-in-worlds: [ ]
conflicts: [ ]
maximum-level: 2
config:
velocity-multiplier: 1.2