mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 05:19:41 +00:00
Explosion Client-Side only
This commit is contained in:
1 parent
d3ca0622e4
commit
9a1bd5f2f8
8 files changed
+149
-9
No files matched your search
@@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.entity.EntityEnergyExplosion;
|
||||
import net.minecraft.entity.Entity;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,7 @@ public class RenderEnergyExplosion extends RenderEnergyAbility {
|
||||
@Override
|
||||
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTicks) {
|
||||
if (!(entity instanceof EntityEnergyExplosion)) return;
|
||||
if (ConfigClient.LowResExplosion) return;
|
||||
EntityEnergyExplosion explosion = (EntityEnergyExplosion) entity;
|
||||
|
||||
setupRenderState();
|
||||
|
||||
@@ -107,6 +107,9 @@ public class EntityEnergyExplosion extends EntityEnergyAbility {
|
||||
@Override
|
||||
protected void writeSpawnNBT(NBTTagCompound nbt) {
|
||||
writeEnergyBaseNBT(nbt);
|
||||
nbt.setDouble("PosX", this.posX);
|
||||
nbt.setDouble("PosY", this.posY);
|
||||
nbt.setDouble("PosZ", this.posZ);
|
||||
nbt.setFloat("ExplosionRadius", maxRadius);
|
||||
nbt.setInteger("ExplosionDuration", durationTicks);
|
||||
nbt.setLong("ExplosionSeed", renderSeed);
|
||||
@@ -115,6 +118,16 @@ public class EntityEnergyExplosion extends EntityEnergyAbility {
|
||||
@Override
|
||||
protected void readSpawnNBT(NBTTagCompound nbt) {
|
||||
readEnergyBaseNBT(nbt);
|
||||
double x = nbt.hasKey("PosX") ? nbt.getDouble("PosX") : this.posX;
|
||||
double y = nbt.hasKey("PosY") ? nbt.getDouble("PosY") : this.posY;
|
||||
double z = nbt.hasKey("PosZ") ? nbt.getDouble("PosZ") : this.posZ;
|
||||
this.setPosition(x, y, z);
|
||||
this.prevPosX = x;
|
||||
this.prevPosY = y;
|
||||
this.prevPosZ = z;
|
||||
this.lastTickPosX = x;
|
||||
this.lastTickPosY = y;
|
||||
this.lastTickPosZ = z;
|
||||
setExplosionRadius(nbt.hasKey("ExplosionRadius") ? nbt.getFloat("ExplosionRadius") : 2.0f);
|
||||
this.durationTicks = nbt.hasKey("ExplosionDuration") ? nbt.getInteger("ExplosionDuration") : durationTicks;
|
||||
if (durationTicks <= 0) durationTicks = 10;
|
||||
@@ -123,4 +136,3 @@ public class EntityEnergyExplosion extends EntityEnergyAbility {
|
||||
this.prevRenderRadius = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,13 @@ import kamkeel.npcs.controllers.data.ability.data.energy.EnergyHomingData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLightningData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyTrajectoryData;
|
||||
import kamkeel.npcs.network.packets.data.energyexplosion.EnergyExplosionSpawnPacket;
|
||||
import kamkeel.npcs.util.AnchorPointHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -49,6 +51,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Base class for all ability projectiles (Orb, Disc, Beam, Laser, Slicer).
|
||||
@@ -425,6 +428,7 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
|
||||
protected void applyDamage(EntityLivingBase target, float dmg, float kb) {
|
||||
if (previewMode) return; // Skip damage in preview mode
|
||||
if (target == null || shouldIgnoreEntity(target)) return;
|
||||
|
||||
// Fire entity impact event (may cancel or modify damage)
|
||||
if (!worldObj.isRemote) {
|
||||
@@ -437,6 +441,7 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
|
||||
// Check for ability extenders (e.g., DBC Addon damage routing)
|
||||
boolean handled = false;
|
||||
boolean defaultDamageApplied = false;
|
||||
if (sourceAbility != null && owner instanceof EntityLivingBase) {
|
||||
double dx = target.posX - posX;
|
||||
double dz = target.posZ - posZ;
|
||||
@@ -449,16 +454,19 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
if (!handled) {
|
||||
// Default damage path
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
target.attackEntityFrom(new NpcDamageSource("npc_ability", (EntityNPCInterface) owner), dmg);
|
||||
defaultDamageApplied = target.attackEntityFrom(new NpcDamageSource("npc_ability", (EntityNPCInterface) owner), dmg);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) owner), dmg);
|
||||
defaultDamageApplied = target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) owner), dmg);
|
||||
} else if (owner instanceof EntityLivingBase) {
|
||||
target.attackEntityFrom(DamageSource.causeMobDamage((EntityLivingBase) owner), dmg);
|
||||
defaultDamageApplied = target.attackEntityFrom(DamageSource.causeMobDamage((EntityLivingBase) owner), dmg);
|
||||
} else {
|
||||
target.attackEntityFrom(new NpcDamageSource("npc_ability", null), dmg);
|
||||
defaultDamageApplied = target.attackEntityFrom(new NpcDamageSource("npc_ability", null), dmg);
|
||||
}
|
||||
}
|
||||
|
||||
boolean allowSecondaryEffects = handled || dmg <= 0 || defaultDamageApplied;
|
||||
if (!allowSecondaryEffects) return;
|
||||
|
||||
if (kb > 0) {
|
||||
double dx = target.posX - posX;
|
||||
double dz = target.posZ - posZ;
|
||||
@@ -508,6 +516,7 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
|
||||
for (EntityLivingBase target : targets) {
|
||||
if (target == owner) continue;
|
||||
if (shouldIgnoreExplosionTarget(target)) continue;
|
||||
|
||||
double dist = Math.sqrt(
|
||||
Math.pow(target.posX - posX, 2) +
|
||||
@@ -525,14 +534,41 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a short-lived voxel render entity so explosions are visible as geometry,
|
||||
* Explosion safety filter.
|
||||
* Reuses standard projectile-friendly checks and blocks passive non-player entities.
|
||||
*/
|
||||
protected boolean shouldIgnoreExplosionTarget(EntityLivingBase target) {
|
||||
if (target == null) return true;
|
||||
if (shouldIgnoreEntity(target)) return true;
|
||||
return isPassiveNonPlayerEntity(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passive mobs (animals/ambient/water creatures) are never damaged by energy explosions.
|
||||
* Players and hostile mobs remain valid unless other friendly-fire checks reject them.
|
||||
*/
|
||||
protected boolean isPassiveNonPlayerEntity(EntityLivingBase target) {
|
||||
if (target instanceof EntityPlayer) return false;
|
||||
if (target instanceof EntityNPCInterface) return false;
|
||||
if (target.isCreatureType(EnumCreatureType.monster, false)) return false;
|
||||
return target.isCreatureType(EnumCreatureType.creature, false)
|
||||
|| target.isCreatureType(EnumCreatureType.ambient, false)
|
||||
|| target.isCreatureType(EnumCreatureType.waterCreature, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a packet-driven client preview so explosions are visible as geometry,
|
||||
* not only as particles.
|
||||
*/
|
||||
protected void spawnExplosionRenderEntity(float explosionRad) {
|
||||
if (worldObj == null || worldObj.isRemote) return;
|
||||
float renderRad = Math.max(0.75f, Math.min(explosionRad, 12.0f));
|
||||
EntityEnergyExplosion fx = new EntityEnergyExplosion(worldObj, this, renderRad);
|
||||
worldObj.spawnEntityInWorld(fx);
|
||||
EnergyExplosionSpawnPacket.sendToTracking(getExplosionVisualInstanceId(), fx, this);
|
||||
}
|
||||
|
||||
protected String getExplosionVisualInstanceId() {
|
||||
return "energy_explosion_" + UUID.randomUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,7 @@ import kamkeel.npcs.network.packets.data.script.ScriptOverlayDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.script.ScriptedParticlePacket;
|
||||
import kamkeel.npcs.network.packets.data.energycharge.EnergyChargeRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.energycharge.EnergyChargeSpawnPacket;
|
||||
import kamkeel.npcs.network.packets.data.energyexplosion.EnergyExplosionSpawnPacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import kamkeel.npcs.network.packets.player.AuctionActionPacket;
|
||||
@@ -589,6 +590,7 @@ public class PacketHandler {
|
||||
DATA_PACKET.registerPacket(new TelegraphRemovePacket());
|
||||
DATA_PACKET.registerPacket(new EnergyChargeSpawnPacket());
|
||||
DATA_PACKET.registerPacket(new EnergyChargeRemovePacket());
|
||||
DATA_PACKET.registerPacket(new EnergyExplosionSpawnPacket());
|
||||
DATA_PACKET.registerPacket(new PlayerAbilitySyncPacket());
|
||||
DATA_PACKET.registerPacket(new PlayerAbilityStatePacket());
|
||||
DATA_PACKET.registerPacket(new AbilityHotbarSyncPacket());
|
||||
|
||||
@@ -74,4 +74,7 @@ public enum EnumDataPacket {
|
||||
// Energy Charge Preview
|
||||
ENERGY_CHARGE_SPAWN,
|
||||
ENERGY_CHARGE_REMOVE,
|
||||
|
||||
// Energy Explosion Preview
|
||||
ENERGY_EXPLOSION_SPAWN,
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package kamkeel.npcs.network.packets.data.energyexplosion;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.entity.EntityEnergyExplosion;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Spawns a client-side explosion visual entity from serialized spawn data.
|
||||
*/
|
||||
public final class EnergyExplosionSpawnPacket extends AbstractPacket {
|
||||
public static final String packetName = "Data|EnergyExplosionSpawn";
|
||||
|
||||
private String instanceId;
|
||||
private NBTTagCompound spawnNbt;
|
||||
|
||||
public EnergyExplosionSpawnPacket() {
|
||||
}
|
||||
|
||||
public EnergyExplosionSpawnPacket(String instanceId, NBTTagCompound spawnNbt) {
|
||||
this.instanceId = instanceId;
|
||||
this.spawnNbt = spawnNbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumDataPacket.ENERGY_EXPLOSION_SPAWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.DATA_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, instanceId);
|
||||
ByteBufUtils.writeNBT(out, spawnNbt);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
ByteBufUtils.readString(in); // Keep wire compatibility for future instance tracking.
|
||||
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
|
||||
|
||||
if (nbt == null) return;
|
||||
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
if (world == null) return;
|
||||
|
||||
EntityEnergyExplosion preview = new EntityEnergyExplosion(world);
|
||||
preview.importSpawnNBT(nbt);
|
||||
world.spawnEntityInWorld(preview);
|
||||
}
|
||||
|
||||
public static void sendToTracking(String instanceId, EntityEnergyExplosion previewEntity, Entity trackingEntity) {
|
||||
if (instanceId == null || previewEntity == null || trackingEntity == null) return;
|
||||
NBTTagCompound nbt = previewEntity.exportSpawnNBT();
|
||||
PacketHandler.Instance.sendTracking(new EnergyExplosionSpawnPacket(instanceId, nbt), trackingEntity);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ import kamkeel.npcs.entity.EntityAbilityPanel;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityAbilityDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyExplosion;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.util.BukkitUtil;
|
||||
@@ -302,7 +301,6 @@ public class CustomNpcs {
|
||||
registerNewEntity(EntityAbilityDome.class, "energydome", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityPanel.class, "energypanel", 64, 3, true);
|
||||
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 3, true);
|
||||
registerNewEntity(EntityEnergyExplosion.class, "energyexplosion", 64, 3, true);
|
||||
|
||||
new RecipeController();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public class ConfigClient {
|
||||
public final static String MODEL = "Model";
|
||||
public final static String TEXTURE = "Texture";
|
||||
public final static String HUD = "Hud";
|
||||
public final static String RENDERING = "Rendering";
|
||||
|
||||
|
||||
/**
|
||||
@@ -52,6 +53,10 @@ public class ConfigClient {
|
||||
public static Property HideEffectsBarProperty;
|
||||
public static boolean HideEffectsBar = false;
|
||||
|
||||
// Rendering Properties
|
||||
public static Property LowResExplosionProperty;
|
||||
public static boolean LowResExplosion = false;
|
||||
|
||||
/**
|
||||
* Questing Properties
|
||||
**/
|
||||
@@ -277,6 +282,14 @@ public class ConfigClient {
|
||||
HideEffectsBarProperty = config.get(VISUAL, "Hide Effects Bar", false, "Hides CNPC+ Inventory Effects Bar");
|
||||
HideEffectsBar = HideEffectsBarProperty.getBoolean(false);
|
||||
|
||||
LowResExplosionProperty = config.get(
|
||||
RENDERING,
|
||||
"Low Res Explosion",
|
||||
false,
|
||||
"Disables most Energy Explosion voxel rendering and keeps particle effects only."
|
||||
);
|
||||
LowResExplosion = LowResExplosionProperty.getBoolean(false);
|
||||
|
||||
DialogSpeedProperty = config.get(VISUAL, "Dialog Speed", true, "Only set for gradual dialogs");
|
||||
DialogSpeed = DialogSpeedProperty.getInt(10);
|
||||
|
||||
|
||||
Reference in new issue
Block a user