mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 23:09:05 +00:00
Better API Handling for Scripting Energy Utilitizes / Damage Handling
This commit is contained in:
1 parent
572a51ad32
commit
ee192a247f
3 files changed
+523
No files matched your search
@@ -0,0 +1,197 @@
|
||||
package kamkeel.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.data.energy.IEnergyHandler;
|
||||
import kamkeel.npcs.entity.*;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.api.IEnergyController;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.*;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Central controller for script-created energy entities and handler registration.
|
||||
* Provides factory methods for creating all energy entity types and routes
|
||||
* damage through registered handlers when entities have customDamageData
|
||||
* but no sourceAbility.
|
||||
*/
|
||||
public class EnergyController implements IEnergyController {
|
||||
|
||||
public static EnergyController Instance = new EnergyController();
|
||||
|
||||
private final List<IEnergyHandler> handlers = new ArrayList<>();
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// HANDLER REGISTRATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public void registerHandler(IEnergyHandler handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
public List<IEnergyHandler> getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// DAMAGE ROUTING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Fire onEnergyDamage on all handlers. Chain of responsibility — first true wins.
|
||||
*/
|
||||
public boolean fireOnEnergyDamage(Entity energyEntity, EntityLivingBase owner,
|
||||
EntityLivingBase target, float damage,
|
||||
float knockback, float knockbackUp,
|
||||
double kbDirX, double kbDirZ,
|
||||
float damageMultiplier,
|
||||
NBTTagCompound damageData) {
|
||||
for (IEnergyHandler handler : handlers) {
|
||||
if (handler.onEnergyDamage(energyEntity, owner, target, damage,
|
||||
knockback, knockbackUp, kbDirX, kbDirZ, damageMultiplier, damageData)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire modifyEnergyDamage on all handlers. Cumulative — each handler's output feeds the next.
|
||||
*/
|
||||
public float fireModifyEnergyDamage(Entity energyEntity, EntityLivingBase owner,
|
||||
float baseDamage, NBTTagCompound damageData) {
|
||||
float damage = baseDamage;
|
||||
for (IEnergyHandler handler : handlers) {
|
||||
damage = handler.modifyEnergyDamage(energyEntity, owner, damage, damageData);
|
||||
}
|
||||
return damage;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// INTERNAL FACTORY METHODS (MC types)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public EntityAbilityOrb createOrbInternal(World world, Entity owner, double x, double y, double z, float size) {
|
||||
EntityAbilityOrb entity = new EntityAbilityOrb(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setStartPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getEntityId());
|
||||
entity.setProjectileSize(size);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EntityAbilityBeam createBeamInternal(World world, Entity owner, double x, double y, double z,
|
||||
float beamWidth, float headSize) {
|
||||
EntityAbilityBeam entity = new EntityAbilityBeam(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setStartPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getEntityId());
|
||||
entity.setBeamWidth(beamWidth);
|
||||
entity.setHeadSize(headSize);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EntityAbilityDisc createDiscInternal(World world, Entity owner, double x, double y, double z,
|
||||
float radius, float thickness) {
|
||||
EntityAbilityDisc entity = new EntityAbilityDisc(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setStartPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getEntityId());
|
||||
entity.setDiscRadius(radius);
|
||||
entity.setDiscThickness(thickness);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EntityAbilityLaser createLaserInternal(World world, Entity owner, double x, double y, double z,
|
||||
float laserWidth) {
|
||||
EntityAbilityLaser entity = new EntityAbilityLaser(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setStartPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getEntityId());
|
||||
entity.setLaserWidth(laserWidth);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EntityAbilityZone createHazardInternal(World world, Entity owner, double x, double y, double z) {
|
||||
EntityAbilityZone entity = new EntityAbilityZone(world);
|
||||
entity.initAsHazard(owner, x, y, z);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EntityAbilityZone createTrapInternal(World world, Entity owner, double x, double y, double z) {
|
||||
EntityAbilityZone entity = new EntityAbilityZone(world);
|
||||
entity.initAsTrap(owner, x, y, z);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EntityEnergySweeper createSweeperInternal(World world, Entity owner, double x, double y, double z) {
|
||||
EntityEnergySweeper entity = new EntityEnergySweeper(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getEntityId());
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EntityEnergyPanel createPanelInternal(World world, Entity owner, double x, double y, double z) {
|
||||
EntityEnergyPanel entity = new EntityEnergyPanel(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getEntityId());
|
||||
return entity;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// IEnergyController (Script API methods)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public IEnergyOrb createOrb(IWorld world, IEntity owner, double x, double y, double z, float size) {
|
||||
EntityAbilityOrb entity = createOrbInternal((World) world.getMCWorld(), owner.getMCEntity(), x, y, z, size);
|
||||
return (IEnergyOrb) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyBeam createBeam(IWorld world, IEntity owner, double x, double y, double z, float beamWidth, float headSize) {
|
||||
EntityAbilityBeam entity = createBeamInternal((World) world.getMCWorld(), owner.getMCEntity(), x, y, z, beamWidth, headSize);
|
||||
return (IEnergyBeam) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyDisc createDisc(IWorld world, IEntity owner, double x, double y, double z, float radius, float thickness) {
|
||||
EntityAbilityDisc entity = createDiscInternal((World) world.getMCWorld(), owner.getMCEntity(), x, y, z, radius, thickness);
|
||||
return (IEnergyDisc) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyLaser createLaser(IWorld world, IEntity owner, double x, double y, double z, float laserWidth) {
|
||||
EntityAbilityLaser entity = createLaserInternal((World) world.getMCWorld(), owner.getMCEntity(), x, y, z, laserWidth);
|
||||
return (IEnergyLaser) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyZone createHazard(IWorld world, IEntity owner, double x, double y, double z) {
|
||||
EntityAbilityZone entity = createHazardInternal((World) world.getMCWorld(), owner.getMCEntity(), x, y, z);
|
||||
return (IEnergyZone) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyZone createTrap(IWorld world, IEntity owner, double x, double y, double z) {
|
||||
EntityAbilityZone entity = createTrapInternal((World) world.getMCWorld(), owner.getMCEntity(), x, y, z);
|
||||
return (IEnergyZone) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergySweeper createSweeper(IWorld world, IEntity owner, double x, double y, double z) {
|
||||
EntityEnergySweeper entity = createSweeperInternal((World) world.getMCWorld(), owner.getMCEntity(), x, y, z);
|
||||
return (IEnergySweeper) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyPanel createPanel(IWorld world, IEntity owner, double x, double y, double z) {
|
||||
EntityEnergyPanel entity = createPanelInternal((World) world.getMCWorld(), owner.getMCEntity(), x, y, z);
|
||||
return (IEnergyPanel) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user