mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 19:54:26 +00:00
Compare commits
12
Commits
dev
..
new-abilities
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ab1dd1e16 | ||
|
|
7c4159dcd2 | ||
|
|
c2c6079b43 | ||
|
|
fb3a392f2e | ||
|
|
956d2e27be | ||
|
|
9546500b4b | ||
|
|
a2beef0549 | ||
|
|
0222a4984e | ||
|
|
d4a89dad1d | ||
|
|
ca7f3f937b | ||
|
|
a59d2d0088 | ||
|
|
9c82fabf1b |
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ plugins {
|
||||
id "dts.typescript-generator"
|
||||
}
|
||||
|
||||
version = "1.11.2"
|
||||
version = "1.11.1"
|
||||
group= "kamkeel.customnpc-plus"
|
||||
archivesBaseName = "CustomNPC-Plus"
|
||||
|
||||
|
||||
+1
-1
@@ -199,7 +199,7 @@ disableCheckstyle = true
|
||||
# ideaCheckSpotlessOnBuild = true
|
||||
|
||||
# Non-GTNH properties
|
||||
modVersion = 1.11.2
|
||||
modVersion = 1.11.0
|
||||
|
||||
# Increase Gradle's JVM memory usage to avoid daemon expiration due to
|
||||
# insufficient heap space on CI builds.
|
||||
|
||||
@@ -6,7 +6,6 @@ import foxz.commandhelper.annotations.SubCommand;
|
||||
import foxz.commandhelper.permissions.OpOnly;
|
||||
import foxz.commandhelper.permissions.ParamCheck;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
@@ -91,7 +90,7 @@ public class CmdDialog extends ChMcLogger {
|
||||
)
|
||||
public boolean reload(String args[]) {
|
||||
new DialogController().load();
|
||||
SyncController.syncAll(SyncType.DIALOG_CATEGORY);
|
||||
SyncController.syncAllDialogs();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import foxz.commandhelper.annotations.SubCommand;
|
||||
import foxz.commandhelper.permissions.OpOnly;
|
||||
import foxz.commandhelper.permissions.ParamCheck;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -171,7 +170,7 @@ public class CmdQuest extends ChMcLogger {
|
||||
)
|
||||
public boolean reload(String args[]) {
|
||||
new QuestController().load();
|
||||
SyncController.syncAll(SyncType.QUEST_CATEGORY);
|
||||
SyncController.syncAllQuests();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package kamkeel.npcs.client.renderer;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
||||
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
@@ -25,7 +26,7 @@ public class EnergyChargePreviewRenderer {
|
||||
|
||||
float partialTicks = event.partialTicks;
|
||||
|
||||
for (EntityEnergyProjectile entity : EnergyChargePreviewManager.ClientInstance.getPreviews()) {
|
||||
for (EntityEnergyAbility entity : EnergyChargePreviewManager.ClientInstance.getPreviews()) {
|
||||
if (entity == null || entity.isDead) continue;
|
||||
|
||||
double x = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks - RenderManager.renderPosX;
|
||||
|
||||
@@ -38,9 +38,6 @@ public abstract class RenderEnergy extends Render {
|
||||
*/
|
||||
protected boolean shouldSkipInitialActiveRender(Entity entity) {
|
||||
if (!(entity instanceof EntityEnergyAbility)) return false;
|
||||
// Moving projectiles must be visible at their launch point. Hiding their first
|
||||
// tick makes faster shots first appear several blocks away from the caster.
|
||||
if (entity instanceof EntityEnergyProjectile) return false;
|
||||
EntityEnergyAbility ability = (EntityEnergyAbility) entity;
|
||||
return !ability.isPreviewMode() && !ability.isCharging() && ability.ticksExisted <= HIDE_INITIAL_ACTIVE_TICKS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
package kamkeel.npcs.client.renderer;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarOrigin;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarShape;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* Renders EntityAbilityPillar.
|
||||
*
|
||||
* Radius: snaps immediately to targetRadius when charging ends — no interpolation.
|
||||
* Height: grows linearly with no easing, at the speed defined in pillarData.
|
||||
*
|
||||
* FROM_GROUND: baseY = posY, tipY = posY + height (grows up).
|
||||
* FROM_ABOVE: baseY = posY, tipY = posY - height (grows down from ceiling anchor).
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderEnergyPillar extends RenderEnergy {
|
||||
|
||||
private static final int CIRCLE_SEGMENTS = 24;
|
||||
private static final float INNER_SCALE = 0.6f;
|
||||
|
||||
@Override
|
||||
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTicks) {
|
||||
EntityAbilityPillar pillar = (EntityAbilityPillar) entity;
|
||||
|
||||
if (shouldSkipInitialActiveRender(pillar)) return;
|
||||
|
||||
setupRenderState();
|
||||
float proximityAlpha = getProximityAlphaFactor(pillar, x, y, z);
|
||||
|
||||
if (pillar.isCharging()) {
|
||||
renderCharging(pillar, x, y, z, partialTicks, proximityAlpha);
|
||||
restoreRenderState();
|
||||
return;
|
||||
}
|
||||
|
||||
// Radius: use raw value directly — snaps on charging end, no interpolation needed
|
||||
float radius = pillar.getPillarRadius();
|
||||
// Height: linearly interpolated between prev and current (no easing)
|
||||
float height = pillar.getInterpolatedPillarHeight(partialTicks);
|
||||
|
||||
if (radius <= 0.01f || height <= 0.01f) {
|
||||
restoreRenderState();
|
||||
return;
|
||||
}
|
||||
|
||||
float baseY, tipY;
|
||||
if (pillar.getPillarOrigin() == PillarOrigin.FROM_ABOVE) {
|
||||
baseY = (float) y;
|
||||
tipY = (float) y - height;
|
||||
} else {
|
||||
baseY = (float) y;
|
||||
tipY = (float) y + height;
|
||||
}
|
||||
|
||||
float rotationAngle = pillar.getRotationSpeed() != 0f
|
||||
? (pillar.ticksExisted + partialTicks) * pillar.getRotationSpeed() : 0f;
|
||||
|
||||
float innerRadius = radius * INNER_SCALE;
|
||||
int innerColor = pillar.getInnerColor();
|
||||
int outerColor = pillar.getOuterColor();
|
||||
float innerAlpha = pillar.getInnerAlpha() * proximityAlpha;
|
||||
|
||||
if (pillar.isOuterColorEnabled()) {
|
||||
float outerRadius = innerRadius + pillar.getOuterColorWidth() * radius;
|
||||
float outerAlpha = pillar.getOuterColorAlpha() * proximityAlpha;
|
||||
float midRadius = innerRadius + (outerRadius - innerRadius) * 0.5f;
|
||||
|
||||
GL11.glDepthMask(false);
|
||||
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, outerRadius, outerColor, outerAlpha * 0.4f, rotationAngle);
|
||||
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, midRadius, outerColor, outerAlpha * 0.7f, rotationAngle);
|
||||
GL11.glDepthMask(true);
|
||||
}
|
||||
|
||||
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, innerRadius, innerColor, innerAlpha, rotationAngle);
|
||||
|
||||
if (pillar.hasLightningEffect()) {
|
||||
float midWorldY = (baseY + tipY) * 0.5f;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x, midWorldY, z);
|
||||
renderAttachedLightning(pillar, INNER_SCALE, radius);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
restoreRenderState();
|
||||
}
|
||||
|
||||
// ==================== CHARGING ====================
|
||||
|
||||
private void renderCharging(EntityAbilityPillar pillar, double x, double y, double z,
|
||||
float partialTicks, float proximityAlpha) {
|
||||
// Use targetRadius directly — pillarRadius during charging is only 0.01 initially
|
||||
// and grows via DataWatcher which is unavailable on preview entities.
|
||||
float targetRadius = pillar.getPillarData().targetRadius;
|
||||
float chargeProgress = pillar.getInterpolatedChargeProgress(partialTicks);
|
||||
float renderRadius = targetRadius * chargeProgress;
|
||||
|
||||
if (renderRadius <= 0.01f) return;
|
||||
|
||||
float pulseTime = pillar.ticksExisted + partialTicks;
|
||||
renderRadius *= (1.0f + (float) Math.sin(pulseTime * 0.2f) * 0.08f);
|
||||
|
||||
float baseY = (float) y;
|
||||
float tipY = baseY + 0.05f;
|
||||
|
||||
float rotationAngle = pillar.getRotationSpeed() != 0f
|
||||
? (pillar.ticksExisted + partialTicks) * pillar.getRotationSpeed() : 0f;
|
||||
|
||||
float innerRadius = renderRadius * INNER_SCALE;
|
||||
int innerColor = pillar.getInnerColor();
|
||||
int outerColor = pillar.getOuterColor();
|
||||
float innerAlpha = pillar.getInnerAlpha() * proximityAlpha;
|
||||
|
||||
if (pillar.hasLightningEffect()) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x, y + 0.025f, z);
|
||||
renderAttachedLightning(pillar, INNER_SCALE, renderRadius);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
if (pillar.isOuterColorEnabled()) {
|
||||
float outerRadius = innerRadius + pillar.getOuterColorWidth() * renderRadius;
|
||||
float outerAlpha = pillar.getOuterColorAlpha() * proximityAlpha;
|
||||
float midRadius = innerRadius + (outerRadius - innerRadius) * 0.5f;
|
||||
|
||||
GL11.glDepthMask(false);
|
||||
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, outerRadius, outerColor, outerAlpha * 0.4f, rotationAngle);
|
||||
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, midRadius, outerColor, outerAlpha * 0.7f, rotationAngle);
|
||||
GL11.glDepthMask(true);
|
||||
}
|
||||
|
||||
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, innerRadius, innerColor, innerAlpha, rotationAngle);
|
||||
}
|
||||
|
||||
// ==================== SHAPE DISPATCH ====================
|
||||
|
||||
private void renderPillarShape(PillarShape shape, double x, float baseY, float tipY,
|
||||
double z, float radius, int color, float alpha, float rotationAngle) {
|
||||
if (shape == PillarShape.SQUARE) {
|
||||
renderSquarePillar(x, baseY, tipY, z, radius, color, alpha, rotationAngle);
|
||||
} else {
|
||||
renderCylinderPillar(x, baseY, tipY, z, radius, color, alpha, rotationAngle);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== CYLINDER ====================
|
||||
|
||||
private void renderCylinderPillar(double cx, float baseY, float tipY, double cz,
|
||||
float radius, int color, float alpha, float rotationAngle) {
|
||||
float[] rgb = extractRGB(color);
|
||||
float r = rgb[0], g = rgb[1], b = rgb[2];
|
||||
|
||||
float[] cosTable = new float[CIRCLE_SEGMENTS + 1];
|
||||
float[] sinTable = new float[CIRCLE_SEGMENTS + 1];
|
||||
double rotRad = Math.toRadians(rotationAngle);
|
||||
for (int i = 0; i <= CIRCLE_SEGMENTS; i++) {
|
||||
double angle = 2.0 * Math.PI * i / CIRCLE_SEGMENTS + rotRad;
|
||||
cosTable[i] = (float) Math.cos(angle);
|
||||
sinTable[i] = (float) Math.sin(angle);
|
||||
}
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorRGBA_F(r, g, b, alpha);
|
||||
for (int i = 0; i < CIRCLE_SEGMENTS; i++) {
|
||||
float x1 = (float) cx + cosTable[i] * radius;
|
||||
float z1 = (float) cz + sinTable[i] * radius;
|
||||
float x2 = (float) cx + cosTable[i + 1] * radius;
|
||||
float z2 = (float) cz + sinTable[i + 1] * radius;
|
||||
tess.setNormal((cosTable[i] + cosTable[i + 1]) * 0.5f, 0, (sinTable[i] + sinTable[i + 1]) * 0.5f);
|
||||
tess.addVertex(x1, baseY, z1);
|
||||
tess.addVertex(x2, baseY, z2);
|
||||
tess.addVertex(x2, tipY, z2);
|
||||
tess.addVertex(x1, tipY, z1);
|
||||
}
|
||||
tess.draw();
|
||||
|
||||
float capMinY = Math.min(baseY, tipY);
|
||||
float capMaxY = Math.max(baseY, tipY);
|
||||
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorRGBA_F(r, g, b, alpha);
|
||||
tess.setNormal(0, -1, 0);
|
||||
for (int i = 0; i < CIRCLE_SEGMENTS; i++) {
|
||||
float x1 = (float) cx + cosTable[i] * radius;
|
||||
float z1 = (float) cz + sinTable[i] * radius;
|
||||
float x2 = (float) cx + cosTable[i + 1] * radius;
|
||||
float z2 = (float) cz + sinTable[i + 1] * radius;
|
||||
tess.addVertex((float) cx, capMinY, (float) cz);
|
||||
tess.addVertex(x2, capMinY, z2);
|
||||
tess.addVertex(x1, capMinY, z1);
|
||||
tess.addVertex((float) cx, capMinY, (float) cz);
|
||||
}
|
||||
tess.draw();
|
||||
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorRGBA_F(r, g, b, alpha);
|
||||
tess.setNormal(0, 1, 0);
|
||||
for (int i = 0; i < CIRCLE_SEGMENTS; i++) {
|
||||
float x1 = (float) cx + cosTable[i] * radius;
|
||||
float z1 = (float) cz + sinTable[i] * radius;
|
||||
float x2 = (float) cx + cosTable[i + 1] * radius;
|
||||
float z2 = (float) cz + sinTable[i + 1] * radius;
|
||||
tess.addVertex((float) cx, capMaxY, (float) cz);
|
||||
tess.addVertex(x1, capMaxY, z1);
|
||||
tess.addVertex(x2, capMaxY, z2);
|
||||
tess.addVertex((float) cx, capMaxY, (float) cz);
|
||||
}
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
// ==================== SQUARE ====================
|
||||
|
||||
private void renderSquarePillar(double cx, float baseY, float tipY, double cz,
|
||||
float radius, int color, float alpha, float rotationAngle) {
|
||||
float[] rgb = extractRGB(color);
|
||||
float r = rgb[0], g = rgb[1], b = rgb[2];
|
||||
|
||||
double rotRad = Math.toRadians(rotationAngle);
|
||||
float cosA = (float) Math.cos(rotRad);
|
||||
float sinA = (float) Math.sin(rotRad);
|
||||
|
||||
float[] lx = {-radius, radius, radius, -radius};
|
||||
float[] lz = {-radius, -radius, radius, radius};
|
||||
float[][] corners = new float[4][2];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
corners[i][0] = (float) cx + lx[i] * cosA - lz[i] * sinA;
|
||||
corners[i][1] = (float) cz + lx[i] * sinA + lz[i] * cosA;
|
||||
}
|
||||
|
||||
float capMinY = Math.min(baseY, tipY);
|
||||
float capMaxY = Math.max(baseY, tipY);
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorRGBA_F(r, g, b, alpha);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int next = (i + 1) % 4;
|
||||
float x1 = corners[i][0], z1 = corners[i][1];
|
||||
float x2 = corners[next][0], z2 = corners[next][1];
|
||||
float nx = (x1 + x2) * 0.5f - (float) cx;
|
||||
float nz = (z1 + z2) * 0.5f - (float) cz;
|
||||
float nlen = (float) Math.sqrt(nx * nx + nz * nz);
|
||||
if (nlen > 0) { nx /= nlen; nz /= nlen; }
|
||||
tess.setNormal(nx, 0, nz);
|
||||
tess.addVertex(x1, baseY, z1);
|
||||
tess.addVertex(x2, baseY, z2);
|
||||
tess.addVertex(x2, tipY, z2);
|
||||
tess.addVertex(x1, tipY, z1);
|
||||
}
|
||||
|
||||
tess.setNormal(0, -1, 0);
|
||||
tess.addVertex(corners[0][0], capMinY, corners[0][1]);
|
||||
tess.addVertex(corners[3][0], capMinY, corners[3][1]);
|
||||
tess.addVertex(corners[2][0], capMinY, corners[2][1]);
|
||||
tess.addVertex(corners[1][0], capMinY, corners[1][1]);
|
||||
|
||||
tess.setNormal(0, 1, 0);
|
||||
tess.addVertex(corners[0][0], capMaxY, corners[0][1]);
|
||||
tess.addVertex(corners[1][0], capMaxY, corners[1][1]);
|
||||
tess.addVertex(corners[2][0], capMaxY, corners[2][1]);
|
||||
tess.addVertex(corners[3][0], capMaxY, corners[3][1]);
|
||||
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceLocation getEntityTexture(Entity entity) {
|
||||
return WHITE_TEXTURE;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,6 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 3D Vector helper class for lightning calculations.
|
||||
* Adapted from Botania's Vector3 by ChickenBones.
|
||||
@@ -183,9 +181,4 @@ public class Vec3d {
|
||||
Vec3d v = (Vec3d) o;
|
||||
return x == v.x && y == v.y && z == v.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -94,7 +93,7 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]) {
|
||||
new DialogController().load();
|
||||
SyncController.syncAll(SyncType.DIALOG_CATEGORY);
|
||||
SyncController.syncAllDialogs();
|
||||
sendResult(sender, "Dialogs Reloaded");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.command.CommandException;
|
||||
@@ -394,7 +393,7 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]) {
|
||||
new QuestController().load();
|
||||
SyncController.syncAll(SyncType.QUEST_CATEGORY);
|
||||
SyncController.syncAllQuests();
|
||||
sendResult(sender, "Quests Reloaded");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,23 +32,12 @@ import kamkeel.npcs.controllers.data.ability.type.AbilitySlam;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityTeleport;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityTrap;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityVortex;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityBeam;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityDisc;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityDome;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityLaser;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityOrb;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityShield;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilitySweeper;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityWall;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.*;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.controllers.data.AbilityScript;
|
||||
import noppes.npcs.controllers.data.ChainedAbilityScript;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
@@ -181,6 +170,8 @@ public class AbilityController implements IAbilityHandler {
|
||||
registerType(AbilityDome::new);
|
||||
registerType(AbilityWall::new);
|
||||
registerType(AbilityShield::new);
|
||||
|
||||
registerType(AbilityPillar::new);
|
||||
}
|
||||
|
||||
private void registerBuiltinConditionTypes() {
|
||||
@@ -397,7 +388,7 @@ public class AbilityController implements IAbilityHandler {
|
||||
customAbilitiesById.put(uuid, ability);
|
||||
customAbilityRevision++;
|
||||
LogWriter.script("Saved custom ability: " + name + " [" + uuid + "]");
|
||||
SyncController.syncAll(SyncType.CUSTOM_ABILITY);
|
||||
SyncController.syncAllCustomAbilities();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error saving custom ability: " + name, e);
|
||||
@@ -473,30 +464,16 @@ public class AbilityController implements IAbilityHandler {
|
||||
pData.abilityData.lockAbility(name);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (uuid != null && !uuid.isEmpty()) {
|
||||
pData.abilityData.setToggleEntryDirect(uuid, 0);
|
||||
}
|
||||
pData.abilityData.setToggleEntryDirect(name, 0);
|
||||
|
||||
if (pData.hotbarData != null) {
|
||||
pData.hotbarData.validateSlots();
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
pData.save();
|
||||
}
|
||||
|
||||
if (pData.player instanceof EntityPlayerMP) {
|
||||
PlayerAbilitySyncHelper.syncAbilities((EntityPlayerMP) pData.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
customAbilityRevision++;
|
||||
LogWriter.script("Deleted custom ability: " + name);
|
||||
SyncController.syncAll(SyncType.CUSTOM_ABILITY);
|
||||
SyncController.syncAllCustomAbilities();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -783,7 +760,7 @@ public class AbilityController implements IAbilityHandler {
|
||||
chainedAbilitiesById.put(uuid, chain);
|
||||
chainedAbilityRevision++;
|
||||
LogWriter.script("Saved chained ability: " + name + " [" + uuid + "]");
|
||||
SyncController.syncAll(SyncType.CHAINED_ABILITY);
|
||||
SyncController.syncAllChainedAbilities();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error saving chained ability: " + name, e);
|
||||
@@ -863,7 +840,7 @@ public class AbilityController implements IAbilityHandler {
|
||||
|
||||
chainedAbilityRevision++;
|
||||
LogWriter.script("Deleted chained ability: " + name);
|
||||
SyncController.syncAll(SyncType.CHAINED_ABILITY);
|
||||
SyncController.syncAllChainedAbilities();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1380,17 +1357,6 @@ public class AbilityController implements IAbilityHandler {
|
||||
return health;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire modifyBarrierMeleeDamage on all extenders. Cumulative — each extender's output feeds the next.
|
||||
*/
|
||||
public float fireModifyBarrierMeleeDamage(EntityEnergyBarrier barrier, EntityLivingBase attacker, float baseDamage) {
|
||||
float damage = baseDamage;
|
||||
for (IAbilityExtender ext : extenders) {
|
||||
damage = ext.modifyBarrierMeleeDamage(barrier, attacker, damage);
|
||||
}
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire onAbilityHeal on all extenders. Chain of responsibility — first true wins.
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -840,7 +840,19 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
return sb.toString();
|
||||
}).tab("General"));
|
||||
|
||||
defs.add(SubGuiAbilityMagic.createMagicField(magicData));
|
||||
defs.add(FieldDef.subGuiField("ability.magic.editor",
|
||||
() -> new SubGuiAbilityMagic(magicData.copy()),
|
||||
gui -> {
|
||||
MagicData result = ((SubGuiAbilityMagic) gui).magicData;
|
||||
magicData.getMagics().clear();
|
||||
for (Map.Entry<Integer, MagicEntry> e : result.getMagics().entrySet()) {
|
||||
magicData.getMagics().put(e.getKey(), e.getValue());
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> magicData.isEmpty()
|
||||
? StatCollector.translateToLocal("ability.magic.usesCaster")
|
||||
: magicData.getMagics().size() + " Magic(s)")
|
||||
.tab("General"));
|
||||
}
|
||||
|
||||
// ── Target tab ───────────────────────────────────────────────
|
||||
@@ -1050,11 +1062,10 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
return null;
|
||||
}
|
||||
|
||||
int windUp = getWindUpTicks();
|
||||
telegraph.setDurationTicks(windUp);
|
||||
telegraph.setDurationTicks(windUpTicks);
|
||||
telegraph.setColor(windUpColor);
|
||||
telegraph.setWarningColor(activeColor);
|
||||
telegraph.setWarningStartTick(Math.max(5, windUp / 4));
|
||||
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
|
||||
telegraph.setHeightOffset(telegraphHeightOffset);
|
||||
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw);
|
||||
@@ -1172,7 +1183,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
this.burstIndex = 0;
|
||||
this.burstEntities.clear();
|
||||
|
||||
if (getWindUpTicks() <= 0) {
|
||||
if (windUpTicks <= 0) {
|
||||
this.phase = AbilityPhase.ACTIVE;
|
||||
} else {
|
||||
this.phase = AbilityPhase.WINDUP;
|
||||
@@ -1194,7 +1205,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
|
||||
switch (phase) {
|
||||
case WINDUP:
|
||||
if (currentTick >= getWindUpTicks()) {
|
||||
if (currentTick >= windUpTicks) {
|
||||
phase = AbilityPhase.ACTIVE;
|
||||
currentTick = 0;
|
||||
return true;
|
||||
|
||||
+19
-7
@@ -34,15 +34,27 @@ public class ConditionHasEffect extends AbilityCondition {
|
||||
return CustomEffectController.getInstance().hasEffect(player, effectId, effectIndex);
|
||||
}
|
||||
|
||||
public void setEffect(int effectId, int effectIndex) {
|
||||
this.effectId = effectId;
|
||||
this.effectIndex = effectIndex;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void getConditionDefinitions(List<FieldDef> defs) {
|
||||
defs.add(SubGuiCustomEffectSelect.createSelectField(this));
|
||||
defs.add(FieldDef.subGuiField("condition.select_effect",
|
||||
() -> new SubGuiCustomEffectSelect(effectId, effectIndex),
|
||||
gui -> {
|
||||
SubGuiCustomEffectSelect sel = (SubGuiCustomEffectSelect) gui;
|
||||
if (sel.getSelectedEffectId() >= 0) {
|
||||
effectId = sel.getSelectedEffectId();
|
||||
effectIndex = sel.getSelectedIndex();
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> {
|
||||
if (effectId < 0) return "None";
|
||||
CustomEffect effect = getEffect();
|
||||
return effect != null ? effect.getName() : "ID:" + effectId;
|
||||
})
|
||||
.clearable(() -> {
|
||||
effectId = -1;
|
||||
effectIndex = 0;
|
||||
}));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -62,7 +74,7 @@ public class ConditionHasEffect extends AbilityCondition {
|
||||
return effectId >= 0;
|
||||
}
|
||||
|
||||
public CustomEffect getEffect() {
|
||||
private CustomEffect getEffect() {
|
||||
HashMap<Integer, CustomEffect> map = CustomEffectController.getInstance().getEffectMap(effectIndex);
|
||||
return map != null ? map.get(effectId) : null;
|
||||
}
|
||||
|
||||
+14
-1
@@ -38,7 +38,20 @@ public class ConditionQuestCompleted extends AbilityCondition {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void getConditionDefinitions(List<FieldDef> defs) {
|
||||
defs.add(GuiQuestSelection.createConditionField(this));
|
||||
defs.add(FieldDef.subGuiField("condition.select_quest",
|
||||
() -> new GuiQuestSelection(questId),
|
||||
gui -> {
|
||||
GuiQuestSelection sel = (GuiQuestSelection) gui;
|
||||
if (sel.selectedQuest != null) {
|
||||
questId = sel.selectedQuest.id;
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> {
|
||||
if (questId < 0) return "None";
|
||||
Quest q = QuestController.Instance.quests.get(questId);
|
||||
return q != null ? q.title : "ID:" + questId;
|
||||
})
|
||||
.clearable(() -> questId = -1));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarMode;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarOrigin;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarShape;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Groups pillar-specific configuration for EntityAbilityPillar.
|
||||
* Enum types are owned by EntityAbilityPillar; this class handles serialization only.
|
||||
*/
|
||||
public class EnergyPillarData {
|
||||
|
||||
public float targetRadius = 2.0f;
|
||||
public float targetHeight = 10.0f;
|
||||
public float radiusGrowSpeed = 0.5f;
|
||||
public float heightGrowSpeed = 1.0f;
|
||||
public PillarMode mode = PillarMode.ANCHORED;
|
||||
public PillarOrigin origin = PillarOrigin.FROM_GROUND;
|
||||
public PillarShape shape = PillarShape.CIRCLE;
|
||||
public int spawnDelay = 10;
|
||||
|
||||
public EnergyPillarData() {
|
||||
}
|
||||
|
||||
public EnergyPillarData(float targetRadius, float targetHeight,
|
||||
float radiusGrowSpeed, float heightGrowSpeed,
|
||||
PillarMode mode, PillarOrigin origin, PillarShape shape,
|
||||
int spawnDelay) {
|
||||
this.targetRadius = targetRadius;
|
||||
this.targetHeight = targetHeight;
|
||||
this.radiusGrowSpeed = radiusGrowSpeed;
|
||||
this.heightGrowSpeed = heightGrowSpeed;
|
||||
this.mode = mode != null ? mode : PillarMode.ANCHORED;
|
||||
this.origin = origin != null ? origin : PillarOrigin.FROM_GROUND;
|
||||
this.shape = shape != null ? shape : PillarShape.CIRCLE;
|
||||
this.spawnDelay = Math.max(0, spawnDelay);
|
||||
}
|
||||
|
||||
public float getTargetRadius() {
|
||||
return targetRadius;
|
||||
}
|
||||
|
||||
public void setTargetRadius(float targetRadius) {
|
||||
this.targetRadius = targetRadius;
|
||||
}
|
||||
|
||||
public float getTargetHeight() {
|
||||
return targetHeight;
|
||||
}
|
||||
|
||||
public void setTargetHeight(float targetHeight) {
|
||||
this.targetHeight = targetHeight;
|
||||
}
|
||||
|
||||
public float getRadiusGrowSpeed() {
|
||||
return radiusGrowSpeed;
|
||||
}
|
||||
|
||||
public void setRadiusGrowSpeed(float radiusGrowSpeed) {
|
||||
this.radiusGrowSpeed = radiusGrowSpeed;
|
||||
}
|
||||
|
||||
public float getHeightGrowSpeed() {
|
||||
return heightGrowSpeed;
|
||||
}
|
||||
|
||||
public void setHeightGrowSpeed(float heightGrowSpeed) {
|
||||
this.heightGrowSpeed = heightGrowSpeed;
|
||||
}
|
||||
|
||||
public PillarMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(PillarMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public PillarOrigin getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
public void setOrigin(PillarOrigin origin) {
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
public PillarShape getShape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public void setShape(PillarShape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
public int getSpawnDelay() {
|
||||
return spawnDelay;
|
||||
}
|
||||
|
||||
public void setSpawnDelay(int spawnDelay) {
|
||||
this.spawnDelay = spawnDelay;
|
||||
}
|
||||
|
||||
public void writeNBT(NBTTagCompound nbt) {
|
||||
nbt.setFloat("targetRadius", targetRadius);
|
||||
nbt.setFloat("targetHeight", targetHeight);
|
||||
nbt.setFloat("radiusGrowSpeed", radiusGrowSpeed);
|
||||
nbt.setFloat("heightGrowSpeed", heightGrowSpeed);
|
||||
nbt.setInteger("pillarMode", mode.ordinal());
|
||||
nbt.setInteger("pillarOrigin", origin.ordinal());
|
||||
nbt.setInteger("pillarShape", shape.ordinal());
|
||||
nbt.setInteger("spawnDelay", spawnDelay);
|
||||
}
|
||||
|
||||
public void readNBT(NBTTagCompound nbt) {
|
||||
this.targetRadius = nbt.hasKey("targetRadius") ? nbt.getFloat("targetRadius") : 1.0f;
|
||||
this.targetHeight = nbt.hasKey("targetHeight") ? nbt.getFloat("targetHeight") : 2.0f;
|
||||
this.radiusGrowSpeed = nbt.hasKey("radiusGrowSpeed") ? nbt.getFloat("radiusGrowSpeed") : 0.1f;
|
||||
this.heightGrowSpeed = nbt.hasKey("heightGrowSpeed") ? nbt.getFloat("heightGrowSpeed") : 0.2f;
|
||||
|
||||
int modeOrd = nbt.hasKey("pillarMode") ? nbt.getInteger("pillarMode") : 0;
|
||||
this.mode = (modeOrd >= 0 && modeOrd < PillarMode.values().length) ? PillarMode.values()[modeOrd] : PillarMode.ANCHORED;
|
||||
|
||||
int originOrd = nbt.hasKey("pillarOrigin") ? nbt.getInteger("pillarOrigin") : 0;
|
||||
this.origin = (originOrd >= 0 && originOrd < PillarOrigin.values().length) ? PillarOrigin.values()[originOrd] : PillarOrigin.FROM_GROUND;
|
||||
|
||||
int shapeOrd = nbt.hasKey("pillarShape") ? nbt.getInteger("pillarShape") : 0;
|
||||
this.shape = (shapeOrd >= 0 && shapeOrd < PillarShape.values().length) ? PillarShape.values()[shapeOrd] : PillarShape.CIRCLE;
|
||||
|
||||
this.spawnDelay = nbt.hasKey("spawnDelay") ? Math.max(0, nbt.getInteger("spawnDelay")) : 0;
|
||||
}
|
||||
|
||||
public EnergyPillarData copy() {
|
||||
return new EnergyPillarData(
|
||||
targetRadius, targetHeight,
|
||||
radiusGrowSpeed, heightGrowSpeed,
|
||||
mode, origin, shape, spawnDelay
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package kamkeel.npcs.controllers.data.ability.extender;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
/**
|
||||
@@ -109,13 +108,6 @@ public interface IAbilityExtender {
|
||||
return baseHealth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify melee damage dealt to a barrier. Cumulative across all extenders.
|
||||
*/
|
||||
default float modifyBarrierMeleeDamage(EntityEnergyBarrier barrier, EntityLivingBase attacker, float baseDamage) {
|
||||
return baseDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an ability is about to heal an entity.
|
||||
* Return true to handle the healing (skip default entity.heal()).
|
||||
|
||||
@@ -43,7 +43,7 @@ public class AbilityCharge extends AbilityMovement implements IAbilityCharge {
|
||||
this.targetingMode = TargetingMode.AGGRO_TARGET;
|
||||
this.maxRange = 20.0f;
|
||||
this.minRange = 4.0f;
|
||||
this.lockMovement = LockMode.WINDUP_AND_ACTIVE;
|
||||
this.lockMovement = LockMode.WINDUP;
|
||||
this.cooldownTicks = 0;
|
||||
this.windUpTicks = 20;
|
||||
// LINE telegraph showing charge path
|
||||
@@ -58,11 +58,6 @@ public class AbilityCharge extends AbilityMovement implements IAbilityCharge {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAbilityMovement() {
|
||||
return true; // This ability drives the NPC's motion itself
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTargetingModeLocked() {
|
||||
return true;
|
||||
|
||||
@@ -3,21 +3,14 @@ package kamkeel.npcs.controllers.data.ability.type;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import noppes.npcs.AbstractDataAbilities;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.UserType;
|
||||
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.api.ability.type.IAbilityCounter;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -32,11 +25,6 @@ public class AbilityCounter extends AbilityDefend implements IAbilityCounter {
|
||||
private int counterAnimationId = -1;
|
||||
private String counterAnimationName = "Ability_Guard_Counter";
|
||||
|
||||
// True only while this counter is synchronously dispatching its retaliation damage.
|
||||
// Another counter that is hit by that retaliation inspects this flag on the source
|
||||
// entity's active counter to avoid reacting and creating infinite mutual retaliation.
|
||||
private transient boolean retaliating;
|
||||
|
||||
public AbilityCounter() {
|
||||
this.typeId = "ability.cnpc.counter";
|
||||
this.name = "Counter";
|
||||
@@ -72,35 +60,6 @@ public class AbilityCounter extends AbilityDefend implements IAbilityCounter {
|
||||
// DEFEND HOOKS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
protected boolean isValidDamageSource(DamageSource source) {
|
||||
if (!super.isValidDamageSource(source)) {
|
||||
return false;
|
||||
}
|
||||
// Break counter-vs-counter recursion: if the hit is itself a retaliation
|
||||
// from another counter that is mid-dispatch, don't counter it back.
|
||||
Entity sourceEntity = source.getEntity();
|
||||
AbstractDataAbilities abilities = getAbilitiesOf(sourceEntity);
|
||||
if (abilities != null) {
|
||||
Ability current = abilities.getCurrentAbility();
|
||||
if (current instanceof AbilityCounter && ((AbilityCounter) current).retaliating) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static AbstractDataAbilities getAbilitiesOf(Entity entity) {
|
||||
if (entity instanceof EntityPlayer) {
|
||||
PlayerData pData = PlayerData.get((EntityPlayer) entity);
|
||||
return pData != null ? pData.abilityData : null;
|
||||
}
|
||||
if (entity instanceof EntityNPCInterface) {
|
||||
return ((EntityNPCInterface) entity).abilities;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float performDefend(EntityLivingBase attacker, float amount) {
|
||||
// For PERCENT mode with DBC, use the full DBC-calculated damage, not vanilla base
|
||||
@@ -119,24 +78,13 @@ public class AbilityCounter extends AbilityDefend implements IAbilityCounter {
|
||||
|
||||
// Counter-attack through the standard ability damage pipeline.
|
||||
// DBCAbilityExtender handles DBC stat routing (ignore flags, scaling, etc.) automatically.
|
||||
if (caster != null && attacker != null && attacker.isEntityAlive() && damage > 0) {
|
||||
retaliating = true;
|
||||
try {
|
||||
applyAbilityDamage(caster, attacker, damage, 0);
|
||||
} finally {
|
||||
retaliating = false;
|
||||
}
|
||||
if (caster != null && attacker.isEntityAlive() && damage > 0) {
|
||||
applyAbilityDamage(caster, attacker, damage, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
retaliating = false;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// OVERRIDES
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -74,10 +74,6 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend {
|
||||
hitCount = 0;
|
||||
lastAttacker = null;
|
||||
lastDamageTaken = 0.0f;
|
||||
pendingDefendAnimation = null;
|
||||
defendAnimEndTick = -1;
|
||||
lastDefendTick = -1;
|
||||
pendingCompletion = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -107,7 +107,7 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
|
||||
readZoneNBT(nbt, 300);
|
||||
this.radius = nbt.getFloat("radius");
|
||||
this.damagePerSecond = nbt.getFloat("damagePerSecond");
|
||||
setDamageInterval(nbt.getInteger("damageInterval"));
|
||||
this.damageInterval = nbt.getInteger("damageInterval");
|
||||
this.affectsCaster = nbt.getBoolean("affectsCaster");
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
|
||||
}
|
||||
|
||||
public void setDamageInterval(int damageInterval) {
|
||||
this.damageInterval = Math.max(EntityAbilityZone.MIN_DAMAGE_INTERVAL, damageInterval);
|
||||
this.damageInterval = damageInterval;
|
||||
}
|
||||
|
||||
public boolean isAffectsCaster() {
|
||||
@@ -171,7 +171,6 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
|
||||
FieldDef.row(
|
||||
FieldDef.floatField("gui.dps", this::getDamagePerSecond, this::setDamagePerSecond),
|
||||
FieldDef.intField("gui.interval", this::getDamageInterval, this::setDamageInterval)
|
||||
.range(EntityAbilityZone.MIN_DAMAGE_INTERVAL, 2000)
|
||||
),
|
||||
FieldDef.boolField("ability.affectsCaster", this::isAffectsCaster, this::setAffectsCaster)
|
||||
.hover("ability.hover.affectsCaster"),
|
||||
|
||||
@@ -97,13 +97,6 @@ public class AbilityProjectile extends Ability implements IAbilityProjectile {
|
||||
dz /= len;
|
||||
}
|
||||
|
||||
if (isRotationLockedForCurrentPhase()) {
|
||||
Vec3 look = caster.getLookVec();
|
||||
if (look != null && (dx * look.xCoord + dy * look.yCoord + dz * look.zCoord) < 0.95) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
applyAbilityDamageWithDirection(caster, target, damage, knockback, dx, dz);
|
||||
world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f);
|
||||
|
||||
|
||||
@@ -300,7 +300,14 @@ public class AbilityTrap extends AbilityZone implements IAbilityTrap {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
protected void addPresetFieldDef(List<FieldDef> defs) {
|
||||
defs.add(SubGuiTrapPresetSelector.createPresetField(this::applyTrapPresetDefaults));
|
||||
defs.add(FieldDef.subGuiField("gui.applyPreset",
|
||||
SubGuiTrapPresetSelector::new,
|
||||
gui -> {
|
||||
SubGuiTrapPresetSelector selector = (SubGuiTrapPresetSelector) gui;
|
||||
if (selector.selectedPreset != null) {
|
||||
applyTrapPresetDefaults(selector.selectedPreset);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
@@ -690,7 +690,14 @@ public abstract class AbilityZone extends Ability {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected void addPresetFieldDef(List<FieldDef> defs) {
|
||||
defs.add(SubGuiZonePresetSelector.createPresetField(this::applyPresetDefaults));
|
||||
defs.add(FieldDef.subGuiField("gui.applyPreset",
|
||||
SubGuiZonePresetSelector::new,
|
||||
gui -> {
|
||||
SubGuiZonePresetSelector selector = (SubGuiZonePresetSelector) gui;
|
||||
if (selector.selectedPreset != null) {
|
||||
applyPresetDefaults(selector.selectedPreset);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
+1
-3
@@ -248,9 +248,7 @@ public abstract class AbilityEnergyProjectile<E extends EntityEnergyProjectile>
|
||||
* NPCs use their resolved target so launch math can track the target immediately.
|
||||
*/
|
||||
protected EntityLivingBase getLaunchTarget(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (isPlayerCaster(caster)) return null;
|
||||
if (isRotationLockedForCurrentPhase()) return null;
|
||||
return target;
|
||||
return isPlayerCaster(caster) ? null : target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+562
@@ -0,0 +1,562 @@
|
||||
package kamkeel.npcs.controllers.data.ability.type.energy;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyCombatData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.HitType;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||
import kamkeel.npcs.entity.EntityEnergyZone;
|
||||
import kamkeel.npcs.network.packets.data.energycharge.EnergyChargeRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.energycharge.EnergyChargeSpawnPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract base for all energy zone abilities (Pillar, etc.).
|
||||
* Extends AbilityEnergy for shared visual/lightning data.
|
||||
*
|
||||
* Handles:
|
||||
* - Multi-zone support with staggered spawning via fireDelay
|
||||
* - Charge visual lifecycle via EnergyChargeSpawnPacket + EnergyChargeTracker
|
||||
* - Windup -> execute -> active -> complete lifecycle
|
||||
* - Telegraph infrastructure (subclass defines shape and radius)
|
||||
* - NBT persistence for shared fields
|
||||
*
|
||||
* Subclasses must implement:
|
||||
* - createEntity() — instantiate the zone entity
|
||||
* - setupEntityCharging() — configure entity for charge visual
|
||||
* - setupEntityPreview() — configure entity for GUI preview
|
||||
* - createEntityArray() — typed array creation (generics limitation)
|
||||
* - getZoneTelegraphRadius() — telegraph size
|
||||
* - addTypeDefinitions() — type-specific GUI fields
|
||||
* - writeTypeSpecificNBT()
|
||||
* - readTypeSpecificNBT()
|
||||
*
|
||||
* @param <E> The zone entity type this ability spawns
|
||||
*/
|
||||
public abstract class AbilityEnergyZone<E extends EntityEnergyZone> extends AbilityEnergy {
|
||||
|
||||
protected static final int MAX_ZONES = 8;
|
||||
|
||||
// ==================== ZONE COUNT & STAGGER ====================
|
||||
|
||||
protected int zoneCount = 1;
|
||||
protected int fireDelay = 0;
|
||||
|
||||
// ==================== SHARED DATA ====================
|
||||
|
||||
protected final EnergyCombatData combatData;
|
||||
protected final EnergyLifespanData lifespanData;
|
||||
|
||||
// ==================== RUNTIME STATE ====================
|
||||
|
||||
protected transient E[] entities;
|
||||
protected transient boolean[] zoneSpawned;
|
||||
protected transient int spawnedCount;
|
||||
protected transient String[] chargeVisualIds;
|
||||
protected transient EntityLivingBase chargeVisualCaster;
|
||||
|
||||
protected transient List<double[]> preCalculatedPositions = new ArrayList<>();
|
||||
|
||||
// ==================== CONSTRUCTOR ====================
|
||||
|
||||
protected AbilityEnergyZone(EnergyDisplayData displayData,
|
||||
EnergyCombatData combatData,
|
||||
EnergyLifespanData lifespanData) {
|
||||
super(displayData);
|
||||
this.combatData = combatData;
|
||||
this.lifespanData = lifespanData;
|
||||
this.burstOverlap = true;
|
||||
}
|
||||
|
||||
// ==================== ABSTRACT METHODS ====================
|
||||
|
||||
/**
|
||||
* Instantiate a single zone entity at the given position.
|
||||
* Called when a zone actually spawns.
|
||||
*/
|
||||
protected abstract E createEntity(EntityLivingBase caster, EntityLivingBase target,
|
||||
double x, double y, double z,
|
||||
EnergyDisplayData resolved, int index);
|
||||
|
||||
/**
|
||||
* Configure entity for charge visual during windup (non-preview).
|
||||
*/
|
||||
protected abstract void setupEntityCharging(E entity, int index);
|
||||
|
||||
/**
|
||||
* Configure entity for GUI preview mode.
|
||||
*/
|
||||
protected abstract void setupEntityPreview(E entity, EntityLivingBase caster,
|
||||
EnergyDisplayData resolved, int index);
|
||||
|
||||
/**
|
||||
* Create typed array. Required because Java generics cannot create generic arrays.
|
||||
*/
|
||||
protected abstract E[] createEntityArray(int size);
|
||||
|
||||
/**
|
||||
* Telegraph radius for this zone type.
|
||||
*/
|
||||
protected abstract float getZoneTelegraphRadius();
|
||||
|
||||
/**
|
||||
* Add type-specific GUI field definitions.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected abstract void addTypeDefinitions(List<FieldDef> defs);
|
||||
|
||||
/**
|
||||
* Write type-specific fields to NBT.
|
||||
* Shared data classes are written by the base class.
|
||||
*/
|
||||
protected abstract void writeTypeSpecificNBT(NBTTagCompound nbt);
|
||||
|
||||
/**
|
||||
* Read type-specific fields from NBT.
|
||||
* Shared data classes are read by the base class.
|
||||
*/
|
||||
protected abstract void readTypeSpecificNBT(NBTTagCompound nbt);
|
||||
|
||||
// ==================== OVERRIDABLE HOOKS ====================
|
||||
|
||||
/**
|
||||
* Resolve the spawn position for zone index.
|
||||
* Default uses preCalculatedPositions when available, falls back to target position.
|
||||
* Subclasses override for type-specific positioning (e.g. Pillar MOVING mode).
|
||||
*/
|
||||
protected double[] getSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
if (index < preCalculatedPositions.size()) {
|
||||
return preCalculatedPositions.get(index);
|
||||
}
|
||||
if (target != null) {
|
||||
return new double[]{target.posX, target.posY, target.posZ};
|
||||
}
|
||||
return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the display data for a specific zone index.
|
||||
* Default returns the shared displayData. Override for per-zone color overrides.
|
||||
*/
|
||||
protected EnergyDisplayData resolveDisplay(int index) {
|
||||
return displayData;
|
||||
}
|
||||
|
||||
// ==================== ZONE COUNT ====================
|
||||
|
||||
public int getZoneCount() {
|
||||
return zoneCount;
|
||||
}
|
||||
|
||||
public void setZoneCount(int count) {
|
||||
this.zoneCount = Math.max(1, Math.min(count, MAX_ZONES));
|
||||
}
|
||||
|
||||
public int getFireDelay() {
|
||||
return fireDelay;
|
||||
}
|
||||
|
||||
public void setFireDelay(int delay) {
|
||||
this.fireDelay = Math.max(0, delay);
|
||||
}
|
||||
|
||||
// ==================== RUNTIME STATE INIT ====================
|
||||
|
||||
protected void initRuntimeState(EntityLivingBase caster) {
|
||||
entities = createEntityArray(zoneCount);
|
||||
zoneSpawned = new boolean[zoneCount];
|
||||
spawnedCount = 0;
|
||||
chargeVisualIds = new String[zoneCount];
|
||||
chargeVisualCaster = caster;
|
||||
}
|
||||
|
||||
// ==================== ENTITY CREATION ====================
|
||||
|
||||
protected E createZoneEntity(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
return createZoneEntityAt(caster, target, index, getSpawnPosition(caster, target, index));
|
||||
}
|
||||
|
||||
protected E createZoneEntityAt(EntityLivingBase caster, EntityLivingBase target, int index, double[] pos) {
|
||||
EnergyDisplayData resolved = resolveDisplay(index);
|
||||
E entity = createEntity(caster, target, pos[0], pos[1], pos[2], resolved, index);
|
||||
entity.setSourceAbility(this);
|
||||
entity.setIgnoreIFrames(this.isIgnoreIFrames());
|
||||
entity.setEffects(this.effects);
|
||||
// Copy ability combat data to entity so hitType, damage, knockback are in sync
|
||||
noppes.npcs.controllers.data.MagicData resolvedMagic = resolveMagicData(caster);
|
||||
if (resolvedMagic != null) {
|
||||
entity.setMagicData(resolvedMagic.copy());
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get spawn position for charge visual during windup.
|
||||
* Default: same as getSpawnPosition. Override for types where windup position
|
||||
* differs from execute position (e.g. Pillar MOVING uses target pos during windup).
|
||||
*/
|
||||
protected double[] getWindupSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
return getSpawnPosition(caster, target, index);
|
||||
}
|
||||
|
||||
protected void spawnZoneEntity(E entity, int index) {
|
||||
if (entity == null) return;
|
||||
spawnAbilityEntity(entity);
|
||||
entities[index] = entity;
|
||||
if (!zoneSpawned[index]) {
|
||||
zoneSpawned[index] = true;
|
||||
spawnedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
protected void spawnZoneAt(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
if (entities != null && entities[index] != null && !entities[index].isDead) return;
|
||||
E entity = createZoneEntity(caster, target, index);
|
||||
spawnZoneEntity(entity, index);
|
||||
}
|
||||
|
||||
// ==================== CHARGE VISUAL ====================
|
||||
|
||||
protected String getChargeVisualId(EntityLivingBase caster, int index) {
|
||||
return "energy_charge:" + caster.getEntityId() + ":" + executionStartTime + ":" + burstIndex + ":" + index;
|
||||
}
|
||||
|
||||
protected void spawnChargeVisual(EntityLivingBase caster, EntityLivingBase target, int index, int chargeDuration) {
|
||||
if (isPreview() || caster == null || caster.worldObj == null || caster.worldObj.isRemote) return;
|
||||
if (chargeVisualIds == null || index < 0 || index >= chargeVisualIds.length) return;
|
||||
|
||||
double[] windupPos = getWindupSpawnPosition(caster, target, index);
|
||||
E previewEntity = createZoneEntityAt(caster, target, index, windupPos);
|
||||
previewEntity.setPreviewMode(true);
|
||||
previewEntity.setPreviewOwner(caster);
|
||||
setupEntityCharging(previewEntity, index);
|
||||
previewEntity.setChargeDuration(Math.max(1, chargeDuration));
|
||||
previewEntity.setTargetEntity(target);
|
||||
|
||||
String id = getChargeVisualId(caster, index);
|
||||
chargeVisualIds[index] = id;
|
||||
chargeVisualCaster = caster;
|
||||
EnergyChargeSpawnPacket.sendToTracking(id, previewEntity, caster);
|
||||
|
||||
EnergyChargeTracker.Instance.add(new EnergyChargeTracker.ChargeEntry(
|
||||
id,
|
||||
previewEntity.getClass().getName(),
|
||||
previewEntity.exportSpawnNBT(),
|
||||
caster.getEntityId(),
|
||||
(int) caster.worldObj.getTotalWorldTime()
|
||||
));
|
||||
}
|
||||
|
||||
protected void removeChargeVisual(EntityLivingBase caster, int index) {
|
||||
if (isPreview() || caster == null || caster.worldObj == null || caster.worldObj.isRemote) return;
|
||||
if (chargeVisualIds == null || index < 0 || index >= chargeVisualIds.length) return;
|
||||
|
||||
String id = chargeVisualIds[index];
|
||||
if (id != null && !id.isEmpty()) {
|
||||
EnergyChargeRemovePacket.sendToTracking(id, caster);
|
||||
EnergyChargeTracker.Instance.remove(id, caster.getEntityId());
|
||||
chargeVisualIds[index] = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeAllChargeVisuals(EntityLivingBase caster) {
|
||||
if (chargeVisualIds == null || caster == null) return;
|
||||
for (int i = 0; i < chargeVisualIds.length; i++) {
|
||||
removeChargeVisual(caster, i);
|
||||
}
|
||||
if (!isPreview() && caster.worldObj != null && !caster.worldObj.isRemote) {
|
||||
EnergyChargeTracker.Instance.removeAllForCaster(caster.getEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== LIFECYCLE ====================
|
||||
|
||||
@Override
|
||||
public boolean allowOverlap() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowFreeOnCast() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTargetingModeLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetingMode[] getAllowedTargetingModes() {
|
||||
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadyForBurstCompletion(int activeTick) {
|
||||
return fireDelay <= 0 || activeTick >= fireDelay * (zoneCount - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
entities = null;
|
||||
zoneSpawned = null;
|
||||
spawnedCount = 0;
|
||||
preCalculatedPositions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, int tick) {
|
||||
if (caster.worldObj.isRemote && !isPreview()) return;
|
||||
|
||||
if (tick == 1) {
|
||||
initRuntimeState(caster);
|
||||
|
||||
if (isPreview()) {
|
||||
for (int i = 0; i < zoneCount; i++) {
|
||||
E previewEntity = createZoneEntity(caster, target, i);
|
||||
setupEntityPreview(previewEntity, caster, resolveDisplay(i), i);
|
||||
spawnAbilityEntity(previewEntity);
|
||||
entities[i] = previewEntity;
|
||||
zoneSpawned[i] = true;
|
||||
spawnedCount++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < zoneCount; i++) {
|
||||
spawnChargeVisual(caster, target, i, windUpTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetForBurst() {
|
||||
removeAllChargeVisuals(chargeVisualCaster);
|
||||
if (!burstOverlap) {
|
||||
cleanup();
|
||||
}
|
||||
entities = null;
|
||||
zoneSpawned = null;
|
||||
spawnedCount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (isPreview()) {
|
||||
if (entities == null) {
|
||||
initRuntimeState(caster);
|
||||
for (int i = 0; i < zoneCount; i++) {
|
||||
E previewEntity = createZoneEntity(caster, target, i);
|
||||
setupEntityPreview(previewEntity, caster, resolveDisplay(i), i);
|
||||
spawnAbilityEntity(previewEntity);
|
||||
entities[i] = previewEntity;
|
||||
zoneSpawned[i] = true;
|
||||
spawnedCount++;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (entities == null || zoneSpawned == null || entities.length != zoneCount) {
|
||||
initRuntimeState(caster);
|
||||
}
|
||||
|
||||
removeAllChargeVisuals(caster);
|
||||
|
||||
spawnZoneAt(caster, target, 0);
|
||||
|
||||
if (fireDelay <= 0) {
|
||||
for (int i = 1; i < zoneCount; i++) {
|
||||
spawnZoneAt(caster, target, i);
|
||||
}
|
||||
} else {
|
||||
for (int i = 1; i < zoneCount; i++) {
|
||||
spawnChargeVisual(caster, target, i, fireDelay * i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, int tick) {
|
||||
if (entities == null || zoneSpawned == null) {
|
||||
signalCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
if (fireDelay > 0) {
|
||||
for (int i = 1; i < zoneCount; i++) {
|
||||
if (tick == fireDelay * i) {
|
||||
removeChargeVisual(caster, i);
|
||||
spawnZoneAt(caster, target, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isFreeOnCast()) {
|
||||
int lastSpawnTick = fireDelay > 0 ? fireDelay * (zoneCount - 1) : 0;
|
||||
if (tick >= lastSpawnTick) {
|
||||
signalCompletion();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean allDead = spawnedCount >= zoneCount;
|
||||
if (allDead) {
|
||||
for (E entity : entities) {
|
||||
if (entity == null || entity.isDead) continue;
|
||||
if (!isPreview() && tick > 5 && entity.worldObj != null
|
||||
&& entity.worldObj.getEntityByID(entity.getEntityId()) != entity) {
|
||||
entity.setDead();
|
||||
continue;
|
||||
}
|
||||
allDead = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allDead) {
|
||||
int lastSpawnTick = fireDelay > 0 ? fireDelay * (zoneCount - 1) : 0;
|
||||
int maxLifetime = lifespanData.getMaxLifetime() > 0 ? lifespanData.getMaxLifetime() : 200;
|
||||
if (tick > lastSpawnTick + maxLifetime + 20) {
|
||||
cleanup();
|
||||
allDead = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (allDead) {
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
|
||||
removeAllChargeVisuals(caster);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) {
|
||||
removeAllChargeVisuals(caster);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
removeAllChargeVisuals(chargeVisualCaster);
|
||||
if (entities != null) {
|
||||
for (int i = 0; i < entities.length; i++) {
|
||||
if (entities[i] != null && !entities[i].isDead) {
|
||||
entities[i].setDead();
|
||||
}
|
||||
entities[i] = null;
|
||||
}
|
||||
}
|
||||
entities = null;
|
||||
zoneSpawned = null;
|
||||
spawnedCount = 0;
|
||||
chargeVisualIds = null;
|
||||
chargeVisualCaster = null;
|
||||
preCalculatedPositions.clear();
|
||||
}
|
||||
|
||||
// ==================== PREVIEW ====================
|
||||
|
||||
@Override
|
||||
public int getMaxPreviewDuration() {
|
||||
return lifespanData.getMaxLifetime() > 0 ? Math.min(lifespanData.getMaxLifetime(), 100) : 100;
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
public final void writeTypeNBT(NBTTagCompound nbt) {
|
||||
writeTypeSpecificNBT(nbt);
|
||||
|
||||
nbt.setInteger("zoneCount", zoneCount);
|
||||
nbt.setInteger("fireDelay", fireDelay);
|
||||
|
||||
writeEnergyNBT(nbt);
|
||||
combatData.writeNBT(nbt);
|
||||
lifespanData.writeNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readTypeNBT(NBTTagCompound nbt) {
|
||||
readTypeSpecificNBT(nbt);
|
||||
|
||||
this.zoneCount = Math.max(1, Math.min(nbt.getInteger("zoneCount"), MAX_ZONES));
|
||||
this.fireDelay = Math.max(0, nbt.getInteger("fireDelay"));
|
||||
|
||||
readEnergyNBT(nbt);
|
||||
combatData.readNBT(nbt);
|
||||
lifespanData.readNBT(nbt);
|
||||
}
|
||||
|
||||
// ==================== GUI ====================
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public final void getAbilityDefinitions(List<FieldDef> defs) {
|
||||
defs.add(FieldDef.enumField("ability.hitType", HitType.class,
|
||||
() -> HitType.fromOrdinal(getHitType()),
|
||||
v -> setHitType(v.ordinal()))
|
||||
.hover("ability.hover.hitType"));
|
||||
defs.add(FieldDef.intField("ability.multiHitDelay", this::getMultiHitDelayTicks, this::setMultiHitDelayTicks)
|
||||
.range(1, 200)
|
||||
.visibleWhen(() -> getHitType() == HitType.MULTI.ordinal())
|
||||
.hover("ability.hover.multiHitDelay"));
|
||||
defs.add(FieldDef.intField("ability.maxHits", this::getMaxHits, this::setMaxHits)
|
||||
.range(1, EnergyCombatData.MAX_HITS)
|
||||
.visibleWhen(() -> getHitType() != HitType.SINGLE.ordinal())
|
||||
.hover("ability.hover.maxHits"));
|
||||
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.intField("ability.zoneCount", this::getZoneCount, this::setZoneCount)
|
||||
.range(1, MAX_ZONES),
|
||||
FieldDef.intField("ability.fireDelay", this::getFireDelay, this::setFireDelay)
|
||||
.range(0, 200).visibleWhen(() -> zoneCount > 1)
|
||||
));
|
||||
|
||||
addTypeDefinitions(defs);
|
||||
|
||||
addEnergyColorDefinitions(defs);
|
||||
|
||||
defs.add(FieldDef.section("ability.section.effects").tab("ability.tab.visual"));
|
||||
defs.add(FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed)
|
||||
.tab("ability.tab.visual"));
|
||||
addEnergyLightningDefinitions(defs);
|
||||
}
|
||||
|
||||
// ==================== COMBAT GETTERS & SETTERS ====================
|
||||
|
||||
public float getDamage() { return combatData.getDamage(); }
|
||||
public void setDamage(float damage) { combatData.setDamage(damage); }
|
||||
|
||||
@Override
|
||||
public float getDisplayDamage() { return combatData.getDamage(); }
|
||||
|
||||
public float getKnockback() { return combatData.knockback; }
|
||||
public void setKnockback(float knockback) { combatData.setKnockback(knockback); }
|
||||
|
||||
public int getHitType() { return combatData.hitType.ordinal(); }
|
||||
public void setHitType(int hitType) { combatData.hitType = HitType.fromOrdinal(hitType); }
|
||||
|
||||
public int getMultiHitDelayTicks() { return combatData.multiHitDelayTicks; }
|
||||
public void setMultiHitDelayTicks(int delay) { combatData.multiHitDelayTicks = Math.max(1, delay); }
|
||||
|
||||
public int getMaxHits() { return combatData.getMaxHits(); }
|
||||
public void setMaxHits(int maxHits) { combatData.setMaxHits(maxHits); }
|
||||
|
||||
public int getMaxLifetime() { return lifespanData.getMaxLifetime(); }
|
||||
public void setMaxLifetime(int ticks) { lifespanData.setMaxLifetime(ticks); }
|
||||
}
|
||||
@@ -0,0 +1,487 @@
|
||||
package kamkeel.npcs.controllers.data.ability.type.energy;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.*;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.LockMode;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.OffsetAxis;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarMode;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarShape;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.entity.EntityAbilityPillar.MIN_HEIGHT;
|
||||
import static kamkeel.npcs.entity.EntityAbilityPillar.MIN_RADIUS;
|
||||
import static kamkeel.npcs.entity.EntityAbilityPillar.MAX_ZONE_HEIGHT;
|
||||
import static kamkeel.npcs.entity.EntityAbilityPillar.MAX_ZONE_RADIUS;
|
||||
|
||||
/**
|
||||
* Pillar zone ability.
|
||||
*
|
||||
* ANCHORED: spawns at target position at execute time.
|
||||
* - trackTarget: predicts where target will be based on current velocity, spawns there.
|
||||
* - followTarget (requires homing): pillar chases target after spawn.
|
||||
* When count > 1: each pillar after index 0 gets a random nearby position.
|
||||
*
|
||||
* MOVING: spawns in front of caster and travels forward.
|
||||
* - Without homing: straight line.
|
||||
* - With homing: steers toward target.
|
||||
* When count > 1: pillarOffset spaces pillars along offsetAxis relative to look vector.
|
||||
* OffsetAxis.Z = along look direction (one behind the other).
|
||||
* OffsetAxis.X = perpendicular to look direction (side by side).
|
||||
*
|
||||
* TODO 1. fix charging visual for ABOVE origin; 2. fix hitbox for ABOVE origin; 3. fix trackTarget to actually track the player
|
||||
*/
|
||||
public class AbilityPillar extends AbilityEnergyZone<EntityAbilityPillar> {
|
||||
|
||||
// ==================== CONFIG ====================
|
||||
|
||||
private EnergyPillarData pillarData = new EnergyPillarData();
|
||||
private EnergyHomingData homingData = new EnergyHomingData();
|
||||
|
||||
private float pillarOffset = 0f;
|
||||
private OffsetAxis offsetAxis = OffsetAxis.Z;
|
||||
|
||||
/** ANCHORED only: follow target after spawn (requires homing). */
|
||||
private boolean followTarget = false;
|
||||
|
||||
/** ANCHORED only: predict target position at spawn time from target velocity. */
|
||||
private boolean trackTarget = false;
|
||||
|
||||
// ==================== CONSTRUCTOR ====================
|
||||
|
||||
public AbilityPillar() {
|
||||
super(new EnergyDisplayData(), new EnergyCombatData(), new EnergyLifespanData());
|
||||
this.typeId = "ability.cnpc.pillar";
|
||||
this.name = "Pillar";
|
||||
this.targetingMode = TargetingMode.AGGRO_TARGET;
|
||||
this.maxRange = 25.0f;
|
||||
this.minRange = 5.0f;
|
||||
this.cooldownTicks = 0;
|
||||
this.windUpTicks = 30;
|
||||
this.lockMovement = LockMode.WINDUP;
|
||||
this.telegraphType = pillarData.shape.getTelegraphType();
|
||||
this.showTelegraph = true;
|
||||
}
|
||||
|
||||
// ==================== ABSTRACT IMPLEMENTATIONS ====================
|
||||
|
||||
@Override
|
||||
protected EntityAbilityPillar createEntity(EntityLivingBase caster, EntityLivingBase target,
|
||||
double x, double y, double z,
|
||||
EnergyDisplayData resolved, int index) {
|
||||
return new EntityAbilityPillar(caster.worldObj, caster, x, y, z,
|
||||
pillarData, resolved, combatData, homingData, lightningData, lifespanData);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupEntityCharging(EntityAbilityPillar entity, int index) {
|
||||
entity.setupCharging(windUpTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupEntityPreview(EntityAbilityPillar entity, EntityLivingBase caster,
|
||||
EnergyDisplayData resolved, int index) {
|
||||
entity.setupPreview(caster, pillarData, resolved, lightningData, windUpTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityAbilityPillar[] createEntityArray(int size) {
|
||||
return new EntityAbilityPillar[size];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getZoneTelegraphRadius() {
|
||||
return pillarData.targetRadius;
|
||||
}
|
||||
|
||||
// ==================== SPAWN POSITIONS ====================
|
||||
|
||||
@Override
|
||||
protected double[] getSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
if (pillarData.mode == PillarMode.MOVING) {
|
||||
return getMovingSpawnPosition(caster, index);
|
||||
}
|
||||
|
||||
// ANCHORED: spawn at target's current position at execute time
|
||||
if (index == 0) {
|
||||
if (target == null) return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||
|
||||
double spawnX = target.posX;
|
||||
double spawnZ = target.posZ;
|
||||
|
||||
if (trackTarget) {
|
||||
double motionX = target.posX - target.prevPosX;
|
||||
double motionZ = target.posZ - target.prevPosZ;
|
||||
|
||||
// Predict where target will be based on current motion and spawnDelay
|
||||
double prediction = pillarData.spawnDelay * homingData.getHomingStrength();
|
||||
|
||||
spawnX += motionX * prediction;
|
||||
spawnZ += motionZ * prediction;
|
||||
}
|
||||
|
||||
return new double[]{spawnX, target.posY, spawnZ};
|
||||
}
|
||||
|
||||
// index > 0: random nearby position
|
||||
double baseX = target != null ? target.posX : caster.posX;
|
||||
double baseZ = target != null ? target.posZ : caster.posZ;
|
||||
double baseY = target != null ? target.posY : caster.posY;
|
||||
float spread = Math.max(pillarData.targetRadius * 2.0f, 3.0f);
|
||||
double angle = Math.random() * Math.PI * 2;
|
||||
double dist = Math.sqrt(Math.random()) * spread;
|
||||
return new double[]{baseX + Math.cos(angle) * dist, baseY, baseZ + Math.sin(angle) * dist};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double[] getWindupSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
if (pillarData.mode == PillarMode.MOVING) {
|
||||
return getMovingSpawnPosition(caster, index);
|
||||
}
|
||||
if (index == 0 && !preCalculatedPositions.isEmpty()) {
|
||||
return preCalculatedPositions.get(0);
|
||||
}
|
||||
if (target != null) return new double[]{target.posX, target.posY, target.posZ};
|
||||
return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn position for MOVING mode.
|
||||
* OffsetAxis.Z = offset along look direction (one behind the other).
|
||||
* OffsetAxis.X = offset perpendicular to look direction (side by side).
|
||||
*/
|
||||
private double[] getMovingSpawnPosition(EntityLivingBase caster, int index) {
|
||||
Vec3 look = caster.getLookVec();
|
||||
if (look == null) return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||
|
||||
float baseDist = Math.max(1.0f, pillarData.targetRadius);
|
||||
|
||||
// Forward direction (normalized XZ)
|
||||
double fwdX = look.xCoord;
|
||||
double fwdZ = look.zCoord;
|
||||
double fwdLen = Math.sqrt(fwdX * fwdX + fwdZ * fwdZ);
|
||||
if (fwdLen > 0) { fwdX /= fwdLen; fwdZ /= fwdLen; }
|
||||
|
||||
// Right direction = perpendicular to forward in XZ plane
|
||||
double rightX = fwdZ;
|
||||
double rightZ = -fwdX;
|
||||
|
||||
double ox, oz;
|
||||
if (offsetAxis == OffsetAxis.Z) {
|
||||
// Along look direction
|
||||
ox = fwdX * pillarOffset * index;
|
||||
oz = fwdZ * pillarOffset * index;
|
||||
} else {
|
||||
// Perpendicular to look direction
|
||||
// Center the group: offset by -(count-1)/2 * spacing + index * spacing
|
||||
double centerOffset = -(zoneCount - 1) * 0.5 * pillarOffset + index * pillarOffset;
|
||||
ox = rightX * centerOffset;
|
||||
oz = rightZ * centerOffset;
|
||||
}
|
||||
|
||||
return new double[]{
|
||||
caster.posX + fwdX * baseDist + ox,
|
||||
caster.posY,
|
||||
caster.posZ + fwdZ * baseDist + oz
|
||||
};
|
||||
}
|
||||
|
||||
// ==================== EXECUTE ====================
|
||||
|
||||
@Override
|
||||
protected void spawnZoneAt(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
super.spawnZoneAt(caster, target, index);
|
||||
EntityAbilityPillar entity = entities[index];
|
||||
if (entity == null || entity.isDead) return;
|
||||
|
||||
if (target != null) {
|
||||
entity.setTarget(target);
|
||||
}
|
||||
|
||||
if (pillarData.mode == PillarMode.ANCHORED) {
|
||||
entity.setFollowTarget(followTarget && homingData.isHoming());
|
||||
}
|
||||
|
||||
if (pillarData.mode == PillarMode.MOVING && !homingData.isHoming()) {
|
||||
Vec3 look = caster.getLookVec();
|
||||
double mx = 0, mz = 0;
|
||||
if (target != null) {
|
||||
double dx = target.posX - entity.posX;
|
||||
double dz = target.posZ - entity.posZ;
|
||||
double len = Math.sqrt(dx * dx + dz * dz);
|
||||
if (len > 0) { mx = (dx / len) * homingData.getSpeed(); mz = (dz / len) * homingData.getSpeed(); }
|
||||
} else if (look != null) {
|
||||
mx = look.xCoord * homingData.getSpeed();
|
||||
mz = look.zCoord * homingData.getSpeed();
|
||||
}
|
||||
entity.setInitialMotion(mx, mz);
|
||||
}
|
||||
|
||||
entity.startGrowing();
|
||||
}
|
||||
|
||||
// ==================== TELEGRAPH ====================
|
||||
|
||||
@Override
|
||||
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster)) return null;
|
||||
|
||||
Telegraph telegraph = pillarData.shape == PillarShape.SQUARE
|
||||
? Telegraph.square(pillarData.targetRadius)
|
||||
: Telegraph.circle(pillarData.targetRadius);
|
||||
|
||||
telegraph.setDurationTicks(windUpTicks);
|
||||
telegraph.setColor(windUpColor);
|
||||
telegraph.setWarningColor(activeColor);
|
||||
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
|
||||
telegraph.setHeightOffset(telegraphHeightOffset);
|
||||
|
||||
double telegraphX, telegraphZ, telegraphY;
|
||||
|
||||
if (pillarData.mode == PillarMode.MOVING) {
|
||||
double[] pos = getMovingSpawnPosition(caster, 0);
|
||||
telegraphX = pos[0];
|
||||
telegraphZ = pos[2];
|
||||
telegraphY = findGroundLevel(caster.worldObj, telegraphX, caster.posY, telegraphZ);
|
||||
} else {
|
||||
if (target == null) return null;
|
||||
// Regular: start at target's current position, telegraph follows target
|
||||
telegraphX = target.posX;
|
||||
telegraphZ = target.posZ;
|
||||
telegraphY = findGroundLevel(caster.worldObj, telegraphX, target.posY, telegraphZ);
|
||||
}
|
||||
|
||||
preCalculatedPositions.clear();
|
||||
preCalculatedPositions.add(new double[]{telegraphX, telegraphY, telegraphZ});
|
||||
|
||||
TelegraphInstance instance = new TelegraphInstance(
|
||||
telegraph, telegraphX, telegraphY, telegraphZ, caster.rotationYaw);
|
||||
instance.setCasterEntityId(caster.getEntityId());
|
||||
|
||||
// ANCHORED: telegraph follows target in real time (regular and trackTarget)
|
||||
// MOVING: telegraph is static at spawn point
|
||||
if (pillarData.mode == PillarMode.ANCHORED && target != null) {
|
||||
instance.setEntityIdToFollow(target.getEntityId());
|
||||
} else {
|
||||
instance.setEntityIdToFollow(-1);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTelegraphRadius() {
|
||||
return pillarData.targetRadius;
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
protected void writeTypeSpecificNBT(NBTTagCompound nbt) {
|
||||
pillarData.writeNBT(nbt);
|
||||
homingData.writeNBT(nbt);
|
||||
nbt.setFloat("pillarOffset", pillarOffset);
|
||||
nbt.setInteger("offsetAxis", offsetAxis.ordinal());
|
||||
nbt.setBoolean("followTarget", followTarget);
|
||||
nbt.setBoolean("trackTarget", trackTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readTypeSpecificNBT(NBTTagCompound nbt) {
|
||||
pillarData.readNBT(nbt);
|
||||
homingData.readNBT(nbt);
|
||||
this.pillarOffset = nbt.hasKey("pillarOffset") ? nbt.getFloat("pillarOffset") : 0f;
|
||||
int axisOrd = nbt.hasKey("offsetAxis") ? nbt.getInteger("offsetAxis") : 1;
|
||||
this.offsetAxis = (axisOrd >= 0 && axisOrd < OffsetAxis.values().length)
|
||||
? OffsetAxis.values()[axisOrd] : OffsetAxis.Z;
|
||||
this.followTarget = nbt.hasKey("followTarget") && nbt.getBoolean("followTarget");
|
||||
this.trackTarget = nbt.hasKey("trackTarget") && nbt.getBoolean("trackTarget");
|
||||
}
|
||||
|
||||
// ==================== GUI ====================
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
protected void addTypeDefinitions(List<FieldDef> defs) {
|
||||
FieldDef.insertAfter(defs, "ability.fireDelay", FieldDef.row(
|
||||
FieldDef.floatField("ability.pillar.offset", this::getPillarOffset, this::setPillarOffset).range(0f, 20f),
|
||||
FieldDef.enumField("ability.pillar.offsetAxis", OffsetAxis.class, this::getOffsetAxis, this::setOffsetAxis)
|
||||
).visibleWhen(() -> zoneCount > 1 && pillarData.mode == PillarMode.MOVING));
|
||||
|
||||
defs.add(FieldDef.section("ability.section.pillar"));
|
||||
|
||||
defs.add(FieldDef.enumField("ability.pillarMode", PillarMode.class,
|
||||
this::getMode, this::setMode));
|
||||
|
||||
defs.add(FieldDef.enumField("ability.pillarOrigin", EntityAbilityPillar.PillarOrigin.class,
|
||||
this::getOrigin, this::setOrigin));
|
||||
|
||||
defs.add(FieldDef.enumField("ability.pillarShape", PillarShape.class,
|
||||
this::getShape, this::setShape));
|
||||
|
||||
defs.add(FieldDef.intField("ability.pillar.spawnDelay",
|
||||
this::getSpawnDelay, this::setSpawnDelay).range(0, getMaxLifetime()));
|
||||
|
||||
defs.add(FieldDef.section("ability.section.size"));
|
||||
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.floatField("ability.pillar.targetRadius", this::getTargetRadius, this::setTargetRadius).range(0.1f, 64f),
|
||||
FieldDef.floatField("ability.pillar.targetHeight", this::getTargetHeight, this::setTargetHeight).range(0.1f, 64f)
|
||||
));
|
||||
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.floatField("ability.pillar.radiusGrowSpeed", this::getRadiusGrowSpeed, this::setRadiusGrowSpeed),
|
||||
FieldDef.floatField("ability.pillar.heightGrowSpeed", this::getHeightGrowSpeed, this::setRadiusGrowSpeed)
|
||||
));
|
||||
|
||||
defs.add(FieldDef.section("ability.section.movement"));
|
||||
|
||||
defs.add(FieldDef.floatField("ability.speed", this::getPillarSpeed, this::setPillarSpeed)
|
||||
.range(0.01f, 10f));
|
||||
|
||||
defs.add(FieldDef.boolField("ability.homing", this::isHoming, this::setHoming));
|
||||
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.floatField("ability.homingStrength", this::getHomingStrength, this::setHomingStrength),
|
||||
FieldDef.floatField("ability.homingRange", this::getHomingRange, this::setHomingRange)
|
||||
).visibleWhen(this::isHoming));
|
||||
|
||||
// ANCHORED-only options
|
||||
defs.add(FieldDef.boolField("ability.pillar.trackTarget", this::isTrackTarget, this::setTrackTarget)
|
||||
.visibleWhen(() -> pillarData.mode == PillarMode.ANCHORED));
|
||||
|
||||
defs.add(FieldDef.boolField("ability.pillar.followTarget", this::isFollowTarget, this::setFollowTarget)
|
||||
.visibleWhen(() -> pillarData.mode == PillarMode.ANCHORED && homingData.isHoming()));
|
||||
|
||||
defs.add(FieldDef.section("ability.section.combat"));
|
||||
|
||||
defs.add(FieldDef.floatField("ability.damage", this::getDamage, this::setDamage).range(0f, 1000f));
|
||||
defs.add(FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback).range(0f, 10f));
|
||||
defs.add(FieldDef.intField("ability.maxLifetime", this::getMaxLifetime, this::setMaxLifetime).range(1, 1200));
|
||||
|
||||
defs.add(AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects));
|
||||
}
|
||||
|
||||
// ==================== GETTERS & SETTERS ====================
|
||||
|
||||
public EnergyPillarData getPillarData() { return pillarData; }
|
||||
public void setPillarData(EnergyPillarData data) { this.pillarData = data != null ? data : new EnergyPillarData(); }
|
||||
|
||||
public float getPillarOffset() { return pillarOffset; }
|
||||
public void setPillarOffset(float offset) { this.pillarOffset = Math.max(0f, Math.min(20f, offset)); }
|
||||
|
||||
public OffsetAxis getOffsetAxis() { return offsetAxis; }
|
||||
public void setOffsetAxis(OffsetAxis axis) { this.offsetAxis = axis != null ? axis : OffsetAxis.Z; }
|
||||
|
||||
public boolean isFollowTarget() { return followTarget; }
|
||||
public void setFollowTarget(boolean v) { this.followTarget = v; }
|
||||
|
||||
public boolean isTrackTarget() { return trackTarget; }
|
||||
public void setTrackTarget(boolean v) { this.trackTarget = v; }
|
||||
|
||||
public float getTargetRadius() {
|
||||
return pillarData.targetRadius;
|
||||
}
|
||||
|
||||
public void setTargetRadius(float targetRadius) {
|
||||
pillarData.targetRadius = Math.max(MIN_RADIUS, Math.min(MAX_ZONE_RADIUS, targetRadius));
|
||||
}
|
||||
|
||||
public float getTargetHeight() {
|
||||
return pillarData.targetHeight;
|
||||
}
|
||||
|
||||
public void setTargetHeight(float targetHeight) {
|
||||
pillarData.targetHeight = Math.max(MIN_HEIGHT, Math.min(MAX_ZONE_HEIGHT, targetHeight));
|
||||
}
|
||||
|
||||
public float getRadiusGrowSpeed() {
|
||||
return pillarData.radiusGrowSpeed;
|
||||
}
|
||||
|
||||
public void setRadiusGrowSpeed(float radiusGrowSpeed) {
|
||||
pillarData.radiusGrowSpeed = Math.max(0.01f, radiusGrowSpeed);
|
||||
}
|
||||
|
||||
public float getHeightGrowSpeed() {
|
||||
return pillarData.heightGrowSpeed;
|
||||
}
|
||||
|
||||
public void setHeightGrowSpeed(float heightGrowSpeed) {
|
||||
pillarData.heightGrowSpeed = Math.max(0.01f, heightGrowSpeed);
|
||||
}
|
||||
|
||||
public PillarMode getMode() {
|
||||
return pillarData.mode;
|
||||
}
|
||||
|
||||
public void setMode(PillarMode mode) {
|
||||
pillarData.mode = mode;
|
||||
}
|
||||
|
||||
public EntityAbilityPillar.PillarOrigin getOrigin() {
|
||||
return pillarData.origin;
|
||||
}
|
||||
|
||||
public void setOrigin(EntityAbilityPillar.PillarOrigin origin) {
|
||||
pillarData.origin = origin;
|
||||
}
|
||||
|
||||
public PillarShape getShape() {
|
||||
return pillarData.shape;
|
||||
}
|
||||
|
||||
public void setShape(PillarShape shape) {
|
||||
pillarData.shape = shape;
|
||||
}
|
||||
|
||||
public int getSpawnDelay() {
|
||||
return pillarData.spawnDelay;
|
||||
}
|
||||
|
||||
public void setSpawnDelay(int spawnDelay) {
|
||||
pillarData.spawnDelay = Math.max(0, Math.min(getMaxLifetime(), spawnDelay));
|
||||
}
|
||||
|
||||
public float getPillarSpeed() {
|
||||
return homingData.speed;
|
||||
}
|
||||
|
||||
public void setPillarSpeed(float speed) {
|
||||
homingData.speed = speed;
|
||||
}
|
||||
|
||||
public boolean isHoming() {
|
||||
return homingData.homing;
|
||||
}
|
||||
|
||||
public void setHoming(boolean homing) {
|
||||
homingData.homing = homing;
|
||||
}
|
||||
|
||||
public float getHomingStrength() {
|
||||
return homingData.homingStrength;
|
||||
}
|
||||
|
||||
public void setHomingStrength(float strength) {
|
||||
homingData.homingStrength = strength;
|
||||
}
|
||||
|
||||
public float getHomingRange() {
|
||||
return homingData.homingRange;
|
||||
}
|
||||
|
||||
public void setHomingRange(float range) {
|
||||
homingData.homingRange = range;
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
package kamkeel.npcs.controllers.data.energycharge;
|
||||
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -18,13 +18,13 @@ public class EnergyChargePreviewManager {
|
||||
|
||||
public static EnergyChargePreviewManager ClientInstance;
|
||||
|
||||
private final ConcurrentHashMap<String, EntityEnergyProjectile> previews = new ConcurrentHashMap<String, EntityEnergyProjectile>();
|
||||
private final ConcurrentHashMap<String, EntityEnergyAbility> previews = new ConcurrentHashMap<String, EntityEnergyAbility>();
|
||||
|
||||
public static void initClient() {
|
||||
ClientInstance = new EnergyChargePreviewManager();
|
||||
}
|
||||
|
||||
public void addPreview(String instanceId, EntityEnergyProjectile entity) {
|
||||
public void addPreview(String instanceId, EntityEnergyAbility entity) {
|
||||
if (instanceId == null || entity == null) return;
|
||||
previews.put(instanceId, entity);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class EnergyChargePreviewManager {
|
||||
previews.remove(instanceId);
|
||||
}
|
||||
|
||||
public Collection<EntityEnergyProjectile> getPreviews() {
|
||||
public Collection<EntityEnergyAbility> getPreviews() {
|
||||
return previews.values();
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ public class EnergyChargePreviewManager {
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<EntityEnergyProjectile> iterator = previews.values().iterator();
|
||||
Iterator<EntityEnergyAbility> iterator = previews.values().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
EntityEnergyProjectile entity = iterator.next();
|
||||
EntityEnergyAbility entity = iterator.next();
|
||||
if (entity == null || entity.isDead || entity.worldObj != world) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerDataSyncHandler;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -30,7 +30,7 @@ public class CNPCData implements IProfileData {
|
||||
public void save(EntityPlayer player) {
|
||||
PlayerData customNPCData = PlayerData.get(player);
|
||||
customNPCData.save();
|
||||
PlayerDataSyncHandler.syncPlayerData((EntityPlayerMP) player, false);
|
||||
SyncController.syncPlayerData((EntityPlayerMP) player, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Contract for a synchronized data type. Implementors handle both
|
||||
* server-side serialization and client-side deserialization for their
|
||||
* specific data type.
|
||||
*
|
||||
* <p>Each handler is registered with {@link SyncRegistry} and covers
|
||||
* all three sync actions: RELOAD (full), UPDATE (single entity),
|
||||
* and REMOVE (delete entity).</p>
|
||||
*
|
||||
* <p>Handlers that don't support UPDATE or REMOVE should use the
|
||||
* default no-op implementations.</p>
|
||||
*/
|
||||
public interface SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
/**
|
||||
* Serialize ALL objects of this type into an NBTTagCompound.
|
||||
* This is the supplier for the cache system.
|
||||
*
|
||||
* <p>Called lazily when the cache is dirty and a player needs data.
|
||||
* The returned compound is cached and chunked for transmission.</p>
|
||||
*
|
||||
* @return the serialized compound, or null if this type has no independent cache
|
||||
*/
|
||||
NBTTagCompound serializeAll();
|
||||
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
/**
|
||||
* Handle a RELOAD action on the client. Deserialize the full
|
||||
* dataset and replace the client-side data.
|
||||
*
|
||||
* <p>Implementations should:
|
||||
* <ol>
|
||||
* <li>Deserialize from the compound into a sync buffer</li>
|
||||
* <li>Atomically swap the sync buffer to the primary map</li>
|
||||
* <li>Reset the sync buffer for the next reload</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param fullCompound the full serialized dataset from {@link #serializeAll()}
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
default void clientHandleReload(NBTTagCompound fullCompound){
|
||||
// No-op: type does not support individual updates
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an UPDATE action on the client.
|
||||
* Deserialize a single object and insert/replace it in the client-side data.
|
||||
*
|
||||
* <p>Default: no-op. Types that don't support individual updates
|
||||
* use {@code syncAll()} for full reload instead.</p>
|
||||
*
|
||||
* @param compound the serialized single object
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
default void clientHandleUpdate(NBTTagCompound compound) {
|
||||
// No-op: type does not support individual updates
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an UPDATE action on the client.
|
||||
* Deserialize a single object and insert/replace it in the client-side data.
|
||||
*
|
||||
* <p>Default: no-op. Types that don't support individual updates
|
||||
* use {@code syncAll()} for full reload instead.</p>
|
||||
*
|
||||
* @param compound the serialized single object
|
||||
* @param categoryKey the parent category key (null if not applicable)
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
default void clientHandleUpdate(NBTTagCompound compound, String categoryKey) {
|
||||
// No-op: type does not support individual updates
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle an UPDATE action on the client. Deserialize a single
|
||||
* entity and insert/replace it in the client-side data.
|
||||
*
|
||||
* <p>Default: no-op. Types that don't support individual updates
|
||||
* use {@code syncAll()} for full reload instead.</p>
|
||||
*
|
||||
* @param compound the serialized single entity
|
||||
* @param categoryId the parent category ID (-1 if not applicable)
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
default void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
// No-op: type does not support individual updates
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a single object from client-side data.
|
||||
* Full object NBTTagCompound sent finer query control
|
||||
* Int-keyed handlers should override {@link #clientHandleRemove(int)} instead.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
default void clientHandleRemove(String key) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a single object with the given ID from client-side data.
|
||||
*
|
||||
* @param id the ID of the object to remove
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
default void clientHandleRemove(int id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this handler supports the UPDATE action.
|
||||
* Used for validation and self-documentation.
|
||||
*/
|
||||
default boolean supportsUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this handler supports the REMOVE action.
|
||||
* Used for validation and self-documentation.
|
||||
*/
|
||||
default boolean supportsRemove() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this type should be included in login sync.
|
||||
* Types that return true will be sent to players on login
|
||||
* and checked for revision deltas on reconnect.
|
||||
*
|
||||
* <p>Default: true. Override to false for types like PLAYERDATA
|
||||
* that are synced through separate mechanisms, or child types
|
||||
* (DIALOG, QUEST) that share their parent's cache.</p>
|
||||
*/
|
||||
default boolean isCachedType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of cache types that must be invalidated when
|
||||
* this type changes. Used for cascade invalidation.
|
||||
*
|
||||
* <p>Most types return just themselves. Parent-child types
|
||||
* (e.g. DIALOG maps to DIALOG_CATEGORY) point children
|
||||
* to the parent's cache.</p>
|
||||
*
|
||||
* @param self the SyncType this handler is registered under
|
||||
* @return the set of types to invalidate
|
||||
*/
|
||||
default Set<SyncType> getInvalidationTargets(SyncType self) {
|
||||
Set<SyncType> set = new HashSet<>();
|
||||
set.add(self);
|
||||
return set;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync;
|
||||
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import noppes.npcs.LogWriter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class SyncRegistry {
|
||||
|
||||
private static final LinkedHashMap<SyncType, SyncHandler> handlers = new LinkedHashMap<>();
|
||||
|
||||
private static SyncType[] loginTypesCache = null;
|
||||
|
||||
private SyncRegistry() {}
|
||||
|
||||
public static void register(SyncType type, SyncHandler handler) {
|
||||
if (type == null) throw new IllegalArgumentException("SyncType must not be null");
|
||||
if (handler == null) throw new IllegalArgumentException("SyncHandler must not be null for " + type);
|
||||
if (handlers.containsKey(type)) throw new IllegalStateException("SyncHandler already registered for " + type);
|
||||
|
||||
handlers.put(type, handler);
|
||||
loginTypesCache = null;
|
||||
}
|
||||
|
||||
public static SyncHandler getHandler(SyncType type) {
|
||||
return handlers.get(type);
|
||||
}
|
||||
|
||||
public static SyncType[] getLoginTypes() {
|
||||
if (loginTypesCache == null) {
|
||||
List<SyncType> list = new ArrayList<>();
|
||||
for (Map.Entry<SyncType, SyncHandler> e : handlers.entrySet())
|
||||
if (e.getValue().isCachedType())
|
||||
list.add(e.getKey());
|
||||
|
||||
loginTypesCache = list.toArray(new SyncType[0]);
|
||||
}
|
||||
return loginTypesCache;
|
||||
}
|
||||
|
||||
public static Set<SyncType> getInvalidationTargets(SyncType type) {
|
||||
SyncHandler handler = handlers.get(type);
|
||||
if (handler == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return handler.getInvalidationTargets(type);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
handlers.clear();
|
||||
loginTypesCache = null;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isRegistered(SyncType type) {
|
||||
return handlers.containsKey(type);
|
||||
}
|
||||
|
||||
public static Collection<SyncType> getRegisteredTypes() {
|
||||
return Collections.unmodifiableCollection(handlers.keySet());
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
import noppes.npcs.controllers.data.RecipeAnvil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#ANVIL_RECIPES}.
|
||||
* RELOAD-only family — does not support individual UPDATE or REMOVE.
|
||||
*/
|
||||
public class AnvilRecipeSyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
RecipeController controller = RecipeController.Instance;
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (RecipeAnvil recipe : controller.anvilRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT(false));
|
||||
}
|
||||
compound.setTag("recipes", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
RecipeAnvil recipe = new RecipeAnvil();
|
||||
recipe.readNBT(list.getCompoundTagAt(i));
|
||||
RecipeController.syncAnvilRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
|
||||
RecipeController.Instance.anvilRecipes = RecipeController.syncAnvilRecipes;
|
||||
RecipeController.syncAnvilRecipes = new HashMap<>();
|
||||
}
|
||||
|
||||
// RELOAD-only: supportsUpdate() and supportsRemove() remain false (default)
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#CARPENTRY_RECIPES}.
|
||||
* RELOAD-only family — does not support individual UPDATE or REMOVE.
|
||||
*/
|
||||
public class CarpentryRecipeSyncHandler implements SyncHandler {
|
||||
|
||||
private static final CarpentryRecipeSyncHandler INSTANCE = new CarpentryRecipeSyncHandler();
|
||||
|
||||
public static CarpentryRecipeSyncHandler getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
RecipeController controller = RecipeController.Instance;
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (RecipeCarpentry recipe : controller.carpentryRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT(false));
|
||||
}
|
||||
compound.setTag("recipes", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound recipeCompound = list.getCompoundTagAt(i);
|
||||
RecipeCarpentry recipe = RecipeCarpentry.create(recipeCompound);
|
||||
recipe.readNBT(recipeCompound);
|
||||
RecipeController.syncRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
|
||||
RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes;
|
||||
RecipeController.syncRecipes = new HashMap<>();
|
||||
}
|
||||
|
||||
// RELOAD-only: supportsUpdate() and supportsRemove() remain false (default)
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#CHAINED_ABILITY}.
|
||||
* String-keyed family using ordered {@link LinkedHashMap} to preserve
|
||||
* registration/reload order. Supports RELOAD only for global sync.
|
||||
*/
|
||||
public class ChainedAbilitySyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (Map.Entry<String, ChainedAbility> entry : AbilityController.Instance.getChainedAbilities().entrySet()) {
|
||||
NBTTagCompound chainNBT = entry.getValue().writeNBT(false);
|
||||
chainNBT.setString("ChainedAbilityId", entry.getKey());
|
||||
list.appendTag(chainNBT);
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
LinkedHashMap<String, ChainedAbility> sync = new LinkedHashMap<>();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound nbt = list.getCompoundTagAt(i);
|
||||
String id = nbt.getString("ChainedAbilityId");
|
||||
ChainedAbility chain = new ChainedAbility();
|
||||
chain.readNBT(nbt);
|
||||
chain.setName(id);
|
||||
sync.put(id, chain);
|
||||
}
|
||||
AbilityController.Instance.setChainedAbilities(sync);
|
||||
}
|
||||
|
||||
// RELOAD-only for global sync: supportsUpdate() and supportsRemove() remain false (default)
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#CUSTOM_ABILITY}.
|
||||
* String-keyed family using ordered {@link LinkedHashMap} to preserve
|
||||
* registration/reload order. Supports RELOAD only for global sync.
|
||||
*/
|
||||
public class CustomAbilitySyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (Map.Entry<String, Ability> entry : AbilityController.Instance.getCustomAbilities().entrySet()) {
|
||||
NBTTagCompound abilityNBT = entry.getValue().writeNBT(false);
|
||||
abilityNBT.setString("CustomAbilityId", entry.getKey());
|
||||
list.appendTag(abilityNBT);
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
LinkedHashMap<String, Ability> sync = new LinkedHashMap<>();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound nbt = list.getCompoundTagAt(i);
|
||||
String name = nbt.getString("CustomAbilityId");
|
||||
Ability ability = AbilityController.Instance.fromNBT(nbt);
|
||||
if (ability != null) {
|
||||
ability.setName(name);
|
||||
sync.put(name, ability);
|
||||
}
|
||||
}
|
||||
AbilityController.Instance.setCustomAbilities(sync);
|
||||
}
|
||||
|
||||
// RELOAD-only for global sync: supportsUpdate() and supportsRemove() remain false (default)
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#CUSTOM_EFFECTS}.
|
||||
* Simple int-keyed map family with RELOAD, UPDATE, and REMOVE support.
|
||||
* Client-side RELOAD precaches effect icons via {@link ClientCacheHandler#getImageData}.
|
||||
*/
|
||||
public class CustomEffectSyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (CustomEffect effect : CustomEffectController.getInstance().getCustomEffects().values()) {
|
||||
list.appendTag(effect.writeToNBT(false));
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
CustomEffectController ce = CustomEffectController.getInstance();
|
||||
ce.customEffectsSync.clear();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
CustomEffect effect = new CustomEffect();
|
||||
effect.readFromNBT(list.getCompoundTagAt(i));
|
||||
ClientCacheHandler.getImageData(effect.icon);
|
||||
ce.customEffectsSync.put(effect.id, effect);
|
||||
}
|
||||
|
||||
ce.getCustomEffects().clear();
|
||||
ce.getCustomEffects().putAll(ce.customEffectsSync);
|
||||
ce.customEffectsSync.clear();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
CustomEffect effect = new CustomEffect();
|
||||
effect.readFromNBT(compound);
|
||||
ClientCacheHandler.getImageData(effect.icon);
|
||||
|
||||
CustomEffectController.Instance.getCustomEffects().put(effect.id, effect);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleRemove(int id) {
|
||||
CustomEffectController.Instance.getCustomEffects().remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRemove() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogCategory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#DIALOG_CATEGORY}.
|
||||
* Parent-child category family. DIALOG children share this cache.
|
||||
* Invalidation from DIALOG or DIALOG_CATEGORY both target this cache.
|
||||
*/
|
||||
public class DialogCategorySyncHandler implements SyncHandler {
|
||||
|
||||
/**
|
||||
* Serialize a single dialog category for UPDATE packets.
|
||||
*/
|
||||
public static NBTTagCompound serializeCategory(DialogCategory dialogCategory) {
|
||||
NBTTagCompound dialogCompound = new NBTTagCompound();
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for (int questID : dialogCategory.dialogs.keySet()) {
|
||||
Dialog dialog = dialogCategory.dialogs.get(questID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
return dialogCompound;
|
||||
}
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList categoryList = new NBTTagList();
|
||||
for (DialogCategory category : DialogController.Instance.categories.values()) {
|
||||
NBTTagCompound questCompound = new NBTTagCompound();
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for (int dialogID : category.dialogs.keySet()) {
|
||||
Dialog quest = category.dialogs.get(dialogID);
|
||||
dialogList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", dialogList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
categoryList.appendTag(questCompound);
|
||||
}
|
||||
compound.setTag("DialogCategories", categoryList);
|
||||
return compound;
|
||||
}
|
||||
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
if (!fullCompound.hasNoTags()) {
|
||||
NBTTagList categories = fullCompound.getTagList("DialogCategories", 10);
|
||||
for (int j = 0; j < fullCompound.getTagList("DialogCategories", 10).tagCount(); j++) {
|
||||
NBTTagCompound categoryCompound = categories.getCompoundTagAt(j);
|
||||
if (categoryCompound.hasNoTags())
|
||||
continue;
|
||||
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
NBTTagList dialogList = categoryCompound.getTagList("Data", 10);
|
||||
if (DialogController.Instance.categoriesSync.containsKey(category.id)) {
|
||||
category = DialogController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for (int i = 0; i < dialogList.tagCount(); i++) {
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(dialogList.getCompoundTagAt(i));
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<Integer, Dialog> dialogs = new HashMap<>();
|
||||
for (DialogCategory category : DialogController.Instance.categoriesSync.values()) {
|
||||
for (Dialog dialog : category.dialogs.values()) {
|
||||
dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
DialogController.Instance.categories = DialogController.Instance.categoriesSync;
|
||||
DialogController.Instance.dialogs = dialogs;
|
||||
DialogController.Instance.categoriesSync = new HashMap<>();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if (DialogController.Instance.categoriesSync.containsKey(category.id)) {
|
||||
category = DialogController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(list.getCompoundTagAt(i));
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categories.put(category.id, category);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleRemove(int id) {
|
||||
DialogCategory dialogCategory = DialogController.Instance.categories.remove(id);
|
||||
if (dialogCategory != null) {
|
||||
DialogController.Instance.dialogs.keySet().removeAll(dialogCategory.dialogs.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRemove() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogCategory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#DIALOG}.
|
||||
* Child family — does not have its own cache. UPDATE and REMOVE only.
|
||||
* Invalidation targets the parent {@link SyncType#DIALOG_CATEGORY} cache.
|
||||
*/
|
||||
public class DialogSyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
/**
|
||||
* DIALOG does not have its own independent cache; it shares
|
||||
* the DIALOG_CATEGORY parent cache.
|
||||
*/
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
// DIALOG does not handle standalone RELOAD; it's part of DIALOG_CATEGORY
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
DialogCategory category = DialogController.Instance.categories.get(categoryId);
|
||||
if (category == null) {
|
||||
return; // Defensive: category may have been removed
|
||||
}
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.category = category;
|
||||
dialog.readNBT(compound);
|
||||
DialogController.Instance.dialogs.put(dialog.id, dialog);
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleRemove(int id) {
|
||||
Dialog dialog = DialogController.Instance.dialogs.remove(id);
|
||||
if (dialog != null) {
|
||||
dialog.category.dialogs.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRemove() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not a cached type — DIALOG shares the DIALOG_CATEGORY cache.
|
||||
*/
|
||||
@Override
|
||||
public boolean isCachedType() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SyncType> getInvalidationTargets(SyncType self) {
|
||||
// Child invalidates the parent cache
|
||||
Set<SyncType> set = new HashSet<>();
|
||||
set.add(SyncType.DIALOG_CATEGORY);
|
||||
return set;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.FactionController;
|
||||
import noppes.npcs.controllers.data.Faction;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#FACTION}.
|
||||
* Simple int-keyed map family with RELOAD, UPDATE, and REMOVE support.
|
||||
*/
|
||||
public class FactionSyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (Faction faction : FactionController.getInstance().factions.values()) {
|
||||
NBTTagCompound factionNBT = new NBTTagCompound();
|
||||
faction.writeNBT(factionNBT);
|
||||
list.appendTag(factionNBT);
|
||||
}
|
||||
compound.setTag("Factions", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("Factions", 10);
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(list.getCompoundTagAt(i));
|
||||
FactionController.getInstance().factionsSync.put(faction.id, faction);
|
||||
}
|
||||
FactionController.getInstance().factions = FactionController.getInstance().factionsSync;
|
||||
FactionController.getInstance().factionsSync = new HashMap<Integer, Faction>();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(compound);
|
||||
FactionController.getInstance().factions.put(faction.id, faction);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleRemove(int id) {
|
||||
FactionController.getInstance().factions.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRemove() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#MAGIC_CYCLE}.
|
||||
* Simple int-keyed map family with RELOAD, UPDATE, and REMOVE support.
|
||||
*/
|
||||
public class MagicCycleSyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
cycle.writeNBT(cycleCompound);
|
||||
list.appendTag(cycleCompound);
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
MagicController mc = MagicController.getInstance();
|
||||
mc.cyclesSync.clear();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(list.getCompoundTagAt(i));
|
||||
mc.cyclesSync.put(cycle.id, cycle);
|
||||
}
|
||||
|
||||
mc.cycles.clear();
|
||||
mc.cycles.putAll(mc.cyclesSync);
|
||||
mc.cyclesSync.clear();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(compound);
|
||||
MagicController.getInstance().cycles.put(cycle.id, cycle);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleRemove(int id) {
|
||||
MagicController.getInstance().cycles.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRemove() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#MAGIC}.
|
||||
* Simple int-keyed map family.
|
||||
* REMOVE dissociates cycle associations before removing the magic entry.
|
||||
*
|
||||
* <p>Note: The original code had a bug where MAGIC REMOVE incorrectly
|
||||
* removed from {@code cycles} instead of {@code magics}. This handler
|
||||
* fixes that by properly removing from {@code magics} after dissociating.</p>
|
||||
*/
|
||||
public class MagicSyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (Magic magic : MagicController.getInstance().magics.values()) {
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
magic.writeNBT(magicCompound);
|
||||
list.appendTag(magicCompound);
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
MagicController mc = MagicController.getInstance();
|
||||
mc.magicSync.clear();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Magic magic = new Magic();
|
||||
magic.readNBT(list.getCompoundTagAt(i));
|
||||
mc.magicSync.put(magic.id, magic);
|
||||
}
|
||||
|
||||
mc.magics.clear();
|
||||
mc.magics.putAll(mc.magicSync);
|
||||
mc.magicSync.clear();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
Magic magic = new Magic();
|
||||
magic.readNBT(compound);
|
||||
MagicController.getInstance().magics.put(magic.id, magic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a magic entry from the client. First dissociates cycle
|
||||
* references, then removes from the magics map.
|
||||
* <p>Bug fix: The original code incorrectly removed from {@code cycles}
|
||||
* instead of {@code magics} after dissociating cycle associations.</p>
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleRemove(int id) {
|
||||
// First remove this magic's association from all cycles
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
cycle.associations.remove(id);
|
||||
}
|
||||
// Then remove the magic itself (fixed: was cycles.remove(id))
|
||||
MagicController.getInstance().magics.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRemove() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.ability.AbilityCooldownSyncPacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.AbilityHotbarSyncPacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
/**
|
||||
* Direct per-player sync helper for player ability state.
|
||||
* This is NOT a cached global sync family — it operates outside the
|
||||
* registry-driven reload/revision system.
|
||||
*
|
||||
* <p>Abilities are synced per-player on demand (e.g. ability unlock,
|
||||
* entity reconstruction, periodic cooldown ticks).</p>
|
||||
*/
|
||||
public final class PlayerAbilitySyncHelper {
|
||||
|
||||
private PlayerAbilitySyncHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Full sync of all player ability state to the client: unlocked abilities,
|
||||
* selection, toggles, hotbar layout, and cooldowns.
|
||||
* Used for entity reconstruction and other full-refresh scenarios.
|
||||
*/
|
||||
public static void syncAbilities(EntityPlayerMP playerMP) {
|
||||
PlayerData playerData = PlayerData.get(playerMP);
|
||||
if (playerData == null) return;
|
||||
|
||||
PlayerAbilitySyncPacket.sendToPlayer(playerMP);
|
||||
AbilityHotbarSyncPacket.sendToPlayer(playerMP);
|
||||
AbilityCooldownSyncPacket.sendToPlayer(playerMP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lightweight sync of cooldown state only (global + per-ability).
|
||||
* Called periodically (every 10 ticks) to keep the client's cooldown
|
||||
* display accurate. Cooldowns are transient and not part of NBT sync.
|
||||
*/
|
||||
public static void syncAbilityCooldowns(EntityPlayerMP playerMP) {
|
||||
PlayerData playerData = PlayerData.get(playerMP);
|
||||
if (playerData == null) return;
|
||||
|
||||
AbilityCooldownSyncPacket.sendToPlayer(playerMP);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#PLAYERDATA}.
|
||||
* Special non-cached per-player path. Not included in login cache iteration.
|
||||
* RELOAD and UPDATE are sent as direct per-player packets.
|
||||
*/
|
||||
public class PlayerDataSyncHandler implements SyncHandler {
|
||||
|
||||
public static void syncPlayerData(EntityPlayerMP player, boolean update) {
|
||||
PlayerData data = PlayerData.get(player);
|
||||
if (data != null)
|
||||
SyncController.syncPlayerData(SyncType.PLAYERDATA, update ? data.getSyncNBTFull() : data.getSyncNBT(), update, player);
|
||||
}
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
/**
|
||||
* PLAYERDATA is not a global cached type — it is per-player.
|
||||
*/
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
if (categoryId == 1) ClientCacheHandler.playerData.setSyncNBTFull(compound);
|
||||
else ClientCacheHandler.playerData.setSyncNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not a cached type — PLAYERDATA uses direct per-player sync.
|
||||
*/
|
||||
@Override
|
||||
public boolean isCachedType() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncEffectPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.data.EffectKey;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.PlayerEffect;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Direct per-player sync helper for player effects.
|
||||
* This is NOT a cached global sync family — it operates outside the
|
||||
* registry-driven reload/revision system.
|
||||
*
|
||||
* <p>Effects are synced per-player on demand (e.g. effect application,
|
||||
* periodic ticks). The data mutates {@code playerData.effectData}
|
||||
* before sending the packet.</p>
|
||||
*/
|
||||
public final class PlayerEffectSyncHelper {
|
||||
|
||||
private PlayerEffectSyncHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Server-side: sync the player's active effects to their client.
|
||||
* Mutates {@code playerData.effectData} before sending.
|
||||
*/
|
||||
public static void syncEffects(EntityPlayerMP playerMP) {
|
||||
ConcurrentHashMap<EffectKey, PlayerEffect> playerEffects = CustomEffectController.getInstance().getPlayerEffects(playerMP);
|
||||
PlayerData playerData = PlayerData.get(playerMP);
|
||||
playerData.effectData.setEffects(playerEffects);
|
||||
|
||||
NBTTagCompound compound = playerData.getPlayerEffects();
|
||||
PacketHandler.Instance.sendToPlayer(new SyncEffectPacket(compound), playerMP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-side: apply incoming effect data to the local player.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientSyncEffects(NBTTagCompound compound) {
|
||||
PlayerData playerData = PlayerData.get(Minecraft.getMinecraft().thePlayer);
|
||||
if (playerData != null) {
|
||||
playerData.setPlayerEffects(compound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
import noppes.npcs.controllers.data.QuestCategory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#QUEST_CATEGORY}.
|
||||
* Parent-child category family. QUEST children share this cache.
|
||||
* Invalidation from QUEST or QUEST_CATEGORY both target this cache.
|
||||
*/
|
||||
public class QuestCategorySyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList categoryList = new NBTTagList();
|
||||
for (QuestCategory category : QuestController.Instance.categories.values()) {
|
||||
NBTTagCompound questCompound = new NBTTagCompound();
|
||||
;
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for (int questID : category.quests.keySet()) {
|
||||
Quest quest = category.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
categoryList.appendTag(questCompound);
|
||||
}
|
||||
compound.setTag("QuestCategories", categoryList);
|
||||
return compound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a single quest category for UPDATE packets.
|
||||
*/
|
||||
public static NBTTagCompound serializeCategory(QuestCategory questCategory) {
|
||||
NBTTagCompound questCompound = new NBTTagCompound();
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for (int questID : questCategory.quests.keySet()) {
|
||||
Quest quest = questCategory.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
return questCompound;
|
||||
}
|
||||
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
if (!fullCompound.hasNoTags()) {
|
||||
NBTTagList categories = fullCompound.getTagList("QuestCategories", 10);
|
||||
for (int j = 0; j < fullCompound.getTagList("QuestCategories", 10).tagCount(); j++) {
|
||||
NBTTagCompound categoryCompound = categories.getCompoundTagAt(j);
|
||||
if (categoryCompound.hasNoTags())
|
||||
continue;
|
||||
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
NBTTagList questList = categoryCompound.getTagList("Data", 10);
|
||||
if (QuestController.Instance.categoriesSync.containsKey(category.id)) {
|
||||
category = QuestController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for (int i = 0; i < questList.tagCount(); i++) {
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(questList.getCompoundTagAt(i));
|
||||
quest.category = category;
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
QuestController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<Integer, Quest> quests = new HashMap<>();
|
||||
for (QuestCategory category : QuestController.Instance.categoriesSync.values()) {
|
||||
for (Quest quest : category.quests.values()) {
|
||||
quests.put(quest.id, quest);
|
||||
}
|
||||
}
|
||||
|
||||
QuestController.Instance.categories = QuestController.Instance.categoriesSync;
|
||||
QuestController.Instance.quests = quests;
|
||||
QuestController.Instance.categoriesSync = new HashMap<>();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if (QuestController.Instance.categoriesSync.containsKey(category.id)) {
|
||||
category = QuestController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(list.getCompoundTagAt(i));
|
||||
quest.category = category;
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
QuestController.Instance.categories.put(category.id, category);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleRemove(int id) {
|
||||
QuestCategory questCategory = QuestController.Instance.categories.remove(id);
|
||||
if (questCategory != null) {
|
||||
QuestController.Instance.quests.keySet().removeAll(questCategory.quests.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRemove() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
import noppes.npcs.controllers.data.QuestCategory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#QUEST}.
|
||||
* Child family — does not have its own cache. UPDATE and REMOVE only.
|
||||
* Invalidation targets the parent {@link SyncType#QUEST_CATEGORY} cache.
|
||||
*/
|
||||
public class QuestSyncHandler implements SyncHandler {
|
||||
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
/**
|
||||
* QUEST does not have its own independent cache; it shares
|
||||
* the QUEST_CATEGORY parent cache.
|
||||
*/
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
// QUEST does not handle standalone RELOAD; it's part of QUEST_CATEGORY
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleUpdate(NBTTagCompound compound, int categoryId) {
|
||||
QuestCategory category = QuestController.Instance.categories.get(categoryId);
|
||||
if (category == null)
|
||||
return; // Defensive: category may have been removed
|
||||
|
||||
Quest quest = new Quest();
|
||||
quest.category = category;
|
||||
quest.readNBT(compound);
|
||||
QuestController.Instance.quests.put(quest.id, quest);
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleRemove(int id) {
|
||||
Quest quest = QuestController.Instance.quests.remove(id);
|
||||
if (quest != null)
|
||||
quest.category.quests.remove(id);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRemove() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not a cached type — QUEST shares the QUEST_CATEGORY cache.
|
||||
*/
|
||||
@Override
|
||||
public boolean isCachedType() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SyncType> getInvalidationTargets(SyncType self) {
|
||||
// Child invalidates the parent cache
|
||||
Set<SyncType> set = new HashSet<>();
|
||||
set.add(SyncType.QUEST_CATEGORY);
|
||||
return set;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package kamkeel.npcs.controllers.sync.handlers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Sync handler for {@link SyncType#WORKBENCH_RECIPES}.
|
||||
* RELOAD-only family — does not support individual UPDATE or REMOVE.
|
||||
* Client-side RELOAD routes through {@link RecipeController#reloadGlobalRecipes}.
|
||||
*/
|
||||
public class WorkbenchRecipeSyncHandler implements SyncHandler {
|
||||
|
||||
private static final WorkbenchRecipeSyncHandler INSTANCE = new WorkbenchRecipeSyncHandler();
|
||||
|
||||
public static WorkbenchRecipeSyncHandler getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
// ========== SERVER-SIDE ==========
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeAll() {
|
||||
RecipeController controller = RecipeController.Instance;
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (RecipeCarpentry recipe : controller.globalRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT(false));
|
||||
}
|
||||
compound.setTag("recipes", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
// ========== CLIENT-SIDE ==========
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void clientHandleReload(NBTTagCompound fullCompound) {
|
||||
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound recipeCompound = list.getCompoundTagAt(i);
|
||||
RecipeCarpentry recipe = RecipeCarpentry.create(recipeCompound);
|
||||
recipe.readNBT(recipeCompound);
|
||||
RecipeController.syncRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
|
||||
RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes);
|
||||
RecipeController.syncRecipes = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SyncType> getInvalidationTargets(SyncType self) {
|
||||
Set<SyncType> set = new HashSet<>();
|
||||
set.add(SyncType.WORKBENCH_RECIPES);
|
||||
return set;
|
||||
}
|
||||
|
||||
// RELOAD-only: supportsUpdate() and supportsRemove() remain false (default)
|
||||
}
|
||||
@@ -264,18 +264,18 @@ public class EntityAbilityLaser extends EntityEnergyProjectile {
|
||||
Vec3 anchorPos = AnchorPointHelper.calculateAnchorPosition(livingOwner, anchorData);
|
||||
setPosition(anchorPos.xCoord, anchorPos.yCoord, anchorPos.zCoord);
|
||||
|
||||
// Aim where the owner is looking so track speed and rotation lock still apply.
|
||||
double aimX = livingOwner.posX + dirX * maxLength;
|
||||
double aimY = livingOwner.posY + livingOwner.getEyeHeight() + dirY * maxLength;
|
||||
double aimZ = livingOwner.posZ + dirZ * maxLength;
|
||||
double dx = aimX - anchorPos.xCoord;
|
||||
double dy = aimY - anchorPos.yCoord;
|
||||
double dz = aimZ - anchorPos.zCoord;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0.0001) {
|
||||
dirX = dx / len;
|
||||
dirY = dy / len;
|
||||
dirZ = dz / len;
|
||||
Entity targetEntity = getTargetEntity();
|
||||
if (targetEntity instanceof EntityLivingBase && targetEntity.isEntityAlive()) {
|
||||
EntityLivingBase target = (EntityLivingBase) targetEntity;
|
||||
double dx = target.posX - anchorPos.xCoord;
|
||||
double dy = (target.posY + target.getEyeHeight() - 0.4) - anchorPos.yCoord;
|
||||
double dz = target.posZ - anchorPos.zCoord;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0.0001) {
|
||||
dirX = dx / len;
|
||||
dirY = dy / len;
|
||||
dirZ = dz / len;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Vec3 direction = Vec3.createVectorHelper(dirX, dirY, dirZ);
|
||||
|
||||
@@ -0,0 +1,442 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.*;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Pillar zone entity.
|
||||
*
|
||||
* Lifecycle:
|
||||
* 1. Charging — charge visual grows in radius at ground level during windup.
|
||||
* 2. spawnDelay — entity is alive, not growing, no damage.
|
||||
* 3. Active — pillarHeight grows linearly at heightGrowSpeed; damage checks begin.
|
||||
*
|
||||
* Radius snaps to targetRadius immediately when charging ends — no interpolation.
|
||||
* Height grows linearly with no easing.
|
||||
*
|
||||
* FROM_ABOVE: posY = top anchor. Hitbox: posY - height to posY.
|
||||
* FROM_GROUND: posY = ground anchor. Hitbox: posY to posY + height.
|
||||
*
|
||||
* ANCHORED modes:
|
||||
* - followTarget: pillar moves directly toward target each tick (requires homing=true).
|
||||
* - trackTarget: spawn position predicted once from target velocity at spawn time.
|
||||
*/
|
||||
public class EntityAbilityPillar extends EntityEnergyZone {
|
||||
|
||||
public static final float MIN_HEIGHT = 0.05f;
|
||||
public static final float MIN_RADIUS = 0.01f;
|
||||
private static final int DW_PILLAR_RADIUS = 21;
|
||||
private static final int DW_PILLAR_HEIGHT = 22;
|
||||
|
||||
// ==================== ENUMS ====================
|
||||
|
||||
public enum PillarMode { ANCHORED, MOVING }
|
||||
|
||||
public enum PillarOrigin { FROM_GROUND, FROM_ABOVE }
|
||||
|
||||
public enum PillarShape {
|
||||
CIRCLE, SQUARE;
|
||||
|
||||
public TelegraphType getTelegraphType() {
|
||||
return this == CIRCLE ? TelegraphType.CIRCLE : TelegraphType.SQUARE;
|
||||
}
|
||||
}
|
||||
|
||||
public enum OffsetAxis { X, Z }
|
||||
|
||||
// ==================== CONFIG ====================
|
||||
|
||||
private EnergyPillarData pillarData = new EnergyPillarData();
|
||||
|
||||
// ==================== DIMENSIONS ====================
|
||||
|
||||
private float pillarRadius = 0.01f;
|
||||
private float pillarHeight = MIN_HEIGHT;
|
||||
|
||||
// Height interpolation only — radius snaps immediately
|
||||
private float renderPillarHeight = MIN_HEIGHT;
|
||||
private float prevRenderPillarHeight = MIN_HEIGHT;
|
||||
|
||||
// ==================== HOMING ====================
|
||||
|
||||
protected EnergyHomingData homingData = new EnergyHomingData();
|
||||
|
||||
// ==================== ANCHORED MODES ====================
|
||||
|
||||
/** If true, pillar follows target directly each tick (ANCHORED + homing only). */
|
||||
private boolean followTarget = false;
|
||||
|
||||
// ==================== RUNTIME STATE ====================
|
||||
|
||||
private boolean growing = false;
|
||||
private int spawnDelayTick = 0;
|
||||
|
||||
// ==================== CONSTRUCTORS ====================
|
||||
|
||||
public EntityAbilityPillar(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntityAbilityPillar(World world, EntityLivingBase owner,
|
||||
double x, double y, double z,
|
||||
EnergyPillarData pillarData, EnergyDisplayData display,
|
||||
EnergyCombatData combat, EnergyHomingData homing,
|
||||
EnergyLightningData lightning, EnergyLifespanData lifespan) {
|
||||
super(world);
|
||||
this.ownerEntityId = owner != null ? owner.getEntityId() : -1;
|
||||
this.pillarData = pillarData != null ? pillarData.copy() : new EnergyPillarData();
|
||||
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||
this.combatData = combat != null ? combat.copy() : new EnergyCombatData();
|
||||
this.homingData = homing != null ? homing.copy() : new EnergyHomingData();
|
||||
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||
this.lifespanData = lifespan != null ? lifespan.copy() : new EnergyLifespanData();
|
||||
|
||||
if (this.pillarData.origin == PillarOrigin.FROM_ABOVE) {
|
||||
this.setPosition(x, y + this.pillarData.targetHeight, z);
|
||||
} else {
|
||||
snapToGround(x, y, z);
|
||||
}
|
||||
|
||||
setPillarRadiusInternal(0.01f);
|
||||
setPillarHeightInternal(MIN_HEIGHT);
|
||||
syncHitbox();
|
||||
}
|
||||
|
||||
// ==================== ENTITY INIT ====================
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
super.entityInit();
|
||||
this.dataWatcher.addObject(DW_PILLAR_RADIUS, 0.01f);
|
||||
this.dataWatcher.addObject(DW_PILLAR_HEIGHT, MIN_HEIGHT);
|
||||
}
|
||||
|
||||
// ==================== INTERNAL SETTERS ====================
|
||||
|
||||
private void setPillarRadiusInternal(float value) {
|
||||
this.pillarRadius = value;
|
||||
if (!previewMode && worldObj != null && !worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_PILLAR_RADIUS, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void setPillarHeightInternal(float value) {
|
||||
this.pillarHeight = value;
|
||||
if (!previewMode && worldObj != null && !worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_PILLAR_HEIGHT, value);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== SETUP ====================
|
||||
|
||||
public void setTarget(EntityLivingBase target) {
|
||||
this.targetEntityId = target != null ? target.getEntityId() : -1;
|
||||
}
|
||||
|
||||
public void setFollowTarget(boolean follow) {
|
||||
this.followTarget = follow;
|
||||
}
|
||||
|
||||
public void setInitialMotion(double mx, double mz) {
|
||||
this.motionX = mx;
|
||||
this.motionZ = mz;
|
||||
}
|
||||
|
||||
public void setupPreview(EntityLivingBase owner, EnergyPillarData pillarData,
|
||||
EnergyDisplayData display, EnergyLightningData lightning,
|
||||
int chargeDuration) {
|
||||
setupPreview(owner);
|
||||
this.pillarData = pillarData != null ? pillarData.copy() : new EnergyPillarData();
|
||||
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||
setupCharging(chargeDuration);
|
||||
setPillarRadiusInternal(0.01f);
|
||||
setPillarHeightInternal(MIN_HEIGHT);
|
||||
this.renderPillarHeight = MIN_HEIGHT;
|
||||
this.prevRenderPillarHeight = MIN_HEIGHT;
|
||||
}
|
||||
|
||||
public void startGrowing() {
|
||||
setCharging(false);
|
||||
this.spawnDelayTick = 0;
|
||||
this.growing = pillarData.spawnDelay <= 0;
|
||||
// Radius snaps immediately to target — no interpolation
|
||||
setPillarRadiusInternal(pillarData.targetRadius);
|
||||
setPillarHeightInternal(MIN_HEIGHT);
|
||||
this.renderPillarHeight = MIN_HEIGHT;
|
||||
this.prevRenderPillarHeight = MIN_HEIGHT;
|
||||
syncHitbox();
|
||||
}
|
||||
|
||||
// ==================== CHARGING ====================
|
||||
|
||||
@Override
|
||||
protected void updateCharging() {
|
||||
chargeTick++;
|
||||
|
||||
// Follow entity position during charging preview (e.g. charge visual follows target)
|
||||
if (pillarData.mode == PillarMode.ANCHORED && targetEntityId != -1 && worldObj != null) {
|
||||
Entity target = getTargetEntity();
|
||||
if (target instanceof EntityLivingBase && !target.isDead) {
|
||||
snapToGround(target.posX, target.posY, target.posZ);
|
||||
}
|
||||
}
|
||||
|
||||
// Radius grows during charging for the visual disc effect
|
||||
float progress = getChargeProgress();
|
||||
setPillarRadiusInternal(pillarData.targetRadius * progress);
|
||||
setPillarHeightInternal(MIN_HEIGHT);
|
||||
syncHitbox();
|
||||
}
|
||||
|
||||
// ==================== ZONE UPDATE ====================
|
||||
|
||||
@Override
|
||||
protected void updateZone() {
|
||||
prevRenderPillarHeight = renderPillarHeight;
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
float dwRadius = this.dataWatcher.getWatchableObjectFloat(DW_PILLAR_RADIUS);
|
||||
float dwHeight = this.dataWatcher.getWatchableObjectFloat(DW_PILLAR_HEIGHT);
|
||||
// Radius: snap directly, no interpolation
|
||||
this.pillarRadius = dwRadius;
|
||||
// Height: linear tracking, no easing
|
||||
this.pillarHeight = dwHeight;
|
||||
renderPillarHeight = pillarHeight;
|
||||
return;
|
||||
}
|
||||
|
||||
// spawnDelay: no growth, no damage
|
||||
if (!growing) {
|
||||
spawnDelayTick++;
|
||||
if (spawnDelayTick >= pillarData.spawnDelay) {
|
||||
growing = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Linear height growth — no easing, exact speed per tick
|
||||
if (pillarHeight < pillarData.targetHeight) {
|
||||
setPillarHeightInternal(Math.min(pillarData.targetHeight, pillarHeight + pillarData.heightGrowSpeed));
|
||||
}
|
||||
// Radius stays at targetRadius (set in startGrowing)
|
||||
|
||||
syncHitbox();
|
||||
|
||||
if (pillarData.mode == PillarMode.MOVING) {
|
||||
updateMovement();
|
||||
} else if (pillarData.mode == PillarMode.ANCHORED && followTarget) {
|
||||
updateFollowTarget();
|
||||
}
|
||||
|
||||
// No damage during spawnDelay — only when growing
|
||||
if (pillarHeight > MIN_HEIGHT) {
|
||||
checkEntityCollision();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== MOVEMENT ====================
|
||||
|
||||
private void updateMovement() {
|
||||
if (!homingData.isHoming()) {
|
||||
this.posX += motionX;
|
||||
this.posZ += motionZ;
|
||||
repositionY();
|
||||
return;
|
||||
}
|
||||
|
||||
Entity target = getTargetEntity();
|
||||
if (target == null || !target.isEntityAlive()) {
|
||||
this.posX += motionX;
|
||||
this.posZ += motionZ;
|
||||
repositionY();
|
||||
return;
|
||||
}
|
||||
|
||||
double dx = target.posX - posX;
|
||||
double dz = target.posZ - posZ;
|
||||
double dist = Math.sqrt(dx * dx + dz * dz);
|
||||
|
||||
if (dist > 0 && dist <= homingData.getHomingRange()) {
|
||||
float strength = homingData.getHomingStrength();
|
||||
double desiredVX = (dx / dist) * homingData.getSpeed();
|
||||
double desiredVZ = (dz / dist) * homingData.getSpeed();
|
||||
motionX += (desiredVX - motionX) * strength;
|
||||
motionZ += (desiredVZ - motionZ) * strength;
|
||||
|
||||
double vLen = Math.sqrt(motionX * motionX + motionZ * motionZ);
|
||||
if (vLen > 0) {
|
||||
motionX = (motionX / vLen) * homingData.getSpeed();
|
||||
motionZ = (motionZ / vLen) * homingData.getSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
this.posX += motionX;
|
||||
this.posZ += motionZ;
|
||||
repositionY();
|
||||
}
|
||||
|
||||
/**
|
||||
* ANCHORED followTarget: moves directly toward target each tick.
|
||||
*/
|
||||
private void updateFollowTarget() {
|
||||
Entity target = getTargetEntity();
|
||||
if (target == null || !target.isEntityAlive()) return;
|
||||
|
||||
double dx = target.posX - posX;
|
||||
double dz = target.posZ - posZ;
|
||||
double dist = Math.sqrt(dx * dx + dz * dz);
|
||||
|
||||
if (dist > 0.1) {
|
||||
float speed = homingData.getSpeed();
|
||||
double step = Math.min(dist, speed);
|
||||
this.posX += (dx / dist) * step;
|
||||
this.posZ += (dz / dist) * step;
|
||||
repositionY();
|
||||
}
|
||||
}
|
||||
|
||||
private void repositionY() {
|
||||
if (pillarData.origin == PillarOrigin.FROM_ABOVE) {
|
||||
double groundY = kamkeel.npcs.controllers.data.ability.Ability.findGroundLevel(worldObj, posX, posY, posZ);
|
||||
this.setPosition(posX, groundY + pillarData.targetHeight, posZ);
|
||||
} else {
|
||||
snapToGround(posX, posY, posZ);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== COLLISION ====================
|
||||
|
||||
private void checkEntityCollision() {
|
||||
AxisAlignedBB broadBox = buildHitBox();
|
||||
if (broadBox == null) return;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, broadBox);
|
||||
|
||||
for (EntityLivingBase entity : entities) {
|
||||
if (shouldIgnoreEntity(entity)) continue;
|
||||
if (!canHitEntityNow(entity)) continue;
|
||||
if (!isInPillar(entity)) continue;
|
||||
|
||||
boolean hit = applyDamage(entity, getDamage());
|
||||
if (hit) {
|
||||
applyEffects(entity);
|
||||
recordEntityHit(entity);
|
||||
if (shouldTerminateAfterHit()) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AxisAlignedBB buildHitBox() {
|
||||
float minY, maxY;
|
||||
if (pillarData.origin == PillarOrigin.FROM_ABOVE) {
|
||||
maxY = (float) posY;
|
||||
minY = (float) posY - pillarHeight;
|
||||
} else {
|
||||
minY = (float) posY;
|
||||
maxY = (float) posY + pillarHeight;
|
||||
}
|
||||
return AxisAlignedBB.getBoundingBox(
|
||||
posX - pillarRadius, minY, posZ - pillarRadius,
|
||||
posX + pillarRadius, maxY, posZ + pillarRadius);
|
||||
}
|
||||
|
||||
private boolean isInPillar(EntityLivingBase entity) {
|
||||
double dx = entity.posX - posX;
|
||||
double dz = entity.posZ - posZ;
|
||||
switch (pillarData.shape) {
|
||||
case SQUARE: return Math.abs(dx) <= pillarRadius && Math.abs(dz) <= pillarRadius;
|
||||
case CIRCLE: default: return Math.sqrt(dx * dx + dz * dz) <= pillarRadius;
|
||||
}
|
||||
}
|
||||
|
||||
private void syncHitbox() {
|
||||
float w = Math.max(0.1f, pillarRadius * 2.0f);
|
||||
float h = Math.max(0.1f, pillarHeight);
|
||||
this.setSize(w, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isInRangeToRenderDist(double distance) {
|
||||
double extent = Math.max(pillarRadius, pillarHeight) * 2.0D;
|
||||
double range = Math.max(128.0D, extent * 4.0D + 64.0D);
|
||||
return distance < range * range;
|
||||
}
|
||||
|
||||
// ==================== RENDERER GETTERS ====================
|
||||
|
||||
public float getPillarRadius() { return pillarRadius; }
|
||||
public float getPillarHeight() { return pillarHeight; }
|
||||
public float getInterpolatedPillarHeight(float partialTicks) {
|
||||
return prevRenderPillarHeight + (renderPillarHeight - prevRenderPillarHeight) * partialTicks;
|
||||
}
|
||||
public PillarMode getPillarMode() { return pillarData.mode; }
|
||||
public PillarOrigin getPillarOrigin() { return pillarData.origin; }
|
||||
public PillarShape getPillarShape() { return pillarData.shape; }
|
||||
public boolean isGrowing() { return growing; }
|
||||
public EnergyPillarData getPillarData() { return pillarData; }
|
||||
|
||||
// ==================== SETTERS ====================
|
||||
|
||||
public void setPillarData(EnergyPillarData data) { this.pillarData = data != null ? data.copy() : new EnergyPillarData(); }
|
||||
public void setHomingData(EnergyHomingData homing) { this.homingData = homing != null ? homing.copy() : new EnergyHomingData(); }
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
protected void writeZoneNBT(NBTTagCompound nbt) {
|
||||
pillarData.writeNBT(nbt);
|
||||
homingData.writeNBT(nbt);
|
||||
nbt.setFloat("PillarRadius", pillarRadius);
|
||||
nbt.setFloat("PillarHeight", pillarHeight);
|
||||
nbt.setInteger("SpawnDelayTick", spawnDelayTick);
|
||||
nbt.setBoolean("Growing", growing);
|
||||
nbt.setBoolean("FollowTarget", followTarget);
|
||||
nbt.setInteger("TargetEntityId", targetEntityId);
|
||||
nbt.setDouble("MotionX", motionX);
|
||||
nbt.setDouble("MotionZ", motionZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readZoneNBT(NBTTagCompound nbt) {
|
||||
pillarData.readNBT(nbt);
|
||||
homingData.readNBT(nbt);
|
||||
|
||||
float radius = Math.max(0.01f, nbt.getFloat("PillarRadius"));
|
||||
float height = Math.max(MIN_HEIGHT, nbt.getFloat("PillarHeight"));
|
||||
|
||||
this.pillarRadius = radius;
|
||||
this.pillarHeight = height;
|
||||
|
||||
if (this.dataWatcher != null) {
|
||||
this.dataWatcher.updateObject(DW_PILLAR_RADIUS, radius);
|
||||
this.dataWatcher.updateObject(DW_PILLAR_HEIGHT, height);
|
||||
}
|
||||
|
||||
this.renderPillarHeight = height;
|
||||
this.prevRenderPillarHeight = height;
|
||||
|
||||
this.spawnDelayTick = nbt.getInteger("SpawnDelayTick");
|
||||
this.growing = nbt.getBoolean("Growing");
|
||||
this.followTarget = nbt.hasKey("FollowTarget") && nbt.getBoolean("FollowTarget");
|
||||
this.targetEntityId = nbt.hasKey("TargetEntityId") ? nbt.getInteger("TargetEntityId") : -1;
|
||||
this.motionX = nbt.getDouble("MotionX");
|
||||
this.motionZ = nbt.getDouble("MotionZ");
|
||||
|
||||
syncHitbox();
|
||||
}
|
||||
}
|
||||
@@ -155,8 +155,6 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
// HAZARD-SPECIFIC PROPERTIES
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public static final int MIN_DAMAGE_INTERVAL = 5;
|
||||
|
||||
private float damagePerSecond = 1.0f;
|
||||
private int damageInterval = 20;
|
||||
private boolean ignoreIFrames = false;
|
||||
@@ -293,7 +291,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
zone.shape = shape;
|
||||
zone.radius = radius;
|
||||
zone.damagePerSecond = damagePerSecond;
|
||||
zone.damageInterval = Math.max(MIN_DAMAGE_INTERVAL, damageInterval);
|
||||
zone.damageInterval = damageInterval;
|
||||
zone.ignoreIFrames = ignoreIFrames;
|
||||
zone.affectsCaster = affectsCaster;
|
||||
zone.durationTicks = durationTicks;
|
||||
@@ -311,6 +309,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
zone.effects.add(e.copy());
|
||||
}
|
||||
}
|
||||
zone.ticksSinceDamage = damageInterval;
|
||||
return zone;
|
||||
}
|
||||
|
||||
@@ -519,7 +518,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
if (!isInZone(entity)) continue;
|
||||
|
||||
if (damagePerSecond > 0) {
|
||||
applyDamage(entity, owner, damagePerSecond * (damageInterval / 20.0f));
|
||||
applyDamage(entity, owner, damagePerSecond);
|
||||
}
|
||||
|
||||
applyEffects(entity);
|
||||
@@ -816,7 +815,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
||||
public float getDamagePerSecond() { return damagePerSecond; }
|
||||
public void setDamagePerSecond(float dps) { this.damagePerSecond = dps; }
|
||||
public int getDamageInterval() { return damageInterval; }
|
||||
public void setDamageInterval(int ticks) { this.damageInterval = Math.max(MIN_DAMAGE_INTERVAL, ticks); }
|
||||
public void setDamageInterval(int ticks) { this.damageInterval = ticks; }
|
||||
public boolean isAffectsCaster() { return affectsCaster; }
|
||||
public void setAffectsCaster(boolean affects) { this.affectsCaster = affects; }
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.util.AbilityTargetHelper;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyBarrierData;
|
||||
import kamkeel.npcs.network.packets.data.energy.BarrierClientSyncPacket;
|
||||
@@ -17,7 +15,6 @@ import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.controllers.data.MagicData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -117,7 +114,6 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
||||
protected EnergyBarrierData barrierData = new EnergyBarrierData();
|
||||
protected float currentHealth;
|
||||
protected int ticksAlive = 0;
|
||||
protected long barrierDeathTime = -1;
|
||||
|
||||
// ==================== DATA WATCHER INDICES ====================
|
||||
protected static final int DW_HEALTH_PERCENT = 21;
|
||||
@@ -440,17 +436,8 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
||||
|
||||
float damage = amount * barrierData.meleeDamageMultiplier;
|
||||
|
||||
Entity attacker = source.getEntity();
|
||||
|
||||
// No LivingHurtEvent fires for a barrier, so scale the hit here.
|
||||
if (attacker instanceof EntityLivingBase) {
|
||||
damage = AbilityController.Instance.fireModifyBarrierMeleeDamage(this, (EntityLivingBase) attacker, damage);
|
||||
}
|
||||
if (attacker instanceof EntityPlayer && ConfigMain.AttributesEnabled && !DBCAddon.IsAvailable()) {
|
||||
damage = AttributeAttackUtil.calculateOutgoing((EntityPlayer) attacker, damage);
|
||||
}
|
||||
|
||||
// Apply magic interactions from attacker's magic vs barrier's magic
|
||||
Entity attacker = source.getEntity();
|
||||
if (attacker != null) {
|
||||
MagicData attackerMagic = null;
|
||||
if (attacker instanceof EntityPlayer) {
|
||||
@@ -523,13 +510,15 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
||||
}
|
||||
}
|
||||
|
||||
if (barrierDeathTime < 0 && !isCharging()) {
|
||||
barrierDeathTime = worldObj.getTotalWorldTime()
|
||||
+ (barrierData.useDuration ? barrierData.durationTicks : BARRIER_HARD_LIFETIME_CAP);
|
||||
// Duration check
|
||||
if (barrierData.useDuration && ticksAlive >= barrierData.durationTicks) {
|
||||
onBarrierDestroyed();
|
||||
this.setDead();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Duration check
|
||||
if (barrierDeathTime >= 0 && worldObj.getTotalWorldTime() >= barrierDeathTime) {
|
||||
// Absolute hard lifetime cap (safety net for barriers with no duration)
|
||||
if (ticksAlive > BARRIER_HARD_LIFETIME_CAP) {
|
||||
onBarrierDestroyed();
|
||||
this.setDead();
|
||||
return true;
|
||||
@@ -876,7 +865,6 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
||||
protected void writeBarrierBaseNBT(NBTTagCompound nbt) {
|
||||
writeEnergyBaseNBT(nbt);
|
||||
nbt.setInteger("TicksAlive", ticksAlive);
|
||||
nbt.setLong("BarrierDeathTime", barrierDeathTime);
|
||||
nbt.setFloat("CurrentHealth", currentHealth);
|
||||
nbt.setBoolean("Charging", charging);
|
||||
nbt.setInteger("ChargeTick", chargeTick);
|
||||
@@ -891,7 +879,6 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
||||
protected void readBarrierBaseNBT(NBTTagCompound nbt) {
|
||||
readEnergyBaseNBT(nbt);
|
||||
this.ticksAlive = nbt.getInteger("TicksAlive");
|
||||
this.barrierDeathTime = nbt.hasKey("BarrierDeathTime") ? nbt.getLong("BarrierDeathTime") : -1;
|
||||
this.currentHealth = nbt.getFloat("CurrentHealth");
|
||||
if (Float.isNaN(currentHealth) || Float.isInfinite(currentHealth) || currentHealth < 0) currentHealth = barrierData.maxHealth;
|
||||
this.charging = nbt.hasKey("Charging") && nbt.getBoolean("Charging");
|
||||
|
||||
@@ -911,17 +911,42 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
|
||||
@Override
|
||||
public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements) {
|
||||
int steps = Math.max(1, posRotationIncrements);
|
||||
double dx = x - this.posX;
|
||||
double dy = y - this.posY;
|
||||
double dz = z - this.posZ;
|
||||
double dotToCurrentMotion = dx * this.motionX + dy * this.motionY + dz * this.motionZ;
|
||||
|
||||
// Spawn-time and large correction snaps: avoid visible startup rubber-banding.
|
||||
if (worldObj != null && worldObj.isRemote) {
|
||||
double distSq = dx * dx + dy * dy + dz * dz;
|
||||
// Launch-time stale tracker packets can arrive one update late and point behind
|
||||
// an already-predicted projectile. Skipping these avoids visible backward "bounce".
|
||||
if (ticksExisted <= 24 && distSq <= 4.0D && dotToCurrentMotion < -0.0025D) {
|
||||
return;
|
||||
}
|
||||
if (ticksExisted <= 2 || distSq > 16.0D) {
|
||||
this.setPosition(x, y, z);
|
||||
syncPositionState(x, y, z, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.interpTargetX = x;
|
||||
this.interpTargetY = y;
|
||||
this.interpTargetZ = z;
|
||||
this.rotationYaw = yaw;
|
||||
this.rotationPitch = pitch;
|
||||
|
||||
// Energy projectiles are tracked every tick. Minecraft's usual three-tick
|
||||
// interpolation continually falls behind that update rate at higher speeds.
|
||||
// One tick still gives RenderManager a full partial-tick transition without
|
||||
// accumulating a correction that later has to snap.
|
||||
this.interpSteps = 1;
|
||||
if (worldObj != null && worldObj.isRemote && ticksExisted <= 24 && dotToCurrentMotion < 0.0D) {
|
||||
// Keep existing velocity when correction points opposite current travel
|
||||
// to prevent launch-time reverse lerp.
|
||||
this.interpTargetMotionX = this.motionX;
|
||||
this.interpTargetMotionY = this.motionY;
|
||||
this.interpTargetMotionZ = this.motionZ;
|
||||
} else {
|
||||
this.interpTargetMotionX = dx / steps;
|
||||
this.interpTargetMotionY = dy / steps;
|
||||
this.interpTargetMotionZ = dz / steps;
|
||||
}
|
||||
this.interpSteps = steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -934,7 +959,14 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
this.motionZ = motionZ;
|
||||
}
|
||||
|
||||
/** Move the client copy through the latest server position update. */
|
||||
/**
|
||||
* Handle client-side position interpolation.
|
||||
* Only moves position during active interpolation (interpSteps > 0).
|
||||
* Does NOT predict/drift between server updates — the motion values are
|
||||
* derived from correction deltas, not actual entity velocity, so applying
|
||||
* them between updates causes entities to fly off in wrong directions.
|
||||
* This matches vanilla Minecraft behavior for non-player entities.
|
||||
*/
|
||||
protected void handleClientInterpolation() {
|
||||
if (this.interpSteps > 0) {
|
||||
double dx = this.interpTargetX - this.posX;
|
||||
@@ -952,6 +984,10 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
double newY = this.posY + dy / this.interpSteps;
|
||||
double newZ = this.posZ + dz / this.interpSteps;
|
||||
|
||||
this.motionX = this.motionX + (this.interpTargetMotionX - this.motionX) / this.interpSteps;
|
||||
this.motionY = this.motionY + (this.interpTargetMotionY - this.motionY) / this.interpSteps;
|
||||
this.motionZ = this.motionZ + (this.interpTargetMotionZ - this.motionZ) / this.interpSteps;
|
||||
|
||||
this.setPosition(newX, newY, newZ);
|
||||
this.interpSteps--;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,550 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.EnergyController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.data.effect.AbilityPotionEffect;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyCombatData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.HitType;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.TargetFilter;
|
||||
import kamkeel.npcs.controllers.data.ability.util.AbilityTargetHelper;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NpcDamageSource;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Abstract base class for all energy zone entities.
|
||||
* Extends EntityEnergyAbility for shared visual/owner/charging/magic state.
|
||||
*
|
||||
* Provides:
|
||||
* - Lifetime management via deathWorldTime (robust to chunk unload)
|
||||
* - Combat pipeline: sourceAbility -> customDamageData -> native fallback
|
||||
* - Hit type tracking: SINGLE, MULTI, PIERCE
|
||||
* - Effects application
|
||||
* - affectsCaster flag
|
||||
* - Charging infrastructure (hook only — subclass defines growth behavior)
|
||||
* - Size interpolation: radius/height with target/render/prev layers
|
||||
*
|
||||
* Subclasses must implement:
|
||||
* - updateZone() — tick logic (damage, movement, etc.)
|
||||
* - writeZoneNBT() — type-specific NBT write
|
||||
* - readZoneNBT() — type-specific NBT read
|
||||
*
|
||||
* Subclasses may override:
|
||||
* - updateCharging() — charging growth behavior (default: increments chargeTick only)
|
||||
* - shouldIgnoreEntity() — damage/collision filter
|
||||
*/
|
||||
public abstract class EntityEnergyZone extends EntityEnergyAbility {
|
||||
|
||||
// ==================== SAFETY CONSTANTS ====================
|
||||
|
||||
public static final float MAX_ZONE_RADIUS = 64.0f;
|
||||
public static final float MAX_ZONE_HEIGHT = 64.0f;
|
||||
protected static final double GROUND_OFFSET = 0.05;
|
||||
|
||||
// ==================== LIFESPAN ====================
|
||||
|
||||
protected EnergyLifespanData lifespanData = new EnergyLifespanData();
|
||||
protected long deathWorldTime = -1;
|
||||
|
||||
// ==================== COMBAT ====================
|
||||
|
||||
protected EnergyCombatData combatData = new EnergyCombatData();
|
||||
protected List<AbilityPotionEffect> effects = new ArrayList<>();
|
||||
protected boolean affectsCaster = false;
|
||||
|
||||
// ==================== HIT TRACKING ====================
|
||||
|
||||
/** Entities hit exactly once — PIERCE: never again; SINGLE: zone dies on first hit. */
|
||||
protected final Set<Integer> hitOnceEntities = new HashSet<>();
|
||||
|
||||
/** Last tick each entity was hit, used for MULTI delay. */
|
||||
protected final Map<Integer, Integer> lastHitTickByEntity = new HashMap<>();
|
||||
|
||||
protected int hitCount = 0;
|
||||
|
||||
protected int targetEntityId = -1;
|
||||
|
||||
// ==================== SIZE — LOGICAL ====================
|
||||
|
||||
/** Current radius used for collision and damage checks. */
|
||||
protected float radius = 1.0f;
|
||||
|
||||
/** Current height used for collision and damage checks. */
|
||||
protected float height = 1.0f;
|
||||
|
||||
// ==================== SIZE — INTERPOLATION ====================
|
||||
|
||||
/** Target radius the zone is growing or shrinking toward. */
|
||||
protected float targetRadius = 1.0f;
|
||||
|
||||
/** Target height the zone is growing or shrinking toward. */
|
||||
protected float targetHeight = 1.0f;
|
||||
|
||||
/** Smoothed radius sent to the renderer each frame. */
|
||||
protected float renderRadius = 1.0f;
|
||||
|
||||
/** Smoothed height sent to the renderer each frame. */
|
||||
protected float renderHeight = 1.0f;
|
||||
|
||||
/** Previous-tick render radius for partialTicks interpolation. */
|
||||
protected float prevRenderRadius = 1.0f;
|
||||
|
||||
/** Previous-tick render height for partialTicks interpolation. */
|
||||
protected float prevRenderHeight = 1.0f;
|
||||
|
||||
// ==================== CONSTRUCTOR ====================
|
||||
|
||||
public EntityEnergyZone(World world) {
|
||||
super(world);
|
||||
this.setSize(0.1f, 0.1f);
|
||||
this.noClip = true;
|
||||
}
|
||||
|
||||
// ==================== ENTITY LIFECYCLE ====================
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
this.prevPosX = this.posX;
|
||||
this.prevPosY = this.posY;
|
||||
this.prevPosZ = this.posZ;
|
||||
this.prevRenderRadius = this.renderRadius;
|
||||
this.prevRenderHeight = this.renderHeight;
|
||||
|
||||
if (!previewMode) {
|
||||
super.onUpdate();
|
||||
} else {
|
||||
this.ticksExisted++;
|
||||
|
||||
if (isCharging() && chargeDuration > 0 && chargeTick > chargeDuration + PREVIEW_CHARGE_GRACE) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
if (ticksExisted > HARD_LIFETIME_CAP) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// During charging, snap render values so they follow subclass growth without lag.
|
||||
// After charging, lerp smoothly toward current logical size.
|
||||
if (isCharging()) {
|
||||
this.renderRadius = this.radius;
|
||||
this.renderHeight = this.height;
|
||||
updateCharging();
|
||||
return;
|
||||
} else {
|
||||
this.renderRadius += (this.radius - this.renderRadius) * 0.15f;
|
||||
this.renderHeight += (this.height - this.renderHeight) * 0.15f;
|
||||
}
|
||||
|
||||
if (!previewMode) {
|
||||
if (deathWorldTime < 0 && worldObj != null) {
|
||||
deathWorldTime = worldObj.getTotalWorldTime() + lifespanData.getMaxLifetime();
|
||||
}
|
||||
|
||||
if (deathWorldTime > 0 && worldObj.getTotalWorldTime() >= deathWorldTime) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ownerEntityId >= 0 && ticksExisted > 5) {
|
||||
Entity owner = worldObj.getEntityByID(ownerEntityId);
|
||||
if (owner != null) {
|
||||
if (owner.isDead) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
if (owner instanceof EntityNPCInterface && ((EntityNPCInterface) owner).isKilled()) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateZone();
|
||||
}
|
||||
|
||||
// ==================== HOOKS ====================
|
||||
|
||||
/**
|
||||
* Subclass tick logic — damage, movement, custom behavior.
|
||||
* Called every tick after charging ends and lifetime is validated.
|
||||
*/
|
||||
protected abstract void updateZone();
|
||||
|
||||
/**
|
||||
* Charging growth hook. Called every tick while isCharging() is true.
|
||||
* Default implementation increments chargeTick only.
|
||||
* Override to define what dimensions grow during the windup phase.
|
||||
*/
|
||||
protected void updateCharging() {
|
||||
chargeTick++;
|
||||
}
|
||||
|
||||
// ==================== CHARGING SETUP ====================
|
||||
|
||||
/**
|
||||
* Initialize charging state. Subclasses call this and then set their own target values.
|
||||
* Does not zero radius or height — subclass decides starting values.
|
||||
*/
|
||||
public void setupCharging(int chargeDuration) {
|
||||
setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
}
|
||||
|
||||
// ==================== DAMAGE PIPELINE ====================
|
||||
|
||||
/**
|
||||
* Apply damage to a target through the full energy pipeline:
|
||||
* sourceAbility extender -> customDamageData -> native damage source.
|
||||
*
|
||||
* @param target entity to damage
|
||||
* @param damage raw damage amount
|
||||
* @return true if damage was applied
|
||||
*/
|
||||
protected boolean applyDamage(EntityLivingBase target, float damage) {
|
||||
if (previewMode) return false;
|
||||
if (target == null) return false;
|
||||
if (damage <= 0 && sourceAbility == null && customDamageData == null) return false;
|
||||
|
||||
Entity owner = getOwnerEntity();
|
||||
int previousHurtResistantTime = Ability.clearHurtResistanceIfNeeded(target, ignoreIFrames);
|
||||
try {
|
||||
boolean handled = false;
|
||||
|
||||
if (sourceAbility != null && owner instanceof EntityLivingBase) {
|
||||
double dx = target.posX - posX;
|
||||
double dz = target.posZ - posZ;
|
||||
handled = AbilityController.Instance.fireOnAbilityDamage(
|
||||
sourceAbility, (EntityLivingBase) owner, target,
|
||||
damage, 0.0f, 0.0f, dx, dz, 1.0f);
|
||||
}
|
||||
|
||||
if (!handled && customDamageData != null && owner instanceof EntityLivingBase) {
|
||||
double dx = target.posX - posX;
|
||||
double dz = target.posZ - posZ;
|
||||
handled = EnergyController.Instance.fireOnEnergyDamage(
|
||||
this, (EntityLivingBase) owner, target,
|
||||
damage, 0.0f, 0.0f, dx, dz, 1.0f, customDamageData);
|
||||
}
|
||||
|
||||
if (!handled) {
|
||||
float finalDamage = damage;
|
||||
|
||||
if (magicData != null && !magicData.isEmpty() && owner instanceof EntityLivingBase) {
|
||||
finalDamage = AttributeAttackUtil.calculateAbilityDamage(
|
||||
(EntityLivingBase) owner, target, damage, magicData);
|
||||
}
|
||||
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
return target.attackEntityFrom(new NpcDamageSource("npc_ability", (EntityNPCInterface) owner), finalDamage);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
return target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) owner), finalDamage);
|
||||
} else if (owner instanceof EntityLivingBase) {
|
||||
return target.attackEntityFrom(DamageSource.causeMobDamage((EntityLivingBase) owner), finalDamage);
|
||||
} else {
|
||||
return target.attackEntityFrom(new NpcDamageSource("npc_ability", null), finalDamage);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} finally {
|
||||
Ability.restoreHurtResistanceIfNeeded(target, ignoreIFrames, previousHurtResistantTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply potion effects to a target.
|
||||
*/
|
||||
protected void applyEffects(EntityLivingBase target) {
|
||||
if (target == null || effects.isEmpty()) return;
|
||||
for (AbilityPotionEffect effect : effects) {
|
||||
effect.apply(target);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== HIT TYPE LOGIC ====================
|
||||
|
||||
/**
|
||||
* Whether this zone can hit the given entity right now, based on hit type.
|
||||
*/
|
||||
protected boolean canHitEntityNow(EntityLivingBase entity) {
|
||||
if (entity == null) return false;
|
||||
int entityId = entity.getEntityId();
|
||||
switch (combatData.hitType) {
|
||||
case SINGLE:
|
||||
case PIERCE:
|
||||
return !hitOnceEntities.contains(entityId);
|
||||
case MULTI:
|
||||
Integer lastTick = lastHitTickByEntity.get(entityId);
|
||||
if (lastTick == null) return true;
|
||||
return (ticksExisted - lastTick) >= Math.max(1, combatData.multiHitDelayTicks);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that an entity was hit this tick.
|
||||
*/
|
||||
protected void recordEntityHit(EntityLivingBase entity) {
|
||||
if (entity == null) return;
|
||||
int entityId = entity.getEntityId();
|
||||
hitOnceEntities.add(entityId);
|
||||
lastHitTickByEntity.put(entityId, ticksExisted);
|
||||
hitCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the zone should die after a successful hit (SINGLE only).
|
||||
*/
|
||||
protected boolean shouldTerminateAfterHit() {
|
||||
return combatData.hitType == HitType.SINGLE;
|
||||
}
|
||||
|
||||
// ==================== ENTITY FILTER ====================
|
||||
|
||||
/**
|
||||
* Whether an entity should be ignored for damage and collision.
|
||||
* Subclasses may override to add type-specific filters.
|
||||
*/
|
||||
protected boolean shouldIgnoreEntity(EntityLivingBase entity) {
|
||||
if (entity == null) return true;
|
||||
Entity owner = getOwnerEntity();
|
||||
if (entity == owner && !affectsCaster) return true;
|
||||
if (owner instanceof EntityLivingBase) {
|
||||
return !AbilityTargetHelper.shouldAffect((EntityLivingBase) owner, entity, TargetFilter.ENEMIES, affectsCaster);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getTargetEntityId() {
|
||||
return targetEntityId;
|
||||
}
|
||||
|
||||
public void setTargetEntityId(int id) {
|
||||
this.targetEntityId = id;
|
||||
}
|
||||
|
||||
public Entity getTargetEntity() {
|
||||
if (targetEntityId == -1) return null;
|
||||
return worldObj.getEntityByID(targetEntityId);
|
||||
}
|
||||
|
||||
public void setTargetEntity(Entity entity) {
|
||||
if (entity == null) return;
|
||||
this.targetEntityId = entity.getEntityId();
|
||||
}
|
||||
|
||||
// ==================== SIZE INTERPOLATION ====================
|
||||
|
||||
public float getInterpolatedRadius(float partialTicks) {
|
||||
return prevRenderRadius + (renderRadius - prevRenderRadius) * partialTicks;
|
||||
}
|
||||
|
||||
public float getInterpolatedHeight(float partialTicks) {
|
||||
return prevRenderHeight + (renderHeight - prevRenderHeight) * partialTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Snap all radius interpolation layers to a single value.
|
||||
* Use on init or after teleport to avoid pop artifacts.
|
||||
*/
|
||||
protected void setVisualRadius(float value) {
|
||||
this.radius = value;
|
||||
this.renderRadius = value;
|
||||
this.prevRenderRadius = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Snap all height interpolation layers to a single value.
|
||||
*/
|
||||
protected void setVisualHeight(float value) {
|
||||
this.height = value;
|
||||
this.renderHeight = value;
|
||||
this.prevRenderHeight = value;
|
||||
}
|
||||
|
||||
// ==================== GROUND SNAP ====================
|
||||
|
||||
/**
|
||||
* Position this zone at ground level beneath x/y/z.
|
||||
*/
|
||||
protected void snapToGround(double x, double y, double z) {
|
||||
double groundY = Ability.findGroundLevel(worldObj, x, y, z) + GROUND_OFFSET;
|
||||
this.setPosition(x, groundY, z);
|
||||
}
|
||||
|
||||
// ==================== PREVIEW ====================
|
||||
|
||||
/**
|
||||
* Set up this zone for GUI preview rendering.
|
||||
*/
|
||||
public void setupPreview(EntityLivingBase owner) {
|
||||
this.previewMode = true;
|
||||
this.previewOwner = owner;
|
||||
}
|
||||
|
||||
// ==================== GETTERS & SETTERS ====================
|
||||
|
||||
public float getDamage() { return combatData.getDamage(); }
|
||||
public void setDamage(float damage) { combatData.setDamage(damage); }
|
||||
|
||||
public float getKnockback() { return combatData.knockback; }
|
||||
public void setKnockback(float knockback) { combatData.setKnockback(knockback); }
|
||||
|
||||
public int getHitType() { return combatData.hitType.ordinal(); }
|
||||
public void setHitType(int hitType) { combatData.hitType = HitType.fromOrdinal(hitType); }
|
||||
|
||||
public int getMultiHitDelayTicks() { return combatData.multiHitDelayTicks; }
|
||||
public void setMultiHitDelayTicks(int ticks) { combatData.multiHitDelayTicks = Math.max(1, ticks); }
|
||||
|
||||
public boolean isAffectsCaster() { return affectsCaster; }
|
||||
public void setAffectsCaster(boolean affectsCaster) { this.affectsCaster = affectsCaster; }
|
||||
|
||||
public int getMaxLifetime() { return lifespanData.getMaxLifetime(); }
|
||||
public void setMaxLifetime(int ticks) { lifespanData.setMaxLifetime(ticks); }
|
||||
|
||||
public float getRadius() { return radius; }
|
||||
public void setRadius(float radius) { this.radius = sanitize(radius, 1.0f, MAX_ZONE_RADIUS); }
|
||||
|
||||
public float getZoneHeight() { return height; }
|
||||
public void setZoneHeight(float height) { this.height = sanitize(height, 1.0f, MAX_ZONE_HEIGHT); }
|
||||
|
||||
public float getTargetRadius() { return targetRadius; }
|
||||
public void setTargetRadius(float radius) { this.targetRadius = sanitize(radius, 1.0f, MAX_ZONE_RADIUS); }
|
||||
|
||||
public float getTargetHeight() { return targetHeight; }
|
||||
public void setTargetHeight(float height) { this.targetHeight = sanitize(height, 1.0f, MAX_ZONE_HEIGHT); }
|
||||
|
||||
public void setEffects(List<AbilityPotionEffect> effects) {
|
||||
if (effects == null || effects.isEmpty()) {
|
||||
this.effects = new ArrayList<>();
|
||||
} else {
|
||||
this.effects = new ArrayList<>(effects.size());
|
||||
for (AbilityPotionEffect effect : effects) {
|
||||
this.effects.add(effect.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
protected void writeSpawnNBT(NBTTagCompound nbt) {
|
||||
writeEnergyBaseNBT(nbt);
|
||||
writeZoneBaseNBT(nbt);
|
||||
writeZoneNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readSpawnNBT(NBTTagCompound nbt) {
|
||||
readEnergyBaseNBT(nbt);
|
||||
readZoneBaseNBT(nbt);
|
||||
readZoneNBT(nbt);
|
||||
}
|
||||
|
||||
protected void writeZoneBaseNBT(NBTTagCompound nbt) {
|
||||
nbt.setDouble("PosX", posX);
|
||||
nbt.setDouble("PosY", posY);
|
||||
nbt.setDouble("PosZ", posZ);
|
||||
|
||||
nbt.setFloat("Radius", radius);
|
||||
nbt.setFloat("Height", height);
|
||||
nbt.setFloat("TargetRadius", targetRadius);
|
||||
nbt.setFloat("TargetHeight", targetHeight);
|
||||
|
||||
lifespanData.writeNBT(nbt);
|
||||
nbt.setLong("DeathWorldTime", deathWorldTime);
|
||||
|
||||
combatData.writeNBT(nbt);
|
||||
nbt.setBoolean("AffectsCaster", affectsCaster);
|
||||
|
||||
nbt.setBoolean("Charging", isCharging());
|
||||
nbt.setInteger("ChargeDuration", chargeDuration);
|
||||
nbt.setInteger("ChargeTick", chargeTick);
|
||||
|
||||
nbt.setInteger("TargetEntityId", targetEntityId);
|
||||
|
||||
NBTTagList effectsList = new NBTTagList();
|
||||
for (AbilityPotionEffect effect : effects) {
|
||||
effectsList.appendTag(effect.writeNBT());
|
||||
}
|
||||
nbt.setTag("Effects", effectsList);
|
||||
}
|
||||
|
||||
protected void readZoneBaseNBT(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey("PosX")) {
|
||||
double px = nbt.getDouble("PosX");
|
||||
double py = nbt.getDouble("PosY");
|
||||
double pz = nbt.getDouble("PosZ");
|
||||
this.setPosition(px, py, pz);
|
||||
this.prevPosX = px; this.prevPosY = py; this.prevPosZ = pz;
|
||||
this.lastTickPosX = px; this.lastTickPosY = py; this.lastTickPosZ = pz;
|
||||
}
|
||||
|
||||
this.radius = sanitize(nbt.getFloat("Radius"), 1.0f, MAX_ZONE_RADIUS);
|
||||
this.height = sanitize(nbt.getFloat("Height"), 1.0f, MAX_ZONE_HEIGHT);
|
||||
this.targetRadius = sanitize(nbt.getFloat("TargetRadius"), 1.0f, MAX_ZONE_RADIUS);
|
||||
this.targetHeight = sanitize(nbt.getFloat("TargetHeight"), 1.0f, MAX_ZONE_HEIGHT);
|
||||
|
||||
this.renderRadius = this.radius;
|
||||
this.prevRenderRadius = this.radius;
|
||||
this.renderHeight = this.height;
|
||||
this.prevRenderHeight = this.height;
|
||||
|
||||
lifespanData.readNBT(nbt);
|
||||
this.deathWorldTime = nbt.hasKey("DeathWorldTime") ? nbt.getLong("DeathWorldTime") : -1;
|
||||
|
||||
combatData.readNBT(nbt);
|
||||
this.affectsCaster = nbt.getBoolean("AffectsCaster");
|
||||
|
||||
boolean isChargingVal = nbt.hasKey("Charging") && nbt.getBoolean("Charging");
|
||||
this.charging = isChargingVal;
|
||||
if (!worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_CHARGING, (byte) (isChargingVal ? 1 : 0));
|
||||
}
|
||||
this.chargeDuration = nbt.hasKey("ChargeDuration") ? nbt.getInteger("ChargeDuration") : 0;
|
||||
this.chargeTick = nbt.hasKey("ChargeTick") ? nbt.getInteger("ChargeTick") : 0;
|
||||
this.targetEntityId = nbt.hasKey("TargetEntityId") ? nbt.getInteger("TargetEntityId") : -1;
|
||||
|
||||
this.effects.clear();
|
||||
if (nbt.hasKey("Effects")) {
|
||||
NBTTagList effectsList = nbt.getTagList("Effects", 10);
|
||||
for (int i = 0; i < effectsList.tagCount(); i++) {
|
||||
AbilityPotionEffect effect = AbilityPotionEffect.fromNBT(effectsList.getCompoundTagAt(i));
|
||||
if (effect != null && effect.isValid()) {
|
||||
this.effects.add(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclass-specific NBT write. Called after writeZoneBaseNBT.
|
||||
*/
|
||||
protected abstract void writeZoneNBT(NBTTagCompound nbt);
|
||||
|
||||
/**
|
||||
* Subclass-specific NBT read. Called after readZoneBaseNBT.
|
||||
*/
|
||||
protected abstract void readZoneNBT(NBTTagCompound nbt);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumSyncType {
|
||||
FACTION,
|
||||
DIALOG,
|
||||
DIALOG_CATEGORY,
|
||||
QUEST,
|
||||
QUEST_CATEGORY,
|
||||
PLAYERDATA,
|
||||
MAGIC,
|
||||
MAGIC_CYCLE,
|
||||
WORKBENCH_RECIPES,
|
||||
CARPENTRY_RECIPES,
|
||||
ANVIL_RECIPES,
|
||||
CUSTOM_EFFECTS,
|
||||
CUSTOM_ABILITY,
|
||||
CHAINED_ABILITY
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Immutable, object-based sync-type identity for the CNPC+ sync backend.
|
||||
*
|
||||
* <p>Each {@code SyncType} has a canonical namespaced string ID ({@code modid:path})
|
||||
* and is registered via the static {@link #register} factory. Built-in CNPC+
|
||||
* families are exposed as {@code public static final} constants.</p>
|
||||
*
|
||||
* <p>Identity is based on the canonical {@link #id} string, which is unique
|
||||
* across all registered types. Two references with the same {@code id}
|
||||
* are always the same object (identity == equality for registered types).</p>
|
||||
*
|
||||
* <p>The {@code ordinal} field provides a stable integer identity for
|
||||
* wire encoding during the migration period. It is assigned at registration
|
||||
* time in declaration order and must NOT be used as a protocol identifier
|
||||
* once string-on-wire migration is complete.</p>
|
||||
*/
|
||||
public final class SyncType {
|
||||
|
||||
// ──────────────────── Registry ────────────────────
|
||||
private static final Map<String, SyncType> REGISTRY = new LinkedHashMap<>();
|
||||
private static int nextOrdinal = 0;
|
||||
|
||||
// ──────────────────── CNPC+ families ────────────────────
|
||||
public static final SyncType FACTION = register("cnpc:faction");
|
||||
public static final SyncType DIALOG = register("cnpc:dialog");
|
||||
public static final SyncType DIALOG_CATEGORY = register("cnpc:dialog_category");
|
||||
public static final SyncType QUEST = register("cnpc:quest");
|
||||
public static final SyncType QUEST_CATEGORY = register("cnpc:quest_category");
|
||||
public static final SyncType PLAYERDATA = register("cnpc:playerdata");
|
||||
public static final SyncType MAGIC = register("cnpc:magic");
|
||||
public static final SyncType MAGIC_CYCLE = register("cnpc:magic_cycle");
|
||||
public static final SyncType WORKBENCH_RECIPES = register("cnpc:workbench_recipes");
|
||||
public static final SyncType CARPENTRY_RECIPES = register("cnpc:carpentry_recipes");
|
||||
public static final SyncType ANVIL_RECIPES = register("cnpc:anvil_recipes");
|
||||
public static final SyncType CUSTOM_EFFECTS = register("cnpc:custom_effects");
|
||||
public static final SyncType CUSTOM_ABILITY = register("cnpc:custom_ability");
|
||||
public static final SyncType CHAINED_ABILITY = register("cnpc:chained_ability");
|
||||
|
||||
// ──────────────────── Instance fields ────────────────────
|
||||
private final String id;
|
||||
private final int ordinal;
|
||||
|
||||
private SyncType(String id, int ordinal) {
|
||||
this.id = id;
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
// ──────────────────── Public API ────────────────────
|
||||
|
||||
/**
|
||||
* The canonical namespaced identifier, e.g. {@code "cnpc:faction"}.
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stable integer ordinal assigned at registration time.
|
||||
* Used for wire encoding during the migration period only.
|
||||
*/
|
||||
public int ordinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
// ──────────────────── Registration ────────────────────
|
||||
|
||||
/**
|
||||
* Register a new {@code SyncType} with the given canonical ID.
|
||||
*
|
||||
* @param id namespaced identifier ({@code modid:path})
|
||||
* @return the newly created and registered {@code SyncType}
|
||||
* @throws IllegalArgumentException if the ID is null, empty, or lacks a colon
|
||||
* @throws IllegalStateException if a type with the same ID is already registered
|
||||
* @throws IllegalStateException if the registry has been frozen
|
||||
*/
|
||||
public static SyncType register(String id) {
|
||||
if (id == null || id.isEmpty()) throw new IllegalArgumentException("SyncType id must not be null or empty");
|
||||
if (!id.contains(":")) throw new IllegalArgumentException("SyncType id must be namespaced (modid:path): " + id);
|
||||
if (REGISTRY.containsKey(id)) throw new IllegalStateException("Duplicate SyncType registration: " + id);
|
||||
|
||||
SyncType type = new SyncType(id, nextOrdinal++);
|
||||
REGISTRY.put(id, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a registered SyncType by its canonical string ID.
|
||||
*
|
||||
* @return the registered type, or {@code null} if not found
|
||||
*/
|
||||
public static SyncType byId(String id) {
|
||||
return id == null ? null : REGISTRY.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a registered SyncType by its ordinal.
|
||||
* Used during migration for decoding ordinal-based wire traffic.
|
||||
*
|
||||
* @return the registered type, or {@code null} if ordinal is out of range
|
||||
*/
|
||||
public static SyncType byOrdinal(int ordinal) {
|
||||
if (ordinal < 0) return null;
|
||||
|
||||
for (SyncType type : REGISTRY.values())
|
||||
if (type.ordinal == ordinal) return type;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered SyncType instances in registration order.
|
||||
*/
|
||||
public static Collection<SyncType> values() {
|
||||
return Collections.unmodifiableCollection(REGISTRY.values());
|
||||
}
|
||||
|
||||
// ──────────────────── Object overrides ────────────────────
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SyncType)) return false;
|
||||
return id.equals(((SyncType) o).id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.packets.player.SyncRevisionInfoPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -21,20 +21,19 @@ import noppes.npcs.controllers.AuctionConfigSync;
|
||||
import noppes.npcs.controllers.ScriptConfigSync;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class LoginPacket extends AbstractPacket {
|
||||
public static final String packetName = "CNPC+|Login";
|
||||
|
||||
private String serverCacheKey = "";
|
||||
private final Map<SyncType, Integer> revisionSnapshot = new LinkedHashMap<>();
|
||||
private final EnumMap<EnumSyncType, Integer> revisionSnapshot = new EnumMap<>(EnumSyncType.class);
|
||||
|
||||
public LoginPacket() {
|
||||
}
|
||||
|
||||
public LoginPacket(String serverCacheKey, Map<SyncType, Integer> revisionSnapshot) {
|
||||
public LoginPacket(String serverCacheKey, EnumMap<EnumSyncType, Integer> revisionSnapshot) {
|
||||
if (serverCacheKey != null) {
|
||||
this.serverCacheKey = serverCacheKey;
|
||||
}
|
||||
@@ -59,15 +58,17 @@ public final class LoginPacket extends AbstractPacket {
|
||||
out.writeBoolean(ConfigMain.ProfilesEnabled);
|
||||
ByteBufUtils.writeString(out, serverCacheKey);
|
||||
out.writeShort(revisionSnapshot.size());
|
||||
for (Map.Entry<SyncType, Integer> entry : revisionSnapshot.entrySet()) {
|
||||
for (Map.Entry<EnumSyncType, Integer> entry : revisionSnapshot.entrySet()) {
|
||||
out.writeInt(entry.getKey().ordinal());
|
||||
out.writeInt(entry.getValue());
|
||||
}
|
||||
|
||||
// Send auction config (server-side sync)
|
||||
NBTTagCompound auctionConfig = new NBTTagCompound();
|
||||
AuctionConfigSync.writeToNBT(auctionConfig);
|
||||
ByteBufUtils.writeNBT(out, auctionConfig);
|
||||
|
||||
// Send script config (server-side sync)
|
||||
NBTTagCompound scriptConfig = new NBTTagCompound();
|
||||
ScriptConfigSync.writeToNBT(scriptConfig);
|
||||
ByteBufUtils.writeNBT(out, scriptConfig);
|
||||
@@ -81,20 +82,20 @@ public final class LoginPacket extends AbstractPacket {
|
||||
|
||||
String serverKey = ByteBufUtils.readString(in);
|
||||
int revisionCount = in.readUnsignedShort();
|
||||
Map<SyncType, Integer> serverRevisions = new LinkedHashMap<>();
|
||||
EnumMap<EnumSyncType, Integer> serverRevisions = new EnumMap<>(EnumSyncType.class);
|
||||
for (int i = 0; i < revisionCount; i++) {
|
||||
SyncType type = SyncType.byOrdinal(in.readInt());
|
||||
EnumSyncType type = EnumSyncType.values()[in.readInt()];
|
||||
int revision = in.readInt();
|
||||
if (type != null) {
|
||||
serverRevisions.put(type, revision);
|
||||
}
|
||||
serverRevisions.put(type, revision);
|
||||
}
|
||||
|
||||
ClientCacheHandler.setActiveServer(serverKey, serverRevisions);
|
||||
|
||||
// Read auction config
|
||||
NBTTagCompound auctionConfig = ByteBufUtils.readNBT(in);
|
||||
AuctionClientConfig.readFromNBT(auctionConfig);
|
||||
|
||||
// Read script config
|
||||
NBTTagCompound scriptConfig = ByteBufUtils.readNBT(in);
|
||||
ScriptClientConfig.readFromNBT(scriptConfig);
|
||||
|
||||
|
||||
+9
-12
@@ -8,24 +8,24 @@ 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.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PlayerUpdateSkinOverlaysPacket extends AbstractPacket {
|
||||
public static final String packetName = "Data|PlayerUpdateSkinOverlays";
|
||||
|
||||
private String playerUUID;
|
||||
private String playerName;
|
||||
private NBTTagCompound compound;
|
||||
|
||||
public PlayerUpdateSkinOverlaysPacket() {
|
||||
}
|
||||
|
||||
public PlayerUpdateSkinOverlaysPacket(UUID playerUUID, NBTTagCompound compound) {
|
||||
this.playerUUID = playerUUID == null ? "" : playerUUID.toString();
|
||||
public PlayerUpdateSkinOverlaysPacket(String playerName, NBTTagCompound compound) {
|
||||
this.playerName = playerName;
|
||||
this.compound = compound;
|
||||
}
|
||||
|
||||
@@ -41,21 +41,18 @@ public final class PlayerUpdateSkinOverlaysPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, this.playerUUID);
|
||||
ByteBufUtils.writeString(out, this.playerName);
|
||||
ByteBufUtils.writeNBT(out, this.compound);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
String uuid = ByteBufUtils.readString(in);
|
||||
String playerName = ByteBufUtils.readString(in);
|
||||
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
|
||||
if (uuid == null || uuid.isEmpty())
|
||||
return;
|
||||
|
||||
try {
|
||||
NoppesUtil.updateSkinOverlayData(UUID.fromString(uuid), nbt);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(playerName);
|
||||
if (sendingPlayer != null) {
|
||||
NoppesUtil.updateSkinOverlayData(sendingPlayer, nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
@@ -68,7 +68,7 @@ public final class EnergyChargeSpawnPacket extends AbstractPacket {
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
if (world == null) return;
|
||||
|
||||
EntityEnergyProjectile preview = createPreviewEntity(className, world);
|
||||
EntityEnergyAbility preview = createPreviewEntity(className, world);
|
||||
if (preview == null) return;
|
||||
|
||||
preview.setPreviewMode(true);
|
||||
@@ -84,22 +84,22 @@ public final class EnergyChargeSpawnPacket extends AbstractPacket {
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static EntityEnergyProjectile createPreviewEntity(String className, World world) {
|
||||
private static EntityEnergyAbility createPreviewEntity(String className, World world) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(className);
|
||||
if (!EntityEnergyProjectile.class.isAssignableFrom(clazz)) {
|
||||
if (!EntityEnergyAbility.class.isAssignableFrom(clazz)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Constructor<?> constructor = clazz.getConstructor(World.class);
|
||||
Object instance = constructor.newInstance(world);
|
||||
return (EntityEnergyProjectile) instance;
|
||||
return (EntityEnergyAbility) instance;
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToTracking(String instanceId, EntityEnergyProjectile previewEntity, Entity trackingEntity) {
|
||||
public static void sendToTracking(String instanceId, EntityEnergyAbility previewEntity, Entity trackingEntity) {
|
||||
if (previewEntity == null || trackingEntity == null) return;
|
||||
String className = previewEntity.getClass().getName();
|
||||
NBTTagCompound nbt = previewEntity.exportSpawnNBT();
|
||||
|
||||
@@ -9,9 +9,13 @@ 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.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -55,6 +59,15 @@ public final class GuiDataPacket extends LargeAbstractPacket {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
IGuiData.legacySetGuiData(ByteBufUtils.readBigNBT(data));
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
if (gui instanceof GuiNPCInterface && ((GuiNPCInterface) gui).hasSubGui()) {
|
||||
gui = ((GuiNPCInterface) gui).getSubGui();
|
||||
} else if (gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface) gui).hasSubGui()) {
|
||||
gui = ((GuiContainerNPCInterface) gui).getSubGui();
|
||||
}
|
||||
if (gui instanceof IGuiData) {
|
||||
NBTTagCompound nbt = ByteBufUtils.readBigNBT(data);
|
||||
((IGuiData) gui).setGuiData(nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerEffectSyncHelper;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
@@ -54,7 +54,7 @@ public final class SyncEffectPacket extends LargeAbstractPacket {
|
||||
return;
|
||||
try {
|
||||
NBTTagCompound tag = ByteBufUtils.readBigNBT(data);
|
||||
PlayerEffectSyncHelper.clientSyncEffects(tag);
|
||||
SyncController.clientSyncEffects(tag);
|
||||
} catch (RuntimeException e) {
|
||||
LogWriter.error(String.format("Attempted to Sync Effects but it was too big"));
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -22,13 +22,16 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A large sync packet that sends chunked data to the client for a given SyncType
|
||||
* along with a SyncAction (RELOAD, UPDATE, REMOVE).
|
||||
*/
|
||||
public final class SyncPacket extends LargeAbstractPacket {
|
||||
|
||||
private SyncType syncType;
|
||||
private EnumSyncType enumSyncType;
|
||||
private EnumSyncAction enumSyncAction;
|
||||
private NBTTagCompound syncData;
|
||||
private int operationID;
|
||||
private String operationKey;
|
||||
private int revision = -1;
|
||||
private byte[] cachedPayload;
|
||||
private byte[][] cachedChunks;
|
||||
@@ -36,21 +39,23 @@ public final class SyncPacket extends LargeAbstractPacket {
|
||||
public SyncPacket() {
|
||||
}
|
||||
|
||||
public SyncPacket(SyncType syncType, EnumSyncAction enumSyncAction, int catId, NBTTagCompound syncData) {
|
||||
this(syncType, enumSyncAction, catId, null, -1, syncData);
|
||||
/**
|
||||
* Constructs a new LargeSyncPacket.
|
||||
*/
|
||||
public SyncPacket(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int catId, NBTTagCompound syncData) {
|
||||
this(enumSyncType, enumSyncAction, catId, -1, syncData);
|
||||
}
|
||||
|
||||
public SyncPacket(SyncType syncType, EnumSyncAction enumSyncAction, int operationId, String operationKey, int revision, NBTTagCompound syncData) {
|
||||
this.syncType = syncType;
|
||||
public SyncPacket(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int catId, int revision, NBTTagCompound syncData) {
|
||||
this.enumSyncType = enumSyncType;
|
||||
this.enumSyncAction = enumSyncAction;
|
||||
this.syncData = syncData;
|
||||
this.operationID = operationId;
|
||||
this.operationKey = operationKey;
|
||||
this.operationID = catId;
|
||||
this.revision = revision;
|
||||
}
|
||||
|
||||
public SyncPacket(SyncType syncType, SyncController.CachedSyncPayload payload) {
|
||||
this.syncType = syncType;
|
||||
public SyncPacket(EnumSyncType enumSyncType, SyncController.CachedSyncPayload payload) {
|
||||
this.enumSyncType = enumSyncType;
|
||||
this.enumSyncAction = EnumSyncAction.RELOAD;
|
||||
this.operationID = -1;
|
||||
this.revision = payload.getRevision();
|
||||
@@ -74,21 +79,13 @@ public final class SyncPacket extends LargeAbstractPacket {
|
||||
return cachedPayload;
|
||||
}
|
||||
|
||||
boolean hasKey = operationKey != null;
|
||||
boolean hasNbt = syncData != null;
|
||||
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
buffer.writeInt(syncType.ordinal());
|
||||
buffer.writeInt(enumSyncType.ordinal());
|
||||
buffer.writeInt(enumSyncAction.ordinal());
|
||||
buffer.writeInt(operationID);
|
||||
buffer.writeInt(revision);
|
||||
|
||||
// UPDATE/REMOVE UNIQUE FIELDS
|
||||
buffer.writeBoolean(hasKey);
|
||||
if (hasKey) ByteBufUtils.writeString(buffer, operationKey);
|
||||
buffer.writeBoolean(hasNbt);
|
||||
if (hasNbt) ByteBufUtils.writeBigNBT(buffer, syncData);
|
||||
ByteBufUtils.writeBigNBT(buffer, syncData);
|
||||
|
||||
byte[] bytes = new byte[buffer.readableBytes()];
|
||||
buffer.readBytes(bytes);
|
||||
@@ -134,40 +131,39 @@ public final class SyncPacket extends LargeAbstractPacket {
|
||||
if (CustomNpcs.side() != Side.CLIENT)
|
||||
return;
|
||||
|
||||
// Reconstruct everything from the ByteBuf
|
||||
int syncTypeOrdinal = data.readInt();
|
||||
int syncActionOrdinal = data.readInt();
|
||||
operationID = data.readInt();
|
||||
revision = data.readInt();
|
||||
int categoryID = data.readInt();
|
||||
int incomingRevision = data.readInt();
|
||||
|
||||
EnumSyncType type = EnumSyncType.values()[syncTypeOrdinal];
|
||||
EnumSyncAction action = EnumSyncAction.values()[syncActionOrdinal];
|
||||
|
||||
// These fields only exist for UPDATE/REMOVE
|
||||
if (action != EnumSyncAction.RELOAD) {
|
||||
if (data.readBoolean()) operationKey = ByteBufUtils.readString(data);
|
||||
if (data.readBoolean()) syncData = ByteBufUtils.readBigNBT(data);
|
||||
} else
|
||||
syncData = ByteBufUtils.readBigNBT(data);
|
||||
|
||||
|
||||
syncType = SyncType.byOrdinal(syncTypeOrdinal);
|
||||
if (syncType == null) {
|
||||
LogWriter.error("[SyncPacket] Unknown sync type ordinal: " + syncTypeOrdinal + "; skipping");
|
||||
return;
|
||||
try {
|
||||
NBTTagCompound tag = ByteBufUtils.readBigNBT(data);
|
||||
// Now do your client-side logic (similar to your old clientSync() or clientSyncUpdate() approach)
|
||||
handleSyncPacketClient(type, action, categoryID, incomingRevision, tag);
|
||||
} catch (RuntimeException e) {
|
||||
LogWriter.error(String.format("Attempted to Sync %s but it was too big", type.toString()));
|
||||
}
|
||||
|
||||
handleSync(syncType, action, operationID, operationKey, revision, syncData);
|
||||
}
|
||||
|
||||
private void handleSync(SyncType type, EnumSyncAction action, int id, String key, int revision, NBTTagCompound data) {
|
||||
switch (action) {
|
||||
private void handleSyncPacketClient(
|
||||
EnumSyncType enumSyncType,
|
||||
EnumSyncAction enumSyncAction,
|
||||
int id,
|
||||
int incomingRevision,
|
||||
NBTTagCompound data
|
||||
) {
|
||||
switch (enumSyncAction) {
|
||||
case RELOAD:
|
||||
SyncController.clientHandleAll(type, revision, data);
|
||||
SyncController.clientSync(enumSyncType, incomingRevision, data);
|
||||
break;
|
||||
case UPDATE:
|
||||
SyncController.clientHandleUpdate(type, id, key, revision, data);
|
||||
SyncController.clientUpdate(enumSyncType, id, incomingRevision, data);
|
||||
break;
|
||||
case REMOVE:
|
||||
SyncController.clientHandleRemove(type, id, key, revision);
|
||||
SyncController.clientSyncRemove(enumSyncType, id, incomingRevision);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||
@@ -23,12 +23,12 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||
|
||||
private String serverKey = "";
|
||||
private String previousServerKey = "";
|
||||
private final Map<SyncType, Integer> revisions = new LinkedHashMap<>();
|
||||
private final EnumMap<EnumSyncType, Integer> revisions = new EnumMap<>(EnumSyncType.class);
|
||||
|
||||
public SyncRevisionInfoPacket() {
|
||||
}
|
||||
|
||||
public SyncRevisionInfoPacket(String serverKey, String previousServerKey, Map<SyncType, Integer> revisions) {
|
||||
public SyncRevisionInfoPacket(String serverKey, String previousServerKey, EnumMap<EnumSyncType, Integer> revisions) {
|
||||
if (serverKey != null) {
|
||||
this.serverKey = serverKey;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||
ByteBufUtils.writeString(out, serverKey);
|
||||
ByteBufUtils.writeString(out, previousServerKey);
|
||||
out.writeShort(revisions.size());
|
||||
for (Map.Entry<SyncType, Integer> entry : revisions.entrySet()) {
|
||||
for (Map.Entry<EnumSyncType, Integer> entry : revisions.entrySet()) {
|
||||
out.writeInt(entry.getKey().ordinal());
|
||||
out.writeInt(entry.getValue());
|
||||
}
|
||||
@@ -71,15 +71,13 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||
String incomingServerKey = ByteBufUtils.readString(in);
|
||||
String incomingPreviousKey = ByteBufUtils.readString(in);
|
||||
int revisionCount = in.readUnsignedShort();
|
||||
Map<SyncType, Integer> incomingRevisions = new LinkedHashMap<>();
|
||||
EnumMap<EnumSyncType, Integer> incomingRevisions = new EnumMap<>(EnumSyncType.class);
|
||||
for (int i = 0; i < revisionCount; i++) {
|
||||
SyncType type = SyncType.byOrdinal(in.readInt());
|
||||
EnumSyncType type = EnumSyncType.values()[in.readInt()];
|
||||
int revision = in.readInt();
|
||||
if (type != null) {
|
||||
incomingRevisions.put(type, revision);
|
||||
}
|
||||
incomingRevisions.put(type, revision);
|
||||
}
|
||||
|
||||
SyncController.completeLoginRevisionHandshake((EntityPlayerMP) player, incomingServerKey, incomingPreviousKey, incomingRevisions);
|
||||
SyncController.handleClientRevisionReport((EntityPlayerMP) player, incomingServerKey, incomingPreviousKey, incomingRevisions);
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -50,7 +50,10 @@ public final class AbilityHotbarSelectPacket extends AbstractPacket {
|
||||
// Deselect
|
||||
data.abilityData.setSelectedIndex(-1);
|
||||
} else {
|
||||
data.abilityData.setSelectedIndex(data.abilityData.getUnlockedAbilityList().indexOf(key));
|
||||
int index = data.abilityData.getUnlockedAbilityList().indexOf(key);
|
||||
if (index >= 0) {
|
||||
data.abilityData.setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
data.save();
|
||||
}
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public final class CategoryItemsRequestPacket extends AbstractPacket {
|
||||
|
||||
// Send tag map for the items
|
||||
HashMap<String, HashSet<UUID>> tagMap = getTagMapByCat(type, categoryId);
|
||||
if (tagMap != null) {
|
||||
if (tagMap != null && !tagMap.isEmpty()) {
|
||||
TagController.sendCategoryTagMap((EntityPlayerMP) player, tagMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -64,13 +63,7 @@ public final class RoleSavePacket extends AbstractPacket {
|
||||
if (!PacketUtil.verifyItemPacket(packetName, EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
|
||||
NBTTagCompound roleCompound = ByteBufUtils.readNBT(in);
|
||||
if (npc.roleInterface instanceof RoleTrader) {
|
||||
// An admin edit wins over the linked market; the market is written from it afterwards.
|
||||
((RoleTrader) npc.roleInterface).readFromNBT(roleCompound, false);
|
||||
} else {
|
||||
npc.roleInterface.readFromNBT(roleCompound);
|
||||
}
|
||||
npc.roleInterface.readFromNBT(ByteBufUtils.readNBT(in));
|
||||
npc.updateClient = true;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -36,6 +38,9 @@ public final class TagsGetPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!PacketUtil.verifyItemPacket(packetName, player, EnumItemPacketType.WAND, EnumItemPacketType.CLONER))
|
||||
return;
|
||||
|
||||
NoppesUtilServer.sendTagDataAll((EntityPlayerMP) player);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Register<T> {
|
||||
protected final String namespace;
|
||||
protected final Map<String, Supplier<T>> entries = new LinkedHashMap<>();
|
||||
|
||||
public Register(String registryKey, String namespace) {
|
||||
private Register(String registryKey, String namespace) {
|
||||
this.registryKey = registryKey;
|
||||
this.namespace = namespace;
|
||||
}
|
||||
@@ -36,31 +36,6 @@ public class Register<T> {
|
||||
return factory.get();
|
||||
}
|
||||
|
||||
public Map<String, Supplier<T>> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public void forEach(Consumer<T> action) {
|
||||
entries.values().forEach(s -> action.accept(s.get()));
|
||||
}
|
||||
|
||||
public static <T> Register<T> create(String registryKey, String namespace, String displayName) {
|
||||
registerNamespace(registryKey, namespace, displayName);
|
||||
return new Register<>(registryKey, namespace);
|
||||
}
|
||||
|
||||
public static void registerNamespace(String registryKey, String namespace, String displayName) {
|
||||
if (!REGISTERED_NAMESPACES.containsKey(registryKey))
|
||||
REGISTERED_NAMESPACES.put(registryKey, new ArrayList<>());
|
||||
|
||||
if (REGISTERED_NAMESPACES.get(registryKey).contains(namespace)) {
|
||||
LogWriter.error("REGISTER: Namespace " + namespace + " already registered for registry " + registryKey + "!");
|
||||
}
|
||||
|
||||
REGISTERED_NAMESPACES.get(registryKey).add(namespace);
|
||||
NAMESPACE_DISPLAY_NAMES.put(namespace, displayName);
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String registryKey) {
|
||||
if (REGISTERED_NAMESPACES.isEmpty()) return true;
|
||||
|
||||
|
||||
@@ -786,14 +786,7 @@ public abstract class AbstractDataAbilities {
|
||||
fireTickEvent(currentAbility, target);
|
||||
|
||||
// Script may have completed/cancelled the ability during the tick event
|
||||
if (currentAbility == null) return;
|
||||
if (!currentAbility.isExecuting()) {
|
||||
// tick() can end the ability (DAZED -> IDLE)
|
||||
if (phaseChanged && currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(target);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) return;
|
||||
|
||||
// Fire extender tick hook (e.g., per-tick resource drain)
|
||||
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, entity, target,
|
||||
|
||||
@@ -225,9 +225,6 @@ public class CommonProxy implements IGuiHandler {
|
||||
public void buildPackageIndex() {
|
||||
}
|
||||
|
||||
public void loadComplete() {
|
||||
}
|
||||
|
||||
public boolean isScriptingEnabled() {
|
||||
return ConfigScript.ScriptingEnabled;
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
|
||||
import com.gtnewhorizon.gtnhmixins.LateMixin;
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import noppes.npcs.config.ConfigMixin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The mixins into other mods' player models, loaded by UniMixins after every
|
||||
* mod jar is on the class path. Only found when UniMixins is installed; the
|
||||
* early plugin then leaves these out.
|
||||
*/
|
||||
@LateMixin
|
||||
public class CustomNPCsLateMixins implements ILateMixinLoader {
|
||||
|
||||
@Override
|
||||
public String getMixinConfig() {
|
||||
return "mixins.customnpcs.late.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixins(Set<String> loadedMods) {
|
||||
List<String> mixins = new ArrayList<>();
|
||||
if (!FMLLaunchHandler.side().isClient() || !ConfigMixin.AnimationMixin) {
|
||||
return mixins;
|
||||
}
|
||||
mixins.addAll(OptionalModelMixins.playerModelMixins(true));
|
||||
System.out.println("[CustomNPC+] Late player model mixins: " + mixins);
|
||||
return mixins;
|
||||
}
|
||||
}
|
||||
@@ -29,17 +29,7 @@ import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
||||
import kamkeel.npcs.developer.Developer;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import kamkeel.npcs.entity.*;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.util.BukkitUtil;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -125,7 +115,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11.2")
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11.1")
|
||||
public class CustomNpcs {
|
||||
|
||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
||||
@@ -304,6 +294,7 @@ public class CustomNpcs {
|
||||
registerNewEntity(EntityEnergyDome.class, "energydome", 64, 3, true);
|
||||
registerNewEntity(EntityEnergyPanel.class, "energypanel", 64, 3, true);
|
||||
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 1, true);
|
||||
registerNewEntity(EntityAbilityPillar.class, "abilitypillar", 64, 1, true);
|
||||
|
||||
new RecipeController();
|
||||
|
||||
@@ -318,9 +309,6 @@ public class CustomNpcs {
|
||||
new AttributeController();
|
||||
new MagicController();
|
||||
|
||||
SyncController.register();
|
||||
|
||||
|
||||
APIRegistry.Instance.register("CNPC+ API", "https://kamkeel.github.io/CustomNPC-Plus/");
|
||||
}
|
||||
|
||||
@@ -343,7 +331,6 @@ public class CustomNpcs {
|
||||
|
||||
@EventHandler
|
||||
public void loadComplete(FMLLoadCompleteEvent ev) {
|
||||
proxy.loadComplete();
|
||||
proxy.buildPackageIndex();
|
||||
|
||||
// Load built-in animations on the client so they're available for ability preview.
|
||||
|
||||
@@ -188,32 +188,29 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
if (maxCooldown > minCooldown) {
|
||||
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
||||
}
|
||||
long now = npc.worldObj.getTotalWorldTime();
|
||||
cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + ability.getCooldownTicks();
|
||||
|
||||
// Additionally set per-ability cooldown if enabled
|
||||
if (ability.isPerAbilityCooldown() && ability.getCooldownTicks() > 0) {
|
||||
// Global timer only paces the NPC; the ability tracks its own cooldown
|
||||
cooldownEndTime = now + baseCooldown;
|
||||
setPerAbilityCooldown(ability.getName(), now + ability.getCooldownTicks(), ability.getCooldownTicks());
|
||||
} else {
|
||||
cooldownEndTime = now + baseCooldown + ability.getCooldownTicks();
|
||||
long endTime = npc.worldObj.getTotalWorldTime() + ability.getCooldownTicks();
|
||||
setPerAbilityCooldown(ability.getName(), endTime, ability.getCooldownTicks());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rollChainCooldown(ChainedAbility chain) {
|
||||
long now = npc.worldObj.getTotalWorldTime();
|
||||
boolean perAbility = chain.isPerAbilityCooldown() && chain.getCooldownTicks() > 0;
|
||||
|
||||
if (!chain.isIgnoreCooldown()) {
|
||||
int baseCooldown = minCooldown;
|
||||
if (maxCooldown > minCooldown) {
|
||||
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
||||
}
|
||||
cooldownEndTime = perAbility ? now + baseCooldown : now + baseCooldown + chain.getCooldownTicks();
|
||||
cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + chain.getCooldownTicks();
|
||||
}
|
||||
|
||||
if (perAbility) {
|
||||
setPerAbilityCooldown(chain.getName(), now + chain.getCooldownTicks(), chain.getCooldownTicks());
|
||||
// Additionally set per-ability cooldown if enabled
|
||||
if (chain.isPerAbilityCooldown() && chain.getCooldownTicks() > 0) {
|
||||
long endTime = npc.worldObj.getTotalWorldTime() + chain.getCooldownTicks();
|
||||
setPerAbilityCooldown(chain.getName(), endTime, chain.getCooldownTicks());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -550,11 +550,12 @@ public class NoppesUtilPlayer {
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
Quest quest = data.quest;
|
||||
if (quest == null)
|
||||
if (!data.quest.questInterface.isPartyCompleted(party))
|
||||
return false;
|
||||
|
||||
if (!data.quest.questInterface.isPartyCompleted(party))
|
||||
|
||||
Quest quest = data.quest;
|
||||
if (quest == null)
|
||||
return false;
|
||||
|
||||
if (data.quest.completion == EnumQuestCompletion.Instant)
|
||||
|
||||
@@ -343,6 +343,11 @@ public class NoppesUtilServer {
|
||||
sendOpenGui(player, gui, npc, 0, 0, 0);
|
||||
}
|
||||
|
||||
public static void sendOpenGuiNoDelay(EntityPlayer player,
|
||||
EnumGuiType gui, EntityNPCInterface npc) {
|
||||
sendOpenGuiNoDelay(player, gui, npc, 0, 0, 0);
|
||||
}
|
||||
|
||||
public static void sendOpenGui(final EntityPlayer player,
|
||||
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
@@ -364,6 +369,28 @@ public class NoppesUtilServer {
|
||||
ScrollListPacket.sendList((EntityPlayerMP) player, list, EnumScrollData.OPTIONAL);
|
||||
}
|
||||
|
||||
public static void sendOpenGuiNoDelay(final EntityPlayer player,
|
||||
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
setEditingNpc(player, npc);
|
||||
sendExtraData(player, npc, gui, i, j, k);
|
||||
|
||||
if (CustomNpcs.proxy.getServerGuiElement(gui.ordinal(), player, player.worldObj, i, j, k) != null) {
|
||||
player.openGui(CustomNpcs.instance, gui.ordinal(), player.worldObj, i, j, k);
|
||||
return;
|
||||
} else {
|
||||
GuiOpenPacket.openGUI((EntityPlayerMP) player, gui, i, j, k);
|
||||
}
|
||||
ArrayList<String> list = getScrollData(player, gui, npc);
|
||||
if (list == null || list.isEmpty())
|
||||
return;
|
||||
|
||||
ScrollListPacket.sendList((EntityPlayerMP) player, list, EnumScrollData.OPTIONAL);
|
||||
}
|
||||
|
||||
|
||||
private static void sendExtraData(EntityPlayer player, EntityNPCInterface npc, EnumGuiType gui, int i, int j, int k) {
|
||||
if (gui == EnumGuiType.PlayerFollower || gui == EnumGuiType.PlayerFollowerHire || gui == EnumGuiType.PlayerTrader || gui == EnumGuiType.PlayerTransporter) {
|
||||
sendRoleData(player, npc);
|
||||
@@ -613,7 +640,7 @@ public class NoppesUtilServer {
|
||||
playerdata.save();
|
||||
}
|
||||
if (pl != null) {
|
||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
||||
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||
}
|
||||
sendPlayerData(type, player, name);
|
||||
}
|
||||
@@ -1202,7 +1229,7 @@ public class NoppesUtilServer {
|
||||
playerdata.save();
|
||||
|
||||
if (pl != null) {
|
||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
||||
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1234,7 +1261,7 @@ public class NoppesUtilServer {
|
||||
|
||||
playerdata.save();
|
||||
if (pl != null) {
|
||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
||||
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Which mixins into other mods' player models to load, each only when its
|
||||
* class is there. With UniMixins the late loader asks after every mod jar is
|
||||
* on the class path. Without it the early plugin asks before that, finds the
|
||||
* jar in the mods folder and lends it to the class loader so Mixin can read
|
||||
* the target.
|
||||
*/
|
||||
public final class OptionalModelMixins {
|
||||
|
||||
/** Jars lent to the class loader early, taken off the source list again once read. */
|
||||
private static final List<URL> lentJars = new ArrayList<URL>();
|
||||
|
||||
private OptionalModelMixins() {
|
||||
}
|
||||
|
||||
/** UniMixins is a coremod, so its late loader interface is readable this early. */
|
||||
public static boolean lateLoaderAvailable() {
|
||||
try {
|
||||
return Launch.classLoader.getClassBytes("com.gtnewhorizon.gtnhmixins.ILateMixinLoader") != null;
|
||||
} catch (IOException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** The mixin names, relative to the late package. */
|
||||
public static List<String> playerModelMixins(boolean late) {
|
||||
List<String> mixins = new ArrayList<String>();
|
||||
if (hasClass("noppes.mpm.client.model.ModelMPM", late)) {
|
||||
mixins.add("MixinMPMModel");
|
||||
}
|
||||
if (hasClass("noppes.mpm.client.model.ModelScaleRenderer", late)) {
|
||||
mixins.add("MixinMPMModelScaleRenderer");
|
||||
}
|
||||
if (hasClass("micdoodle8.mods.galacticraft.core.client.model.ModelPlayerGC", late)) {
|
||||
mixins.add("MixinGalacticraftPlayerModel");
|
||||
}
|
||||
if (hasClass("api.player.model.ModelPlayerAPI", late)) {
|
||||
mixins.add("MixinPlayerAPIModel");
|
||||
}
|
||||
return mixins;
|
||||
}
|
||||
|
||||
/**
|
||||
* FML lists every class-path source as a mod source, so a lent jar left
|
||||
* on the list is found twice and refused as a duplicate. Off the list the
|
||||
* jar stays readable, and FML adds it once itself.
|
||||
*/
|
||||
public static void releaseLentJars() {
|
||||
if (lentJars.isEmpty()) return;
|
||||
Launch.classLoader.getSources().removeAll(lentJars);
|
||||
System.out.println("[CustomNPC+] Took " + lentJars.size() + " optional mod jar(s) back off the source list");
|
||||
lentJars.clear();
|
||||
}
|
||||
|
||||
private static boolean hasClass(String className, boolean late) {
|
||||
try {
|
||||
if (Launch.classLoader.getClassBytes(className) != null) {
|
||||
System.out.println("[CustomNPC+] Optional class " + className + ": on the class path");
|
||||
return true;
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
System.out.println("[CustomNPC+] Could not inspect optional class " + className + ": " + exception);
|
||||
}
|
||||
File jar = late ? null : jarHolding(className);
|
||||
if (jar == null) {
|
||||
System.out.println("[CustomNPC+] Optional class " + className + ": not found");
|
||||
return false;
|
||||
}
|
||||
// Mixin drops a @Pseudo target it cannot read when the config is
|
||||
// prepared. Lending the jar now lets it read the class.
|
||||
try {
|
||||
URL url = jar.toURI().toURL();
|
||||
Launch.classLoader.addURL(url);
|
||||
lentJars.add(url);
|
||||
System.out.println("[CustomNPC+] Optional class " + className + ": in mods/"
|
||||
+ jar.getName() + ", lent to the class path");
|
||||
return true;
|
||||
} catch (MalformedURLException exception) {
|
||||
System.out.println("[CustomNPC+] Optional class " + className + ": in mods/"
|
||||
+ jar.getName() + " but it could not be lent to the class path: " + exception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** The jar under mods/ that holds the class, or null. */
|
||||
private static File jarHolding(String className) {
|
||||
String entry = className.replace('.', '/') + ".class";
|
||||
File[] folders = {new File("mods"), new File("mods" + File.separator + "1.7.10")};
|
||||
for (File folder : folders) {
|
||||
File[] jars = folder.listFiles();
|
||||
if (jars == null) continue;
|
||||
for (File jar : jars) {
|
||||
if (!jar.getName().toLowerCase().endsWith(".jar")) continue;
|
||||
try (ZipFile zip = new ZipFile(jar)) {
|
||||
if (zip.getEntry(entry) != null) return jar;
|
||||
} catch (IOException ignored) {
|
||||
// Not a readable jar; nothing to find in it.
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,7 @@ import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.data.attribute.tracker.PlayerAttributeTracker;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerDataSyncHandler;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerEffectSyncHelper;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCounter;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
@@ -143,7 +141,7 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
|
||||
if (playerData.updateClient) {
|
||||
PlayerDataSyncHandler.syncPlayerData((EntityPlayerMP) player, true);
|
||||
SyncController.syncPlayerData((EntityPlayerMP) player, true);
|
||||
playerData.updateClient = false;
|
||||
}
|
||||
|
||||
@@ -153,8 +151,8 @@ public class ScriptPlayerEventHandler {
|
||||
|
||||
if (player.ticksExisted % 10 == 0) {
|
||||
EntityPlayerMP mp = (EntityPlayerMP) player;
|
||||
PlayerEffectSyncHelper.syncEffects(mp);
|
||||
PlayerAbilitySyncHelper.syncAbilityCooldowns(mp);
|
||||
SyncController.syncEffects(mp);
|
||||
SyncController.syncAbilityCooldowns(mp);
|
||||
PlayerAbilitySyncPacket.sendToPlayer(mp);
|
||||
playerData.abilityData.ensureLockStateClear();
|
||||
}
|
||||
|
||||
@@ -4,15 +4,13 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.handlers.CarpentryRecipeSyncHandler;
|
||||
import kamkeel.npcs.controllers.sync.handlers.WorkbenchRecipeSyncHandler;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.packets.data.ClonerPacket;
|
||||
import kamkeel.npcs.network.packets.data.MarkDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
|
||||
@@ -138,7 +136,7 @@ public class ServerEventsHandler {
|
||||
mounted = event.target;
|
||||
if (isRemote)
|
||||
CustomNpcs.proxy.openGui(MathHelper.floor_double(mounted.posX), MathHelper.floor_double(mounted.posY), MathHelper.floor_double(mounted.posZ), EnumGuiType.MobSpawnerMounter, event.entityPlayer);
|
||||
} else if (item.getItem() == CustomItems.wand && event.target instanceof EntityVillager) {
|
||||
} else if (item.getItem() == CustomItems.wand && !isRemote && event.target instanceof EntityVillager) {
|
||||
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.EDIT_VILLAGER))
|
||||
return;
|
||||
event.setCanceled(true);
|
||||
@@ -257,22 +255,20 @@ public class ServerEventsHandler {
|
||||
|
||||
if (block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
SyncType.WORKBENCH_RECIPES,
|
||||
EnumSyncType.WORKBENCH_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
null,
|
||||
SyncController.getCurrentServerRevision(SyncType.WORKBENCH_RECIPES),
|
||||
WorkbenchRecipeSyncHandler.getInstance().serializeAll()
|
||||
SyncController.getCurrentRevision(EnumSyncType.WORKBENCH_RECIPES),
|
||||
SyncController.workbenchNBT()
|
||||
), (EntityPlayerMP) player);
|
||||
}
|
||||
if (block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
SyncType.CARPENTRY_RECIPES,
|
||||
EnumSyncType.CARPENTRY_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
null,
|
||||
SyncController.getCurrentServerRevision(SyncType.CARPENTRY_RECIPES),
|
||||
CarpentryRecipeSyncHandler.getInstance().serializeAll()
|
||||
SyncController.getCurrentRevision(EnumSyncType.CARPENTRY_RECIPES),
|
||||
SyncController.carpentryNBT()
|
||||
), (EntityPlayerMP) player);
|
||||
}
|
||||
if ((block == CustomItems.banner || block == CustomItems.wallBanner || block == CustomItems.sign) && event.action == Action.RIGHT_CLICK_BLOCK) {
|
||||
|
||||
@@ -6,8 +6,6 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerEffectSyncHelper;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
@@ -47,12 +45,13 @@ public class ServerTickHandler {
|
||||
playerData.onLogin();
|
||||
}
|
||||
|
||||
ProfileController.Instance.login(player);
|
||||
SyncController.beginLogin(player);
|
||||
PlayerEffectSyncHelper.syncEffects(player);
|
||||
SyncController.syncEffects(player);
|
||||
ScriptController.Instance.syncClientScripts(player);
|
||||
|
||||
// Sync clean ability state to the new client (after beginLogin initializes sync state)
|
||||
PlayerAbilitySyncHelper.syncAbilities(player);
|
||||
SyncController.syncAbilities(player);
|
||||
|
||||
// Send auction notifications on login
|
||||
if (AuctionController.Instance != null) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.constants.EnumPotionType;
|
||||
import noppes.npcs.controllers.data.Line;
|
||||
import noppes.npcs.controllers.data.Lines;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -24,13 +23,6 @@ public class VersionCompatibility {
|
||||
boolean aimShot = compound.getBoolean("AimWhileShooting");
|
||||
compound.setInteger("AimType", !aimShot ? 0 : 1);
|
||||
}
|
||||
|
||||
// Restore burning on Fire projectiles saved before pBurnItem existed
|
||||
if (compound.hasKey("pEffect") && !compound.hasKey("pBurnItem")) {
|
||||
if (EnumPotionType.fromOrdinal(compound.getInteger("pEffect")) == EnumPotionType.Fire) {
|
||||
compound.setBoolean("pBurnItem", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (npc.npcVersion < 22) {
|
||||
if (compound.hasKey("CanLeap")) {
|
||||
|
||||
@@ -10,7 +10,7 @@ public class EntityAITransform extends EntityAIBase {
|
||||
|
||||
public EntityAITransform(EntityNPCInterface npc) {
|
||||
this.npc = npc;
|
||||
setMutexBits(0);
|
||||
setMutexBits(AiMutex.PASSIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,6 +67,10 @@ public class BlockBorder extends BlockContainer {
|
||||
}
|
||||
|
||||
tile.rotation = l;
|
||||
|
||||
if (par5EntityLivingBase instanceof EntityPlayer && par1World.isRemote) {
|
||||
CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.Border, (EntityPlayer) par5EntityLivingBase);
|
||||
}
|
||||
}
|
||||
|
||||
private TileBorder getTile(World world, int x, int y, int z) {
|
||||
|
||||
@@ -40,6 +40,7 @@ public class BlockCampfire extends BlockLightable {
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
if (item == null)
|
||||
return true;
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if ((item.getItem() == Items.flint || item.getItem() == Items.flint_and_steel) && unlitBlock() == this) {
|
||||
super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
|
||||
|
||||
@@ -49,6 +49,13 @@ public class BlockNpcRedstone extends BlockContainer {
|
||||
par1World.notifyBlocksOfNeighborChange(par2, par3, par4 + 1, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack item) {
|
||||
if (entityliving instanceof EntityPlayer && world.isRemote) {
|
||||
CustomNpcs.proxy.openGui(i, j, k, EnumGuiType.RedstoneBlock, (EntityPlayer) entityliving);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {
|
||||
onBlockAdded(par1World, par2, par3, par4);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package noppes.npcs.client;
|
||||
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.controllers.MusicController;
|
||||
@@ -18,8 +18,8 @@ import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
import noppes.npcs.util.CacheHashMap;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -32,14 +32,14 @@ public class ClientCacheHandler {
|
||||
|
||||
private static String activeServerKey = "";
|
||||
private static String lastServerKey = "";
|
||||
private static final Map<String, Map<SyncType, Integer>> clientRevisionCache = new HashMap<>();
|
||||
private static final Map<String, EnumMap<EnumSyncType, Integer>> clientRevisionCache = new HashMap<>();
|
||||
|
||||
public static Party party;
|
||||
|
||||
public static boolean allowProfiles = true;
|
||||
public static boolean allowParties = true;
|
||||
|
||||
public static void setActiveServer(String serverKey, Map<SyncType, Integer> serverRevisions) {
|
||||
public static void setActiveServer(String serverKey, EnumMap<EnumSyncType, Integer> serverRevisions) {
|
||||
String normalizedKey = serverKey == null ? "" : serverKey;
|
||||
String previousKey = activeServerKey == null ? "" : activeServerKey;
|
||||
lastServerKey = previousKey;
|
||||
@@ -54,9 +54,9 @@ public class ClientCacheHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<SyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
|
||||
EnumMap<EnumSyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
|
||||
activeServerKey,
|
||||
ignored -> new LinkedHashMap<>()
|
||||
ignored -> new EnumMap<>(EnumSyncType.class)
|
||||
);
|
||||
if (serverRevisions != null && !serverRevisions.isEmpty()) {
|
||||
cached.keySet().retainAll(serverRevisions.keySet());
|
||||
@@ -67,19 +67,19 @@ public class ClientCacheHandler {
|
||||
return lastServerKey == null ? "" : lastServerKey;
|
||||
}
|
||||
|
||||
public static Map<SyncType, Integer> getCachedRevisionsForServer(String serverKey) {
|
||||
public static EnumMap<EnumSyncType, Integer> getCachedRevisionsForServer(String serverKey) {
|
||||
String key = serverKey == null ? "" : serverKey;
|
||||
if (key.isEmpty()) {
|
||||
return new LinkedHashMap<>();
|
||||
return new EnumMap<>(EnumSyncType.class);
|
||||
}
|
||||
Map<SyncType, Integer> revisions = clientRevisionCache.get(key);
|
||||
EnumMap<EnumSyncType, Integer> revisions = clientRevisionCache.get(key);
|
||||
if (revisions == null) {
|
||||
return new LinkedHashMap<>();
|
||||
return new EnumMap<>(EnumSyncType.class);
|
||||
}
|
||||
return new LinkedHashMap<>(revisions);
|
||||
return new EnumMap<>(revisions);
|
||||
}
|
||||
|
||||
public static void updateClientRevision(SyncType type, int revision) {
|
||||
public static void updateClientRevision(EnumSyncType type, int revision) {
|
||||
if (revision < 0) {
|
||||
return;
|
||||
}
|
||||
@@ -87,9 +87,9 @@ public class ClientCacheHandler {
|
||||
if (key.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<SyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
|
||||
EnumMap<EnumSyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
|
||||
key,
|
||||
ignored -> new LinkedHashMap<>()
|
||||
ignored -> new EnumMap<>(EnumSyncType.class)
|
||||
);
|
||||
revisions.put(type, revision);
|
||||
}
|
||||
@@ -126,11 +126,14 @@ public class ClientCacheHandler {
|
||||
ClientCacheHandler.playerAnimations.clear();
|
||||
ProfileClientConfig.reset();
|
||||
|
||||
// Clear Texture Caches
|
||||
GuiSoundSelection.cachedDomains.clear();
|
||||
GuiTextureSelection.cachedTextures.clear();
|
||||
|
||||
// Clear music/bard sounds
|
||||
MusicController.Instance.stopAllSounds();
|
||||
|
||||
// Clear Quest Tracker
|
||||
HudComponent component = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker);
|
||||
if (component != null) {
|
||||
component.loadData(new NBTTagCompound());
|
||||
@@ -143,6 +146,7 @@ public class ClientCacheHandler {
|
||||
ClientCacheHandler.customOverlays.clear();
|
||||
ClientCacheHandler.skinOverlays.clear();
|
||||
|
||||
// Clear Texture Caches
|
||||
GuiSoundSelection.cachedDomains.clear();
|
||||
GuiTextureSelection.cachedTextures.clear();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import noppes.npcs.client.gui.hud.QuestTrackingComponent;
|
||||
import noppes.npcs.client.gui.hud.ability.AbilityHotbarComponent;
|
||||
import noppes.npcs.client.gui.player.AuctionTooltipHandler;
|
||||
import noppes.npcs.client.KeyPressHandler;
|
||||
import noppes.npcs.client.model.PlayerModelAnimation;
|
||||
import noppes.npcs.client.renderer.MarkRenderer;
|
||||
import noppes.npcs.client.renderer.RenderCNPCPlayer;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
@@ -47,7 +46,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ClientEventHandler {
|
||||
private static boolean loggedPlayerRenderer;
|
||||
public static final RenderCNPCPlayer renderCNPCSelf = new RenderCNPCPlayer();
|
||||
public static final RenderCNPCPlayer renderCNPCPlayer = new RenderCNPCPlayer();
|
||||
public static HashMap<Integer, Long> disabledButtonTimes = new HashMap<>();
|
||||
@@ -64,7 +62,6 @@ public class ClientEventHandler {
|
||||
public static boolean renderingEntityInGUI;
|
||||
public static EntityNPCInterface renderingNpc;
|
||||
public static EntityPlayer renderingPlayer;
|
||||
public static boolean renderingPlayerAnimation;
|
||||
public static HashMap<EnumAnimationPart, String[]> partNames = new HashMap<>();
|
||||
public static HashMap<Class<?>, Field[]> declaredFieldCache = new HashMap<>();
|
||||
|
||||
@@ -73,7 +70,6 @@ public class ClientEventHandler {
|
||||
public static ModelBase playerModel;
|
||||
|
||||
private Class<?> renderPlayerJBRA;
|
||||
private PlayerModelAnimation.Pose equippedItemPose;
|
||||
|
||||
public ClientEventHandler() {
|
||||
try {
|
||||
@@ -165,7 +161,6 @@ public class ClientEventHandler {
|
||||
public void onRenderEntity(RenderLivingEvent.Pre event) {
|
||||
if (event.entity instanceof EntityNPCInterface) {
|
||||
ClientEventHandler.renderingPlayer = null;
|
||||
ClientEventHandler.renderingPlayerAnimation = false;
|
||||
ClientEventHandler.renderingNpc = (EntityNPCInterface) event.entity;
|
||||
}
|
||||
ClientEventHandler.renderer = event.renderer;
|
||||
@@ -232,17 +227,6 @@ public class ClientEventHandler {
|
||||
public void onRenderPlayer(RenderPlayerEvent.Pre event) {
|
||||
ClientEventHandler.renderingNpc = null;
|
||||
ClientEventHandler.renderingPlayer = event.entityPlayer;
|
||||
ClientEventHandler.renderingPlayerAnimation = PlayerModelAnimation.shouldApply(event.entityPlayer);
|
||||
if (!loggedPlayerRenderer) {
|
||||
loggedPlayerRenderer = true;
|
||||
String model = event.renderer.mainModel == null ? "null"
|
||||
: event.renderer.mainModel.getClass().getName();
|
||||
String arm = event.renderer.modelBipedMain == null
|
||||
|| event.renderer.modelBipedMain.bipedRightArm == null ? "null"
|
||||
: event.renderer.modelBipedMain.bipedRightArm.getClass().getName();
|
||||
System.out.println("[CustomNPC+] Active player renderer="
|
||||
+ event.renderer.getClass().getName() + "; model=" + model + "; arm=" + arm);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
@@ -253,10 +237,8 @@ public class ClientEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderPlayer(RenderPlayerEvent.Post event) {
|
||||
restoreEquippedItemPose();
|
||||
EntityPlayer player = event.entityPlayer;
|
||||
ClientEventHandler.renderingPlayer = null;
|
||||
ClientEventHandler.renderingPlayerAnimation = false;
|
||||
|
||||
if (hasOverlays(player)) {
|
||||
if (renderPlayerJBRA != null && renderPlayerJBRA.isInstance(event.renderer))
|
||||
@@ -284,35 +266,6 @@ public class ClientEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void applyEquippedItemPose(RenderPlayerEvent.Specials.Pre event) {
|
||||
restoreEquippedItemPose();
|
||||
if (!ClientEventHandler.renderingPlayerAnimation) {
|
||||
return;
|
||||
}
|
||||
|
||||
ModelBiped model = event.renderer.modelBipedMain;
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
equippedItemPose = PlayerModelAnimation.capture(model);
|
||||
PlayerModelAnimation.apply(model);
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
|
||||
public void restoreEquippedItemPose(RenderPlayerEvent.Specials.Post event) {
|
||||
restoreEquippedItemPose();
|
||||
}
|
||||
|
||||
private void restoreEquippedItemPose() {
|
||||
if (equippedItemPose == null) {
|
||||
return;
|
||||
}
|
||||
equippedItemPose.restore();
|
||||
equippedItemPose = null;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void cancelSpecials(RenderPlayerEvent.Specials.Pre event) {
|
||||
if (event.renderer instanceof RenderCNPCPlayer) {
|
||||
|
||||
@@ -7,31 +7,11 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.client.command.CommandCNPCDebugger;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyBeam;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyDisc;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyLaser;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyOrb;
|
||||
import kamkeel.npcs.client.renderer.RenderSweeper;
|
||||
import kamkeel.npcs.client.renderer.RenderZone;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyDome;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyPanel;
|
||||
import kamkeel.npcs.client.renderer.EnergyChargePreviewRenderer;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyExplosion;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergySlicer;
|
||||
import kamkeel.npcs.client.renderer.TelegraphRenderer;
|
||||
import kamkeel.npcs.client.renderer.*;
|
||||
import kamkeel.npcs.client.renderer.lightning.LightningHandler;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityEnergySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergyExplosion;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import kamkeel.npcs.entity.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
@@ -294,6 +274,7 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyPanel.class, new RenderEnergyPanel());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergySlicer.class, new RenderEnergySlicer());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyExplosion.class, new RenderEnergyExplosion());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityPillar.class, new RenderEnergyPillar());
|
||||
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityCustomNpc.class, new RenderCustomNpc());
|
||||
|
||||
@@ -344,6 +325,7 @@ public class ClientProxy extends CommonProxy {
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.shortLamp), new ItemShortLampRenderer());
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.tallLamp), new ItemTallLampRenderer());
|
||||
}
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
NPCButton = new KeyBinding("NPC Inventory", Keyboard.KEY_N, "key.categories.customnpc");
|
||||
SpecialKey = new KeyBinding("key.customnpcs.special", Keyboard.KEY_GRAVE, "key.categories.customnpc");
|
||||
@@ -383,6 +365,14 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
// Lightning effect rendering system
|
||||
MinecraftForge.EVENT_BUS.register(new LightningHandler());
|
||||
|
||||
if (ConfigClient.InventoryGuiEnabled) {
|
||||
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
||||
if (TabRegistry.getTabList().isEmpty()) {
|
||||
TabRegistry.registerTab(new InventoryTabVanilla());
|
||||
}
|
||||
TabRegistry.registerTab(new InventoryTabCustomNpc());
|
||||
}
|
||||
}
|
||||
|
||||
public FakePlayer getCommandPlayer(IWorld world) {
|
||||
@@ -711,7 +701,9 @@ public class ClientProxy extends CommonProxy {
|
||||
if (!player.worldObj.isRemote || !(guiscreen instanceof GuiScreen))
|
||||
return;
|
||||
|
||||
minecraft.displayGuiScreen((GuiScreen) guiscreen);
|
||||
if (guiscreen != null) {
|
||||
minecraft.displayGuiScreen((GuiScreen) guiscreen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -806,7 +798,8 @@ public class ClientProxy extends CommonProxy {
|
||||
if (location == null)
|
||||
return;
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
texturemanager.bindTexture((ResourceLocation) location);
|
||||
if (location != null)
|
||||
texturemanager.bindTexture((ResourceLocation) location);
|
||||
} catch (NullPointerException ex) {
|
||||
|
||||
} catch (ReportedException ex) {
|
||||
@@ -850,18 +843,6 @@ public class ClientProxy extends CommonProxy {
|
||||
return Minecraft.getMinecraft().currentScreen != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadComplete() {
|
||||
// Deferred from load() so TConstruct registers its tabs first
|
||||
if (ConfigClient.InventoryGuiEnabled) {
|
||||
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
||||
if (TabRegistry.getTabList().isEmpty()) {
|
||||
TabRegistry.registerTab(new InventoryTabVanilla());
|
||||
}
|
||||
TabRegistry.registerTab(new InventoryTabCustomNpc());
|
||||
}
|
||||
}
|
||||
|
||||
public void buildPackageIndex() {
|
||||
try {
|
||||
PackageFinder.init(Thread.currentThread().getContextClassLoader());
|
||||
|
||||
@@ -38,7 +38,6 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
public class NoppesUtil {
|
||||
@@ -52,15 +51,11 @@ public class NoppesUtil {
|
||||
}
|
||||
|
||||
public static void updateSkinOverlayData(EntityPlayer player, NBTTagCompound compound) {
|
||||
updateSkinOverlayData(player.getUniqueID(), compound);
|
||||
}
|
||||
|
||||
public static void updateSkinOverlayData(UUID playerUUID, NBTTagCompound compound) {
|
||||
HashMap<Integer, SkinOverlay> skinOverlays = new HashMap<>();
|
||||
HashMap<Integer, SkinOverlay> oldOverlays = new HashMap<>();
|
||||
NBTTagList skinOverlayList = compound.getTagList("SkinOverlayData", 10);
|
||||
if (ClientCacheHandler.skinOverlays.containsKey(playerUUID)) {
|
||||
oldOverlays = ClientCacheHandler.skinOverlays.get(playerUUID);
|
||||
if (ClientCacheHandler.skinOverlays.containsKey(player.getUniqueID())) {
|
||||
oldOverlays = ClientCacheHandler.skinOverlays.get(player.getUniqueID());
|
||||
}
|
||||
|
||||
for (int i = 0; i < skinOverlayList.tagCount(); i++) {
|
||||
@@ -71,7 +66,7 @@ public class NoppesUtil {
|
||||
}
|
||||
skinOverlays.put(tagID, overlay);
|
||||
}
|
||||
ClientCacheHandler.skinOverlays.put(playerUUID, skinOverlays);
|
||||
ClientCacheHandler.skinOverlays.put(player.getUniqueID(), skinOverlays);
|
||||
}
|
||||
|
||||
public static void clickSound() {
|
||||
|
||||
@@ -127,6 +127,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
this.list = ClientCloneController.Instance.getClones(activeTab);
|
||||
scroll.setList(getSearchList());
|
||||
}
|
||||
|
||||
@@ -112,19 +112,19 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS
|
||||
}
|
||||
if (button.id == 10) {
|
||||
slot = 1;
|
||||
setSubGui(new GuiDialogSelection(availabitily.dialogId));
|
||||
setSubGui(new GuiDialogSelection(availabitily.questId));
|
||||
}
|
||||
if (button.id == 11) {
|
||||
slot = 2;
|
||||
setSubGui(new GuiDialogSelection(availabitily.dialog2Id));
|
||||
setSubGui(new GuiDialogSelection(availabitily.quest2Id));
|
||||
}
|
||||
if (button.id == 12) {
|
||||
slot = 3;
|
||||
setSubGui(new GuiDialogSelection(availabitily.dialog3Id));
|
||||
setSubGui(new GuiDialogSelection(availabitily.quest3Id));
|
||||
}
|
||||
if (button.id == 13) {
|
||||
slot = 4;
|
||||
setSubGui(new GuiDialogSelection(availabitily.dialog4Id));
|
||||
setSubGui(new GuiDialogSelection(availabitily.quest4Id));
|
||||
}
|
||||
if (button.id == 20) {
|
||||
availabitily.dialogId = -1;
|
||||
|
||||
@@ -81,6 +81,7 @@ public class SubGuiNpcBiomes extends SubGuiInterface {
|
||||
if (scroll1.hasSelected()) {
|
||||
data.biomes.add(scroll1.getSelected());
|
||||
scroll1.selected = -1;
|
||||
scroll1.selected = -1;
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
@@ -13,17 +12,6 @@ public class SubGuiTrapPresetSelector extends SubGuiInterface {
|
||||
|
||||
public String selectedPreset = null;
|
||||
|
||||
public static FieldDef createPresetField(java.util.function.Consumer<String> applyPreset) {
|
||||
return FieldDef.subGuiField("gui.applyPreset",
|
||||
SubGuiTrapPresetSelector::new,
|
||||
gui -> {
|
||||
SubGuiTrapPresetSelector selector = (SubGuiTrapPresetSelector) gui;
|
||||
if (selector.selectedPreset != null) {
|
||||
applyPreset.accept(selector.selectedPreset);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final String[] PRESET_NAMES = {"HIDDEN", "VENOM", "EXPLOSIVE", "CURSED", "SHOCK", "SNARE"};
|
||||
private static final String[] PRESET_LABELS = {
|
||||
"ability.preset.hidden", "ability.preset.venom", "ability.preset.explosive",
|
||||
|
||||
@@ -4,7 +4,6 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
@@ -13,17 +12,6 @@ public class SubGuiZonePresetSelector extends SubGuiInterface {
|
||||
|
||||
public String selectedPreset = null;
|
||||
|
||||
public static FieldDef createPresetField(java.util.function.Consumer<String> applyPreset) {
|
||||
return FieldDef.subGuiField("gui.applyPreset",
|
||||
SubGuiZonePresetSelector::new,
|
||||
gui -> {
|
||||
SubGuiZonePresetSelector selector = (SubGuiZonePresetSelector) gui;
|
||||
if (selector.selectedPreset != null) {
|
||||
applyPreset.accept(selector.selectedPreset);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final String[] PRESET_NAMES = {"DEFAULT", "TOXIC", "INFERNO", "ARCANE", "ELECTRIC", "FROST"};
|
||||
private static final String[] PRESET_LABELS = {
|
||||
"ability.preset.default", "ability.preset.toxic", "ability.preset.inferno",
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -13,7 +11,6 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicData;
|
||||
import noppes.npcs.controllers.data.MagicEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -39,22 +36,6 @@ public class SubGuiAbilityMagic extends SubGuiInterface implements ICustomScroll
|
||||
|
||||
private GuiNpcTextField splitField;
|
||||
|
||||
public static FieldDef createMagicField(MagicData magicData) {
|
||||
return FieldDef.subGuiField("ability.magic.editor",
|
||||
() -> new SubGuiAbilityMagic(magicData.copy()),
|
||||
gui -> {
|
||||
MagicData result = ((SubGuiAbilityMagic) gui).magicData;
|
||||
magicData.getMagics().clear();
|
||||
for (Map.Entry<Integer, MagicEntry> e : result.getMagics().entrySet()) {
|
||||
magicData.getMagics().put(e.getKey(), e.getValue());
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> magicData.isEmpty()
|
||||
? StatCollector.translateToLocal("ability.magic.usesCaster")
|
||||
: magicData.getMagics().size() + " Magic(s)")
|
||||
.tab("General");
|
||||
}
|
||||
|
||||
public SubGuiAbilityMagic(MagicData data) {
|
||||
this.magicData = data;
|
||||
setBackground("menubg.png");
|
||||
|
||||
@@ -3,8 +3,6 @@ package noppes.npcs.client.gui.advanced;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.ConditionHasEffect;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
@@ -27,23 +25,6 @@ import java.util.Map;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SubGuiCustomEffectSelect extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
|
||||
|
||||
public static FieldDef createSelectField(ConditionHasEffect condition) {
|
||||
return FieldDef.subGuiField("condition.select_effect",
|
||||
() -> new SubGuiCustomEffectSelect(condition.getEffectId(), condition.getEffectIndex()),
|
||||
gui -> {
|
||||
SubGuiCustomEffectSelect sel = (SubGuiCustomEffectSelect) gui;
|
||||
if (sel.getSelectedEffectId() >= 0) {
|
||||
condition.setEffect(sel.getSelectedEffectId(), sel.getSelectedIndex());
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> {
|
||||
if (condition.getEffectId() < 0) return "None";
|
||||
CustomEffect effect = condition.getEffect();
|
||||
return effect != null ? effect.getName() : "ID:" + condition.getEffectId();
|
||||
})
|
||||
.clearable(() -> condition.setEffect(-1, 0));
|
||||
}
|
||||
|
||||
private GuiCustomScroll scroll;
|
||||
private final HashMap<String, Integer> displayNameToId = new HashMap<>();
|
||||
private final HashMap<String, Integer> allDisplayNameToId = new HashMap<>();
|
||||
|
||||
@@ -39,7 +39,6 @@ public class QuestTrackingComponent extends HudComponent {
|
||||
if (turnIn != null && !turnIn.isEmpty()) {
|
||||
turnInLines.add(convertColorCodes(turnIn));
|
||||
}
|
||||
updateOverlayHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,19 +239,6 @@ public class QuestTrackingComponent extends HudComponent {
|
||||
}
|
||||
|
||||
// ---------- Helper rendering methods ----------- (methods unchanged) ...
|
||||
private void updateOverlayHeight() {
|
||||
int lineHeight = mc.fontRenderer.FONT_HEIGHT + 4;
|
||||
int contentHeight = 5;
|
||||
contentHeight += questTitleLines.size() * lineHeight + 8;
|
||||
contentHeight += questCategoryLines.size() * lineHeight + 8;
|
||||
contentHeight += objectiveLines.size() * lineHeight;
|
||||
if (!turnInLines.isEmpty()) {
|
||||
contentHeight += 8;
|
||||
}
|
||||
contentHeight += turnInLines.size() * lineHeight;
|
||||
overlayHeight = contentHeight;
|
||||
}
|
||||
|
||||
private int renderTextBlock(List<String> lines, int startY, int align, int color) {
|
||||
int y = startY;
|
||||
FontRenderer font = mc.fontRenderer;
|
||||
|
||||
@@ -58,12 +58,9 @@ public class GuiNpcAnvil extends GuiContainerNPCInterface {
|
||||
|
||||
// Compute the repair status message based on container.repairCost and player's XP.
|
||||
String status = "";
|
||||
int textColor = CustomNpcResourceListener.DefaultTextColor;
|
||||
|
||||
if (container.repairCost > 0) {
|
||||
if (container.repairCost > mc.thePlayer.experienceTotal) {
|
||||
status = "Repair cost: " + container.repairCost + " XP";
|
||||
textColor = 0xFF0000; // red when not enough XP
|
||||
} else {
|
||||
status = "Repair cost: " + container.repairCost + " XP";
|
||||
}
|
||||
@@ -75,6 +72,10 @@ public class GuiNpcAnvil extends GuiContainerNPCInterface {
|
||||
status = "Item is already fully repaired";
|
||||
}
|
||||
}
|
||||
int textColor = CustomNpcResourceListener.DefaultTextColor;
|
||||
if (container.repairCost > mc.thePlayer.experienceTotal) {
|
||||
textColor = 0xFF0000; // red when not enough XP
|
||||
}
|
||||
fontRendererObj.drawString(status, guiLeft + 5, guiTop + 75, textColor);
|
||||
}
|
||||
|
||||
|
||||
@@ -429,9 +429,6 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC
|
||||
}
|
||||
|
||||
private boolean isMouseOverScrollbar(int mouseX, int mouseY) {
|
||||
if (maxScrollY <= 0)
|
||||
return false;
|
||||
|
||||
int scrollbarX = guiLeft + xSize + 30;
|
||||
int scrollbarY = guiTop + 27;
|
||||
int scrollbarHeight = ySize - 35;
|
||||
|
||||
@@ -21,7 +21,6 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
|
||||
private final ResourceLocation slot = new ResourceLocation("customnpcs", "textures/gui/slot.png");
|
||||
private RoleTrader role;
|
||||
private boolean marketRelinked = false;
|
||||
|
||||
// Currency cost textfield IDs start at 100 (100-117 for slots 0-17)
|
||||
private static final int CURRENCY_FIELD_ID_START = 100;
|
||||
@@ -117,13 +116,8 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Relinking already loaded the target market server-side
|
||||
if (marketRelinked)
|
||||
return;
|
||||
|
||||
// Role first, so the market is written from the edited data
|
||||
PacketClient.sendClient(new RoleSavePacket(role.writeToNBT(new NBTTagCompound())));
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, false));
|
||||
PacketClient.sendClient(new RoleSavePacket(role.writeToNBT(new NBTTagCompound())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,7 +129,6 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
String name = guiNpcTextField.getText();
|
||||
if (!name.equalsIgnoreCase(role.marketName)) {
|
||||
role.marketName = name;
|
||||
marketRelinked = true;
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, true));
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -288,9 +288,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
|
||||
// Set the script context for context-aware hook autocomplete
|
||||
activeArea.setScriptContext(getScriptContext());
|
||||
activeArea.enableCodeHighlighting();
|
||||
|
||||
updateScriptDocumentImports(activeArea, container);
|
||||
|
||||
activeArea.enableCodeHighlighting();
|
||||
|
||||
// Setup fullscreen key binding
|
||||
GuiScriptTextArea.KEYS.FULLSCREEN.setTask(e -> {
|
||||
@@ -299,7 +299,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
});
|
||||
|
||||
activeArea.enableCodeHighlighting();
|
||||
this.addTextField(activeArea);
|
||||
|
||||
// ==================== FULLSCREEN BUTTON ====================
|
||||
@@ -458,7 +457,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
this.getTextField(2).setText(this.getTextField(2).getText() + addString);
|
||||
previousHookClicked = "";
|
||||
|
||||
updateScriptDocumentImports(getActiveScriptArea(), container);
|
||||
GuiScriptTextArea activeArea = getActiveScriptArea();
|
||||
updateScriptDocumentImports(activeArea, container);
|
||||
activeArea.enableCodeHighlighting();
|
||||
|
||||
} else {
|
||||
previousHookClicked = hook;
|
||||
}
|
||||
@@ -484,10 +486,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
for (String fqn : ctx.getNamespaceFQNs())
|
||||
wildcardImports.add(fqn + ".*");
|
||||
activeArea.addImplicitImports(wildcardImports.toArray(new String[0]));
|
||||
|
||||
|
||||
// Format to update which implicit imports are actually used
|
||||
activeArea.formatCodeText();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loaded 100 of 154 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user