add functionality for maces

This commit is contained in:
Justus Wolff
2026-03-04 16:18:26 +01:00
parent 53b4f6a04a
commit a3d1b3fcf3
121 changed files with 934 additions and 28 deletions

View File

@@ -18,7 +18,6 @@ import java.util.List;
import java.util.UUID;
public interface Terminator {
String getBotName();
int getEntityId();
@@ -74,6 +73,7 @@ public interface Terminator {
void faceLocation(Location location);
void attack(Entity target);
void attack(Entity target, double extra);
void attemptBlockPlace(Location loc, Material type, boolean down);
@@ -103,6 +103,8 @@ public interface Terminator {
void setDefaultItem(ItemStack item);
ItemStack getDefaultItem();
Vector getOffset();
Vector getVelocity();

View File

@@ -7,7 +7,10 @@ import net.nuggetmc.tplus.api.utils.MathUtils;
import net.nuggetmc.tplus.api.utils.PlayerUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;

View File

@@ -13,6 +13,7 @@ import net.nuggetmc.tplus.api.event.BotDeathEvent;
import net.nuggetmc.tplus.api.event.BotFallDamageEvent;
import net.nuggetmc.tplus.api.event.TerminatorLocateTargetEvent;
import net.nuggetmc.tplus.api.utils.BotUtils;
import net.nuggetmc.tplus.api.utils.ItemUtils;
import net.nuggetmc.tplus.api.utils.MathUtils;
import net.nuggetmc.tplus.api.utils.PlayerUtils;
import org.bukkit.*;
@@ -1394,12 +1395,111 @@ public class LegacyAgent extends Agent {
return check;
}
private double clamp(double value, double min, double max) {
return Math.max(min, Math.min(max, value));
}
/*private double getdistfromfloor(LivingEntity entity) {
return Math.abs(entity.getWorld().getHighestBlockYAt(entity.getLocation()) - entity.getLocation().getY());
}*/
private boolean tryWindchargeMaceAttack(Terminator bot, LivingEntity target) {
LivingEntity botEntity = bot.getBukkitEntity();
if (botEntity == null) {
return false;
}
// Get inventory - Citizens NPCs should have inventory even if not Player instance
ItemStack mainHand;
if (botEntity instanceof Player player) {
mainHand = player.getInventory().getItemInMainHand();
} else {
return false;
}
// Check if bot has a mace in main hand
if (bot.getDefaultItem().getType() != Material.MACE && mainHand.getType() != Material.MACE) {
return false;
}
if (!bot.isBotOnGround() && Math.random() >= 0.5) return false;
// Face the ground at own position to launch upward
bot.look(org.bukkit.block.BlockFace.DOWN);
// Jump boost from windcharge with higher velocity
bot.setItem(new ItemStack(Material.WIND_CHARGE, 1));
Vector jumpVel = new Vector(0, 0.6, 0);
Vector cvel = bot.getVelocity().add(jumpVel);
cvel.setX(clamp(cvel.getX(), -0.05, 0.05));
cvel.setZ(clamp(cvel.getZ(), -0.05, 0.05));
bot.setVelocity(cvel);
World world = bot.getLocation().getWorld();
if (world != null) {
world.playSound(bot.getLocation(), Sound.ENTITY_WIND_CHARGE_WIND_BURST, SoundCategory.PLAYERS, 1, 1);
world.spawnParticle(Particle.GUST_EMITTER_SMALL, target.getLocation(), 1, 0, 0, 0, 0.1);
}
Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, () -> {
while (!bot.isBotOnGround() && bot.getLocation().distanceSquared(target.getLocation()) > 3) {}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
double falldist = -(bot.getVelocity().getY()*10); // CERTAINLY not the best way but meh
//Bukkit.getLogger().info("fall dist: "+falldist+" cvy: "+bot.getVelocity().getY());
if (bot.isBotOnGround()) {
//Bukkit.getLogger().info("Bot -> ground, no mace");
return;
}
double extradmg = 0;
if (falldist >= 1.5) {
extradmg += clamp(falldist,0,3)*4; // first 3 blocks handling
falldist = clamp(falldist-3,0,Double.MAX_VALUE);
extradmg += clamp(falldist,0,5)*2; // next 5 blocks handling
falldist = clamp(falldist-5,0,Double.MAX_VALUE);
extradmg += falldist; // remaining blocks handling
}
bot.setItem(bot.getDefaultItem());
bot.faceLocation(target.getLocation());
bot.punch();
if (bot.getLocation().distanceSquared(target.getLocation()) <= 5) {
double exdmg = extradmg;
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
bot.attack(target, exdmg); // apply damage only if within range
// effect stuff
if (world != null && exdmg > 0) {
bot.setVelocity(bot.getVelocity().setY(0.1)); // no fall damage
// schedule next mace attempt to make a streak potentially
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {tryWindchargeMaceAttack(bot, target);}, 0);
world.playSound(bot.getLocation(), Sound.ITEM_MACE_SMASH_GROUND, SoundCategory.PLAYERS, 1, 1);
world.spawnParticle(Particle.EXPLOSION, target.getLocation(), 10, 0.5, 0.5, 0.5, 0.1);
} else {
//Bukkit.getLogger().info("exdmg !> 0");
}
}, 1);
} else {
//Bukkit.getLogger().info("Bot out of range.");
}
}, 0);
}, 8);
return true;
}
private void attack(Terminator bot, LivingEntity target, Location loc) {
if ((target instanceof Player && PlayerUtils.isInvincible(((Player) target).getGameMode())) || target.getNoDamageTicks() >= 5 || loc.distance(target.getLocation()) >= 4)
return;
if (tryWindchargeMaceAttack(bot, target)) {
return;
}
bot.attack(target);
}
public void setRegion(BoundingBox region, double regionWeightX, double regionWeightY, double regionWeightZ) {
this.region = region;

View File

@@ -46,6 +46,7 @@ public class ItemUtils {
case IRON_SWORD:
case DIAMOND_AXE:
case NETHERITE_PICKAXE:
case MACE:
return 6;
case DIAMOND_SWORD: