mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 19:54:26 +00:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ab1dd1e16 | ||
|
|
7c4159dcd2 | ||
|
|
c2c6079b43 | ||
|
|
fb3a392f2e | ||
|
|
956d2e27be | ||
|
|
9546500b4b | ||
|
|
a2beef0549 | ||
|
|
0222a4984e | ||
|
|
d4a89dad1d | ||
|
|
ca7f3f937b | ||
|
|
a59d2d0088 | ||
|
|
9c82fabf1b |
No files matched your search
+1
-38
@@ -6,7 +6,7 @@ plugins {
|
|||||||
id "dts.typescript-generator"
|
id "dts.typescript-generator"
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "1.11.2"
|
version = "1.11.1"
|
||||||
group= "kamkeel.customnpc-plus"
|
group= "kamkeel.customnpc-plus"
|
||||||
archivesBaseName = "CustomNPC-Plus"
|
archivesBaseName = "CustomNPC-Plus"
|
||||||
|
|
||||||
@@ -57,43 +57,6 @@ sourceSets.main.java {
|
|||||||
srcDirs += apiDir
|
srcDirs += apiDir
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Scribe fixtures -- an offline generator for CustomNPC+ save data.
|
|
||||||
//
|
|
||||||
// Its own source set, so nothing here reaches the mod jar. It runs CustomNPC+'s
|
|
||||||
// own writeToNBT/writeNBT methods against a bootstrapped-but-unlaunched
|
|
||||||
// Minecraft, and writes the results into a world layout copied from each
|
|
||||||
// controller. See src/fixtures/README.md.
|
|
||||||
// ============================================================================
|
|
||||||
sourceSets {
|
|
||||||
fixtures {
|
|
||||||
java.srcDirs = ['src/fixtures/java']
|
|
||||||
compileClasspath += sourceSets.main.output + sourceSets.main.compileClasspath
|
|
||||||
runtimeClasspath += sourceSets.main.output + sourceSets.main.runtimeClasspath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register('scribeFixtures', JavaExec) {
|
|
||||||
group 'CustomNPC+'
|
|
||||||
description 'Generates CustomNPC+ save fixtures for Scribe. -Pout=<dir>, -Pworlds=<a,b>'
|
|
||||||
dependsOn 'fixturesClasses'
|
|
||||||
classpath = sourceSets.fixtures.runtimeClasspath
|
|
||||||
mainClass = 'kamkeel.npcs.fixtures.FixtureGenerator'
|
|
||||||
// Off the project dir, because CustomNpcs.getWorldSaveDirectory() resolves "." and
|
|
||||||
// a stray relative write would land in the repo root.
|
|
||||||
workingDir = project.buildDir
|
|
||||||
doFirst {
|
|
||||||
// Resolved against the project directory, not workingDir, so -Pout=build/x means what it
|
|
||||||
// looks like rather than build/build/x.
|
|
||||||
def out = project.hasProperty('out') ? project.file(project.property('out'))
|
|
||||||
: new File(project.buildDir, 'scribe-fixtures')
|
|
||||||
args = [out.absolutePath]
|
|
||||||
if (project.hasProperty('worlds')) {
|
|
||||||
args += ['--worlds', project.property('worlds')]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// TypeScript Definition Generation Task
|
// TypeScript Definition Generation Task
|
||||||
// Generates .d.ts files from Java API sources for scripting IDE support
|
// Generates .d.ts files from Java API sources for scripting IDE support
|
||||||
|
|||||||
+1
-1
@@ -199,7 +199,7 @@ disableCheckstyle = true
|
|||||||
# ideaCheckSpotlessOnBuild = true
|
# ideaCheckSpotlessOnBuild = true
|
||||||
|
|
||||||
# Non-GTNH properties
|
# Non-GTNH properties
|
||||||
modVersion = 1.11.2
|
modVersion = 1.11.0
|
||||||
|
|
||||||
# Increase Gradle's JVM memory usage to avoid daemon expiration due to
|
# Increase Gradle's JVM memory usage to avoid daemon expiration due to
|
||||||
# insufficient heap space on CI builds.
|
# insufficient heap space on CI builds.
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* One piece of content, the category it belongs in, and why it exists.
|
|
||||||
*
|
|
||||||
* <p>The note is the part that does not survive serialization. A directory of numbered files says
|
|
||||||
* nothing about which one is the dialog whose availability is gated four ways, and the next person
|
|
||||||
* to need that case will otherwise author a second one.
|
|
||||||
*/
|
|
||||||
public final class Case<T> {
|
|
||||||
|
|
||||||
public final String category;
|
|
||||||
public final T value;
|
|
||||||
public final String note;
|
|
||||||
|
|
||||||
public Case(String category, T value, String note) {
|
|
||||||
this.category = category;
|
|
||||||
this.value = value;
|
|
||||||
this.note = note;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.worlds.DefaultsWorld;
|
|
||||||
import kamkeel.npcs.fixtures.worlds.EdgeWorld;
|
|
||||||
import kamkeel.npcs.fixtures.worlds.LegacyWorld;
|
|
||||||
import kamkeel.npcs.fixtures.worlds.MaximalWorld;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates CustomNPC+ save data offline, for use as test fixtures.
|
|
||||||
*
|
|
||||||
* <p>The point is that the bytes are written by CustomNPC+ itself. Hand-authoring a
|
|
||||||
* {@code factions.dat} that looks right is easy and proves nothing: it asserts what its author
|
|
||||||
* believed the format to be. Everything here goes through the shipping data classes' own
|
|
||||||
* serialization, so a fixture is evidence about the format rather than about the author.
|
|
||||||
*
|
|
||||||
* <p>Usage: {@code gradlew scribeFixtures -Pout=<dir> [-Pworlds=maximal,edge]}
|
|
||||||
*/
|
|
||||||
public final class FixtureGenerator {
|
|
||||||
|
|
||||||
private static final List<FixtureWorld> ALL = Arrays.<FixtureWorld>asList(
|
|
||||||
new MaximalWorld(),
|
|
||||||
new DefaultsWorld(),
|
|
||||||
new EdgeWorld(),
|
|
||||||
new LegacyWorld());
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
if (args.length < 1) {
|
|
||||||
System.err.println("usage: FixtureGenerator <output-dir> [--worlds a,b,c]");
|
|
||||||
System.exit(2);
|
|
||||||
}
|
|
||||||
File out = new File(args[0]).getAbsoluteFile();
|
|
||||||
|
|
||||||
List<FixtureWorld> selected = new ArrayList<FixtureWorld>(ALL);
|
|
||||||
for (int i = 1; i < args.length - 1; i++) {
|
|
||||||
if ("--worlds".equals(args[i])) {
|
|
||||||
selected = select(args[i + 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("[fixtures] bootstrapping Minecraft");
|
|
||||||
Fixtures.bootMinecraft();
|
|
||||||
|
|
||||||
Manifest manifest = new Manifest();
|
|
||||||
recordKnownWarnings(manifest);
|
|
||||||
|
|
||||||
int normalized = 0;
|
|
||||||
for (FixtureWorld world : selected) {
|
|
||||||
WorldWriter writer = new WorldWriter(out, world.name(), manifest);
|
|
||||||
manifest.world(world.name(), world.purpose());
|
|
||||||
int before = manifest.count();
|
|
||||||
world.build(writer);
|
|
||||||
normalized += writer.normalizedCount();
|
|
||||||
System.out.println("[fixtures] " + pad(world.name())
|
|
||||||
+ (manifest.count() - before) + " files");
|
|
||||||
}
|
|
||||||
|
|
||||||
manifest.write(new File(out, "manifest.json"));
|
|
||||||
Readme.write(new File(out, "README.md"), selected, manifest);
|
|
||||||
|
|
||||||
System.out.println("[fixtures] " + manifest.count() + " files total -> " + out);
|
|
||||||
System.out.println("[fixtures] dialogs " + manifest.countOf("dialog")
|
|
||||||
+ ", quests " + manifest.countOf("quest"));
|
|
||||||
// Reported every run so the one normalization cannot quietly spread to other keys.
|
|
||||||
System.out.println("[fixtures] " + normalized + " wall-clock values pinned (TimePast)");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Facts a consumer cannot get from the bytes, and would otherwise learn from a flaky test.
|
|
||||||
*
|
|
||||||
* <p>Each was found by reading the writer, not by guessing.
|
|
||||||
*/
|
|
||||||
private static void recordKnownWarnings(Manifest manifest) {
|
|
||||||
manifest.warn("NORMALIZED: TimePast is pinned to 0 in every document. PlayerMail.writeNBT "
|
|
||||||
+ "stamps it with System.currentTimeMillis() - time, and a PlayerMail hangs off every "
|
|
||||||
+ "dialog and every quest whether or not mail was configured -- so left alone, every "
|
|
||||||
+ "file here would differ between two runs and a version-controlled corpus would churn "
|
|
||||||
+ "completely on each regeneration. This is the ONLY key these fixtures rewrite after "
|
|
||||||
+ "CustomNPC+ produced it. Nothing reads the value back except a live-clock display.");
|
|
||||||
manifest.warn("Quest.writeToNBTPartial writes NextQuestTitle from the live QuestController, "
|
|
||||||
+ "which is empty offline, so NextQuestTitle is written as the value set on the object "
|
|
||||||
+ "rather than resolved from the target quest. NextQuestId is the real link.");
|
|
||||||
manifest.warn("PlayerMail.writeNBT writes MailQuestTitle only when the quest resolves in the "
|
|
||||||
+ "live QuestController. Offline it never resolves, so the key is absent.");
|
|
||||||
manifest.warn("These worlds hold no level.dat and no region files. They are the customnpcs/ "
|
|
||||||
+ "directory of a world, which is the part CustomNPC+ owns.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<FixtureWorld> select(String csv) {
|
|
||||||
Map<String, FixtureWorld> byName = new LinkedHashMap<String, FixtureWorld>();
|
|
||||||
for (FixtureWorld w : ALL) {
|
|
||||||
byName.put(w.name(), w);
|
|
||||||
}
|
|
||||||
List<FixtureWorld> selected = new ArrayList<FixtureWorld>();
|
|
||||||
for (String name : csv.split(",")) {
|
|
||||||
FixtureWorld w = byName.get(name.trim());
|
|
||||||
if (w == null) {
|
|
||||||
throw new IllegalArgumentException("No such world: " + name + " (have " + byName.keySet() + ")");
|
|
||||||
}
|
|
||||||
selected.add(w);
|
|
||||||
}
|
|
||||||
return selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String pad(String name) {
|
|
||||||
StringBuilder sb = new StringBuilder(name);
|
|
||||||
while (sb.length() < 12) {
|
|
||||||
sb.append(' ');
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures;
|
|
||||||
|
|
||||||
/** One generated world. Each answers a different question, so tests can load only what they need. */
|
|
||||||
public interface FixtureWorld {
|
|
||||||
|
|
||||||
/** Directory name, and the name a test refers to. */
|
|
||||||
String name();
|
|
||||||
|
|
||||||
/** What this world is for. Goes into the manifest, because a folder of ids explains nothing. */
|
|
||||||
String purpose();
|
|
||||||
|
|
||||||
void build(WorldWriter out);
|
|
||||||
}
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.Loader;
|
|
||||||
import kamkeel.npcs.addon.DBCAddon;
|
|
||||||
import net.minecraft.init.Bootstrap;
|
|
||||||
import net.minecraft.init.Items;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.nbt.NBTTagString;
|
|
||||||
import noppes.npcs.NoppesUtilServer;
|
|
||||||
import sun.misc.Unsafe;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared machinery for the fixture generator: bringing Minecraft far enough up to serialize, and
|
|
||||||
* building the item stacks the content refers to.
|
|
||||||
*
|
|
||||||
* <p>Nothing here decides what a fixture contains. That lives in the world builders.
|
|
||||||
*/
|
|
||||||
public final class Fixtures {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A fixed instant, used everywhere a fixture wants a timestamp.
|
|
||||||
*
|
|
||||||
* <p>2021-03-14T01:59:26Z. Any constant would do; what matters is that it is a constant, so
|
|
||||||
* two runs of the generator produce the same bytes and a diff means something changed.
|
|
||||||
*/
|
|
||||||
public static final long EPOCH = 1615687166000L;
|
|
||||||
|
|
||||||
private static boolean booted;
|
|
||||||
|
|
||||||
private Fixtures() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers vanilla blocks and items so item stacks can be serialized.
|
|
||||||
*
|
|
||||||
* <p>{@link Item#itemRegistry} is Forge's {@code FMLControlledNamespacedRegistry}, and
|
|
||||||
* {@link noppes.npcs.NoppesUtilServer#writeItem} asks it for a registry name -- so a stack
|
|
||||||
* written before this call would be saved as {@code minecraft:air} rather than failing, which
|
|
||||||
* is the quiet kind of wrong.
|
|
||||||
*/
|
|
||||||
public static void bootMinecraft() {
|
|
||||||
if (booted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
installBareLoader();
|
|
||||||
Bootstrap.func_151354_b();
|
|
||||||
// PlayerData.getNBT ends with DBCAddon.instance.writeToNBT(...), and the field is only set
|
|
||||||
// by the constructor. DBCAddon is a shell whose methods a companion mod replaces by mixin,
|
|
||||||
// so every method here is a no-op -- constructing one costs nothing and is what stops a
|
|
||||||
// player record from throwing on its last line. Without the addon installed this is
|
|
||||||
// exactly the state a real server is in.
|
|
||||||
new DBCAddon();
|
|
||||||
booted = true;
|
|
||||||
verifyRegistry();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes {@code Loader.instance()} answerable without launching FML.
|
|
||||||
*
|
|
||||||
* <p>Registering an item goes {@code FMLControlledNamespacedRegistry.addObject} ->
|
|
||||||
* {@code GameData.register} -> {@code GameData.addPrefix}, and addPrefix asks
|
|
||||||
* {@code Loader.instance().activeModContainer()} which namespace to use. Reaching that
|
|
||||||
* normally constructs a {@code Loader}, whose constructor builds a {@code ModClassLoader} and
|
|
||||||
* casts its parent to LaunchWrapper's {@code LaunchClassLoader} -- which fails outside a
|
|
||||||
* LaunchWrapper launch, and is where this generator first stopped.
|
|
||||||
*
|
|
||||||
* <p>So the singleton is filled with an allocated-but-unconstructed Loader. Its
|
|
||||||
* {@code modController} is null, {@code activeModContainer()} returns null, and addPrefix
|
|
||||||
* takes its own documented branch: <i>"no mod container, assume minecraft"</i>. That is
|
|
||||||
* exactly the branch real vanilla registration takes, because no mod is active while
|
|
||||||
* {@code Item.registerItems()} runs.
|
|
||||||
*
|
|
||||||
* <p>Nothing about the naming rule is reimplemented here -- Forge still computes it. What this
|
|
||||||
* removes is only the classloader assumption. {@link #verifyRegistry()} then checks the result
|
|
||||||
* against what real CustomNPC+ save files contain, so the shortcut is measured rather than
|
|
||||||
* trusted. On the registration path {@code Loader} is touched at that one call and nowhere
|
|
||||||
* else; the other uses in GameData are world remapping and mod-declared substitutions.
|
|
||||||
*/
|
|
||||||
private static void installBareLoader() {
|
|
||||||
try {
|
|
||||||
Field instance = Loader.class.getDeclaredField("instance");
|
|
||||||
instance.setAccessible(true);
|
|
||||||
if (instance.get(null) != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
|
||||||
theUnsafe.setAccessible(true);
|
|
||||||
Unsafe unsafe = (Unsafe) theUnsafe.get(null);
|
|
||||||
instance.set(null, unsafe.allocateInstance(Loader.class));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Could not install a bare FML Loader. Without it the item registry cannot be "
|
|
||||||
+ "populated outside a LaunchWrapper launch.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks that registration produced the names real save files contain.
|
|
||||||
*
|
|
||||||
* <p>{@code minecraft:diamond}, not {@code diamond}: the prefix comes from Forge, and a
|
|
||||||
* generator that quietly lost it would emit fixtures that every reader tested against them
|
|
||||||
* would then agree with. The expected values here were read out of the CustomNPC+ worlds in
|
|
||||||
* {@code run/saves/}, not from the code that produces them.
|
|
||||||
*/
|
|
||||||
private static void verifyRegistry() {
|
|
||||||
String diamond = Item.itemRegistry.getNameForObject(Items.diamond);
|
|
||||||
if (!"minecraft:diamond".equals(diamond)) {
|
|
||||||
throw new IllegalStateException("Item registry produced '" + diamond
|
|
||||||
+ "' where real CustomNPC+ saves contain 'minecraft:diamond'. Item stacks in these "
|
|
||||||
+ "fixtures would not match anything the mod writes.");
|
|
||||||
}
|
|
||||||
NBTTagCompound probe = new NBTTagCompound();
|
|
||||||
NoppesUtilServer.writeItem(new ItemStack(Items.golden_apple, 2, 1), probe);
|
|
||||||
if (!"minecraft:golden_apple".equals(probe.getString("id"))
|
|
||||||
|| probe.getByte("Count") != 2
|
|
||||||
|| probe.getShort("Damage") != 1) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"NoppesUtilServer.writeItem produced " + probe + ", which is not an item stack.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A stack of a vanilla item, by registry name, so the fixture reads as what it is. */
|
|
||||||
public static ItemStack item(String registryName, int count, int damage) {
|
|
||||||
Item item = (Item) Item.itemRegistry.getObject(registryName);
|
|
||||||
if (item == null) {
|
|
||||||
throw new IllegalArgumentException("No such item: " + registryName);
|
|
||||||
}
|
|
||||||
return new ItemStack(item, count, damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack item(String registryName, int count) {
|
|
||||||
return item(registryName, count, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A stack carrying custom NBT, which is the case that matters most to Scribe: item state above
|
|
||||||
* (id, damage) is what the Flattening and Data Components rearranged.
|
|
||||||
*/
|
|
||||||
public static ItemStack namedItem(String registryName, int count, int damage, String displayName) {
|
|
||||||
ItemStack stack = item(registryName, count, damage);
|
|
||||||
NBTTagCompound display = new NBTTagCompound();
|
|
||||||
display.setString("Name", displayName);
|
|
||||||
NBTTagList lore = new NBTTagList();
|
|
||||||
lore.appendTag(new NBTTagString("Written by the Scribe fixture generator"));
|
|
||||||
display.setTag("Lore", lore);
|
|
||||||
|
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
|
||||||
tag.setTag("display", display);
|
|
||||||
tag.setBoolean("Unbreakable", true);
|
|
||||||
tag.setInteger("RepairCost", 7);
|
|
||||||
stack.stackTagCompound = tag;
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A stack whose identity is a pre-Flattening variant -- damage as a variant selector rather
|
|
||||||
* than durability. Scribe converts these through a table that throws on a gap, so a fixture
|
|
||||||
* holding one is the only way to find out which entries the table is still missing.
|
|
||||||
*/
|
|
||||||
public static ItemStack variant(String registryName, int count, int variantDamage) {
|
|
||||||
return item(registryName, count, variantDamage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An index of what was generated, why, and where it landed.
|
|
||||||
*
|
|
||||||
* <p>Deliberately not a second copy of the data. The files are the fixture; this says which file
|
|
||||||
* holds which case, so a test can pick the one it needs without opening twenty of them, and so a
|
|
||||||
* reviewer can see the intent that a compound of integers does not carry.
|
|
||||||
*/
|
|
||||||
public final class Manifest {
|
|
||||||
|
|
||||||
/** One generated file. */
|
|
||||||
public static final class Entry {
|
|
||||||
final String world;
|
|
||||||
final String system;
|
|
||||||
final String id;
|
|
||||||
final String path;
|
|
||||||
final String note;
|
|
||||||
|
|
||||||
Entry(String world, String system, String id, String path, String note) {
|
|
||||||
this.world = world;
|
|
||||||
this.system = system;
|
|
||||||
this.id = id;
|
|
||||||
this.path = path;
|
|
||||||
this.note = note;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final List<Entry> entries = new ArrayList<Entry>();
|
|
||||||
private final Set<String> warnings = new LinkedHashSet<String>();
|
|
||||||
private final List<String[]> worlds = new ArrayList<String[]>();
|
|
||||||
|
|
||||||
public void world(String name, String purpose) {
|
|
||||||
worlds.add(new String[]{name, purpose});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void record(String world, String system, String id, String path, String note) {
|
|
||||||
entries.add(new Entry(world, system, id, path, note));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Records something a consumer of these fixtures has to know and could not discover from the
|
|
||||||
* bytes -- above all, the places CustomNPC+ writes a value that changes between runs.
|
|
||||||
*/
|
|
||||||
public void warn(String warning) {
|
|
||||||
warnings.add(warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> warnings() {
|
|
||||||
return warnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int count() {
|
|
||||||
return entries.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int countOf(String system) {
|
|
||||||
int n = 0;
|
|
||||||
for (Entry e : entries) {
|
|
||||||
if (e.system.equals(system)) {
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(File file) throws IOException {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("{\n");
|
|
||||||
sb.append(" \"generatedBy\": \"CustomNPC+ scribeFixtures\",\n");
|
|
||||||
sb.append(" \"note\": \"The files are the fixture. This index records intent and location, ");
|
|
||||||
sb.append("not a second copy of the data. Readable renderings of every .dat sit under ");
|
|
||||||
sb.append("<world>/_readable/, written by CustomNPC+'s own NBTJsonUtil.\",\n");
|
|
||||||
|
|
||||||
sb.append(" \"warnings\": [\n");
|
|
||||||
int wi = 0;
|
|
||||||
for (String w : warnings) {
|
|
||||||
sb.append(" ").append(quote(w));
|
|
||||||
sb.append(++wi < warnings.size() ? ",\n" : "\n");
|
|
||||||
}
|
|
||||||
sb.append(" ],\n");
|
|
||||||
|
|
||||||
sb.append(" \"worlds\": {\n");
|
|
||||||
for (int i = 0; i < worlds.size(); i++) {
|
|
||||||
String[] w = worlds.get(i);
|
|
||||||
sb.append(" ").append(quote(w[0])).append(": ").append(quote(w[1]));
|
|
||||||
sb.append(i + 1 < worlds.size() ? ",\n" : "\n");
|
|
||||||
}
|
|
||||||
sb.append(" },\n");
|
|
||||||
|
|
||||||
sb.append(" \"entries\": [\n");
|
|
||||||
for (int i = 0; i < entries.size(); i++) {
|
|
||||||
Entry e = entries.get(i);
|
|
||||||
sb.append(" {");
|
|
||||||
sb.append("\"world\": ").append(quote(e.world));
|
|
||||||
sb.append(", \"system\": ").append(quote(e.system));
|
|
||||||
sb.append(", \"id\": ").append(quote(e.id));
|
|
||||||
sb.append(", \"path\": ").append(quote(e.path));
|
|
||||||
sb.append(", \"note\": ").append(quote(e.note));
|
|
||||||
sb.append("}");
|
|
||||||
sb.append(i + 1 < entries.size() ? ",\n" : "\n");
|
|
||||||
}
|
|
||||||
sb.append(" ]\n");
|
|
||||||
sb.append("}\n");
|
|
||||||
|
|
||||||
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
|
|
||||||
try {
|
|
||||||
out.write(sb.toString());
|
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSON string escaping. Hand-rolled rather than pulled from a library because the manifest is
|
|
||||||
* the one file here that is not written by CustomNPC+, so it should have no dependency that
|
|
||||||
* could change what it produces between environments.
|
|
||||||
*/
|
|
||||||
private static String quote(String s) {
|
|
||||||
StringBuilder sb = new StringBuilder("\"");
|
|
||||||
for (int i = 0; i < s.length(); i++) {
|
|
||||||
char c = s.charAt(i);
|
|
||||||
switch (c) {
|
|
||||||
case '"':
|
|
||||||
sb.append("\\\"");
|
|
||||||
break;
|
|
||||||
case '\\':
|
|
||||||
sb.append("\\\\");
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
sb.append("\\n");
|
|
||||||
break;
|
|
||||||
case '\r':
|
|
||||||
sb.append("\\r");
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
sb.append("\\t");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (c < 0x20 || c > 0x7E) {
|
|
||||||
sb.append(String.format("\\u%04x", (int) c));
|
|
||||||
} else {
|
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.append('"').toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTBase;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces the values CustomNPC+ writes from the wall clock with a constant.
|
|
||||||
*
|
|
||||||
* <p>This is the one place a generated file departs from what the mod would write, and it exists
|
|
||||||
* because of a specific property of one writer. {@code PlayerMail.writeNBT} does:
|
|
||||||
*
|
|
||||||
* <pre>compound.setLong("TimePast", System.currentTimeMillis() - time);</pre>
|
|
||||||
*
|
|
||||||
* <p>and a {@code PlayerMail} hangs off every dialog and every quest whether or not any mail was
|
|
||||||
* configured -- so <i>every</i> dialog and quest file differs between two runs, on that one key.
|
|
||||||
*
|
|
||||||
* <p><b>Why normalize rather than document and accept.</b> There is no "the" value here to be
|
|
||||||
* faithful to; the mod writes a different one every second. Left alone, regenerating rewrites all
|
|
||||||
* 70-odd files, so a corpus held in version control churns completely on every run and a real
|
|
||||||
* change is invisible in the noise. Pinning it to zero makes the corpus byte-reproducible, which
|
|
||||||
* is what lets a diff mean something.
|
|
||||||
*
|
|
||||||
* <p>Zero is also the honest value: {@code TimePast} means "how long ago, relative to now", and a
|
|
||||||
* file on disk has no now. Nothing reads it back -- {@code PlayerMail.readNBT} loads
|
|
||||||
* {@code timePast} and the field is only used for display against a live clock.
|
|
||||||
*
|
|
||||||
* <p>Every key touched is listed here rather than matched by pattern, and the count is reported,
|
|
||||||
* so this can never quietly grow to cover a field that actually matters.
|
|
||||||
*/
|
|
||||||
public final class Normalize {
|
|
||||||
|
|
||||||
/** Keys written from the wall clock. Exhaustive, and each one deliberate. */
|
|
||||||
private static final List<String> WALL_CLOCK_KEYS = Arrays.asList("TimePast");
|
|
||||||
|
|
||||||
private Normalize() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Rewrites wall-clock keys in place, at any depth. Returns how many were changed. */
|
|
||||||
public static int wallClock(NBTTagCompound compound) {
|
|
||||||
int changed = 0;
|
|
||||||
for (String key : keysOf(compound)) {
|
|
||||||
NBTBase tag = compound.getTag(key);
|
|
||||||
if (tag == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (WALL_CLOCK_KEYS.contains(key) && tag.getId() == 4) {
|
|
||||||
compound.setLong(key, 0L);
|
|
||||||
changed++;
|
|
||||||
} else if (tag.getId() == 10) {
|
|
||||||
changed += wallClock((NBTTagCompound) tag);
|
|
||||||
} else if (tag.getId() == 9) {
|
|
||||||
NBTTagList list = (NBTTagList) tag;
|
|
||||||
if (list.func_150303_d() == 10) {
|
|
||||||
for (int i = 0; i < list.tagCount(); i++) {
|
|
||||||
// getCompoundTagAt returns the live entry, so this edits in place.
|
|
||||||
changed += wallClock(list.getCompoundTagAt(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static List<String> keysOf(NBTTagCompound compound) {
|
|
||||||
return new ArrayList<String>(compound.func_150296_c());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/** Writes the README that ships beside the generated worlds. */
|
|
||||||
public final class Readme {
|
|
||||||
|
|
||||||
private Readme() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(File file, List<FixtureWorld> worlds, Manifest manifest) throws IOException {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("# CustomNPC+ fixtures\n\n");
|
|
||||||
sb.append("Generated by `gradlew scribeFixtures` in the CustomNPC+ repository, on the\n");
|
|
||||||
sb.append("`scribe` branch. Do not edit by hand -- regenerate.\n\n");
|
|
||||||
|
|
||||||
sb.append("## What these are\n\n");
|
|
||||||
sb.append("Real CustomNPC+ save data, written by CustomNPC+'s own serialization running\n");
|
|
||||||
sb.append("against a bootstrapped-but-unlaunched Minecraft. No world was played to produce\n");
|
|
||||||
sb.append("them and no byte here was hand-authored.\n\n");
|
|
||||||
sb.append("That distinction is the whole point. A hand-written `factions.dat` asserts what\n");
|
|
||||||
sb.append("its author believed the format to be, so a reader tested against it only proves\n");
|
|
||||||
sb.append("it agrees with that belief. These files are evidence about the format itself.\n\n");
|
|
||||||
|
|
||||||
sb.append("## Layout\n\n");
|
|
||||||
sb.append("```\n");
|
|
||||||
for (FixtureWorld world : worlds) {
|
|
||||||
sb.append(world.name()).append("/customnpcs/ <- a CustomNPC+ world directory, and nothing else\n");
|
|
||||||
}
|
|
||||||
sb.append("_readable/<world>/ <- NBTJsonUtil renderings of the .dat files, for humans\n");
|
|
||||||
sb.append("manifest.json <- which file holds which case, and why\n");
|
|
||||||
sb.append("```\n\n");
|
|
||||||
sb.append("Each `<world>/` holds `customnpcs/` and nothing else, so it drops straight into\n");
|
|
||||||
sb.append("a save directory -- or, in Scribe, works as-is as a `cnpc_data_sets` overlay.\n");
|
|
||||||
sb.append("The readable renderings sit outside the world directories for that reason.\n\n");
|
|
||||||
sb.append("`_readable/` is a debugging aid, not a fixture: it is CustomNPC+'s own JSON\n");
|
|
||||||
sb.append("rendering, which suffixes scalars with their type (`5b`, `5L`, `1.0f`) and is\n");
|
|
||||||
sb.append("therefore deliberately not strict JSON. The widths being visible is the point.\n\n");
|
|
||||||
|
|
||||||
sb.append("## The worlds\n\n");
|
|
||||||
for (FixtureWorld world : worlds) {
|
|
||||||
sb.append("- **`").append(world.name()).append("`** -- ").append(world.purpose()).append("\n");
|
|
||||||
}
|
|
||||||
sb.append("\n");
|
|
||||||
|
|
||||||
sb.append("## Two formats, not one\n\n");
|
|
||||||
sb.append("- **`.dat`** -- gzipped NBT, written with `CompressedStreamTools`. Factions,\n");
|
|
||||||
sb.append(" custom effects, recipes, magic, animations, linked items, tags, and the rest.\n");
|
|
||||||
sb.append("- **Dialogs and quests are not `.dat`.** They are `NBTJsonUtil` text files at\n");
|
|
||||||
sb.append(" `customnpcs/dialogs/<category>/<id>.json`. The directory *is* the category and\n");
|
|
||||||
sb.append(" the filename *is* the id -- neither appears inside the file, because\n");
|
|
||||||
sb.append(" `saveDialog` writes `writeToNBTPartial`, which omits `DialogId`.\n\n");
|
|
||||||
|
|
||||||
sb.append("## Reproducibility\n\n");
|
|
||||||
sb.append("Regenerating produces byte-identical output, with the exceptions below. Those\n");
|
|
||||||
sb.append("are properties of CustomNPC+'s writers, not of this generator.\n\n");
|
|
||||||
for (String warning : manifest.warnings()) {
|
|
||||||
sb.append("- ").append(warning).append("\n");
|
|
||||||
}
|
|
||||||
sb.append("\n");
|
|
||||||
|
|
||||||
sb.append("## Totals\n\n");
|
|
||||||
sb.append("`").append(manifest.count()).append("` files: ");
|
|
||||||
sb.append(manifest.countOf("dialog")).append(" dialogs, ");
|
|
||||||
sb.append(manifest.countOf("quest")).append(" quests, ");
|
|
||||||
sb.append(manifest.count() - manifest.countOf("dialog") - manifest.countOf("quest"));
|
|
||||||
sb.append(" other documents.\n");
|
|
||||||
|
|
||||||
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
|
|
||||||
try {
|
|
||||||
out.write(sb.toString());
|
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,221 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import noppes.npcs.NoppesStringUtils;
|
|
||||||
import noppes.npcs.controllers.data.CustomEffect;
|
|
||||||
import noppes.npcs.controllers.data.Dialog;
|
|
||||||
import noppes.npcs.controllers.data.Quest;
|
|
||||||
import noppes.npcs.util.NBTJsonUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes one CustomNPC+ world.
|
|
||||||
*
|
|
||||||
* <p><b>What is authoritative and what is copied.</b> Every byte of content here comes from
|
|
||||||
* CustomNPC+'s own {@code writeToNBT} / {@code writeNBT} and from {@link NBTJsonUtil} and
|
|
||||||
* {@link CompressedStreamTools}. What this class supplies is only <i>where the file goes and what
|
|
||||||
* it is called</i>, because the controllers reach that through
|
|
||||||
* {@code CustomNpcs.getWorldSaveDirectory()}, which returns null without a running server, and
|
|
||||||
* because every {@code save*} fires {@code SyncController.syncUpdate} into a network stack that
|
|
||||||
* does not exist offline.
|
|
||||||
*
|
|
||||||
* <p>So each method below names the controller and method it was copied from. If a layout changes
|
|
||||||
* upstream, that reference is where to look. The layout logic is a handful of lines per system;
|
|
||||||
* the serialization, which is the part a fixture actually asserts, is never reimplemented.
|
|
||||||
*
|
|
||||||
* <p>The generated {@code <world>/customnpcs/} directory is exactly a CustomNPC+ world and holds
|
|
||||||
* nothing else. Readable renderings of the binary files go in a sibling {@code _readable/} tree so
|
|
||||||
* that dropping {@code customnpcs/} into a real save is safe.
|
|
||||||
*/
|
|
||||||
public final class WorldWriter {
|
|
||||||
|
|
||||||
private final String world;
|
|
||||||
private final File root;
|
|
||||||
private final File customnpcs;
|
|
||||||
private final File readable;
|
|
||||||
private final Manifest manifest;
|
|
||||||
private int normalized;
|
|
||||||
|
|
||||||
public WorldWriter(File outputRoot, String world, Manifest manifest) {
|
|
||||||
this.world = world;
|
|
||||||
this.root = new File(outputRoot, world);
|
|
||||||
this.customnpcs = new File(root, "customnpcs");
|
|
||||||
// Outside the world directory, not inside it. A generated <world>/ is meant to be usable
|
|
||||||
// as a drop-in overlay -- Scribe's smoke harness copies a set's contents straight into a
|
|
||||||
// server's world -- so it must contain customnpcs/ and nothing else.
|
|
||||||
this.readable = new File(new File(outputRoot, "_readable"), world);
|
|
||||||
this.manifest = manifest;
|
|
||||||
mkdirs(customnpcs);
|
|
||||||
mkdirs(readable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String world() {
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
// Dialogs -- DialogController.saveDialog / loadCategoryDir
|
|
||||||
//
|
|
||||||
// The directory is the category and the filename is the id. Neither appears inside the file:
|
|
||||||
// saveDialog writes writeToNBTPartial, which omits DialogId, and loadCategoryDir recovers the
|
|
||||||
// id by parsing the filename. A dialog's identity is where it sits.
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
public void dialog(String category, Dialog dialog, String note) {
|
|
||||||
String dir = NoppesStringUtils.cleanFileName(category);
|
|
||||||
File file = new File(new File(customnpcs, "dialogs"), dir + "/" + dialog.id + ".json");
|
|
||||||
writeJson(file, dialog.writeToNBTPartial(new NBTTagCompound()));
|
|
||||||
manifest.record(world, "dialog", String.valueOf(dialog.id), rel(file), note);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
// Quests -- QuestController.saveQuest / loadCategoryDir
|
|
||||||
//
|
|
||||||
// Same shape as dialogs, and the same identity rule.
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
public void quest(String category, Quest quest, String note) {
|
|
||||||
String dir = NoppesStringUtils.cleanFileName(category);
|
|
||||||
File file = new File(new File(customnpcs, "quests"), dir + "/" + quest.id + ".json");
|
|
||||||
writeJson(file, quest.writeToNBTPartial(new NBTTagCompound()));
|
|
||||||
manifest.record(world, "quest", String.valueOf(quest.id), rel(file), note);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
// Custom effects -- CustomEffectController.saveCustomEffect / loadEffectsFromDir
|
|
||||||
//
|
|
||||||
// The filename is the name: loadEffectsFromDir overwrites whatever `name` the file contained
|
|
||||||
// with the filename minus .json. An empty category means the effect sits at the root of
|
|
||||||
// customeffects/, which is what CategoryManager calls Uncategorized -- there is no category
|
|
||||||
// file anywhere, only the directory.
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
public void effect(String category, CustomEffect effect, String note) {
|
|
||||||
effect(category, effect.getName(), effect, note);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* As {@link #effect}, with the filename stated separately.
|
|
||||||
*
|
|
||||||
* <p>Needed because the filename and the {@code name} key are genuinely independent on disk,
|
|
||||||
* and a fixture proving the loader prefers the filename has to be able to disagree with it.
|
|
||||||
*/
|
|
||||||
public void effect(String category, String fileName, CustomEffect effect, String note) {
|
|
||||||
File dir = new File(customnpcs, "customeffects");
|
|
||||||
if (category != null && !category.isEmpty()) {
|
|
||||||
dir = new File(dir, NoppesStringUtils.cleanFileName(category));
|
|
||||||
}
|
|
||||||
File file = new File(dir, NoppesStringUtils.cleanFileName(fileName) + ".json");
|
|
||||||
writeJson(file, effect.writeToNBT(true));
|
|
||||||
manifest.record(world, "effect", String.valueOf(effect.id), rel(file), note);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A dialog written from a compound rather than from a {@link Dialog}.
|
|
||||||
*
|
|
||||||
* <p>Only for the legacy world, which ages a document by removing keys a newer CustomNPC+
|
|
||||||
* added. The compound still comes from CustomNPC+'s writer; what is synthesized is the
|
|
||||||
* subtraction. Every caller must say in its note which keys it removed and why.
|
|
||||||
*/
|
|
||||||
public void dialogRaw(String category, int id, NBTTagCompound compound, String note) {
|
|
||||||
String dir = NoppesStringUtils.cleanFileName(category);
|
|
||||||
File file = new File(new File(customnpcs, "dialogs"), dir + "/" + id + ".json");
|
|
||||||
writeJson(file, compound);
|
|
||||||
manifest.record(world, "dialog", String.valueOf(id), rel(file), note);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** As {@link #dialogRaw}, for quests. */
|
|
||||||
public void questRaw(String category, int id, NBTTagCompound compound, String note) {
|
|
||||||
String dir = NoppesStringUtils.cleanFileName(category);
|
|
||||||
File file = new File(new File(customnpcs, "quests"), dir + "/" + id + ".json");
|
|
||||||
writeJson(file, compound);
|
|
||||||
manifest.record(world, "quest", String.valueOf(id), rel(file), note);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A gzipped NBT document at the root of the world.
|
|
||||||
*
|
|
||||||
* <p>The shape every {@code .dat} controller uses -- FactionController.saveFactions,
|
|
||||||
* CustomEffectController.saveCustomEffects, GlobalDataController.save and the rest: build one
|
|
||||||
* compound, {@code CompressedStreamTools.writeCompressed} it, rotate the previous file to
|
|
||||||
* {@code _old}. The rotation is not reproduced, because a generated world has no previous file
|
|
||||||
* and inventing a {@code .dat_old} would be inventing history.
|
|
||||||
*/
|
|
||||||
public void dat(String system, String fileName, NBTTagCompound compound, String note) {
|
|
||||||
File file = new File(customnpcs, fileName);
|
|
||||||
mkdirs(file.getParentFile());
|
|
||||||
normalized += Normalize.wallClock(compound);
|
|
||||||
try {
|
|
||||||
OutputStream out = new FileOutputStream(file);
|
|
||||||
try {
|
|
||||||
CompressedStreamTools.writeCompressed(compound, out);
|
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IllegalStateException("Failed writing " + file, e);
|
|
||||||
}
|
|
||||||
renderReadable(fileName, compound);
|
|
||||||
manifest.record(world, system, fileName, rel(file), note);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A JSON document at an explicit path under {@code customnpcs/}, for the per-player records. */
|
|
||||||
public void json(String system, String id, String relativePath, NBTTagCompound compound, String note) {
|
|
||||||
File file = new File(customnpcs, relativePath);
|
|
||||||
writeJson(file, compound);
|
|
||||||
manifest.record(world, system, id, rel(file), note);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeJson(File file, NBTTagCompound compound) {
|
|
||||||
mkdirs(file.getParentFile());
|
|
||||||
normalized += Normalize.wallClock(compound);
|
|
||||||
try {
|
|
||||||
NBTJsonUtil.SaveFile(file, compound);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException("Failed writing " + file, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** How many wall-clock values were pinned in this world. See {@link Normalize}. */
|
|
||||||
public int normalizedCount() {
|
|
||||||
return normalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes CustomNPC+'s own JSON rendering of a binary document beside the world, for reading.
|
|
||||||
*
|
|
||||||
* <p>Not a fixture and not parseable as strict JSON -- NBTJsonUtil suffixes scalars with their
|
|
||||||
* type ({@code 5b}, {@code 5L}, {@code 1.0f}), which is exactly what makes it worth having:
|
|
||||||
* the widths are visible, and a fixture whose value silently became a byte shows up here.
|
|
||||||
*/
|
|
||||||
private void renderReadable(String fileName, NBTTagCompound compound) {
|
|
||||||
File file = new File(readable, fileName + ".txt");
|
|
||||||
mkdirs(file.getParentFile());
|
|
||||||
try {
|
|
||||||
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
|
|
||||||
try {
|
|
||||||
out.write(NBTJsonUtil.Convert(compound));
|
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IllegalStateException("Failed writing " + file, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String rel(File file) {
|
|
||||||
String base = root.getAbsolutePath();
|
|
||||||
String path = file.getAbsolutePath();
|
|
||||||
return path.startsWith(base) ? path.substring(base.length() + 1).replace('\\', '/') : path;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void mkdirs(File dir) {
|
|
||||||
if (dir != null && !dir.exists() && !dir.mkdirs()) {
|
|
||||||
throw new IllegalStateException("Could not create " + dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,484 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.content;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.Case;
|
|
||||||
import kamkeel.npcs.fixtures.Fixtures;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import noppes.npcs.constants.EnumAvailabilityDialog;
|
|
||||||
import noppes.npcs.constants.EnumAvailabilityFaction;
|
|
||||||
import noppes.npcs.constants.EnumAvailabilityFactionType;
|
|
||||||
import noppes.npcs.constants.EnumAvailabilityQuest;
|
|
||||||
import noppes.npcs.constants.EnumDayTime;
|
|
||||||
import noppes.npcs.constants.EnumOptionType;
|
|
||||||
import noppes.npcs.controllers.data.Dialog;
|
|
||||||
import noppes.npcs.controllers.data.DialogImage;
|
|
||||||
import noppes.npcs.controllers.data.DialogOption;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dialogs, built by axis rather than by example.
|
|
||||||
*
|
|
||||||
* <p>A dialog has about forty fields across six sub-objects, and picking a few realistic-looking
|
|
||||||
* ones covers the fields the author happened to think of. So each block below walks one axis to
|
|
||||||
* its ends -- every enum constant, every slot, both sides of every boolean -- and the id ranges
|
|
||||||
* are reserved per axis so a new case does not renumber the others.
|
|
||||||
*
|
|
||||||
* <p>Ranges: 1-9 basics, 10-29 options, 30-59 availability, 60-79 appearance, 80-89 images,
|
|
||||||
* 90-99 mail / quest link / faction rewards.
|
|
||||||
*/
|
|
||||||
public final class DialogFixtures {
|
|
||||||
|
|
||||||
private DialogFixtures() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Case<Dialog>> maximal() {
|
|
||||||
List<Case<Dialog>> out = new ArrayList<Case<Dialog>>();
|
|
||||||
basics(out);
|
|
||||||
options(out);
|
|
||||||
availability(out);
|
|
||||||
appearance(out);
|
|
||||||
images(out);
|
|
||||||
attachments(out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ basics
|
|
||||||
|
|
||||||
private static void basics(List<Case<Dialog>> out) {
|
|
||||||
Dialog bare = dialog(1, "Bare", "");
|
|
||||||
out.add(new Case<Dialog>("Basics", bare,
|
|
||||||
"every field left at its constructor default, with an empty text. The baseline a "
|
|
||||||
+ "reader's defaults are compared against"));
|
|
||||||
|
|
||||||
Dialog plain = dialog(2, "Plain Greeting",
|
|
||||||
"Hello {player},\n\nWelcome to our village. I hope you enjoy your stay");
|
|
||||||
out.add(new Case<Dialog>("Basics", plain,
|
|
||||||
"title and text only, with the {player} placeholder and embedded newlines that "
|
|
||||||
+ "CustomNPC+'s own default dialog uses"));
|
|
||||||
|
|
||||||
Dialog longText = dialog(3, "Long Text", repeat(
|
|
||||||
"This sentence exists so the stored text crosses the length CustomNPC+ warns about. ", 200));
|
|
||||||
out.add(new Case<Dialog>("Basics", longText,
|
|
||||||
"text over 15000 chars, which DialogController logs as an 'Extremely big dialog'. "
|
|
||||||
+ "Loads normally -- the check is a warning, not a limit"));
|
|
||||||
|
|
||||||
Dialog unicode = dialog(4, Text.KATAKANA_FACTION + " " + Text.EM_DASH + " " + Text.ELEVES,
|
|
||||||
Text.CYRILLIC_QUEST + "\n" + Text.RTL + "\n" + Text.ASTRAL);
|
|
||||||
out.add(new Case<Dialog>("Basics", unicode,
|
|
||||||
"title and text outside Latin-1, including one astral-plane code point. NBT strings "
|
|
||||||
+ "are modified UTF-8, so the astral char is stored as a surrogate pair"));
|
|
||||||
|
|
||||||
Dialog formatted = dialog(5, Text.SECTION + "6Formatted " + Text.SECTION + "lTitle",
|
|
||||||
Text.SECTION + "cRed " + Text.SECTION + "aGreen " + Text.SECTION + "r" + "plain");
|
|
||||||
out.add(new Case<Dialog>("Basics", formatted,
|
|
||||||
"section-sign colour codes in title and text, which is how all CustomNPC+ content is "
|
|
||||||
+ "coloured"));
|
|
||||||
|
|
||||||
Dialog command = dialog(6, "Runs A Command", "The gate opens.");
|
|
||||||
command.command = "/say {player} opened the gate";
|
|
||||||
out.add(new Case<Dialog>("Basics", command,
|
|
||||||
"DialogCommand set -- a command run on the server when the dialog opens"));
|
|
||||||
|
|
||||||
Dialog sounds = dialog(7, "Sounds", "Listen.");
|
|
||||||
sounds.sound = "customnpcs:dialog.open";
|
|
||||||
sounds.textSound = "minecraft:random.orb";
|
|
||||||
sounds.textPitch = 0.75F;
|
|
||||||
out.add(new Case<Dialog>("Basics", sounds,
|
|
||||||
"DialogSound plus a non-default TextSound and TextPitch. Note DialogSound is written "
|
|
||||||
+ "only when non-empty, so the key is absent on every other dialog here"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ options
|
|
||||||
|
|
||||||
private static void options(List<Case<Dialog>> out) {
|
|
||||||
// One dialog per option type, because the type drives what the other fields mean.
|
|
||||||
int id = 10;
|
|
||||||
for (EnumOptionType type : EnumOptionType.values()) {
|
|
||||||
Dialog d = dialog(id, "Option " + type.name(), "Choose.");
|
|
||||||
DialogOption option = new DialogOption();
|
|
||||||
option.title = type.name() + " option";
|
|
||||||
option.optionType = type;
|
|
||||||
option.dialogId = type == EnumOptionType.DialogOption ? 2 : -1;
|
|
||||||
option.optionColor = 0x00FF00;
|
|
||||||
option.command = type == EnumOptionType.CommandBlock ? "/time set day" : "";
|
|
||||||
d.options.put(0, option);
|
|
||||||
out.add(new Case<Dialog>("Options", d,
|
|
||||||
"a single option of type " + type.name() + " (ordinal " + type.ordinal() + ")"));
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dialog full = dialog(20, "Six Options", "Pick one.");
|
|
||||||
for (int slot = 0; slot < 6; slot++) {
|
|
||||||
DialogOption option = new DialogOption();
|
|
||||||
option.title = "Option in slot " + slot;
|
|
||||||
option.optionType = EnumOptionType.DialogOption;
|
|
||||||
option.dialogId = 2;
|
|
||||||
option.optionColor = 0x100000 * (slot + 1);
|
|
||||||
full.options.put(slot, option);
|
|
||||||
}
|
|
||||||
out.add(new Case<Dialog>("Options", full,
|
|
||||||
"six options in contiguous slots 0-5, each a different colour"));
|
|
||||||
|
|
||||||
// Slots are a map key, not a list index. A reader that treats Options as an ordered list
|
|
||||||
// silently renumbers this one.
|
|
||||||
Dialog sparse = dialog(21, "Sparse Slots", "The gaps matter.");
|
|
||||||
int[] slots = {0, 3, 7, 12};
|
|
||||||
for (int slot : slots) {
|
|
||||||
DialogOption option = new DialogOption();
|
|
||||||
option.title = "Slot " + slot;
|
|
||||||
option.optionType = EnumOptionType.DialogOption;
|
|
||||||
option.dialogId = 2;
|
|
||||||
sparse.options.put(slot, option);
|
|
||||||
}
|
|
||||||
out.add(new Case<Dialog>("Options", sparse,
|
|
||||||
"options at non-contiguous slots 0, 3, 7 and 12. OptionSlot is stored per entry, so "
|
|
||||||
+ "the gaps survive; a reader treating the list as positional loses them"));
|
|
||||||
|
|
||||||
Dialog dangling = dialog(22, "Dangling Option", "Where does this go?");
|
|
||||||
DialogOption toNowhere = new DialogOption();
|
|
||||||
toNowhere.title = "To a dialog that is not here";
|
|
||||||
toNowhere.optionType = EnumOptionType.DialogOption;
|
|
||||||
toNowhere.dialogId = 999999;
|
|
||||||
dangling.options.put(0, toNowhere);
|
|
||||||
out.add(new Case<Dialog>("Options", dangling,
|
|
||||||
"an option pointing at a dialog id that does not exist in this world. Conversion must "
|
|
||||||
+ "keep the id rather than resolve it"));
|
|
||||||
|
|
||||||
Dialog emptyTitle = dialog(23, "Empty Option Title", "...");
|
|
||||||
DialogOption blank = new DialogOption();
|
|
||||||
blank.title = "";
|
|
||||||
blank.optionType = EnumOptionType.DialogOption;
|
|
||||||
blank.dialogId = 2;
|
|
||||||
blank.optionColor = 0;
|
|
||||||
emptyTitle.options.put(0, blank);
|
|
||||||
out.add(new Case<Dialog>("Options", emptyTitle,
|
|
||||||
"an option with an empty title and DialogColor 0. On read, colour 0 is replaced by the "
|
|
||||||
+ "default 0xe0e0e0 -- so this file does not round-trip, by design upstream"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ availability
|
|
||||||
|
|
||||||
private static void availability(List<Case<Dialog>> out) {
|
|
||||||
// Every EnumAvailabilityQuest constant, one dialog each. These are the rules whose loss
|
|
||||||
// makes a gated dialog visible to everybody, so each constant gets its own file.
|
|
||||||
int id = 30;
|
|
||||||
for (EnumAvailabilityQuest rule : EnumAvailabilityQuest.values()) {
|
|
||||||
Dialog d = dialog(id, "Quest rule " + rule.name(), "Gated on a quest.");
|
|
||||||
d.availability.questAvailable = rule;
|
|
||||||
d.availability.questId = 1;
|
|
||||||
out.add(new Case<Dialog>("Availability", d,
|
|
||||||
"AvailabilityQuest = " + rule.name() + " (ordinal " + rule.ordinal()
|
|
||||||
+ ") against quest 1"));
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All four quest slots at once, each a different rule and a different target.
|
|
||||||
Dialog fourQuests = dialog(40, "Four Quest Rules", "Four gates.");
|
|
||||||
fourQuests.availability.questAvailable = EnumAvailabilityQuest.After;
|
|
||||||
fourQuests.availability.questId = 1;
|
|
||||||
fourQuests.availability.quest2Available = EnumAvailabilityQuest.Before;
|
|
||||||
fourQuests.availability.quest2Id = 2;
|
|
||||||
fourQuests.availability.quest3Available = EnumAvailabilityQuest.Active;
|
|
||||||
fourQuests.availability.quest3Id = 3;
|
|
||||||
fourQuests.availability.quest4Available = EnumAvailabilityQuest.NotAcceptable;
|
|
||||||
fourQuests.availability.quest4Id = 4;
|
|
||||||
out.add(new Case<Dialog>("Availability", fourQuests,
|
|
||||||
"all four AvailabilityQuest slots set to different rules and different quests. The "
|
|
||||||
+ "case a reader that reads only the first slot passes anyway"));
|
|
||||||
|
|
||||||
int dialogRuleId = 41;
|
|
||||||
for (EnumAvailabilityDialog rule : EnumAvailabilityDialog.values()) {
|
|
||||||
Dialog d = dialog(dialogRuleId, "Dialog rule " + rule.name(), "Gated on a dialog.");
|
|
||||||
d.availability.dialogAvailable = rule;
|
|
||||||
d.availability.dialogId = 2;
|
|
||||||
out.add(new Case<Dialog>("Availability", d,
|
|
||||||
"AvailabilityDialog = " + rule.name() + " against dialog 2 -- read tracking"));
|
|
||||||
dialogRuleId++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dialog fourDialogs = dialog(44, "Four Dialog Rules", "Four read-gates.");
|
|
||||||
fourDialogs.availability.dialogAvailable = EnumAvailabilityDialog.After;
|
|
||||||
fourDialogs.availability.dialogId = 1;
|
|
||||||
fourDialogs.availability.dialog2Available = EnumAvailabilityDialog.Before;
|
|
||||||
fourDialogs.availability.dialog2Id = 2;
|
|
||||||
fourDialogs.availability.dialog3Available = EnumAvailabilityDialog.After;
|
|
||||||
fourDialogs.availability.dialog3Id = 3;
|
|
||||||
fourDialogs.availability.dialog4Available = EnumAvailabilityDialog.Before;
|
|
||||||
fourDialogs.availability.dialog4Id = 4;
|
|
||||||
out.add(new Case<Dialog>("Availability", fourDialogs,
|
|
||||||
"all four AvailabilityDialog slots set"));
|
|
||||||
|
|
||||||
// Faction rules: type x stance, both slots.
|
|
||||||
int factionRuleId = 45;
|
|
||||||
for (EnumAvailabilityFactionType type : EnumAvailabilityFactionType.values()) {
|
|
||||||
for (EnumAvailabilityFaction stance : EnumAvailabilityFaction.values()) {
|
|
||||||
if (type == EnumAvailabilityFactionType.Always && stance != EnumAvailabilityFaction.Friendly) {
|
|
||||||
continue; // Always ignores the stance; one file is enough for it.
|
|
||||||
}
|
|
||||||
Dialog d = dialog(factionRuleId, "Faction " + type.name() + " " + stance.name(),
|
|
||||||
"Gated on standing.");
|
|
||||||
d.availability.factionAvailable = type;
|
|
||||||
d.availability.factionStance = stance;
|
|
||||||
d.availability.factionId = 10;
|
|
||||||
out.add(new Case<Dialog>("Availability", d,
|
|
||||||
"AvailabilityFaction = " + type.name() + ", stance " + stance.name()
|
|
||||||
+ ", against faction 10 (Hidden Watchers)"));
|
|
||||||
factionRuleId++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Dialog bothFactions = dialog(53, "Both Faction Slots", "Two standings.");
|
|
||||||
bothFactions.availability.factionAvailable = EnumAvailabilityFactionType.Is;
|
|
||||||
bothFactions.availability.factionStance = EnumAvailabilityFaction.Friendly;
|
|
||||||
bothFactions.availability.factionId = 0;
|
|
||||||
bothFactions.availability.faction2Available = EnumAvailabilityFactionType.IsNot;
|
|
||||||
bothFactions.availability.faction2Stance = EnumAvailabilityFaction.Hostile;
|
|
||||||
bothFactions.availability.faction2Id = 2;
|
|
||||||
out.add(new Case<Dialog>("Availability", bothFactions,
|
|
||||||
"both faction slots, one Is/Friendly and one IsNot/Hostile"));
|
|
||||||
|
|
||||||
int daytimeId = 54;
|
|
||||||
for (EnumDayTime time : EnumDayTime.values()) {
|
|
||||||
Dialog d = dialog(daytimeId, "Daytime " + time.name(), "Time-gated.");
|
|
||||||
d.availability.daytime = time;
|
|
||||||
out.add(new Case<Dialog>("Availability", d,
|
|
||||||
"AvailabilityDayTime = " + time.name() + " (ordinal " + time.ordinal() + ")"));
|
|
||||||
daytimeId++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dialog level = dialog(57, "Min Level", "You look experienced.");
|
|
||||||
level.availability.minPlayerLevel = 30;
|
|
||||||
out.add(new Case<Dialog>("Availability", level,
|
|
||||||
"AvailabilityMinPlayerLevel = 30"));
|
|
||||||
|
|
||||||
Dialog everything = dialog(58, "Every Rule At Once", "Nothing gets through this.");
|
|
||||||
everything.availability.daytime = EnumDayTime.Night;
|
|
||||||
everything.availability.minPlayerLevel = 99;
|
|
||||||
everything.availability.dialogAvailable = EnumAvailabilityDialog.After;
|
|
||||||
everything.availability.dialogId = 1;
|
|
||||||
everything.availability.dialog2Available = EnumAvailabilityDialog.Before;
|
|
||||||
everything.availability.dialog2Id = 2;
|
|
||||||
everything.availability.dialog3Available = EnumAvailabilityDialog.After;
|
|
||||||
everything.availability.dialog3Id = 3;
|
|
||||||
everything.availability.dialog4Available = EnumAvailabilityDialog.Before;
|
|
||||||
everything.availability.dialog4Id = 4;
|
|
||||||
everything.availability.questAvailable = EnumAvailabilityQuest.After;
|
|
||||||
everything.availability.questId = 1;
|
|
||||||
everything.availability.quest2Available = EnumAvailabilityQuest.Active;
|
|
||||||
everything.availability.quest2Id = 2;
|
|
||||||
everything.availability.quest3Available = EnumAvailabilityQuest.NotActive;
|
|
||||||
everything.availability.quest3Id = 3;
|
|
||||||
everything.availability.quest4Available = EnumAvailabilityQuest.Acceptable;
|
|
||||||
everything.availability.quest4Id = 4;
|
|
||||||
everything.availability.factionAvailable = EnumAvailabilityFactionType.Is;
|
|
||||||
everything.availability.factionStance = EnumAvailabilityFaction.Friendly;
|
|
||||||
everything.availability.factionId = 0;
|
|
||||||
everything.availability.faction2Available = EnumAvailabilityFactionType.IsNot;
|
|
||||||
everything.availability.faction2Stance = EnumAvailabilityFaction.Hostile;
|
|
||||||
everything.availability.faction2Id = 2;
|
|
||||||
out.add(new Case<Dialog>("Availability", everything,
|
|
||||||
"every availability slot set simultaneously -- ten rules plus daytime and level. The "
|
|
||||||
+ "single densest availability block in these fixtures"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ appearance
|
|
||||||
|
|
||||||
private static void appearance(List<Case<Dialog>> out) {
|
|
||||||
Dialog flags = dialog(60, "Flags Inverted", "Every boolean off its default.");
|
|
||||||
flags.hideNPC = true;
|
|
||||||
flags.showWheel = true;
|
|
||||||
flags.disableEsc = true;
|
|
||||||
flags.darkenScreen = false;
|
|
||||||
flags.showOptionLine = false;
|
|
||||||
flags.renderGradual = true;
|
|
||||||
flags.showPreviousBlocks = false;
|
|
||||||
out.add(new Case<Dialog>("Appearance", flags,
|
|
||||||
"all seven display booleans flipped away from their defaults. Four of them read back "
|
|
||||||
+ "as true when their key is absent, so a writer that omits defaults changes "
|
|
||||||
+ "behaviour"));
|
|
||||||
|
|
||||||
Dialog colors = dialog(61, "Colors", "Coloured.");
|
|
||||||
colors.color = 0x336699;
|
|
||||||
colors.titleColor = 0xCC3300;
|
|
||||||
out.add(new Case<Dialog>("Appearance", colors,
|
|
||||||
"Color and TitleColor off the 0xe0e0e0 default"));
|
|
||||||
|
|
||||||
Dialog colorData = dialog(62, "Color Data Enabled", "Full chrome colours.");
|
|
||||||
colorData.colorData.setEnableColorSettings(true);
|
|
||||||
colorData.colorData.setLineColor1(0xff112233);
|
|
||||||
colorData.colorData.setLineColor2(0xff445566);
|
|
||||||
colorData.colorData.setLineColor3(0xff778899);
|
|
||||||
colorData.colorData.setSlotColor(0xffaabbcc);
|
|
||||||
colorData.colorData.setButtonAcceptColor(0xff00ff00);
|
|
||||||
colorData.colorData.setButtonRejectColor(0xffff0000);
|
|
||||||
out.add(new Case<Dialog>("Appearance", colorData,
|
|
||||||
"DialogColorData with ColorSettings enabled and all six colours set. The six keys are "
|
|
||||||
+ "written ONLY when the flag is on -- see id 63 for the other half"));
|
|
||||||
|
|
||||||
Dialog colorDataOff = dialog(63, "Color Data Disabled", "Colours set but not enabled.");
|
|
||||||
colorDataOff.colorData.setEnableColorSettings(false);
|
|
||||||
colorDataOff.colorData.setLineColor1(0xff112233);
|
|
||||||
colorDataOff.colorData.setSlotColor(0xffaabbcc);
|
|
||||||
out.add(new Case<Dialog>("Appearance", colorDataOff,
|
|
||||||
"ColorSettings off with colours assigned. Proves the six colour keys are absent from "
|
|
||||||
+ "the file, so the values are lost upstream and there is nothing to convert"));
|
|
||||||
|
|
||||||
Dialog layout = dialog(64, "Layout", "Positioned.");
|
|
||||||
layout.textWidth = 420;
|
|
||||||
layout.textHeight = 260;
|
|
||||||
layout.textOffsetX = -12;
|
|
||||||
layout.textOffsetY = 34;
|
|
||||||
layout.titlePos = 2;
|
|
||||||
layout.titleOffsetX = 8;
|
|
||||||
layout.titleOffsetY = -6;
|
|
||||||
layout.optionOffsetX = 5;
|
|
||||||
layout.optionOffsetY = -5;
|
|
||||||
layout.optionSpaceX = 3;
|
|
||||||
layout.optionSpaceY = 14;
|
|
||||||
layout.npcScale = 2.25F;
|
|
||||||
layout.npcOffsetX = -40;
|
|
||||||
layout.npcOffsetY = 18;
|
|
||||||
out.add(new Case<Dialog>("Appearance", layout,
|
|
||||||
"every geometry field set, several negative. Fourteen integers and one float that a "
|
|
||||||
+ "dialog screen has to place things by"));
|
|
||||||
|
|
||||||
for (byte alignment = 0; alignment <= 2; alignment++) {
|
|
||||||
Dialog d = dialog(65 + alignment, "Alignment " + alignment, "Aligned.");
|
|
||||||
d.alignment = alignment;
|
|
||||||
out.add(new Case<Dialog>("Appearance", d,
|
|
||||||
"DialogAlignment = " + alignment + " (0 bottom, 1 top, 2 centre). Stored as a byte, "
|
|
||||||
+ "not an int -- the one narrow scalar on a dialog"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ images
|
|
||||||
|
|
||||||
private static void images(List<Case<Dialog>> out) {
|
|
||||||
Dialog one = dialog(80, "One Image", "Look.");
|
|
||||||
one.dialogImages.put(0, image(0, "customnpcs:textures/gui/dialog.png", 1));
|
|
||||||
out.add(new Case<Dialog>("Images", one,
|
|
||||||
"a single DialogImage with every field at a non-default"));
|
|
||||||
|
|
||||||
Dialog many = dialog(81, "Three Images", "Look again.");
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
DialogImage img = image(i, "customnpcs:textures/gui/image" + i + ".png", i);
|
|
||||||
img.x = 10 * i;
|
|
||||||
img.y = 20 * i;
|
|
||||||
img.alignment = i;
|
|
||||||
many.dialogImages.put(i, img);
|
|
||||||
}
|
|
||||||
out.add(new Case<Dialog>("Images", many,
|
|
||||||
"three images with imageType 0, 1 and 2 -- Default, Text and Option"));
|
|
||||||
|
|
||||||
Dialog defaults = dialog(82, "Default Image", "An untouched image.");
|
|
||||||
defaults.dialogImages.put(0, new DialogImage(0));
|
|
||||||
out.add(new Case<Dialog>("Images", defaults,
|
|
||||||
"a DialogImage left entirely at its constructor defaults, including an empty texture"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ attachments
|
|
||||||
|
|
||||||
private static void attachments(List<Case<Dialog>> out) {
|
|
||||||
Dialog quest = dialog(90, "Starts A Quest", "Take this.");
|
|
||||||
quest.quest = 1;
|
|
||||||
out.add(new Case<Dialog>("Attachments", quest,
|
|
||||||
"DialogQuest = 1 -- opening this dialog starts quest 1. The link a conversion that "
|
|
||||||
+ "drops the field turns into a quest nobody can be given"));
|
|
||||||
|
|
||||||
Dialog mail = dialog(91, "Sends Mail", "Check your inbox.");
|
|
||||||
mail.mail.subject = "A letter from the village";
|
|
||||||
mail.mail.sender = "Elder Marrow";
|
|
||||||
mail.mail.time = Fixtures.EPOCH;
|
|
||||||
mail.mail.beenRead = false;
|
|
||||||
NBTTagCompound message = new NBTTagCompound();
|
|
||||||
message.setString("Text", "Thank you for your help.");
|
|
||||||
mail.mail.message = message;
|
|
||||||
mail.mail.items[0] = Fixtures.item("minecraft:golden_apple", 3, 1);
|
|
||||||
mail.mail.items[2] = Fixtures.namedItem("minecraft:diamond_sword", 1, 12, "Villager's Thanks");
|
|
||||||
out.add(new Case<Dialog>("Attachments", mail,
|
|
||||||
"DialogMail with subject, sender, a message compound and two of four item slots -- "
|
|
||||||
+ "one of them a variant damage, one carrying custom NBT. NOTE: TimePast inside "
|
|
||||||
+ "this compound is not reproducible between runs"));
|
|
||||||
|
|
||||||
Dialog reward = dialog(92, "Faction Reward", "The Legion remembers.");
|
|
||||||
reward.factionOptions.factionId = 14;
|
|
||||||
reward.factionOptions.factionPoints = 250;
|
|
||||||
reward.factionOptions.decreaseFactionPoints = false;
|
|
||||||
reward.factionOptions.faction2Id = 15;
|
|
||||||
reward.factionOptions.faction2Points = 100;
|
|
||||||
reward.factionOptions.decreaseFaction2Points = true;
|
|
||||||
out.add(new Case<Dialog>("Attachments", reward,
|
|
||||||
"both faction reward slots -- one granting points, one decreasing them"));
|
|
||||||
|
|
||||||
Dialog everything = dialog(93, "Everything At Once",
|
|
||||||
"This dialog exercises every sub-object CustomNPC+ hangs off a dialog.");
|
|
||||||
everything.quest = 2;
|
|
||||||
everything.command = "/say done";
|
|
||||||
everything.sound = "customnpcs:dialog.open";
|
|
||||||
everything.color = 0x445566;
|
|
||||||
everything.titleColor = 0x998877;
|
|
||||||
everything.hideNPC = true;
|
|
||||||
everything.renderGradual = true;
|
|
||||||
everything.npcScale = 1.5F;
|
|
||||||
everything.availability.daytime = EnumDayTime.Day;
|
|
||||||
everything.availability.minPlayerLevel = 5;
|
|
||||||
everything.availability.questAvailable = EnumAvailabilityQuest.Before;
|
|
||||||
everything.availability.questId = 3;
|
|
||||||
everything.factionOptions.factionId = 0;
|
|
||||||
everything.factionOptions.factionPoints = 10;
|
|
||||||
everything.colorData.setEnableColorSettings(true);
|
|
||||||
everything.colorData.setSlotColor(0xff00ffff);
|
|
||||||
everything.mail.subject = "Everything";
|
|
||||||
everything.mail.sender = "The Generator";
|
|
||||||
everything.mail.time = Fixtures.EPOCH;
|
|
||||||
everything.mail.items[0] = Fixtures.item("minecraft:emerald", 64);
|
|
||||||
everything.dialogImages.put(0, image(0, "customnpcs:textures/gui/all.png", 2));
|
|
||||||
DialogOption opt = new DialogOption();
|
|
||||||
opt.title = "Continue";
|
|
||||||
opt.optionType = EnumOptionType.DialogOption;
|
|
||||||
opt.dialogId = 2;
|
|
||||||
opt.optionColor = 0xFFAA00;
|
|
||||||
everything.options.put(0, opt);
|
|
||||||
out.add(new Case<Dialog>("Attachments", everything,
|
|
||||||
"one dialog touching every sub-object at once: options, availability, faction rewards, "
|
|
||||||
+ "colour data, mail, an image and a quest link"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ helpers
|
|
||||||
|
|
||||||
private static Dialog dialog(int id, String title, String text) {
|
|
||||||
Dialog dialog = new Dialog();
|
|
||||||
dialog.id = id;
|
|
||||||
dialog.title = title;
|
|
||||||
dialog.text = text;
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DialogImage image(int id, String texture, int imageType) {
|
|
||||||
DialogImage image = new DialogImage(id);
|
|
||||||
image.texture = texture;
|
|
||||||
image.x = 12;
|
|
||||||
image.y = 34;
|
|
||||||
image.width = 64;
|
|
||||||
image.height = 48;
|
|
||||||
image.textureX = 8;
|
|
||||||
image.textureY = 16;
|
|
||||||
image.scale = 1.75F;
|
|
||||||
image.color = 0x88CCFF;
|
|
||||||
image.selectedColor = 0xFFCC88;
|
|
||||||
image.alpha = 0.5F;
|
|
||||||
image.rotation = 45.0F;
|
|
||||||
image.imageType = imageType;
|
|
||||||
image.alignment = 1;
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
static String repeat(String s, int times) {
|
|
||||||
StringBuilder sb = new StringBuilder(s.length() * times);
|
|
||||||
for (int i = 0; i < times; i++) {
|
|
||||||
sb.append(s);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.content;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.Case;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import noppes.npcs.controllers.ScriptContainer;
|
|
||||||
import noppes.npcs.controllers.data.CustomEffect;
|
|
||||||
import noppes.npcs.controllers.data.EffectScript;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom effects, which persist in two places at once.
|
|
||||||
*
|
|
||||||
* <p>Each effect is a file at {@code customeffects/<Name>.json} -- or
|
|
||||||
* {@code customeffects/<Category>/<Name>.json}, where the subdirectory is the category -- written
|
|
||||||
* with {@code writeToNBT(true)}. <b>The filename is the name</b>: {@code loadEffectsFromDir}
|
|
||||||
* overwrites whatever {@code name} the file contained with the filename minus {@code .json}, so
|
|
||||||
* the {@code name} key inside is dead weight and the two can legitimately disagree. There is a
|
|
||||||
* fixture for that below.
|
|
||||||
*
|
|
||||||
* <p>Alongside them, {@code customeffects.dat} is an index of {@code {Name, ID}} pairs plus
|
|
||||||
* {@code lastID} -- not the effects themselves. An effect whose name is empty is left out of the
|
|
||||||
* index entirely, which is its own case.
|
|
||||||
*/
|
|
||||||
public final class EffectFixtures {
|
|
||||||
|
|
||||||
private EffectFixtures() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Case<CustomEffect>> maximal() {
|
|
||||||
List<Case<CustomEffect>> out = new ArrayList<Case<CustomEffect>>();
|
|
||||||
|
|
||||||
CustomEffect bare = effect(1, "Bare");
|
|
||||||
out.add(new Case<CustomEffect>("", bare,
|
|
||||||
"every field at its constructor default. Note menuName defaults to a coloured "
|
|
||||||
+ "'NEW EFFECT' containing a section sign, so even the bare case is not ASCII"));
|
|
||||||
|
|
||||||
CustomEffect full = effect(2, "Fully Configured");
|
|
||||||
full.menuName = Text.SECTION + "bFully " + Text.SECTION + "6Configured";
|
|
||||||
full.length = 1200;
|
|
||||||
full.everyXTick = 10;
|
|
||||||
full.lossOnDeath = false;
|
|
||||||
full.icon = "customnpcs:textures/gui/effects.png";
|
|
||||||
full.iconX = 32;
|
|
||||||
full.iconY = 48;
|
|
||||||
full.width = 24;
|
|
||||||
full.height = 24;
|
|
||||||
out.add(new Case<CustomEffect>("", full,
|
|
||||||
"every scalar off its default: a 60-second duration, a 10-tick period, an icon with "
|
|
||||||
+ "its atlas offsets and size, and lossOnDeath cleared"));
|
|
||||||
|
|
||||||
CustomEffect animated = effect(3, "Animated Icon");
|
|
||||||
animated.animated = true;
|
|
||||||
animated.frameCount = 8;
|
|
||||||
animated.frametime = 3;
|
|
||||||
animated.icon = "customnpcs:textures/gui/anim.png";
|
|
||||||
out.add(new Case<CustomEffect>("", animated,
|
|
||||||
"an animated icon -- iconAnimated, iconFrameCount and iconFrameTime. Both counts are "
|
|
||||||
+ "clamped to a minimum of 1 on read, so zero cannot round-trip"));
|
|
||||||
|
|
||||||
CustomEffect tagged = effect(4, "Tagged");
|
|
||||||
tagged.tagUUIDs.addAll(Arrays.asList(
|
|
||||||
UUID.fromString("0e5f2b6a-1c3d-4e5f-8a9b-0c1d2e3f4a5b"),
|
|
||||||
UUID.fromString("1a2b3c4d-5e6f-4071-8293-a4b5c6d7e8f9"),
|
|
||||||
UUID.fromString("ffffffff-ffff-4fff-bfff-ffffffffffff")));
|
|
||||||
out.add(new Case<CustomEffect>("", tagged,
|
|
||||||
"three tag UUIDs. TagController.writeTagUUIDs omits the key entirely when the set is "
|
|
||||||
+ "empty, so every other effect here has no TagUUIDs key at all"));
|
|
||||||
|
|
||||||
CustomEffect scripted = effect(5, "Scripted");
|
|
||||||
scripted.setScriptHandler(script(
|
|
||||||
"function onEffectAdd(event) { event.player.message('effect added'); }\n"
|
|
||||||
+ "function onEffectTick(event) {}\n"
|
|
||||||
+ "function onEffectRemove(event) {}\n", true, "ECMAScript"));
|
|
||||||
out.add(new Case<CustomEffect>("", scripted,
|
|
||||||
"a ScriptData compound carrying ScriptLanguage, ScriptEnabled and a ScriptContent "
|
|
||||||
+ "unit with three hook functions"));
|
|
||||||
|
|
||||||
CustomEffect scriptDisabled = effect(6, "Script Disabled");
|
|
||||||
scriptDisabled.setScriptHandler(script("function onEffectTick(event) {}", false, "javascript"));
|
|
||||||
out.add(new Case<CustomEffect>("", scriptDisabled,
|
|
||||||
"ScriptEnabled false, and a language string that is not the canonical 'ECMAScript' -- "
|
|
||||||
+ "normalizeLanguage runs on read, not on write"));
|
|
||||||
|
|
||||||
CustomEffect hugeScript = effect(7, "Huge Script");
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
while (sb.length() < 70000) {
|
|
||||||
sb.append("// a line of script that exists only to push past the 65535 char limit\n");
|
|
||||||
}
|
|
||||||
hugeScript.setScriptHandler(script(sb.toString(), true, "ECMAScript"));
|
|
||||||
out.add(new Case<CustomEffect>("", hugeScript,
|
|
||||||
"a script over 65535 characters. NBT strings cannot hold that, so ScriptContainer "
|
|
||||||
+ "splits it across Script plus ExpandedScript0..N, bounded by "
|
|
||||||
+ "ConfigScript.ExpandedScriptLimit which defaults to 2. Check the written file "
|
|
||||||
+ "to see how many parts survived -- this fixture exists to record that"));
|
|
||||||
|
|
||||||
CustomEffect noName = effect(8, "");
|
|
||||||
out.add(new Case<CustomEffect>("", noName,
|
|
||||||
"an EMPTY name. writeMapNBT skips these, so this effect is absent from "
|
|
||||||
+ "customeffects.dat while its file exists on disk -- and since the filename is "
|
|
||||||
+ "the name, its file is '.json'. Recorded rather than avoided"));
|
|
||||||
|
|
||||||
CustomEffect categorised = effect(10, "In A Category");
|
|
||||||
out.add(new Case<CustomEffect>("Buffs", categorised,
|
|
||||||
"an effect inside a category subdirectory. Categories are directories and nothing "
|
|
||||||
+ "else -- there is no category file and no id stored anywhere"));
|
|
||||||
|
|
||||||
CustomEffect unicode = effect(11, "Unicode");
|
|
||||||
unicode.menuName = Text.KATAKANA_FACTION + " " + Text.EM_DASH + " " + Text.ELEVES;
|
|
||||||
out.add(new Case<CustomEffect>("Buffs", unicode,
|
|
||||||
"a non-Latin menu name inside a category"));
|
|
||||||
|
|
||||||
CustomEffect extremes = effect(12, "Extremes");
|
|
||||||
extremes.length = Integer.MAX_VALUE;
|
|
||||||
extremes.everyXTick = Integer.MAX_VALUE;
|
|
||||||
extremes.iconX = Integer.MIN_VALUE;
|
|
||||||
extremes.iconY = Integer.MIN_VALUE;
|
|
||||||
extremes.width = 0;
|
|
||||||
extremes.height = 0;
|
|
||||||
extremes.frameCount = 0;
|
|
||||||
extremes.frametime = 0;
|
|
||||||
out.add(new Case<CustomEffect>("", extremes,
|
|
||||||
"integer boundaries, plus zero width, height, frame count and frame time. Width and "
|
|
||||||
+ "height fall back to 16 on read only when their key is ABSENT, so an explicit "
|
|
||||||
+ "zero survives where a missing key does not"));
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The filename for {@link #nameMismatch()}, deliberately unequal to the effect's name field.
|
|
||||||
*/
|
|
||||||
public static final String MISMATCH_FILENAME = "Name On Disk";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An effect whose {@code name} key disagrees with its filename.
|
|
||||||
*
|
|
||||||
* <p>Kept out of {@link #maximal()} because it cannot be expressed there: everything in that
|
|
||||||
* list is written to a file named after the effect, which is what makes a mismatch impossible
|
|
||||||
* to state. loadEffectsFromDir assigns {@code effect.name} from the filename after reading, so
|
|
||||||
* the key inside is discarded and a reader that trusts it gets a different answer.
|
|
||||||
*/
|
|
||||||
public static CustomEffect nameMismatch() {
|
|
||||||
CustomEffect mismatched = effect(9, "Name Inside The File");
|
|
||||||
return mismatched;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The index document. Copied from CustomEffectController.writeMapNBT. */
|
|
||||||
public static NBTTagCompound index(List<Case<CustomEffect>> effects, int lastUsedId) {
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
for (Case<CustomEffect> c : effects) {
|
|
||||||
CustomEffect effect = c.value;
|
|
||||||
// writeMapNBT skips unnamed effects. Reproduced, because the omission is the contract.
|
|
||||||
if (!effect.getName().isEmpty()) {
|
|
||||||
NBTTagCompound entry = new NBTTagCompound();
|
|
||||||
entry.setString("Name", effect.getName());
|
|
||||||
entry.setInteger("ID", effect.id);
|
|
||||||
list.appendTag(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setTag("CustomEffects", list);
|
|
||||||
compound.setInteger("lastID", lastUsedId);
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CustomEffect effect(int id, String name) {
|
|
||||||
CustomEffect effect = new CustomEffect();
|
|
||||||
effect.id = id;
|
|
||||||
effect.name = name;
|
|
||||||
return effect;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static EffectScript script(String source, boolean enabled, String language) {
|
|
||||||
EffectScript handler = new EffectScript();
|
|
||||||
handler.setLanguage(language);
|
|
||||||
handler.setEnabled(enabled);
|
|
||||||
ScriptContainer container = new ScriptContainer(handler);
|
|
||||||
container.script = source;
|
|
||||||
handler.addScriptUnit(container);
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.content;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import noppes.npcs.controllers.data.Faction;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factions, and the {@code factions.dat} document that holds them.
|
|
||||||
*
|
|
||||||
* <p>Layout copied from FactionController.getNBT: {@code lastID} plus an {@code NPCFactions} list
|
|
||||||
* of {@link Faction#writeNBT} compounds. The controller iterates a HashMap; this iterates a list,
|
|
||||||
* so the order is stable between runs. Order is not part of the format -- the loader keys each
|
|
||||||
* entry on its own {@code Slot} -- but an unstable order would make every regeneration a diff.
|
|
||||||
*/
|
|
||||||
public final class FactionFixtures {
|
|
||||||
|
|
||||||
private FactionFixtures() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The three CustomNPC+ creates for a new world, when factions.dat is absent or empty. */
|
|
||||||
public static List<Faction> vanillaDefaults() {
|
|
||||||
return new ArrayList<Faction>(Arrays.asList(
|
|
||||||
new Faction(0, "Friendly", 0x00DD00, 2000),
|
|
||||||
new Faction(1, "Neutral", 0xF2DD00, 1000),
|
|
||||||
new Faction(2, "Aggressive", 0xDD0000, 0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Every flag and threshold moved off its default, and the mutual-hostility graph populated.
|
|
||||||
*
|
|
||||||
* <p>The three booleans are the interesting part for a port: {@code hideFaction} suppresses the
|
|
||||||
* standing message, {@code getsAttacked} lets vanilla mobs target members, {@code isPassive}
|
|
||||||
* stops members retaliating. They are independent, so they get an entry each rather than one
|
|
||||||
* faction with all three set.
|
|
||||||
*/
|
|
||||||
public static List<Faction> maximal() {
|
|
||||||
List<Faction> factions = vanillaDefaults();
|
|
||||||
|
|
||||||
Faction hidden = faction(10, "Hidden Watchers", 0x2B2B2B, 900);
|
|
||||||
hidden.hideFaction = true;
|
|
||||||
hidden.neutralPoints = 250;
|
|
||||||
hidden.friendlyPoints = 2750;
|
|
||||||
factions.add(hidden);
|
|
||||||
|
|
||||||
Faction attacked = faction(11, "Hunted", 0xAA5500, 1200);
|
|
||||||
attacked.getsAttacked = true;
|
|
||||||
factions.add(attacked);
|
|
||||||
|
|
||||||
Faction passive = faction(12, "Pacifists", 0x55FFFF, 1800);
|
|
||||||
passive.isPassive = true;
|
|
||||||
factions.add(passive);
|
|
||||||
|
|
||||||
Faction all = faction(13, "Every Flag", 0xFF00FF, 0);
|
|
||||||
all.hideFaction = true;
|
|
||||||
all.getsAttacked = true;
|
|
||||||
all.isPassive = true;
|
|
||||||
all.neutralPoints = 0;
|
|
||||||
all.friendlyPoints = 0;
|
|
||||||
factions.add(all);
|
|
||||||
|
|
||||||
// A hostility graph rather than a single edge: the reader has to keep a set per faction,
|
|
||||||
// and a reader that keeps one integer looks correct until the second entry.
|
|
||||||
Faction warring = faction(14, "Iron Legion", 0xB0B0B0, 400);
|
|
||||||
warring.attackFactions.addAll(Arrays.asList(2, 10, 11, 12));
|
|
||||||
factions.add(warring);
|
|
||||||
|
|
||||||
Faction rival = faction(15, "Ash Covenant", 0x7A0000, 600);
|
|
||||||
rival.attackFactions.addAll(Arrays.asList(14, 0));
|
|
||||||
factions.add(rival);
|
|
||||||
|
|
||||||
// Thresholds inverted -- friendly below neutral. CustomNPC+ does not validate this, and
|
|
||||||
// Availability and Faction read the boundary differently, so it is worth having on disk.
|
|
||||||
Faction inverted = faction(16, "Inverted Bands", 0x123456, 1000);
|
|
||||||
inverted.neutralPoints = 1800;
|
|
||||||
inverted.friendlyPoints = 200;
|
|
||||||
factions.add(inverted);
|
|
||||||
|
|
||||||
Faction negative = faction(17, "Debtors", 0x000080, -500);
|
|
||||||
negative.neutralPoints = -1000;
|
|
||||||
negative.friendlyPoints = -100;
|
|
||||||
factions.add(negative);
|
|
||||||
|
|
||||||
return factions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Names and values that are legal, unusual, and have broken a reader somewhere. */
|
|
||||||
public static List<Faction> edge() {
|
|
||||||
List<Faction> factions = new ArrayList<Faction>();
|
|
||||||
|
|
||||||
factions.add(faction(0, "", 0, 0));
|
|
||||||
|
|
||||||
// Built from code points rather than written as literals. This source stays pure ASCII on
|
|
||||||
// purpose: a generator whose own file gets mojibaked by a CP-1252 toolchain would emit
|
|
||||||
// fixtures that assert the mojibake, and every reader downstream would agree with it.
|
|
||||||
Faction unicode = faction(1, Text.KATAKANA_FACTION + " " + Text.EM_DASH + " " + Text.ELEVES,
|
|
||||||
0xFFFFFF, 1000);
|
|
||||||
factions.add(unicode);
|
|
||||||
|
|
||||||
Faction formatting = faction(2,
|
|
||||||
Text.SECTION + "cRed " + Text.SECTION + "lBold" + Text.SECTION + "r", 0xFF5555, 1000);
|
|
||||||
factions.add(formatting);
|
|
||||||
|
|
||||||
Faction longName = faction(3, repeat("Faction With A Very Long Name ", 12), 0x00FF00, 1000);
|
|
||||||
factions.add(longName);
|
|
||||||
|
|
||||||
Faction extremes = faction(4, "Integer Extremes", 0xFFFFFF, Integer.MAX_VALUE);
|
|
||||||
extremes.neutralPoints = Integer.MIN_VALUE;
|
|
||||||
extremes.friendlyPoints = Integer.MAX_VALUE;
|
|
||||||
extremes.color = -1;
|
|
||||||
factions.add(extremes);
|
|
||||||
|
|
||||||
// Points to factions that are not in this file. A converter that resolves eagerly breaks
|
|
||||||
// here; one that keeps the id does not.
|
|
||||||
Faction dangling = faction(5, "Dangling References", 0x808080, 1000);
|
|
||||||
dangling.attackFactions.addAll(Arrays.asList(9001, -3, 0));
|
|
||||||
factions.add(dangling);
|
|
||||||
|
|
||||||
// A non-contiguous, high id. Nothing requires ids to be dense, and lastID is separate.
|
|
||||||
factions.add(faction(4096, "Sparse Id", 0x00FFFF, 1000));
|
|
||||||
|
|
||||||
return factions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The controller-shaped document. Copied from FactionController.getNBT. */
|
|
||||||
public static NBTTagCompound document(List<Faction> factions, int lastUsedId) {
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
for (Faction faction : factions) {
|
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
|
||||||
faction.writeNBT(tag);
|
|
||||||
list.appendTag(tag);
|
|
||||||
}
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setInteger("lastID", lastUsedId);
|
|
||||||
compound.setTag("NPCFactions", list);
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Faction faction(int id, String name, int color, int defaultPoints) {
|
|
||||||
return new Faction(id, name, color, defaultPoints);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String repeat(String s, int times) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < times; i++) {
|
|
||||||
sb.append(s);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.content;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.Case;
|
|
||||||
import kamkeel.npcs.fixtures.Fixtures;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import noppes.npcs.controllers.data.PlayerData;
|
|
||||||
import noppes.npcs.controllers.data.Quest;
|
|
||||||
import noppes.npcs.controllers.data.QuestData;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Per-player records, and the name/uuid index beside them.
|
|
||||||
*
|
|
||||||
* <p>A record is {@code playerdata/<uuid>.json}, written by {@code PlayerData.getNBT}, which
|
|
||||||
* composes fifteen sub-writers -- dialog, bank, quest, transport, faction, item giver, mail,
|
|
||||||
* timers, skin overlays, animation, effect, magic, trade, ability and hotbar. Only some are
|
|
||||||
* populated here; the rest write their empty form, which is itself worth having, since "what an
|
|
||||||
* untouched sub-record looks like" is a contract too.
|
|
||||||
*
|
|
||||||
* <p>{@code playerdatamap.dat} is a flat {@code {Name, UUID}} list. It is a lookup index rebuilt
|
|
||||||
* by scanning the directory when absent, so it is derived rather than authoritative -- but it is
|
|
||||||
* what CustomNPC+ reads first.
|
|
||||||
*
|
|
||||||
* <p>The record can also be gzipped NBT rather than JSON, chosen by {@code ConfigMain.DatFormat}.
|
|
||||||
* Both forms are generated, because a reader that only handles the default will meet the other on
|
|
||||||
* somebody's server.
|
|
||||||
*/
|
|
||||||
public final class PlayerFixtures {
|
|
||||||
|
|
||||||
private PlayerFixtures() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** uuid -> display name, in a fixed order so the index document is reproducible. */
|
|
||||||
public static Map<String, String> roster() {
|
|
||||||
Map<String, String> roster = new LinkedHashMap<String, String>();
|
|
||||||
roster.put("29cc52dd-2c50-4e8f-a388-be6c497cf0b4", "Fresh");
|
|
||||||
roster.put("8667ba71-b85a-4004-af54-457a9734eed7", "Progressed");
|
|
||||||
roster.put("069a79f4-44e9-4726-a5be-fca90e38aaf5", "Notch");
|
|
||||||
roster.put("00000000-0000-0000-0000-000000000000", "NilUuid");
|
|
||||||
return roster;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Case<PlayerData>> records() {
|
|
||||||
List<Case<PlayerData>> out = new ArrayList<Case<PlayerData>>();
|
|
||||||
|
|
||||||
PlayerData fresh = player("29cc52dd-2c50-4e8f-a388-be6c497cf0b4", "Fresh");
|
|
||||||
out.add(new Case<PlayerData>("", fresh,
|
|
||||||
"a player who has done nothing. Every one of the fifteen sub-records writes its empty "
|
|
||||||
+ "form -- the baseline for what an untouched record contains"));
|
|
||||||
|
|
||||||
PlayerData progressed = player("8667ba71-b85a-4004-af54-457a9734eed7", "Progressed");
|
|
||||||
progressed.dialogData.dialogsRead.addAll(Arrays.asList(1, 2, 3, 41, 90));
|
|
||||||
progressed.factionData.factionData.put(0, 1800);
|
|
||||||
progressed.factionData.factionData.put(1, 1000);
|
|
||||||
progressed.factionData.factionData.put(2, 0);
|
|
||||||
progressed.factionData.factionData.put(14, -250);
|
|
||||||
progressed.questData.finishedQuests.put(1, Fixtures.EPOCH);
|
|
||||||
progressed.questData.finishedQuests.put(30, Fixtures.EPOCH + 86400000L);
|
|
||||||
progressed.questData.activeQuests.put(2, questData(2, false));
|
|
||||||
progressed.questData.activeQuests.put(71, questData(71, true));
|
|
||||||
progressed.companionID = 4;
|
|
||||||
progressed.profileSlot = 2;
|
|
||||||
out.add(new Case<PlayerData>("", progressed,
|
|
||||||
"read dialogs, standing in four factions including a negative one, two finished "
|
|
||||||
+ "quests with completion timestamps, and two active quests -- one of them marked "
|
|
||||||
+ "complete but not turned in. Also a companion id and a non-zero profile slot"));
|
|
||||||
|
|
||||||
PlayerData extras = player("069a79f4-44e9-4726-a5be-fca90e38aaf5", "Notch");
|
|
||||||
QuestData withExtras = questData(75, false);
|
|
||||||
withExtras.extraData.setTag("Killed", killed("Zombie", 14, "Skeleton", 3));
|
|
||||||
withExtras.extraData.setBoolean("LocationFound", true);
|
|
||||||
withExtras.extraData.setBoolean("Location2Found", true);
|
|
||||||
extras.questData.activeQuests.put(75, withExtras);
|
|
||||||
extras.dialogData.dialogsRead.add(58);
|
|
||||||
out.add(new Case<PlayerData>("", extras,
|
|
||||||
"an active quest whose ExtraData holds per-objective progress, in the shapes the "
|
|
||||||
+ "quest classes actually read. Kill counts are a Killed tag list of Slot/Value "
|
|
||||||
+ "compounds -- NBTTags.getStringIntegerMap -- not loose integers keyed by mob "
|
|
||||||
+ "name, and a reached location is a boolean under its own key. The quest stores "
|
|
||||||
+ "only the targets, so a reader that ignores ExtraData can never show progress"));
|
|
||||||
|
|
||||||
PlayerData party = player("11111111-2222-3333-4444-555555555555", "PartyMember");
|
|
||||||
QuestData shared = questData(76, false);
|
|
||||||
// The per-player half of a party kill quest: QuestKill keys it by the player's own name
|
|
||||||
// rather than by slot, so two members of one party each carry their own tally.
|
|
||||||
shared.extraData.setTag("PartyMemberKilled", killed("Creeper", 2));
|
|
||||||
shared.extraData.setTag("Killed", killed("Creeper", 5));
|
|
||||||
party.questData.activeQuests.put(76, shared);
|
|
||||||
out.add(new Case<PlayerData>("", party,
|
|
||||||
"a party kill quest, which stores the group total under Killed and each member's own "
|
|
||||||
+ "share under <playerName>Killed. The second key is composed from a name, so it "
|
|
||||||
+ "cannot be enumerated from the quest -- only from the party that took it"));
|
|
||||||
|
|
||||||
PlayerData foreign = player("22222222-3333-4444-5555-666666666666", "AddonUser");
|
|
||||||
QuestData unclaimed = questData(77, false);
|
|
||||||
// ExtraData is an opaque compound: nothing validates its keys, so an addon that stores
|
|
||||||
// its own progress there produces a file no objective kind here can read. Deliberate,
|
|
||||||
// and the case a reader has to report rather than silently drop.
|
|
||||||
unclaimed.extraData.setInteger("dbcaddon:KiCharged", 900);
|
|
||||||
unclaimed.extraData.setString("dbcaddon:Form", "SuperSaiyan");
|
|
||||||
foreign.questData.activeQuests.put(77, unclaimed);
|
|
||||||
out.add(new Case<PlayerData>("", foreign,
|
|
||||||
"an active quest whose ExtraData holds only keys no objective kind claims, which is "
|
|
||||||
+ "what an addon writing its own progress leaves behind. Nothing validates this "
|
|
||||||
+ "compound, so a reader meets it on a real server and has to say so rather than "
|
|
||||||
+ "drop it"));
|
|
||||||
|
|
||||||
PlayerData nil = player("00000000-0000-0000-0000-000000000000", "NilUuid");
|
|
||||||
nil.dialogData.dialogsRead.add(1);
|
|
||||||
out.add(new Case<PlayerData>("", nil,
|
|
||||||
"the nil UUID, which is legal in the file and names no player. A reader that treats "
|
|
||||||
+ "it as absent rather than as a value diverges here"));
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** PlayerDataController.writeNBT -- a flat Name/UUID list, with no lastID. */
|
|
||||||
public static NBTTagCompound index(Map<String, String> roster) {
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
for (Map.Entry<String, String> entry : roster.entrySet()) {
|
|
||||||
NBTTagCompound player = new NBTTagCompound();
|
|
||||||
// The controller keys the map by NAME and stores the uuid as the value, which is the
|
|
||||||
// opposite of what the file's key order suggests at a glance.
|
|
||||||
player.setString("Name", entry.getValue());
|
|
||||||
player.setString("UUID", entry.getKey());
|
|
||||||
list.appendTag(player);
|
|
||||||
}
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setTag("PlayerDataMap", list);
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PlayerData player(String uuid, String name) {
|
|
||||||
PlayerData data = new PlayerData();
|
|
||||||
data.uuid = uuid;
|
|
||||||
data.playername = name;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An entry in a player's active quest list.
|
|
||||||
*
|
|
||||||
* <p>{@code QuestData} needs a {@link Quest} to construct, but only writes three keys and
|
|
||||||
* never touches it -- the quest id is the map key in the enclosing list, not part of the
|
|
||||||
* entry. So a bare Quest carrying the right id is enough and nothing is invented.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* A counter map in the shape {@code NBTTags.nbtStringIntegerMap} writes and
|
|
||||||
* {@code getStringIntegerMap} reads: a list of {@code {Slot, Value}} compounds.
|
|
||||||
*
|
|
||||||
* <p>Written out by hand rather than through {@code NBTTags} so the fixture states the shape
|
|
||||||
* it is asserting. A generator that borrows the reader's own helper agrees with it by
|
|
||||||
* construction and proves nothing about it.
|
|
||||||
*/
|
|
||||||
private static NBTTagList killed(Object... slotsAndCounts) {
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
for (int at = 0; at < slotsAndCounts.length; at += 2) {
|
|
||||||
NBTTagCompound entry = new NBTTagCompound();
|
|
||||||
entry.setString("Slot", (String) slotsAndCounts[at]);
|
|
||||||
entry.setInteger("Value", ((Integer) slotsAndCounts[at + 1]).intValue());
|
|
||||||
list.appendTag(entry);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static QuestData questData(int questId, boolean completed) {
|
|
||||||
Quest quest = new Quest();
|
|
||||||
quest.id = questId;
|
|
||||||
QuestData data = new QuestData(quest);
|
|
||||||
data.isCompleted = completed;
|
|
||||||
data.sendAlerts = true;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,445 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.content;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.Case;
|
|
||||||
import kamkeel.npcs.fixtures.Fixtures;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import noppes.npcs.constants.EnumPartyExchange;
|
|
||||||
import noppes.npcs.constants.EnumPartyObjectives;
|
|
||||||
import noppes.npcs.constants.EnumPartyRequirements;
|
|
||||||
import noppes.npcs.constants.EnumProfileSync;
|
|
||||||
import noppes.npcs.constants.EnumQuestCompletion;
|
|
||||||
import noppes.npcs.constants.EnumQuestRepeat;
|
|
||||||
import noppes.npcs.constants.EnumQuestType;
|
|
||||||
import noppes.npcs.controllers.data.Quest;
|
|
||||||
import noppes.npcs.quests.QuestDialog;
|
|
||||||
import noppes.npcs.quests.QuestItem;
|
|
||||||
import noppes.npcs.quests.QuestKill;
|
|
||||||
import noppes.npcs.quests.QuestLocation;
|
|
||||||
import noppes.npcs.quests.QuestManual;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quests, one axis at a time.
|
|
||||||
*
|
|
||||||
* <p><b>A quest has no availability.</b> Worth stating because it is easy to conclude otherwise:
|
|
||||||
* {@code Quest.readNBTPartial} calls {@code VersionCompatibility.CheckAvailabilityCompatibility},
|
|
||||||
* whose name says availability, and which is in fact a generic "fill in keys this file predates"
|
|
||||||
* pass applied to every {@code ICompatibilty}. {@code Quest} declares no {@code Availability}
|
|
||||||
* field, {@code writeToNBTPartial} writes no {@code Availability*} key, and neither does the 1.20
|
|
||||||
* line. Gating is a property of the dialog that offers the quest.
|
|
||||||
*
|
|
||||||
* <p>Ranges: 1-9 the six types, 10-29 repeat and completion, 30-49 rewards, 50-69 party and
|
|
||||||
* profile, 70-89 objectives in depth, 90-99 combinations.
|
|
||||||
*/
|
|
||||||
public final class QuestFixtures {
|
|
||||||
|
|
||||||
private QuestFixtures() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Case<Quest>> maximal() {
|
|
||||||
List<Case<Quest>> out = new ArrayList<Case<Quest>>();
|
|
||||||
types(out);
|
|
||||||
repeatAndCompletion(out);
|
|
||||||
rewards(out);
|
|
||||||
partyAndProfile(out);
|
|
||||||
objectives(out);
|
|
||||||
combinations(out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ types
|
|
||||||
|
|
||||||
private static void types(List<Case<Quest>> out) {
|
|
||||||
int id = 1;
|
|
||||||
for (EnumQuestType type : EnumQuestType.values()) {
|
|
||||||
Quest quest = quest(id, "Type " + type.name(), type);
|
|
||||||
populateObjective(quest, type);
|
|
||||||
out.add(new Case<Quest>("Types", quest,
|
|
||||||
"quest type " + type.name() + " (ordinal " + type.ordinal() + ") with its "
|
|
||||||
+ "objective populated. NOTE: Kill and AreaKill both build a QuestKill and "
|
|
||||||
+ "write the same keys -- the only thing separating them on disk is Type"));
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Kill and AreaKill differ by Type alone, so they get compared directly. */
|
|
||||||
private static void populateObjective(Quest quest, EnumQuestType type) {
|
|
||||||
if (type == EnumQuestType.Item) {
|
|
||||||
QuestItem items = (QuestItem) quest.questInterface;
|
|
||||||
items.items.items.put(0, Fixtures.item("minecraft:iron_ingot", 12));
|
|
||||||
items.items.items.put(1, Fixtures.namedItem("minecraft:written_book", 1, 0, "Proof"));
|
|
||||||
items.leaveItems = true;
|
|
||||||
items.ignoreDamage = true;
|
|
||||||
items.ignoreNBT = false;
|
|
||||||
} else if (type == EnumQuestType.Dialog) {
|
|
||||||
QuestDialog dialogs = (QuestDialog) quest.questInterface;
|
|
||||||
dialogs.dialogs.put(0, 1);
|
|
||||||
dialogs.dialogs.put(1, 2);
|
|
||||||
dialogs.dialogs.put(2, 3);
|
|
||||||
} else if (type == EnumQuestType.Kill || type == EnumQuestType.AreaKill) {
|
|
||||||
QuestKill kill = (QuestKill) quest.questInterface;
|
|
||||||
kill.targets.put("Zombie", 20);
|
|
||||||
kill.targets.put("Skeleton", 15);
|
|
||||||
kill.targetType = type == EnumQuestType.AreaKill ? 1 : 0;
|
|
||||||
kill.customTargetType = "noppes.npcs.entity.EntityCustomNpc";
|
|
||||||
} else if (type == EnumQuestType.Location) {
|
|
||||||
QuestLocation location = (QuestLocation) quest.questInterface;
|
|
||||||
location.location = "Northern Watchtower";
|
|
||||||
location.location2 = "Sunken Crypt";
|
|
||||||
location.location3 = "The Long Bridge";
|
|
||||||
} else if (type == EnumQuestType.Manual) {
|
|
||||||
QuestManual manual = (QuestManual) quest.questInterface;
|
|
||||||
manual.manuals.put("Speak to the smith", 1);
|
|
||||||
manual.manuals.put("Gather reeds", 30);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ repeat and completion
|
|
||||||
|
|
||||||
private static void repeatAndCompletion(List<Case<Quest>> out) {
|
|
||||||
int id = 10;
|
|
||||||
for (EnumQuestRepeat repeat : EnumQuestRepeat.values()) {
|
|
||||||
Quest quest = quest(id, "Repeat " + repeat.name(), EnumQuestType.Manual);
|
|
||||||
quest.repeat = repeat;
|
|
||||||
// The two CUSTOM modes are the only ones that read customCooldown, but it is written
|
|
||||||
// unconditionally, so setting it everywhere shows that.
|
|
||||||
quest.customCooldown = 3600000L;
|
|
||||||
((QuestManual) quest.questInterface).manuals.put("Do the thing", 1);
|
|
||||||
out.add(new Case<Quest>("Repeat", quest,
|
|
||||||
"QuestRepeat = " + repeat.name() + " (ordinal " + repeat.ordinal() + ") with "
|
|
||||||
+ "CustomCooldown 3600000. MCDAILY/MCWEEKLY count world ticks, RLDAILY/RLWEEKLY "
|
|
||||||
+ "count wall time, and only MCCUSTOM/RLCUSTOM read the cooldown"));
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int completionId = 18;
|
|
||||||
for (EnumQuestCompletion completion : EnumQuestCompletion.values()) {
|
|
||||||
Quest quest = quest(completionId, "Completion " + completion.name(), EnumQuestType.Manual);
|
|
||||||
quest.completion = completion;
|
|
||||||
quest.completerNpc = completion == EnumQuestCompletion.Npc ? "Quest Giver" : "";
|
|
||||||
((QuestManual) quest.questInterface).manuals.put("Do the thing", 1);
|
|
||||||
out.add(new Case<Quest>("Repeat", quest,
|
|
||||||
"QuestCompletion = " + completion.name() + ". Npc requires turning in to the named "
|
|
||||||
+ "NPC; Instant completes the moment the objective is met"));
|
|
||||||
completionId++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Quest cooldownExtremes = quest(20, "Cooldown Extremes", EnumQuestType.Manual);
|
|
||||||
cooldownExtremes.repeat = EnumQuestRepeat.RLCUSTOM;
|
|
||||||
cooldownExtremes.customCooldown = Long.MAX_VALUE;
|
|
||||||
((QuestManual) cooldownExtremes.questInterface).manuals.put("Wait", 1);
|
|
||||||
out.add(new Case<Quest>("Repeat", cooldownExtremes,
|
|
||||||
"CustomCooldown at Long.MAX_VALUE -- the one long on a quest, and the field most "
|
|
||||||
+ "likely to be narrowed to an int by a reader"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ rewards
|
|
||||||
|
|
||||||
private static void rewards(List<Case<Quest>> out) {
|
|
||||||
Quest exp = quest(30, "Experience Reward", EnumQuestType.Manual);
|
|
||||||
exp.rewardExp = 2500;
|
|
||||||
((QuestManual) exp.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", exp, "RewardExp only"));
|
|
||||||
|
|
||||||
Quest items = quest(31, "Item Rewards", EnumQuestType.Manual);
|
|
||||||
items.rewardItems.items.put(0, Fixtures.item("minecraft:diamond", 5));
|
|
||||||
items.rewardItems.items.put(1, Fixtures.item("minecraft:gold_ingot", 32));
|
|
||||||
items.rewardItems.items.put(8, Fixtures.namedItem("minecraft:diamond_pickaxe", 1, 3, "Miner's Due"));
|
|
||||||
((QuestManual) items.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", items,
|
|
||||||
"three of the nine reward slots filled, including slot 8 and one stack with custom "
|
|
||||||
+ "NBT. Stored under the Rewards tag as an NpcMiscInventory"));
|
|
||||||
|
|
||||||
Quest full = quest(32, "Nine Item Rewards", EnumQuestType.Manual);
|
|
||||||
String[] nine = {
|
|
||||||
"minecraft:stone", "minecraft:dirt", "minecraft:oak_stairs", "minecraft:torch",
|
|
||||||
"minecraft:bread", "minecraft:coal", "minecraft:string", "minecraft:bone",
|
|
||||||
"minecraft:paper"
|
|
||||||
};
|
|
||||||
for (int i = 0; i < nine.length; i++) {
|
|
||||||
full.rewardItems.items.put(i, Fixtures.item(nine[i], i + 1));
|
|
||||||
}
|
|
||||||
((QuestManual) full.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", full,
|
|
||||||
"all nine reward slots filled, each a different count -- the inventory at capacity"));
|
|
||||||
|
|
||||||
Quest random = quest(33, "Random Reward", EnumQuestType.Manual);
|
|
||||||
random.randomReward = true;
|
|
||||||
random.rewardItems.items.put(0, Fixtures.item("minecraft:emerald", 1));
|
|
||||||
random.rewardItems.items.put(1, Fixtures.item("minecraft:redstone", 1));
|
|
||||||
((QuestManual) random.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", random,
|
|
||||||
"RandomReward true -- one of the reward slots is granted rather than all of them"));
|
|
||||||
|
|
||||||
Quest faction = quest(34, "Faction Reward", EnumQuestType.Manual);
|
|
||||||
faction.factionOptions.factionId = 14;
|
|
||||||
faction.factionOptions.factionPoints = 500;
|
|
||||||
faction.factionOptions.decreaseFactionPoints = false;
|
|
||||||
faction.factionOptions.faction2Id = 15;
|
|
||||||
faction.factionOptions.faction2Points = 250;
|
|
||||||
faction.factionOptions.decreaseFaction2Points = true;
|
|
||||||
((QuestManual) faction.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", faction,
|
|
||||||
"both faction reward slots, nested under QuestFactionPoints -- note a dialog writes "
|
|
||||||
+ "the same FactionOptions keys flat, not nested"));
|
|
||||||
|
|
||||||
Quest mail = quest(35, "Mail Reward", EnumQuestType.Manual);
|
|
||||||
mail.mail.subject = "Your reward";
|
|
||||||
mail.mail.sender = "The Guild";
|
|
||||||
mail.mail.time = Fixtures.EPOCH;
|
|
||||||
NBTTagCompound message = new NBTTagCompound();
|
|
||||||
message.setString("Text", "Enclosed, with thanks.");
|
|
||||||
mail.mail.message = message;
|
|
||||||
mail.mail.items[0] = Fixtures.item("minecraft:gold_nugget", 64);
|
|
||||||
mail.mail.items[3] = Fixtures.item("minecraft:cake", 1);
|
|
||||||
((QuestManual) mail.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", mail,
|
|
||||||
"QuestMail with two of four item slots, including the last slot"));
|
|
||||||
|
|
||||||
Quest command = quest(36, "Command On Completion", EnumQuestType.Manual);
|
|
||||||
command.command = "/give {player} minecraft:diamond 1";
|
|
||||||
((QuestManual) command.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", command, "QuestCommand with a {player} placeholder"));
|
|
||||||
|
|
||||||
Quest chain = quest(37, "Chains To Another", EnumQuestType.Manual);
|
|
||||||
chain.nextQuestid = 30;
|
|
||||||
chain.nextQuestTitle = "Experience Reward";
|
|
||||||
((QuestManual) chain.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", chain,
|
|
||||||
"NextQuestId 30 with a matching NextQuestTitle. On read CustomNPC+ overwrites the "
|
|
||||||
+ "title from the live controller and blanks it when the target is missing, so "
|
|
||||||
+ "the id is the real link and the title is a cache"));
|
|
||||||
|
|
||||||
Quest danglingChain = quest(38, "Chains Nowhere", EnumQuestType.Manual);
|
|
||||||
danglingChain.nextQuestid = 999999;
|
|
||||||
danglingChain.nextQuestTitle = "A quest that does not exist";
|
|
||||||
((QuestManual) danglingChain.questInterface).manuals.put("Earn it", 1);
|
|
||||||
out.add(new Case<Quest>("Rewards", danglingChain,
|
|
||||||
"NextQuestId pointing at nothing, with a stale title still on disk -- what a world "
|
|
||||||
+ "looks like after the target quest was deleted"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ party and profile
|
|
||||||
|
|
||||||
private static void partyAndProfile(List<Case<Quest>> out) {
|
|
||||||
// The party block is written only when AllowParty is true. Both halves matter.
|
|
||||||
Quest disabled = quest(50, "Party Disabled", EnumQuestType.Manual);
|
|
||||||
disabled.partyOptions.allowParty = false;
|
|
||||||
disabled.partyOptions.minPartySize = 4;
|
|
||||||
disabled.partyOptions.maxPartySize = 8;
|
|
||||||
((QuestManual) disabled.questInterface).manuals.put("Solo", 1);
|
|
||||||
out.add(new Case<Quest>("Party", disabled,
|
|
||||||
"AllowParty false with sizes assigned. Proves the eight party keys are ABSENT from "
|
|
||||||
+ "the file when the flag is off -- the values are lost upstream, so there is "
|
|
||||||
+ "nothing for a converter to preserve"));
|
|
||||||
|
|
||||||
Quest enabled = quest(51, "Party Enabled", EnumQuestType.Manual);
|
|
||||||
enabled.partyOptions.allowParty = true;
|
|
||||||
enabled.partyOptions.onlyParty = true;
|
|
||||||
enabled.partyOptions.partyRequirements = EnumPartyRequirements.All;
|
|
||||||
enabled.partyOptions.rewardControl = EnumPartyExchange.Enrolled;
|
|
||||||
enabled.partyOptions.completeFor = EnumPartyExchange.Valid;
|
|
||||||
enabled.partyOptions.executeCommand = EnumPartyExchange.All;
|
|
||||||
enabled.partyOptions.minPartySize = 2;
|
|
||||||
enabled.partyOptions.maxPartySize = 6;
|
|
||||||
enabled.partyOptions.objectiveRequirement = EnumPartyObjectives.Leader;
|
|
||||||
((QuestManual) enabled.questInterface).manuals.put("Together", 1);
|
|
||||||
out.add(new Case<Quest>("Party", enabled,
|
|
||||||
"AllowParty true and all eight party keys set to non-default enum constants"));
|
|
||||||
|
|
||||||
int id = 52;
|
|
||||||
for (EnumPartyRequirements requirement : EnumPartyRequirements.values()) {
|
|
||||||
Quest quest = quest(id, "Party Requirement " + requirement.name(), EnumQuestType.Manual);
|
|
||||||
quest.partyOptions.allowParty = true;
|
|
||||||
quest.partyOptions.partyRequirements = requirement;
|
|
||||||
((QuestManual) quest.questInterface).manuals.put("Together", 1);
|
|
||||||
out.add(new Case<Quest>("Party", quest,
|
|
||||||
"PartyRequirements = " + requirement.name() + " (ordinal " + requirement.ordinal() + ")"));
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
for (EnumPartyExchange exchange : EnumPartyExchange.values()) {
|
|
||||||
Quest quest = quest(id, "Party Reward " + exchange.name(), EnumQuestType.Manual);
|
|
||||||
quest.partyOptions.allowParty = true;
|
|
||||||
quest.partyOptions.rewardControl = exchange;
|
|
||||||
((QuestManual) quest.questInterface).manuals.put("Together", 1);
|
|
||||||
out.add(new Case<Quest>("Party", quest,
|
|
||||||
"RewardControl = " + exchange.name() + " (ordinal " + exchange.ordinal() + ")"));
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
for (EnumPartyObjectives objective : EnumPartyObjectives.values()) {
|
|
||||||
Quest quest = quest(id, "Party Objective " + objective.name(), EnumQuestType.Manual);
|
|
||||||
quest.partyOptions.allowParty = true;
|
|
||||||
quest.partyOptions.objectiveRequirement = objective;
|
|
||||||
((QuestManual) quest.questInterface).manuals.put("Together", 1);
|
|
||||||
out.add(new Case<Quest>("Party", quest,
|
|
||||||
"ObjectiveRequirement = " + objective.name() + " (ordinal " + objective.ordinal() + ")"));
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Quest profileOff = quest(62, "Profiles Disabled", EnumQuestType.Manual);
|
|
||||||
profileOff.profileOptions.enableOptions = false;
|
|
||||||
profileOff.profileOptions.cooldownControl = EnumProfileSync.Shared;
|
|
||||||
((QuestManual) profileOff.questInterface).manuals.put("Alone", 1);
|
|
||||||
out.add(new Case<Quest>("Party", profileOff,
|
|
||||||
"EnableProfiles false with a Shared cooldown assigned -- the two profile keys are "
|
|
||||||
+ "absent from the file, same shape as the party block"));
|
|
||||||
|
|
||||||
int profileId = 63;
|
|
||||||
for (EnumProfileSync sync : EnumProfileSync.values()) {
|
|
||||||
Quest quest = quest(profileId, "Profile " + sync.name(), EnumQuestType.Manual);
|
|
||||||
quest.profileOptions.enableOptions = true;
|
|
||||||
quest.profileOptions.cooldownControl = sync;
|
|
||||||
quest.profileOptions.completeControl = sync;
|
|
||||||
((QuestManual) quest.questInterface).manuals.put("Alone", 1);
|
|
||||||
out.add(new Case<Quest>("Party", quest,
|
|
||||||
"EnableProfiles true, CooldownControl and CompleteControl = " + sync.name()));
|
|
||||||
profileId++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ objectives in depth
|
|
||||||
|
|
||||||
private static void objectives(List<Case<Quest>> out) {
|
|
||||||
Quest emptyKill = quest(70, "Kill Nothing", EnumQuestType.Kill);
|
|
||||||
out.add(new Case<Quest>("Objectives", emptyKill,
|
|
||||||
"a Kill quest with an EMPTY target list. isCompleted counts completed targets against "
|
|
||||||
+ "the target count, so zero of zero passes -- this quest is complete on accept"));
|
|
||||||
|
|
||||||
Quest manyKill = quest(71, "Kill Many Kinds", EnumQuestType.Kill);
|
|
||||||
QuestKill kill = (QuestKill) manyKill.questInterface;
|
|
||||||
String[] mobs = {"Zombie", "Skeleton", "Creeper", "Spider", "Enderman", "Blaze"};
|
|
||||||
for (int i = 0; i < mobs.length; i++) {
|
|
||||||
kill.targets.put(mobs[i], (i + 1) * 10);
|
|
||||||
}
|
|
||||||
out.add(new Case<Quest>("Objectives", manyKill,
|
|
||||||
"six kill targets. Stored as a TreeMap, so the file is alphabetical rather than "
|
|
||||||
+ "insertion-ordered -- Blaze first, Zombie last"));
|
|
||||||
|
|
||||||
Quest customTarget = quest(72, "Kill A Custom NPC", EnumQuestType.Kill);
|
|
||||||
QuestKill custom = (QuestKill) customTarget.questInterface;
|
|
||||||
custom.targets.put("Village Elder", 1);
|
|
||||||
custom.targetType = 1;
|
|
||||||
custom.customTargetType = "noppes.npcs.entity.EntityCustomNpc";
|
|
||||||
out.add(new Case<Quest>("Objectives", customTarget,
|
|
||||||
"TargetType 1 with a CustomTargetType class name -- targets an NPC by display name "
|
|
||||||
+ "rather than an entity by type"));
|
|
||||||
|
|
||||||
Quest emptyItems = quest(73, "Bring Nothing", EnumQuestType.Item);
|
|
||||||
QuestItem noItems = (QuestItem) emptyItems.questInterface;
|
|
||||||
noItems.ignoreDamage = true;
|
|
||||||
noItems.ignoreNBT = true;
|
|
||||||
noItems.leaveItems = true;
|
|
||||||
out.add(new Case<Quest>("Objectives", emptyItems,
|
|
||||||
"an Item quest with no required items and all three matching flags on"));
|
|
||||||
|
|
||||||
Quest variantItems = quest(74, "Bring Variants", EnumQuestType.Item);
|
|
||||||
QuestItem variants = (QuestItem) variantItems.questInterface;
|
|
||||||
variants.items.items.put(0, Fixtures.variant("minecraft:wool", 8, 14));
|
|
||||||
variants.items.items.put(1, Fixtures.variant("minecraft:planks", 4, 3));
|
|
||||||
variants.items.items.put(2, Fixtures.variant("minecraft:dye", 16, 4));
|
|
||||||
out.add(new Case<Quest>("Objectives", variantItems,
|
|
||||||
"three pre-Flattening variants -- red wool (14), jungle planks (3) and lapis dye (4). "
|
|
||||||
+ "Damage is a variant selector here, not durability, and each becomes a distinct "
|
|
||||||
+ "item after 1.13, so this is the case a variant table has to cover"));
|
|
||||||
|
|
||||||
Quest manyDialogs = quest(75, "Read Many Dialogs", EnumQuestType.Dialog);
|
|
||||||
QuestDialog dialogs = (QuestDialog) manyDialogs.questInterface;
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
dialogs.dialogs.put(i, 30 + i);
|
|
||||||
}
|
|
||||||
out.add(new Case<Quest>("Objectives", manyDialogs,
|
|
||||||
"five dialog objectives. NOTE the key collision worth knowing about: a Dialog quest "
|
|
||||||
+ "stores these under QuestDialogs, which is exactly where a pre-split Kill quest "
|
|
||||||
+ "stored its targets -- see the legacy world"));
|
|
||||||
|
|
||||||
Quest oneLocation = quest(76, "One Location", EnumQuestType.Location);
|
|
||||||
((QuestLocation) oneLocation.questInterface).location = "The Old Well";
|
|
||||||
out.add(new Case<Quest>("Objectives", oneLocation,
|
|
||||||
"only the first of three location slots set; the other two are written as empty"));
|
|
||||||
|
|
||||||
Quest manuals = quest(77, "Manual Counters", EnumQuestType.Manual);
|
|
||||||
QuestManual manual = (QuestManual) manuals.questInterface;
|
|
||||||
manual.manuals.put("Deliver the letter", 1);
|
|
||||||
manual.manuals.put("Light the beacons", 3);
|
|
||||||
manual.manuals.put("Survive the night", 1);
|
|
||||||
out.add(new Case<Quest>("Objectives", manuals,
|
|
||||||
"three manual counters -- progress a script or an operator advances by hand"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ combinations
|
|
||||||
|
|
||||||
private static void combinations(List<Case<Quest>> out) {
|
|
||||||
Quest everything = quest(90, "Everything At Once", EnumQuestType.Item);
|
|
||||||
everything.logText = "Bring the ingots, and be quick about it.";
|
|
||||||
everything.completeText = "You have my thanks.";
|
|
||||||
everything.completerNpc = "Quartermaster";
|
|
||||||
everything.command = "/say {player} finished";
|
|
||||||
everything.repeat = EnumQuestRepeat.MCCUSTOM;
|
|
||||||
everything.customCooldown = 172800000L;
|
|
||||||
everything.completion = EnumQuestCompletion.Instant;
|
|
||||||
everything.nextQuestid = 1;
|
|
||||||
everything.nextQuestTitle = "Type Item";
|
|
||||||
everything.rewardExp = 1000;
|
|
||||||
everything.randomReward = true;
|
|
||||||
everything.rewardItems.items.put(0, Fixtures.item("minecraft:diamond", 3));
|
|
||||||
everything.rewardItems.items.put(4, Fixtures.namedItem("minecraft:iron_sword", 1, 5, "Reward"));
|
|
||||||
everything.factionOptions.factionId = 0;
|
|
||||||
everything.factionOptions.factionPoints = 75;
|
|
||||||
everything.partyOptions.allowParty = true;
|
|
||||||
everything.partyOptions.onlyParty = false;
|
|
||||||
everything.partyOptions.partyRequirements = EnumPartyRequirements.Valid;
|
|
||||||
everything.partyOptions.rewardControl = EnumPartyExchange.All;
|
|
||||||
everything.partyOptions.minPartySize = 2;
|
|
||||||
everything.partyOptions.maxPartySize = 4;
|
|
||||||
everything.profileOptions.enableOptions = true;
|
|
||||||
everything.profileOptions.cooldownControl = EnumProfileSync.Shared;
|
|
||||||
everything.profileOptions.completeControl = EnumProfileSync.Individual;
|
|
||||||
everything.mail.subject = "Everything";
|
|
||||||
everything.mail.sender = "Quartermaster";
|
|
||||||
everything.mail.time = Fixtures.EPOCH;
|
|
||||||
everything.mail.items[0] = Fixtures.item("minecraft:emerald", 12);
|
|
||||||
QuestItem items = (QuestItem) everything.questInterface;
|
|
||||||
items.items.items.put(0, Fixtures.item("minecraft:iron_ingot", 20));
|
|
||||||
items.items.items.put(2, Fixtures.variant("minecraft:wool", 1, 11));
|
|
||||||
items.leaveItems = false;
|
|
||||||
items.ignoreDamage = false;
|
|
||||||
items.ignoreNBT = true;
|
|
||||||
out.add(new Case<Quest>("Combinations", everything,
|
|
||||||
"every quest sub-object populated at once: objective, rewards, faction, party, "
|
|
||||||
+ "profile, mail, chain, cooldown and command"));
|
|
||||||
|
|
||||||
Quest bare = quest(91, "Bare", EnumQuestType.Item);
|
|
||||||
out.add(new Case<Quest>("Combinations", bare,
|
|
||||||
"every field at its constructor default, for comparison against id 90"));
|
|
||||||
|
|
||||||
Quest unicode = quest(92, Text.CYRILLIC_QUEST + " " + Text.EM_DASH + " " + Text.ELEVES,
|
|
||||||
EnumQuestType.Manual);
|
|
||||||
unicode.logText = Text.RTL;
|
|
||||||
unicode.completeText = Text.ASTRAL;
|
|
||||||
unicode.completerNpc = Text.KATAKANA_FACTION;
|
|
||||||
((QuestManual) unicode.questInterface).manuals.put(Text.CYRILLIC_QUEST, 1);
|
|
||||||
out.add(new Case<Quest>("Combinations", unicode,
|
|
||||||
"non-Latin title, log text, complete text, completer name and objective key. The "
|
|
||||||
+ "objective key is the interesting one -- it is an NBT map key, not a value"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ helpers
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a quest with its type applied.
|
|
||||||
*
|
|
||||||
* <p>Order matters: {@code setType} replaces {@code questInterface} and stamps it with the
|
|
||||||
* quest id, so both must be set before the objective is populated.
|
|
||||||
*/
|
|
||||||
private static Quest quest(int id, String title, EnumQuestType type) {
|
|
||||||
Quest quest = new Quest();
|
|
||||||
quest.id = id;
|
|
||||||
quest.title = title;
|
|
||||||
quest.setType(type);
|
|
||||||
quest.logText = "Objective for " + title + ".";
|
|
||||||
quest.completeText = "Done: " + title + ".";
|
|
||||||
return quest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.content;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Non-ASCII strings the fixtures use, built from code points.
|
|
||||||
*
|
|
||||||
* <p>Every source file here is pure ASCII, and this class is why. A generator whose own source has
|
|
||||||
* been mojibaked by a CP-1252 toolchain emits fixtures that contain the mojibake, and then every
|
|
||||||
* reader tested against those fixtures agrees with it -- the corruption becomes the specification.
|
|
||||||
* Writing the code points out removes the whole class of accident, at the cost of one indirection.
|
|
||||||
*
|
|
||||||
* <p>The strings themselves matter: CustomNPC+ content is authored by players, in every language,
|
|
||||||
* with the section sign used for colour codes throughout.
|
|
||||||
*/
|
|
||||||
public final class Text {
|
|
||||||
|
|
||||||
private Text() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The colour-code prefix, U+00A7. Appears in CustomNPC+'s own default effect name. */
|
|
||||||
public static final String SECTION = cp(0x00A7);
|
|
||||||
|
|
||||||
/** U+2014. Punctuation above Latin-1 that a byte-oriented reader truncates. */
|
|
||||||
public static final String EM_DASH = cp(0x2014);
|
|
||||||
|
|
||||||
/** "Eleves" with acute and grave accents -- two-byte UTF-8, still one char in Java. */
|
|
||||||
public static final String ELEVES = cp(0x00C9, 0x6C, 0x00E8, 0x76, 0x65, 0x73);
|
|
||||||
|
|
||||||
/** Katakana for "faction". Three-byte UTF-8, and outside anything CP-1252 can represent. */
|
|
||||||
public static final String KATAKANA_FACTION = cp(0x30D5, 0x30A1, 0x30AF, 0x30B7, 0x30E7, 0x30F3);
|
|
||||||
|
|
||||||
/** Cyrillic "Zadanie" (quest). */
|
|
||||||
public static final String CYRILLIC_QUEST = cp(0x0417, 0x0430, 0x0434, 0x0430, 0x043D, 0x0438, 0x0435);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A character outside the Basic Multilingual Plane -- U+1F5FF, the moai. One code point, two
|
|
||||||
* Java chars, four UTF-8 bytes. NBT strings are modified UTF-8, which encodes this as a
|
|
||||||
* surrogate pair rather than as one four-byte sequence, so it is the case where a reader that
|
|
||||||
* treats NBT strings as standard UTF-8 diverges from one that does not.
|
|
||||||
*/
|
|
||||||
public static final String ASTRAL = cp(0x1F5FF);
|
|
||||||
|
|
||||||
/** A right-to-left string: Arabic for "quest". Exercises no encoding rule, only rendering. */
|
|
||||||
public static final String RTL = cp(0x0645, 0x0647, 0x0645, 0x0629);
|
|
||||||
|
|
||||||
private static String cp(int... codePoints) {
|
|
||||||
StringBuilder sb = new StringBuilder(codePoints.length);
|
|
||||||
for (int codePoint : codePoints) {
|
|
||||||
sb.appendCodePoint(codePoint);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,256 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.content;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.Fixtures;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import noppes.npcs.controllers.data.Bank;
|
|
||||||
import noppes.npcs.controllers.data.SpawnData;
|
|
||||||
import noppes.npcs.controllers.data.Tag;
|
|
||||||
import noppes.npcs.controllers.data.TransportCategory;
|
|
||||||
import noppes.npcs.controllers.data.TransportLocation;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The world-level {@code .dat} documents: global, tags, transport, banks and spawns.
|
|
||||||
*
|
|
||||||
* <p>All five share a shape -- one compound holding a list of entries plus a {@code lastID} -- and
|
|
||||||
* each list is built here in a fixed order rather than by iterating the controller's HashMap, so
|
|
||||||
* regeneration is a no-op rather than a reshuffle.
|
|
||||||
*
|
|
||||||
* <p>Every document format below is copied from its controller's {@code getNBT}, named per method.
|
|
||||||
*/
|
|
||||||
public final class WorldDataFixtures {
|
|
||||||
|
|
||||||
private WorldDataFixtures() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ global.dat
|
|
||||||
|
|
||||||
/** GlobalDataController.saveData -- a single integer, and the smallest document CNPC+ writes. */
|
|
||||||
public static NBTTagCompound global(int itemGiverId) {
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setInteger("itemGiverId", itemGiverId);
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ tags.dat
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tags. Note {@link Tag#uuid} defaults to {@code randomUUID()}, so every fixture here sets one
|
|
||||||
* explicitly -- otherwise the corpus would differ on every run and the reproducibility check
|
|
||||||
* would fail for a reason that has nothing to do with the format.
|
|
||||||
*/
|
|
||||||
public static NBTTagCompound tags() {
|
|
||||||
List<Tag> tags = new ArrayList<Tag>();
|
|
||||||
|
|
||||||
tags.add(tag(1, "Boss", 0xFF0000, "3f2504e0-4f89-41d3-9a0c-0305e82c3301", false));
|
|
||||||
tags.add(tag(2, "Hidden", 0x333333, "3f2504e0-4f89-41d3-9a0c-0305e82c3302", true));
|
|
||||||
tags.add(tag(3, "", 0x00FF00, "3f2504e0-4f89-41d3-9a0c-0305e82c3303", false));
|
|
||||||
tags.add(tag(4, Text.KATAKANA_FACTION, 0xFFFFFF,
|
|
||||||
"3f2504e0-4f89-41d3-9a0c-0305e82c3304", false));
|
|
||||||
tags.add(tag(5, "Extremes", -1, "ffffffff-ffff-ffff-ffff-ffffffffffff", true));
|
|
||||||
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
for (Tag tag : tags) {
|
|
||||||
NBTTagCompound entry = new NBTTagCompound();
|
|
||||||
tag.writeNBT(entry);
|
|
||||||
list.appendTag(entry);
|
|
||||||
}
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setInteger("lastID", 5);
|
|
||||||
compound.setTag("NPCTags", list);
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Tag tag(int id, String name, int color, String uuid, boolean hidden) {
|
|
||||||
Tag tag = new Tag();
|
|
||||||
tag.id = id;
|
|
||||||
tag.name = name;
|
|
||||||
tag.color = color;
|
|
||||||
tag.uuid = UUID.fromString(uuid);
|
|
||||||
tag.hideTag = hidden;
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ transport.dat
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transport locations, grouped into categories.
|
|
||||||
*
|
|
||||||
* <p>The one place CustomNPC+ stores a dimension as a bare {@code int} alongside a position --
|
|
||||||
* which is the signature that stopped being expressible after 1.16, so it is worth having on
|
|
||||||
* disk in both a vanilla dimension and a modded id.
|
|
||||||
*/
|
|
||||||
public static NBTTagCompound transport() {
|
|
||||||
List<TransportCategory> categories = new ArrayList<TransportCategory>();
|
|
||||||
|
|
||||||
TransportCategory overworld = category(1, "Overworld");
|
|
||||||
overworld.locations.put(1, location(1, "Spawn Plaza", 0.5D, 64.0D, 0.5D, 0, 0));
|
|
||||||
overworld.locations.put(2, location(2, "Northern Watchtower", -1204.5D, 96.0D, 3311.5D, 1, 0));
|
|
||||||
overworld.locations.put(3, location(3, "Negative Coordinates",
|
|
||||||
-30000000.0D, -64.0D, -30000000.0D, 2, 0));
|
|
||||||
categories.add(overworld);
|
|
||||||
|
|
||||||
TransportCategory other = category(2, "Other Dimensions");
|
|
||||||
other.locations.put(4, location(4, "Nether Hub", 12.0D, 70.0D, -8.0D, 0, -1));
|
|
||||||
other.locations.put(5, location(5, "The End", 100.0D, 50.0D, 0.0D, 0, 1));
|
|
||||||
// A modded dimension id, which is the case a numeric-to-key translation table must either
|
|
||||||
// cover or refuse rather than silently map to the overworld.
|
|
||||||
other.locations.put(6, location(6, "Modded Dimension", 0.0D, 0.0D, 0.0D, 0, 7265));
|
|
||||||
categories.add(other);
|
|
||||||
|
|
||||||
TransportCategory empty = category(3, "Empty Category");
|
|
||||||
categories.add(empty);
|
|
||||||
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
for (TransportCategory category : categories) {
|
|
||||||
NBTTagCompound entry = new NBTTagCompound();
|
|
||||||
category.writeNBT(entry);
|
|
||||||
list.appendTag(entry);
|
|
||||||
}
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setInteger("lastID", 6);
|
|
||||||
compound.setTag("NPCTransportCategories", list);
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TransportCategory category(int id, String title) {
|
|
||||||
TransportCategory category = new TransportCategory();
|
|
||||||
category.id = id;
|
|
||||||
category.title = title;
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TransportLocation location(int id, String name, double x, double y, double z,
|
|
||||||
int type, int dimension) {
|
|
||||||
TransportLocation location = new TransportLocation();
|
|
||||||
location.id = id;
|
|
||||||
location.name = name;
|
|
||||||
location.posX = x;
|
|
||||||
location.posY = y;
|
|
||||||
location.posZ = z;
|
|
||||||
location.type = type;
|
|
||||||
location.dimension = dimension;
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ bank.dat
|
|
||||||
|
|
||||||
/** BankController.getNBT -- note the key is "Data" and there is no lastID. */
|
|
||||||
public static NBTTagCompound banks() {
|
|
||||||
List<Bank> banks = new ArrayList<Bank>();
|
|
||||||
|
|
||||||
Bank basic = bank(1, "Village Bank", 2, 9);
|
|
||||||
basic.currencyInventory.items.put(0, Fixtures.item("minecraft:emerald", 1));
|
|
||||||
basic.upgradeInventory.items.put(0, Fixtures.item("minecraft:gold_ingot", 8));
|
|
||||||
for (int slot = 0; slot < 9; slot++) {
|
|
||||||
basic.slotTypes.put(slot, slot % 3);
|
|
||||||
}
|
|
||||||
banks.add(basic);
|
|
||||||
|
|
||||||
Bank bare = bank(2, "", 1, 1);
|
|
||||||
banks.add(bare);
|
|
||||||
|
|
||||||
Bank big = bank(3, "Vault", 6, 54);
|
|
||||||
big.currencyInventory.items.put(0, Fixtures.namedItem("minecraft:diamond", 64, 0, "Deposit"));
|
|
||||||
for (int slot = 0; slot < 54; slot++) {
|
|
||||||
big.slotTypes.put(slot, slot % 4);
|
|
||||||
}
|
|
||||||
banks.add(big);
|
|
||||||
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
for (Bank bank : banks) {
|
|
||||||
NBTTagCompound entry = new NBTTagCompound();
|
|
||||||
bank.writeEntityToNBT(entry);
|
|
||||||
list.appendTag(entry);
|
|
||||||
}
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setTag("Data", list);
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Bank bank(int id, String name, int startSlots, int maxSlots) {
|
|
||||||
Bank bank = new Bank();
|
|
||||||
bank.id = id;
|
|
||||||
bank.name = name;
|
|
||||||
bank.startSlots = startSlots;
|
|
||||||
bank.maxSlots = maxSlots;
|
|
||||||
return bank;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------ spawns.dat
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Natural spawn entries.
|
|
||||||
*
|
|
||||||
* <p>The interesting shape here is {@code SpawnCompound<n>}: the per-variant NPC data is
|
|
||||||
* written as a numbered key rather than a list, so a reader has to probe for
|
|
||||||
* {@code SpawnCompound0}, {@code SpawnCompound1}, ... rather than iterate. The dimension set
|
|
||||||
* is written only when non-empty, so the key is absent on most entries.
|
|
||||||
*/
|
|
||||||
public static NBTTagCompound spawns() {
|
|
||||||
List<SpawnData> spawns = new ArrayList<SpawnData>();
|
|
||||||
|
|
||||||
SpawnData plains = spawn(1, "Plains Wanderer", 10);
|
|
||||||
plains.biomes.addAll(Arrays.asList("Plains", "Sunflower Plains", "Forest"));
|
|
||||||
plains.spawnCompounds.put(0, npcStub("Wanderer"));
|
|
||||||
spawns.add(plains);
|
|
||||||
|
|
||||||
SpawnData variants = spawn(2, "Cave Dweller", 3);
|
|
||||||
variants.biomes.add("Extreme Hills");
|
|
||||||
variants.dimensions.addAll(Arrays.asList(0, -1, 7265));
|
|
||||||
variants.monsterSpawning = true;
|
|
||||||
variants.animalSpawning = false;
|
|
||||||
variants.airSpawning = true;
|
|
||||||
variants.liquidSpawning = true;
|
|
||||||
variants.spawnHeightMin = 5;
|
|
||||||
variants.spawnHeightMax = 40;
|
|
||||||
variants.maxAlive = 12;
|
|
||||||
variants.cooldownTicks = 600;
|
|
||||||
variants.attemptsPerCycle = 4;
|
|
||||||
// Three numbered compounds, which is the shape worth pinning.
|
|
||||||
variants.spawnCompounds.put(0, npcStub("Dweller A"));
|
|
||||||
variants.spawnCompounds.put(1, npcStub("Dweller B"));
|
|
||||||
variants.spawnCompounds.put(2, npcStub("Dweller C"));
|
|
||||||
spawns.add(variants);
|
|
||||||
|
|
||||||
SpawnData bare = spawn(3, "", 0);
|
|
||||||
spawns.add(bare);
|
|
||||||
|
|
||||||
NBTTagList list = new NBTTagList();
|
|
||||||
for (SpawnData spawn : spawns) {
|
|
||||||
list.appendTag(spawn.writeNBT(new NBTTagCompound()));
|
|
||||||
}
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
compound.setInteger("lastID", 3);
|
|
||||||
compound.setTag("NPCSpawnData", list);
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SpawnData spawn(int id, String name, int weight) {
|
|
||||||
SpawnData spawn = new SpawnData();
|
|
||||||
spawn.id = id;
|
|
||||||
spawn.name = name;
|
|
||||||
spawn.itemWeight = weight;
|
|
||||||
return spawn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A stand-in for a stored NPC.
|
|
||||||
*
|
|
||||||
* <p>Deliberately not a real {@code EntityCustomNpc}: constructing one needs a World, and a
|
|
||||||
* spawn entry stores whatever compound it was given without inspecting it. A fixture with a
|
|
||||||
* full NPC in it belongs with the NPC system, which is not covered here yet -- so this says
|
|
||||||
* what it is rather than pretending.
|
|
||||||
*/
|
|
||||||
private static NBTTagCompound npcStub(String name) {
|
|
||||||
NBTTagCompound stub = new NBTTagCompound();
|
|
||||||
stub.setString("Name", name);
|
|
||||||
stub.setString("FixtureNote", "placeholder -- not a serialized EntityCustomNpc");
|
|
||||||
return stub;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.worlds;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.FixtureWorld;
|
|
||||||
import kamkeel.npcs.fixtures.WorldWriter;
|
|
||||||
import kamkeel.npcs.fixtures.content.FactionFixtures;
|
|
||||||
import noppes.npcs.constants.EnumOptionType;
|
|
||||||
import noppes.npcs.controllers.data.Dialog;
|
|
||||||
import noppes.npcs.controllers.data.DialogOption;
|
|
||||||
import noppes.npcs.controllers.data.Faction;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* What CustomNPC+ writes for a world nobody has edited.
|
|
||||||
*
|
|
||||||
* <p>Worth its own world because "the defaults" is a real contract and an easy thing to get subtly
|
|
||||||
* wrong: a reader that supplies its own idea of a default agrees with this file on every field it
|
|
||||||
* happens to share and disagrees on the rest, silently. Reproduced from
|
|
||||||
* FactionController.loadFactions and DialogController.loadDefaultDialogs.
|
|
||||||
*/
|
|
||||||
public final class DefaultsWorld implements FixtureWorld {
|
|
||||||
|
|
||||||
public String name() {
|
|
||||||
return "defaults";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String purpose() {
|
|
||||||
return "exactly what CustomNPC+ creates for a fresh world -- the three default factions and "
|
|
||||||
+ "the three Villager dialogs -- and nothing else.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void build(WorldWriter out) {
|
|
||||||
List<Faction> factions = FactionFixtures.vanillaDefaults();
|
|
||||||
out.dat("faction", "factions.dat", FactionFixtures.document(factions, 0),
|
|
||||||
"the three factions FactionController creates when factions.dat is missing or empty: "
|
|
||||||
+ "Friendly 2000, Neutral 1000, Aggressive 0");
|
|
||||||
|
|
||||||
// Copied field for field from DialogController.loadDefaultDialogs.
|
|
||||||
Dialog start = new Dialog();
|
|
||||||
start.id = 1;
|
|
||||||
start.title = "Start";
|
|
||||||
start.text = "Hello {player}, \n\nWelcome to our village. I hope you enjoy your stay";
|
|
||||||
|
|
||||||
Dialog village = new Dialog();
|
|
||||||
village.id = 2;
|
|
||||||
village.title = "Ask about village";
|
|
||||||
village.text = "This village has been around for ages. Enjoy your stay here.";
|
|
||||||
|
|
||||||
Dialog who = new Dialog();
|
|
||||||
who.id = 3;
|
|
||||||
who.title = "Who are you";
|
|
||||||
who.text = "I'm a villager here. I have lived in this village my whole life.";
|
|
||||||
|
|
||||||
DialogOption toVillage = new DialogOption();
|
|
||||||
toVillage.title = "Tell me something about this village";
|
|
||||||
toVillage.dialogId = 2;
|
|
||||||
toVillage.optionType = EnumOptionType.DialogOption;
|
|
||||||
|
|
||||||
DialogOption toWho = new DialogOption();
|
|
||||||
toWho.title = "Who are you?";
|
|
||||||
toWho.dialogId = 3;
|
|
||||||
toWho.optionType = EnumOptionType.DialogOption;
|
|
||||||
|
|
||||||
DialogOption goodbye = new DialogOption();
|
|
||||||
goodbye.title = "Goodbye";
|
|
||||||
goodbye.optionType = EnumOptionType.QuitOption;
|
|
||||||
|
|
||||||
start.options.put(0, toWho);
|
|
||||||
start.options.put(1, toVillage);
|
|
||||||
start.options.put(2, goodbye);
|
|
||||||
|
|
||||||
DialogOption back = new DialogOption();
|
|
||||||
back.title = "Back";
|
|
||||||
back.dialogId = 1;
|
|
||||||
|
|
||||||
village.options.put(1, back);
|
|
||||||
who.options.put(1, back);
|
|
||||||
|
|
||||||
out.dialog("Villager", start,
|
|
||||||
"CustomNPC+'s own default dialog 1, with its three options. Note showWheel is false "
|
|
||||||
+ "here because the object was never read back -- readNBTPartial defaults an "
|
|
||||||
+ "absent DialogShowWheel to true, which the writer does not do");
|
|
||||||
out.dialog("Villager", village, "CustomNPC+'s own default dialog 2");
|
|
||||||
out.dialog("Villager", who, "CustomNPC+'s own default dialog 3");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.worlds;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.FixtureWorld;
|
|
||||||
import kamkeel.npcs.fixtures.WorldWriter;
|
|
||||||
import kamkeel.npcs.fixtures.content.FactionFixtures;
|
|
||||||
import noppes.npcs.controllers.data.Dialog;
|
|
||||||
import noppes.npcs.controllers.data.Faction;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Legal content that readers get wrong.
|
|
||||||
*
|
|
||||||
* <p>Nothing here is corrupt. Every file is something CustomNPC+ will write and load: empty
|
|
||||||
* strings, integer extremes, ids that resolve nowhere, names outside Latin-1, and the same id
|
|
||||||
* living in two categories. The last is the one worth having -- it is what makes "a dialog's
|
|
||||||
* identity is its id" wrong on its own.
|
|
||||||
*/
|
|
||||||
public final class EdgeWorld implements FixtureWorld {
|
|
||||||
|
|
||||||
public String name() {
|
|
||||||
return "edge";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String purpose() {
|
|
||||||
return "legal but awkward content: empty strings, integer extremes, dangling ids, non-Latin "
|
|
||||||
+ "names, and one dialog id occupying two categories at once.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void build(WorldWriter out) {
|
|
||||||
List<Faction> factions = FactionFixtures.edge();
|
|
||||||
out.dat("faction", "factions.dat", FactionFixtures.document(factions, 4096),
|
|
||||||
"empty and non-Latin names, Integer.MIN_VALUE/MAX_VALUE thresholds, colour -1, "
|
|
||||||
+ "attack lists naming factions that are not in the file, and a sparse id of 4096");
|
|
||||||
|
|
||||||
// The same id in two categories. DialogController loads categories directory by
|
|
||||||
// directory, and on the second occurrence renames the file and reassigns the id -- so
|
|
||||||
// this world does not survive a load unchanged, which is exactly the behaviour worth
|
|
||||||
// pinning. Whichever category is read second is decided by File.listFiles order.
|
|
||||||
Dialog first = new Dialog();
|
|
||||||
first.id = 1;
|
|
||||||
first.title = "Start";
|
|
||||||
first.text = "I am dialog 1 in category A.";
|
|
||||||
|
|
||||||
Dialog second = new Dialog();
|
|
||||||
second.id = 1;
|
|
||||||
second.title = "Start";
|
|
||||||
second.text = "I am dialog 1 in category B.";
|
|
||||||
|
|
||||||
out.dialog("Category A", first,
|
|
||||||
"dialog id 1 in the first category. See the note on its twin");
|
|
||||||
out.dialog("Category B", second,
|
|
||||||
"dialog id 1 AGAIN, in a second category, with the same title. CustomNPC+ resolves "
|
|
||||||
+ "this on load by renaming the file and reassigning the id, so a converter that "
|
|
||||||
+ "keys on the id alone silently merges two distinct dialogs. Which one is "
|
|
||||||
+ "reassigned depends on File.listFiles order and is not fixed");
|
|
||||||
|
|
||||||
Dialog emptyEverything = new Dialog();
|
|
||||||
emptyEverything.id = 2;
|
|
||||||
emptyEverything.title = "";
|
|
||||||
emptyEverything.text = "";
|
|
||||||
emptyEverything.command = "";
|
|
||||||
emptyEverything.textSound = "";
|
|
||||||
out.dialog("Empty", emptyEverything,
|
|
||||||
"every string field empty, including TextSound, which has a non-empty default. "
|
|
||||||
+ "DialogSound is absent entirely because the writer omits it when empty");
|
|
||||||
|
|
||||||
Dialog extremes = new Dialog();
|
|
||||||
extremes.id = 3;
|
|
||||||
extremes.title = "Integer Extremes";
|
|
||||||
extremes.text = "Every numeric field at a boundary.";
|
|
||||||
extremes.quest = Integer.MAX_VALUE;
|
|
||||||
extremes.color = Integer.MIN_VALUE;
|
|
||||||
extremes.titleColor = -1;
|
|
||||||
extremes.textWidth = Integer.MAX_VALUE;
|
|
||||||
extremes.textHeight = Integer.MIN_VALUE;
|
|
||||||
extremes.textOffsetX = Integer.MIN_VALUE;
|
|
||||||
extremes.textOffsetY = Integer.MAX_VALUE;
|
|
||||||
extremes.npcScale = Float.MAX_VALUE;
|
|
||||||
extremes.textPitch = Float.MIN_VALUE;
|
|
||||||
extremes.alignment = Byte.MAX_VALUE;
|
|
||||||
out.dialog("Empty", extremes,
|
|
||||||
"integer and float fields at their type boundaries, and DialogAlignment at 127 -- "
|
|
||||||
+ "outside the 0-2 the field documents, because nothing validates it on write");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.worlds;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.FixtureWorld;
|
|
||||||
import kamkeel.npcs.fixtures.WorldWriter;
|
|
||||||
import net.minecraft.nbt.NBTBase;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import noppes.npcs.constants.EnumAvailabilityQuest;
|
|
||||||
import noppes.npcs.constants.EnumQuestType;
|
|
||||||
import noppes.npcs.controllers.data.Dialog;
|
|
||||||
import noppes.npcs.controllers.data.Quest;
|
|
||||||
import noppes.npcs.quests.QuestKill;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Documents as an older CustomNPC+ would have left them.
|
|
||||||
*
|
|
||||||
* <p><b>Synthesized, and the only world here that is.</b> Every other file in these fixtures is
|
|
||||||
* whatever CustomNPC+ writes today. These are produced by writing a current document and then
|
|
||||||
* removing keys and lowering {@code ModRev} -- because producing genuinely old output means
|
|
||||||
* checking out an old CustomNPC+ and running it, which is worth doing and is not this.
|
|
||||||
*
|
|
||||||
* <p>They are still worth having, because the upgrade path is real code with no other test. When a
|
|
||||||
* loaded document's {@code ModRev} differs from {@code VersionCompatibility.ModRev},
|
|
||||||
* {@code CheckAvailabilityCompatibility} walks a freshly constructed object's NBT and copies in
|
|
||||||
* every key the file is missing. A reader that skips that step reads zero for absent integers,
|
|
||||||
* which is a valid-looking value for most of these fields and a wrong one for all of them.
|
|
||||||
*
|
|
||||||
* <p>Each case names exactly what was removed, so the synthesis is auditable rather than implied.
|
|
||||||
*/
|
|
||||||
public final class LegacyWorld implements FixtureWorld {
|
|
||||||
|
|
||||||
/** Anything below VersionCompatibility.ModRev, which is 23 at the time of writing. */
|
|
||||||
private static final int OLD_REV = 17;
|
|
||||||
|
|
||||||
public String name() {
|
|
||||||
return "legacy";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String purpose() {
|
|
||||||
return "documents aged by hand -- keys removed and ModRev lowered -- to exercise the "
|
|
||||||
+ "default-filling upgrade path. The only synthesized world here; every case names "
|
|
||||||
+ "which keys it removed.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void build(WorldWriter out) {
|
|
||||||
agedDialog(out);
|
|
||||||
preUpgradeKillQuest(out);
|
|
||||||
questWithoutAvailability(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void agedDialog(WorldWriter out) {
|
|
||||||
Dialog dialog = new Dialog();
|
|
||||||
dialog.id = 1;
|
|
||||||
dialog.title = "Aged Dialog";
|
|
||||||
dialog.text = "Written by a version that had fewer fields.";
|
|
||||||
dialog.color = 0x336699;
|
|
||||||
|
|
||||||
NBTTagCompound compound = dialog.writeToNBTPartial(new NBTTagCompound());
|
|
||||||
String[] removed = {
|
|
||||||
"TextSound", "TextPitch", "TextWidth", "TextHeight", "ShowOptionLine",
|
|
||||||
"PreviousBlocks", "NPCScale", "Color", "TitleColor", "DialogShowWheel",
|
|
||||||
"DialogDarkScreen", "Images", "ColorSettings"
|
|
||||||
};
|
|
||||||
for (String key : removed) {
|
|
||||||
compound.removeTag(key);
|
|
||||||
}
|
|
||||||
compound.setInteger("ModRev", OLD_REV);
|
|
||||||
|
|
||||||
out.dialogRaw("Aged", 1, compound,
|
|
||||||
"ModRev lowered to " + OLD_REV + " and 13 keys removed: " + join(removed) + ". Ten of "
|
|
||||||
+ "them have a non-zero default that readNBTPartial restores explicitly, and the "
|
|
||||||
+ "Color that was set is among the removed ones -- so a reader that does not "
|
|
||||||
+ "default-fill produces a black dialog with no text sound and a zero scale");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The trap Scribe's own notes record: before the kill/dialog split, a Kill quest stored its
|
|
||||||
* targets under {@code QuestDialogs} -- the dialog quest's key. QuestKill.readEntityFromNBT
|
|
||||||
* still falls back to it when {@code QuestKills} is absent. Miss the fallback and every
|
|
||||||
* pre-upgrade kill quest converts with no targets, which reads as already complete.
|
|
||||||
*/
|
|
||||||
private void preUpgradeKillQuest(WorldWriter out) {
|
|
||||||
Quest quest = new Quest();
|
|
||||||
quest.id = 1;
|
|
||||||
quest.title = "Old Kill Quest";
|
|
||||||
quest.logText = "Cull the pigs.";
|
|
||||||
quest.setType(EnumQuestType.Kill);
|
|
||||||
QuestKill kill = (QuestKill) quest.questInterface;
|
|
||||||
kill.targets.put("Pig", 10);
|
|
||||||
kill.targets.put("Cow", 4);
|
|
||||||
kill.targetType = 0;
|
|
||||||
|
|
||||||
NBTTagCompound compound = quest.writeToNBTPartial(new NBTTagCompound());
|
|
||||||
NBTBase targets = compound.getTag("QuestKills");
|
|
||||||
compound.removeTag("QuestKills");
|
|
||||||
compound.setTag("QuestDialogs", targets);
|
|
||||||
compound.setInteger("ModRev", OLD_REV);
|
|
||||||
|
|
||||||
out.questRaw("Aged", 1, compound,
|
|
||||||
"a Kill quest whose targets sit under QuestDialogs instead of QuestKills, which is "
|
|
||||||
+ "where a pre-split CustomNPC+ put them. QuestKill.readEntityFromNBT falls back "
|
|
||||||
+ "to that key. A reader without the fallback loads two targets as zero targets, "
|
|
||||||
+ "and a quest with no targets counts as complete");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void questWithoutAvailability(WorldWriter out) {
|
|
||||||
Quest quest = new Quest();
|
|
||||||
quest.id = 2;
|
|
||||||
quest.title = "Aged Item Quest";
|
|
||||||
quest.logText = "Bring me three ingots.";
|
|
||||||
quest.setType(EnumQuestType.Item);
|
|
||||||
quest.rewardExp = 500;
|
|
||||||
|
|
||||||
NBTTagCompound compound = quest.writeToNBTPartial(new NBTTagCompound());
|
|
||||||
String[] removed = {
|
|
||||||
"PartyOptions", "ProfileOptions", "CustomCooldown", "RandomReward", "QuestCompletion"
|
|
||||||
};
|
|
||||||
for (String key : removed) {
|
|
||||||
compound.removeTag(key);
|
|
||||||
}
|
|
||||||
compound.setInteger("ModRev", OLD_REV);
|
|
||||||
|
|
||||||
out.questRaw("Aged", 2, compound,
|
|
||||||
"ModRev lowered and the newer sub-objects removed: " + join(removed) + ". Party and "
|
|
||||||
+ "profile options are whole compounds, so this exercises the recursive half of "
|
|
||||||
+ "CompatabilityFix rather than the flat half");
|
|
||||||
|
|
||||||
// A dialog whose quest availability slots were never written at all, which is what every
|
|
||||||
// document below the availability rework looks like.
|
|
||||||
Dialog gated = new Dialog();
|
|
||||||
gated.id = 2;
|
|
||||||
gated.title = "Gated, Then Aged";
|
|
||||||
gated.text = "Only for those who finished quest 1.";
|
|
||||||
gated.availability.questAvailable = EnumAvailabilityQuest.After;
|
|
||||||
gated.availability.questId = 1;
|
|
||||||
|
|
||||||
NBTTagCompound gatedCompound = gated.writeToNBTPartial(new NBTTagCompound());
|
|
||||||
String[] gatedRemoved = {
|
|
||||||
"AvailabilityQuest2", "AvailabilityQuest3", "AvailabilityQuest4",
|
|
||||||
"AvailabilityQuest2Id", "AvailabilityQuest3Id", "AvailabilityQuest4Id"
|
|
||||||
};
|
|
||||||
for (String key : gatedRemoved) {
|
|
||||||
gatedCompound.removeTag(key);
|
|
||||||
}
|
|
||||||
gatedCompound.setInteger("ModRev", OLD_REV);
|
|
||||||
|
|
||||||
out.dialogRaw("Aged", 2, gatedCompound,
|
|
||||||
"the first AvailabilityQuest slot set and the other three absent entirely. Their "
|
|
||||||
+ "defaults are Always/-1, so default-filling and reading-zero happen to agree "
|
|
||||||
+ "here -- which is why this file is a weak test on its own and a useful one "
|
|
||||||
+ "beside the aged dialog above, where they disagree");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String join(String[] keys) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < keys.length; i++) {
|
|
||||||
sb.append(keys[i]);
|
|
||||||
if (i + 1 < keys.length) {
|
|
||||||
sb.append(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
package kamkeel.npcs.fixtures.worlds;
|
|
||||||
|
|
||||||
import kamkeel.npcs.fixtures.Case;
|
|
||||||
import kamkeel.npcs.fixtures.FixtureWorld;
|
|
||||||
import kamkeel.npcs.fixtures.WorldWriter;
|
|
||||||
import kamkeel.npcs.fixtures.content.DialogFixtures;
|
|
||||||
import kamkeel.npcs.fixtures.content.EffectFixtures;
|
|
||||||
import kamkeel.npcs.fixtures.content.FactionFixtures;
|
|
||||||
import kamkeel.npcs.fixtures.content.PlayerFixtures;
|
|
||||||
import kamkeel.npcs.fixtures.content.QuestFixtures;
|
|
||||||
import kamkeel.npcs.fixtures.content.WorldDataFixtures;
|
|
||||||
import noppes.npcs.controllers.data.PlayerData;
|
|
||||||
import noppes.npcs.controllers.data.CustomEffect;
|
|
||||||
import noppes.npcs.controllers.data.Dialog;
|
|
||||||
import noppes.npcs.controllers.data.Faction;
|
|
||||||
import noppes.npcs.controllers.data.Quest;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Every field CustomNPC+ can store, moved off its default at least once.
|
|
||||||
*
|
|
||||||
* <p>The world a reader is measured against. If a field is written by CustomNPC+ and absent from
|
|
||||||
* here, that is a gap in the fixtures rather than a decision.
|
|
||||||
*/
|
|
||||||
public final class MaximalWorld implements FixtureWorld {
|
|
||||||
|
|
||||||
public String name() {
|
|
||||||
return "maximal";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String purpose() {
|
|
||||||
return "every storable field moved off its default at least once, with each enum walked to "
|
|
||||||
+ "all of its constants. The world a reader is measured against.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void build(WorldWriter out) {
|
|
||||||
List<Faction> factions = FactionFixtures.maximal();
|
|
||||||
out.dat("faction", "factions.dat", FactionFixtures.document(factions, 17),
|
|
||||||
factions.size() + " factions: the three CustomNPC+ defaults, each boolean flag alone "
|
|
||||||
+ "and all together, a hostility graph, inverted thresholds and negative points");
|
|
||||||
|
|
||||||
for (Case<Dialog> c : DialogFixtures.maximal()) {
|
|
||||||
out.dialog(c.category, c.value, c.note);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Case<Quest> c : QuestFixtures.maximal()) {
|
|
||||||
out.quest(c.category, c.value, c.note);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Case<CustomEffect>> effects = EffectFixtures.maximal();
|
|
||||||
for (Case<CustomEffect> c : effects) {
|
|
||||||
out.effect(c.category, c.value, c.note);
|
|
||||||
}
|
|
||||||
out.effect("", EffectFixtures.MISMATCH_FILENAME, EffectFixtures.nameMismatch(),
|
|
||||||
"the name key inside the file says 'Name Inside The File' while the file is called '"
|
|
||||||
+ EffectFixtures.MISMATCH_FILENAME + ".json'. loadEffectsFromDir overwrites the "
|
|
||||||
+ "field from the filename after reading, so the filename wins and a reader "
|
|
||||||
+ "trusting the key gets a different answer");
|
|
||||||
|
|
||||||
out.dat("effect", "customeffects.dat", EffectFixtures.index(effects, 12),
|
|
||||||
"the custom effect INDEX -- {Name, ID} pairs and lastID, not the effects themselves, "
|
|
||||||
+ "which are the .json files under customeffects/. The unnamed effect is absent "
|
|
||||||
+ "from this index by design");
|
|
||||||
|
|
||||||
out.dat("global", "global.dat", WorldDataFixtures.global(42),
|
|
||||||
"one integer. The smallest document CustomNPC+ writes, and a useful floor for a "
|
|
||||||
+ "reader's envelope handling");
|
|
||||||
|
|
||||||
out.dat("tag", "tags.dat", WorldDataFixtures.tags(),
|
|
||||||
"five tags with explicit UUIDs, covering hidden, empty-named, non-Latin and a colour "
|
|
||||||
+ "of -1. Tag.uuid defaults to randomUUID(), so these are pinned deliberately");
|
|
||||||
|
|
||||||
out.dat("transport", "transport.dat", WorldDataFixtures.transport(),
|
|
||||||
"three categories and six locations, including negative coordinates, the Nether and "
|
|
||||||
+ "End by numeric id, and a modded dimension 7265 -- the int dimension that "
|
|
||||||
+ "stopped being expressible after 1.16");
|
|
||||||
|
|
||||||
out.dat("bank", "bank.dat", WorldDataFixtures.banks(),
|
|
||||||
"three banks with currency and upgrade inventories and per-slot types. Keyed under "
|
|
||||||
+ "'Data' with no lastID, unlike every other document here");
|
|
||||||
|
|
||||||
out.dat("spawn", "spawns.dat", WorldDataFixtures.spawns(),
|
|
||||||
"three natural spawn entries. One carries three numbered SpawnCompound keys rather "
|
|
||||||
+ "than a list, which a reader has to probe for rather than iterate");
|
|
||||||
|
|
||||||
List<Case<PlayerData>> players = PlayerFixtures.records();
|
|
||||||
for (Case<PlayerData> c : players) {
|
|
||||||
out.json("player", c.value.uuid, "playerdata/" + c.value.uuid + ".json",
|
|
||||||
c.value.getNBT(), c.note);
|
|
||||||
}
|
|
||||||
// The same record as gzipped NBT, which is what ConfigMain.DatFormat selects instead. Same
|
|
||||||
// compound, different container -- a reader has to handle both because a server operator
|
|
||||||
// chooses between them.
|
|
||||||
PlayerData asDat = players.get(1).value;
|
|
||||||
out.dat("player", "playerdata/" + asDat.uuid + ".dat", asDat.getNBT(),
|
|
||||||
"the Progressed player again, written as gzipped NBT rather than JSON. "
|
|
||||||
+ "ConfigMain.DatFormat picks the container; the compound is identical. Both "
|
|
||||||
+ "extensions are loaded by PlayerDataController, so both are real");
|
|
||||||
|
|
||||||
out.dat("player", "playerdatamap.dat", PlayerFixtures.index(PlayerFixtures.roster()),
|
|
||||||
"the name/uuid index. Derived rather than authoritative -- CustomNPC+ rebuilds it by "
|
|
||||||
+ "scanning playerdata/ when the file is missing -- but it is what gets read first");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@ import foxz.commandhelper.annotations.SubCommand;
|
|||||||
import foxz.commandhelper.permissions.OpOnly;
|
import foxz.commandhelper.permissions.OpOnly;
|
||||||
import foxz.commandhelper.permissions.ParamCheck;
|
import foxz.commandhelper.permissions.ParamCheck;
|
||||||
import kamkeel.npcs.controllers.SyncController;
|
import kamkeel.npcs.controllers.SyncController;
|
||||||
import kamkeel.npcs.network.enums.SyncType;
|
|
||||||
import net.minecraft.command.CommandBase;
|
import net.minecraft.command.CommandBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import noppes.npcs.NoppesUtilServer;
|
import noppes.npcs.NoppesUtilServer;
|
||||||
@@ -91,7 +90,7 @@ public class CmdDialog extends ChMcLogger {
|
|||||||
)
|
)
|
||||||
public boolean reload(String args[]) {
|
public boolean reload(String args[]) {
|
||||||
new DialogController().load();
|
new DialogController().load();
|
||||||
SyncController.syncAll(SyncType.DIALOG_CATEGORY);
|
SyncController.syncAllDialogs();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import foxz.commandhelper.annotations.SubCommand;
|
|||||||
import foxz.commandhelper.permissions.OpOnly;
|
import foxz.commandhelper.permissions.OpOnly;
|
||||||
import foxz.commandhelper.permissions.ParamCheck;
|
import foxz.commandhelper.permissions.ParamCheck;
|
||||||
import kamkeel.npcs.controllers.SyncController;
|
import kamkeel.npcs.controllers.SyncController;
|
||||||
import kamkeel.npcs.network.enums.SyncType;
|
|
||||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
@@ -171,7 +170,7 @@ public class CmdQuest extends ChMcLogger {
|
|||||||
)
|
)
|
||||||
public boolean reload(String args[]) {
|
public boolean reload(String args[]) {
|
||||||
new QuestController().load();
|
new QuestController().load();
|
||||||
SyncController.syncAll(SyncType.QUEST_CATEGORY);
|
SyncController.syncAllQuests();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package kamkeel.npcs.client.renderer;
|
|||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
||||||
|
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.entity.RenderManager;
|
import net.minecraft.client.renderer.entity.RenderManager;
|
||||||
@@ -25,7 +26,7 @@ public class EnergyChargePreviewRenderer {
|
|||||||
|
|
||||||
float partialTicks = event.partialTicks;
|
float partialTicks = event.partialTicks;
|
||||||
|
|
||||||
for (EntityEnergyProjectile entity : EnergyChargePreviewManager.ClientInstance.getPreviews()) {
|
for (EntityEnergyAbility entity : EnergyChargePreviewManager.ClientInstance.getPreviews()) {
|
||||||
if (entity == null || entity.isDead) continue;
|
if (entity == null || entity.isDead) continue;
|
||||||
|
|
||||||
double x = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks - RenderManager.renderPosX;
|
double x = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks - RenderManager.renderPosX;
|
||||||
|
|||||||
@@ -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 net.minecraft.util.Vec3;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 3D Vector helper class for lightning calculations.
|
* 3D Vector helper class for lightning calculations.
|
||||||
* Adapted from Botania's Vector3 by ChickenBones.
|
* Adapted from Botania's Vector3 by ChickenBones.
|
||||||
@@ -183,9 +181,4 @@ public class Vec3d {
|
|||||||
Vec3d v = (Vec3d) o;
|
Vec3d v = (Vec3d) o;
|
||||||
return x == v.x && y == v.y && z == v.z;
|
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;
|
package kamkeel.npcs.command;
|
||||||
|
|
||||||
import kamkeel.npcs.controllers.SyncController;
|
import kamkeel.npcs.controllers.SyncController;
|
||||||
import kamkeel.npcs.network.enums.SyncType;
|
|
||||||
import net.minecraft.command.CommandBase;
|
import net.minecraft.command.CommandBase;
|
||||||
import net.minecraft.command.CommandException;
|
import net.minecraft.command.CommandException;
|
||||||
import net.minecraft.command.ICommandSender;
|
import net.minecraft.command.ICommandSender;
|
||||||
@@ -94,7 +93,7 @@ public class DialogCommand extends CommandKamkeelBase {
|
|||||||
)
|
)
|
||||||
public void reload(ICommandSender sender, String args[]) {
|
public void reload(ICommandSender sender, String args[]) {
|
||||||
new DialogController().load();
|
new DialogController().load();
|
||||||
SyncController.syncAll(SyncType.DIALOG_CATEGORY);
|
SyncController.syncAllDialogs();
|
||||||
sendResult(sender, "Dialogs Reloaded");
|
sendResult(sender, "Dialogs Reloaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package kamkeel.npcs.command;
|
|||||||
|
|
||||||
import kamkeel.npcs.controllers.ProfileController;
|
import kamkeel.npcs.controllers.ProfileController;
|
||||||
import kamkeel.npcs.controllers.SyncController;
|
import kamkeel.npcs.controllers.SyncController;
|
||||||
import kamkeel.npcs.network.enums.SyncType;
|
|
||||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||||
import net.minecraft.command.CommandException;
|
import net.minecraft.command.CommandException;
|
||||||
@@ -394,7 +393,7 @@ public class QuestCommand extends CommandKamkeelBase {
|
|||||||
)
|
)
|
||||||
public void reload(ICommandSender sender, String args[]) {
|
public void reload(ICommandSender sender, String args[]) {
|
||||||
new QuestController().load();
|
new QuestController().load();
|
||||||
SyncController.syncAll(SyncType.QUEST_CATEGORY);
|
SyncController.syncAllQuests();
|
||||||
sendResult(sender, "Quests Reloaded");
|
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.AbilityTeleport;
|
||||||
import kamkeel.npcs.controllers.data.ability.type.AbilityTrap;
|
import kamkeel.npcs.controllers.data.ability.type.AbilityTrap;
|
||||||
import kamkeel.npcs.controllers.data.ability.type.AbilityVortex;
|
import kamkeel.npcs.controllers.data.ability.type.AbilityVortex;
|
||||||
import kamkeel.npcs.network.enums.SyncType;
|
import kamkeel.npcs.controllers.data.ability.type.energy.*;
|
||||||
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 net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import noppes.npcs.controllers.data.AbilityScript;
|
import noppes.npcs.controllers.data.AbilityScript;
|
||||||
import noppes.npcs.controllers.data.ChainedAbilityScript;
|
import noppes.npcs.controllers.data.ChainedAbilityScript;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
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.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import noppes.npcs.CustomNpcs;
|
import noppes.npcs.CustomNpcs;
|
||||||
import noppes.npcs.LogWriter;
|
import noppes.npcs.LogWriter;
|
||||||
@@ -181,6 +170,8 @@ public class AbilityController implements IAbilityHandler {
|
|||||||
registerType(AbilityDome::new);
|
registerType(AbilityDome::new);
|
||||||
registerType(AbilityWall::new);
|
registerType(AbilityWall::new);
|
||||||
registerType(AbilityShield::new);
|
registerType(AbilityShield::new);
|
||||||
|
|
||||||
|
registerType(AbilityPillar::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerBuiltinConditionTypes() {
|
private void registerBuiltinConditionTypes() {
|
||||||
@@ -397,7 +388,7 @@ public class AbilityController implements IAbilityHandler {
|
|||||||
customAbilitiesById.put(uuid, ability);
|
customAbilitiesById.put(uuid, ability);
|
||||||
customAbilityRevision++;
|
customAbilityRevision++;
|
||||||
LogWriter.script("Saved custom ability: " + name + " [" + uuid + "]");
|
LogWriter.script("Saved custom ability: " + name + " [" + uuid + "]");
|
||||||
SyncController.syncAll(SyncType.CUSTOM_ABILITY);
|
SyncController.syncAllCustomAbilities();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogWriter.error("Error saving custom ability: " + name, e);
|
LogWriter.error("Error saving custom ability: " + name, e);
|
||||||
@@ -473,30 +464,16 @@ public class AbilityController implements IAbilityHandler {
|
|||||||
pData.abilityData.lockAbility(name);
|
pData.abilityData.lockAbility(name);
|
||||||
changed = true;
|
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) {
|
if (changed) {
|
||||||
pData.save();
|
pData.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pData.player instanceof EntityPlayerMP) {
|
|
||||||
PlayerAbilitySyncHelper.syncAbilities((EntityPlayerMP) pData.player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customAbilityRevision++;
|
customAbilityRevision++;
|
||||||
LogWriter.script("Deleted custom ability: " + name);
|
LogWriter.script("Deleted custom ability: " + name);
|
||||||
SyncController.syncAll(SyncType.CUSTOM_ABILITY);
|
SyncController.syncAllCustomAbilities();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -783,7 +760,7 @@ public class AbilityController implements IAbilityHandler {
|
|||||||
chainedAbilitiesById.put(uuid, chain);
|
chainedAbilitiesById.put(uuid, chain);
|
||||||
chainedAbilityRevision++;
|
chainedAbilityRevision++;
|
||||||
LogWriter.script("Saved chained ability: " + name + " [" + uuid + "]");
|
LogWriter.script("Saved chained ability: " + name + " [" + uuid + "]");
|
||||||
SyncController.syncAll(SyncType.CHAINED_ABILITY);
|
SyncController.syncAllChainedAbilities();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogWriter.error("Error saving chained ability: " + name, e);
|
LogWriter.error("Error saving chained ability: " + name, e);
|
||||||
@@ -863,7 +840,7 @@ public class AbilityController implements IAbilityHandler {
|
|||||||
|
|
||||||
chainedAbilityRevision++;
|
chainedAbilityRevision++;
|
||||||
LogWriter.script("Deleted chained ability: " + name);
|
LogWriter.script("Deleted chained ability: " + name);
|
||||||
SyncController.syncAll(SyncType.CHAINED_ABILITY);
|
SyncController.syncAllChainedAbilities();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1380,17 +1357,6 @@ public class AbilityController implements IAbilityHandler {
|
|||||||
return health;
|
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.
|
* 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();
|
return sb.toString();
|
||||||
}).tab("General"));
|
}).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 ───────────────────────────────────────────────
|
// ── Target tab ───────────────────────────────────────────────
|
||||||
@@ -1050,11 +1062,10 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int windUp = getWindUpTicks();
|
telegraph.setDurationTicks(windUpTicks);
|
||||||
telegraph.setDurationTicks(windUp);
|
|
||||||
telegraph.setColor(windUpColor);
|
telegraph.setColor(windUpColor);
|
||||||
telegraph.setWarningColor(activeColor);
|
telegraph.setWarningColor(activeColor);
|
||||||
telegraph.setWarningStartTick(Math.max(5, windUp / 4));
|
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
|
||||||
telegraph.setHeightOffset(telegraphHeightOffset);
|
telegraph.setHeightOffset(telegraphHeightOffset);
|
||||||
|
|
||||||
TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw);
|
TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw);
|
||||||
@@ -1172,7 +1183,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
|||||||
this.burstIndex = 0;
|
this.burstIndex = 0;
|
||||||
this.burstEntities.clear();
|
this.burstEntities.clear();
|
||||||
|
|
||||||
if (getWindUpTicks() <= 0) {
|
if (windUpTicks <= 0) {
|
||||||
this.phase = AbilityPhase.ACTIVE;
|
this.phase = AbilityPhase.ACTIVE;
|
||||||
} else {
|
} else {
|
||||||
this.phase = AbilityPhase.WINDUP;
|
this.phase = AbilityPhase.WINDUP;
|
||||||
@@ -1194,7 +1205,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
|||||||
|
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
case WINDUP:
|
case WINDUP:
|
||||||
if (currentTick >= getWindUpTicks()) {
|
if (currentTick >= windUpTicks) {
|
||||||
phase = AbilityPhase.ACTIVE;
|
phase = AbilityPhase.ACTIVE;
|
||||||
currentTick = 0;
|
currentTick = 0;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+19
-7
@@ -34,15 +34,27 @@ public class ConditionHasEffect extends AbilityCondition {
|
|||||||
return CustomEffectController.getInstance().hasEffect(player, effectId, effectIndex);
|
return CustomEffectController.getInstance().hasEffect(player, effectId, effectIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEffect(int effectId, int effectIndex) {
|
|
||||||
this.effectId = effectId;
|
|
||||||
this.effectIndex = effectIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@Override
|
@Override
|
||||||
public void getConditionDefinitions(List<FieldDef> defs) {
|
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)
|
@SideOnly(Side.CLIENT)
|
||||||
@@ -62,7 +74,7 @@ public class ConditionHasEffect extends AbilityCondition {
|
|||||||
return effectId >= 0;
|
return effectId >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomEffect getEffect() {
|
private CustomEffect getEffect() {
|
||||||
HashMap<Integer, CustomEffect> map = CustomEffectController.getInstance().getEffectMap(effectIndex);
|
HashMap<Integer, CustomEffect> map = CustomEffectController.getInstance().getEffectMap(effectIndex);
|
||||||
return map != null ? map.get(effectId) : null;
|
return map != null ? map.get(effectId) : null;
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -38,7 +38,20 @@ public class ConditionQuestCompleted extends AbilityCondition {
|
|||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@Override
|
@Override
|
||||||
public void getConditionDefinitions(List<FieldDef> defs) {
|
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)
|
@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.conditions.AbilityCondition;
|
||||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,13 +108,6 @@ public interface IAbilityExtender {
|
|||||||
return baseHealth;
|
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.
|
* Called when an ability is about to heal an entity.
|
||||||
* Return true to handle the healing (skip default entity.heal()).
|
* 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.targetingMode = TargetingMode.AGGRO_TARGET;
|
||||||
this.maxRange = 20.0f;
|
this.maxRange = 20.0f;
|
||||||
this.minRange = 4.0f;
|
this.minRange = 4.0f;
|
||||||
this.lockMovement = LockMode.WINDUP_AND_ACTIVE;
|
this.lockMovement = LockMode.WINDUP;
|
||||||
this.cooldownTicks = 0;
|
this.cooldownTicks = 0;
|
||||||
this.windUpTicks = 20;
|
this.windUpTicks = 20;
|
||||||
// LINE telegraph showing charge path
|
// 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
|
@Override
|
||||||
public boolean isTargetingModeLocked() {
|
public boolean isTargetingModeLocked() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -3,21 +3,14 @@ package kamkeel.npcs.controllers.data.ability.type;
|
|||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import kamkeel.npcs.addon.DBCAddon;
|
import kamkeel.npcs.addon.DBCAddon;
|
||||||
import noppes.npcs.AbstractDataAbilities;
|
|
||||||
import noppes.npcs.controllers.AnimationController;
|
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.enums.UserType;
|
||||||
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
|
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.DamageSource;
|
|
||||||
import noppes.npcs.controllers.data.Animation;
|
import noppes.npcs.controllers.data.Animation;
|
||||||
import noppes.npcs.controllers.data.PlayerData;
|
|
||||||
import noppes.npcs.api.ability.type.IAbilityCounter;
|
import noppes.npcs.api.ability.type.IAbilityCounter;
|
||||||
import noppes.npcs.client.gui.builder.FieldDef;
|
import noppes.npcs.client.gui.builder.FieldDef;
|
||||||
import noppes.npcs.entity.EntityNPCInterface;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -32,11 +25,6 @@ public class AbilityCounter extends AbilityDefend implements IAbilityCounter {
|
|||||||
private int counterAnimationId = -1;
|
private int counterAnimationId = -1;
|
||||||
private String counterAnimationName = "Ability_Guard_Counter";
|
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() {
|
public AbilityCounter() {
|
||||||
this.typeId = "ability.cnpc.counter";
|
this.typeId = "ability.cnpc.counter";
|
||||||
this.name = "Counter";
|
this.name = "Counter";
|
||||||
@@ -72,35 +60,6 @@ public class AbilityCounter extends AbilityDefend implements IAbilityCounter {
|
|||||||
// DEFEND HOOKS
|
// 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
|
@Override
|
||||||
protected float performDefend(EntityLivingBase attacker, float amount) {
|
protected float performDefend(EntityLivingBase attacker, float amount) {
|
||||||
// For PERCENT mode with DBC, use the full DBC-calculated damage, not vanilla base
|
// 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.
|
// Counter-attack through the standard ability damage pipeline.
|
||||||
// DBCAbilityExtender handles DBC stat routing (ignore flags, scaling, etc.) automatically.
|
// DBCAbilityExtender handles DBC stat routing (ignore flags, scaling, etc.) automatically.
|
||||||
if (caster != null && attacker != null && attacker.isEntityAlive() && damage > 0) {
|
if (caster != null && attacker.isEntityAlive() && damage > 0) {
|
||||||
retaliating = true;
|
applyAbilityDamage(caster, attacker, damage, 0);
|
||||||
try {
|
|
||||||
applyAbilityDamage(caster, attacker, damage, 0);
|
|
||||||
} finally {
|
|
||||||
retaliating = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reset() {
|
|
||||||
super.reset();
|
|
||||||
retaliating = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
// OVERRIDES
|
// OVERRIDES
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
|
|||||||
@@ -74,10 +74,6 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend {
|
|||||||
hitCount = 0;
|
hitCount = 0;
|
||||||
lastAttacker = null;
|
lastAttacker = null;
|
||||||
lastDamageTaken = 0.0f;
|
lastDamageTaken = 0.0f;
|
||||||
pendingDefendAnimation = null;
|
|
||||||
defendAnimEndTick = -1;
|
|
||||||
lastDefendTick = -1;
|
|
||||||
pendingCompletion = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
|
|||||||
readZoneNBT(nbt, 300);
|
readZoneNBT(nbt, 300);
|
||||||
this.radius = nbt.getFloat("radius");
|
this.radius = nbt.getFloat("radius");
|
||||||
this.damagePerSecond = nbt.getFloat("damagePerSecond");
|
this.damagePerSecond = nbt.getFloat("damagePerSecond");
|
||||||
setDamageInterval(nbt.getInteger("damageInterval"));
|
this.damageInterval = nbt.getInteger("damageInterval");
|
||||||
this.affectsCaster = nbt.getBoolean("affectsCaster");
|
this.affectsCaster = nbt.getBoolean("affectsCaster");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setDamageInterval(int damageInterval) {
|
public void setDamageInterval(int damageInterval) {
|
||||||
this.damageInterval = Math.max(EntityAbilityZone.MIN_DAMAGE_INTERVAL, damageInterval);
|
this.damageInterval = damageInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAffectsCaster() {
|
public boolean isAffectsCaster() {
|
||||||
@@ -171,7 +171,6 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
|
|||||||
FieldDef.row(
|
FieldDef.row(
|
||||||
FieldDef.floatField("gui.dps", this::getDamagePerSecond, this::setDamagePerSecond),
|
FieldDef.floatField("gui.dps", this::getDamagePerSecond, this::setDamagePerSecond),
|
||||||
FieldDef.intField("gui.interval", this::getDamageInterval, this::setDamageInterval)
|
FieldDef.intField("gui.interval", this::getDamageInterval, this::setDamageInterval)
|
||||||
.range(EntityAbilityZone.MIN_DAMAGE_INTERVAL, 2000)
|
|
||||||
),
|
),
|
||||||
FieldDef.boolField("ability.affectsCaster", this::isAffectsCaster, this::setAffectsCaster)
|
FieldDef.boolField("ability.affectsCaster", this::isAffectsCaster, this::setAffectsCaster)
|
||||||
.hover("ability.hover.affectsCaster"),
|
.hover("ability.hover.affectsCaster"),
|
||||||
|
|||||||
@@ -97,13 +97,6 @@ public class AbilityProjectile extends Ability implements IAbilityProjectile {
|
|||||||
dz /= len;
|
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);
|
applyAbilityDamageWithDirection(caster, target, damage, knockback, dx, dz);
|
||||||
world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f);
|
world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f);
|
||||||
|
|
||||||
|
|||||||
@@ -300,7 +300,14 @@ public class AbilityTrap extends AbilityZone implements IAbilityTrap {
|
|||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@Override
|
@Override
|
||||||
protected void addPresetFieldDef(List<FieldDef> defs) {
|
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)
|
@SideOnly(Side.CLIENT)
|
||||||
|
|||||||
@@ -690,7 +690,14 @@ public abstract class AbilityZone extends Ability {
|
|||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
protected void addPresetFieldDef(List<FieldDef> defs) {
|
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)
|
@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.
|
* NPCs use their resolved target so launch math can track the target immediately.
|
||||||
*/
|
*/
|
||||||
protected EntityLivingBase getLaunchTarget(EntityLivingBase caster, EntityLivingBase target) {
|
protected EntityLivingBase getLaunchTarget(EntityLivingBase caster, EntityLivingBase target) {
|
||||||
if (isPlayerCaster(caster)) return null;
|
return isPlayerCaster(caster) ? null : target;
|
||||||
if (isRotationLockedForCurrentPhase()) return null;
|
|
||||||
return 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;
|
package kamkeel.npcs.controllers.data.energycharge;
|
||||||
|
|
||||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -18,13 +18,13 @@ public class EnergyChargePreviewManager {
|
|||||||
|
|
||||||
public static EnergyChargePreviewManager ClientInstance;
|
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() {
|
public static void initClient() {
|
||||||
ClientInstance = new EnergyChargePreviewManager();
|
ClientInstance = new EnergyChargePreviewManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPreview(String instanceId, EntityEnergyProjectile entity) {
|
public void addPreview(String instanceId, EntityEnergyAbility entity) {
|
||||||
if (instanceId == null || entity == null) return;
|
if (instanceId == null || entity == null) return;
|
||||||
previews.put(instanceId, entity);
|
previews.put(instanceId, entity);
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ public class EnergyChargePreviewManager {
|
|||||||
previews.remove(instanceId);
|
previews.remove(instanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<EntityEnergyProjectile> getPreviews() {
|
public Collection<EntityEnergyAbility> getPreviews() {
|
||||||
return previews.values();
|
return previews.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,9 +55,9 @@ public class EnergyChargePreviewManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<EntityEnergyProjectile> iterator = previews.values().iterator();
|
Iterator<EntityEnergyAbility> iterator = previews.values().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
EntityEnergyProjectile entity = iterator.next();
|
EntityEnergyAbility entity = iterator.next();
|
||||||
if (entity == null || entity.isDead || entity.worldObj != world) {
|
if (entity == null || entity.isDead || entity.worldObj != world) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package kamkeel.npcs.controllers.data.profile;
|
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.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -30,7 +30,7 @@ public class CNPCData implements IProfileData {
|
|||||||
public void save(EntityPlayer player) {
|
public void save(EntityPlayer player) {
|
||||||
PlayerData customNPCData = PlayerData.get(player);
|
PlayerData customNPCData = PlayerData.get(player);
|
||||||
customNPCData.save();
|
customNPCData.save();
|
||||||
PlayerDataSyncHandler.syncPlayerData((EntityPlayerMP) player, false);
|
SyncController.syncPlayerData((EntityPlayerMP) player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
Vec3 anchorPos = AnchorPointHelper.calculateAnchorPosition(livingOwner, anchorData);
|
||||||
setPosition(anchorPos.xCoord, anchorPos.yCoord, anchorPos.zCoord);
|
setPosition(anchorPos.xCoord, anchorPos.yCoord, anchorPos.zCoord);
|
||||||
|
|
||||||
// Aim where the owner is looking so track speed and rotation lock still apply.
|
Entity targetEntity = getTargetEntity();
|
||||||
double aimX = livingOwner.posX + dirX * maxLength;
|
if (targetEntity instanceof EntityLivingBase && targetEntity.isEntityAlive()) {
|
||||||
double aimY = livingOwner.posY + livingOwner.getEyeHeight() + dirY * maxLength;
|
EntityLivingBase target = (EntityLivingBase) targetEntity;
|
||||||
double aimZ = livingOwner.posZ + dirZ * maxLength;
|
double dx = target.posX - anchorPos.xCoord;
|
||||||
double dx = aimX - anchorPos.xCoord;
|
double dy = (target.posY + target.getEyeHeight() - 0.4) - anchorPos.yCoord;
|
||||||
double dy = aimY - anchorPos.yCoord;
|
double dz = target.posZ - anchorPos.zCoord;
|
||||||
double dz = aimZ - anchorPos.zCoord;
|
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
if (len > 0.0001) {
|
||||||
if (len > 0.0001) {
|
dirX = dx / len;
|
||||||
dirX = dx / len;
|
dirY = dy / len;
|
||||||
dirY = dy / len;
|
dirZ = dz / len;
|
||||||
dirZ = dz / len;
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Vec3 direction = Vec3.createVectorHelper(dirX, dirY, dirZ);
|
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
|
// HAZARD-SPECIFIC PROPERTIES
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
public static final int MIN_DAMAGE_INTERVAL = 5;
|
|
||||||
|
|
||||||
private float damagePerSecond = 1.0f;
|
private float damagePerSecond = 1.0f;
|
||||||
private int damageInterval = 20;
|
private int damageInterval = 20;
|
||||||
private boolean ignoreIFrames = false;
|
private boolean ignoreIFrames = false;
|
||||||
@@ -293,7 +291,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
|||||||
zone.shape = shape;
|
zone.shape = shape;
|
||||||
zone.radius = radius;
|
zone.radius = radius;
|
||||||
zone.damagePerSecond = damagePerSecond;
|
zone.damagePerSecond = damagePerSecond;
|
||||||
zone.damageInterval = Math.max(MIN_DAMAGE_INTERVAL, damageInterval);
|
zone.damageInterval = damageInterval;
|
||||||
zone.ignoreIFrames = ignoreIFrames;
|
zone.ignoreIFrames = ignoreIFrames;
|
||||||
zone.affectsCaster = affectsCaster;
|
zone.affectsCaster = affectsCaster;
|
||||||
zone.durationTicks = durationTicks;
|
zone.durationTicks = durationTicks;
|
||||||
@@ -311,6 +309,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
|||||||
zone.effects.add(e.copy());
|
zone.effects.add(e.copy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
zone.ticksSinceDamage = damageInterval;
|
||||||
return zone;
|
return zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,7 +518,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
|||||||
if (!isInZone(entity)) continue;
|
if (!isInZone(entity)) continue;
|
||||||
|
|
||||||
if (damagePerSecond > 0) {
|
if (damagePerSecond > 0) {
|
||||||
applyDamage(entity, owner, damagePerSecond * (damageInterval / 20.0f));
|
applyDamage(entity, owner, damagePerSecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyEffects(entity);
|
applyEffects(entity);
|
||||||
@@ -816,7 +815,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
|
|||||||
public float getDamagePerSecond() { return damagePerSecond; }
|
public float getDamagePerSecond() { return damagePerSecond; }
|
||||||
public void setDamagePerSecond(float dps) { this.damagePerSecond = dps; }
|
public void setDamagePerSecond(float dps) { this.damagePerSecond = dps; }
|
||||||
public int getDamageInterval() { return damageInterval; }
|
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 boolean isAffectsCaster() { return affectsCaster; }
|
||||||
public void setAffectsCaster(boolean affects) { this.affectsCaster = affects; }
|
public void setAffectsCaster(boolean affects) { this.affectsCaster = affects; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package kamkeel.npcs.entity;
|
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.util.AbilityTargetHelper;
|
||||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyBarrierData;
|
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyBarrierData;
|
||||||
import kamkeel.npcs.network.packets.data.energy.BarrierClientSyncPacket;
|
import kamkeel.npcs.network.packets.data.energy.BarrierClientSyncPacket;
|
||||||
@@ -17,7 +15,6 @@ import net.minecraft.util.DamageSource;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import noppes.npcs.CustomNpcs;
|
import noppes.npcs.CustomNpcs;
|
||||||
import noppes.npcs.EventHooks;
|
import noppes.npcs.EventHooks;
|
||||||
import noppes.npcs.config.ConfigMain;
|
|
||||||
import noppes.npcs.controllers.data.MagicData;
|
import noppes.npcs.controllers.data.MagicData;
|
||||||
import noppes.npcs.controllers.data.PlayerData;
|
import noppes.npcs.controllers.data.PlayerData;
|
||||||
import noppes.npcs.entity.EntityNPCInterface;
|
import noppes.npcs.entity.EntityNPCInterface;
|
||||||
@@ -117,7 +114,6 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
|||||||
protected EnergyBarrierData barrierData = new EnergyBarrierData();
|
protected EnergyBarrierData barrierData = new EnergyBarrierData();
|
||||||
protected float currentHealth;
|
protected float currentHealth;
|
||||||
protected int ticksAlive = 0;
|
protected int ticksAlive = 0;
|
||||||
protected long barrierDeathTime = -1;
|
|
||||||
|
|
||||||
// ==================== DATA WATCHER INDICES ====================
|
// ==================== DATA WATCHER INDICES ====================
|
||||||
protected static final int DW_HEALTH_PERCENT = 21;
|
protected static final int DW_HEALTH_PERCENT = 21;
|
||||||
@@ -440,17 +436,8 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
|||||||
|
|
||||||
float damage = amount * barrierData.meleeDamageMultiplier;
|
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
|
// Apply magic interactions from attacker's magic vs barrier's magic
|
||||||
|
Entity attacker = source.getEntity();
|
||||||
if (attacker != null) {
|
if (attacker != null) {
|
||||||
MagicData attackerMagic = null;
|
MagicData attackerMagic = null;
|
||||||
if (attacker instanceof EntityPlayer) {
|
if (attacker instanceof EntityPlayer) {
|
||||||
@@ -523,13 +510,15 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barrierDeathTime < 0 && !isCharging()) {
|
// Duration check
|
||||||
barrierDeathTime = worldObj.getTotalWorldTime()
|
if (barrierData.useDuration && ticksAlive >= barrierData.durationTicks) {
|
||||||
+ (barrierData.useDuration ? barrierData.durationTicks : BARRIER_HARD_LIFETIME_CAP);
|
onBarrierDestroyed();
|
||||||
|
this.setDead();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duration check
|
// Absolute hard lifetime cap (safety net for barriers with no duration)
|
||||||
if (barrierDeathTime >= 0 && worldObj.getTotalWorldTime() >= barrierDeathTime) {
|
if (ticksAlive > BARRIER_HARD_LIFETIME_CAP) {
|
||||||
onBarrierDestroyed();
|
onBarrierDestroyed();
|
||||||
this.setDead();
|
this.setDead();
|
||||||
return true;
|
return true;
|
||||||
@@ -876,7 +865,6 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
|||||||
protected void writeBarrierBaseNBT(NBTTagCompound nbt) {
|
protected void writeBarrierBaseNBT(NBTTagCompound nbt) {
|
||||||
writeEnergyBaseNBT(nbt);
|
writeEnergyBaseNBT(nbt);
|
||||||
nbt.setInteger("TicksAlive", ticksAlive);
|
nbt.setInteger("TicksAlive", ticksAlive);
|
||||||
nbt.setLong("BarrierDeathTime", barrierDeathTime);
|
|
||||||
nbt.setFloat("CurrentHealth", currentHealth);
|
nbt.setFloat("CurrentHealth", currentHealth);
|
||||||
nbt.setBoolean("Charging", charging);
|
nbt.setBoolean("Charging", charging);
|
||||||
nbt.setInteger("ChargeTick", chargeTick);
|
nbt.setInteger("ChargeTick", chargeTick);
|
||||||
@@ -891,7 +879,6 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
|||||||
protected void readBarrierBaseNBT(NBTTagCompound nbt) {
|
protected void readBarrierBaseNBT(NBTTagCompound nbt) {
|
||||||
readEnergyBaseNBT(nbt);
|
readEnergyBaseNBT(nbt);
|
||||||
this.ticksAlive = nbt.getInteger("TicksAlive");
|
this.ticksAlive = nbt.getInteger("TicksAlive");
|
||||||
this.barrierDeathTime = nbt.hasKey("BarrierDeathTime") ? nbt.getLong("BarrierDeathTime") : -1;
|
|
||||||
this.currentHealth = nbt.getFloat("CurrentHealth");
|
this.currentHealth = nbt.getFloat("CurrentHealth");
|
||||||
if (Float.isNaN(currentHealth) || Float.isInfinite(currentHealth) || currentHealth < 0) currentHealth = barrierData.maxHealth;
|
if (Float.isNaN(currentHealth) || Float.isInfinite(currentHealth) || currentHealth < 0) currentHealth = barrierData.maxHealth;
|
||||||
this.charging = nbt.hasKey("Charging") && nbt.getBoolean("Charging");
|
this.charging = nbt.hasKey("Charging") && nbt.getBoolean("Charging");
|
||||||
|
|||||||
@@ -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.PacketClient;
|
||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
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.network.packets.player.SyncRevisionInfoPacket;
|
||||||
import kamkeel.npcs.util.ByteBufUtils;
|
import kamkeel.npcs.util.ByteBufUtils;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
@@ -21,20 +21,19 @@ import noppes.npcs.controllers.AuctionConfigSync;
|
|||||||
import noppes.npcs.controllers.ScriptConfigSync;
|
import noppes.npcs.controllers.ScriptConfigSync;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.EnumMap;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public final class LoginPacket extends AbstractPacket {
|
public final class LoginPacket extends AbstractPacket {
|
||||||
public static final String packetName = "CNPC+|Login";
|
public static final String packetName = "CNPC+|Login";
|
||||||
|
|
||||||
private String serverCacheKey = "";
|
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() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginPacket(String serverCacheKey, Map<SyncType, Integer> revisionSnapshot) {
|
public LoginPacket(String serverCacheKey, EnumMap<EnumSyncType, Integer> revisionSnapshot) {
|
||||||
if (serverCacheKey != null) {
|
if (serverCacheKey != null) {
|
||||||
this.serverCacheKey = serverCacheKey;
|
this.serverCacheKey = serverCacheKey;
|
||||||
}
|
}
|
||||||
@@ -59,15 +58,17 @@ public final class LoginPacket extends AbstractPacket {
|
|||||||
out.writeBoolean(ConfigMain.ProfilesEnabled);
|
out.writeBoolean(ConfigMain.ProfilesEnabled);
|
||||||
ByteBufUtils.writeString(out, serverCacheKey);
|
ByteBufUtils.writeString(out, serverCacheKey);
|
||||||
out.writeShort(revisionSnapshot.size());
|
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.getKey().ordinal());
|
||||||
out.writeInt(entry.getValue());
|
out.writeInt(entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send auction config (server-side sync)
|
||||||
NBTTagCompound auctionConfig = new NBTTagCompound();
|
NBTTagCompound auctionConfig = new NBTTagCompound();
|
||||||
AuctionConfigSync.writeToNBT(auctionConfig);
|
AuctionConfigSync.writeToNBT(auctionConfig);
|
||||||
ByteBufUtils.writeNBT(out, auctionConfig);
|
ByteBufUtils.writeNBT(out, auctionConfig);
|
||||||
|
|
||||||
|
// Send script config (server-side sync)
|
||||||
NBTTagCompound scriptConfig = new NBTTagCompound();
|
NBTTagCompound scriptConfig = new NBTTagCompound();
|
||||||
ScriptConfigSync.writeToNBT(scriptConfig);
|
ScriptConfigSync.writeToNBT(scriptConfig);
|
||||||
ByteBufUtils.writeNBT(out, scriptConfig);
|
ByteBufUtils.writeNBT(out, scriptConfig);
|
||||||
@@ -81,20 +82,20 @@ public final class LoginPacket extends AbstractPacket {
|
|||||||
|
|
||||||
String serverKey = ByteBufUtils.readString(in);
|
String serverKey = ByteBufUtils.readString(in);
|
||||||
int revisionCount = in.readUnsignedShort();
|
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++) {
|
for (int i = 0; i < revisionCount; i++) {
|
||||||
SyncType type = SyncType.byOrdinal(in.readInt());
|
EnumSyncType type = EnumSyncType.values()[in.readInt()];
|
||||||
int revision = in.readInt();
|
int revision = in.readInt();
|
||||||
if (type != null) {
|
serverRevisions.put(type, revision);
|
||||||
serverRevisions.put(type, revision);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientCacheHandler.setActiveServer(serverKey, serverRevisions);
|
ClientCacheHandler.setActiveServer(serverKey, serverRevisions);
|
||||||
|
|
||||||
|
// Read auction config
|
||||||
NBTTagCompound auctionConfig = ByteBufUtils.readNBT(in);
|
NBTTagCompound auctionConfig = ByteBufUtils.readNBT(in);
|
||||||
AuctionClientConfig.readFromNBT(auctionConfig);
|
AuctionClientConfig.readFromNBT(auctionConfig);
|
||||||
|
|
||||||
|
// Read script config
|
||||||
NBTTagCompound scriptConfig = ByteBufUtils.readNBT(in);
|
NBTTagCompound scriptConfig = ByteBufUtils.readNBT(in);
|
||||||
ScriptClientConfig.readFromNBT(scriptConfig);
|
ScriptClientConfig.readFromNBT(scriptConfig);
|
||||||
|
|
||||||
|
|||||||
+9
-12
@@ -8,24 +8,24 @@ import kamkeel.npcs.network.PacketChannel;
|
|||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||||
import kamkeel.npcs.util.ByteBufUtils;
|
import kamkeel.npcs.util.ByteBufUtils;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import noppes.npcs.client.NoppesUtil;
|
import noppes.npcs.client.NoppesUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class PlayerUpdateSkinOverlaysPacket extends AbstractPacket {
|
public final class PlayerUpdateSkinOverlaysPacket extends AbstractPacket {
|
||||||
public static final String packetName = "Data|PlayerUpdateSkinOverlays";
|
public static final String packetName = "Data|PlayerUpdateSkinOverlays";
|
||||||
|
|
||||||
private String playerUUID;
|
private String playerName;
|
||||||
private NBTTagCompound compound;
|
private NBTTagCompound compound;
|
||||||
|
|
||||||
public PlayerUpdateSkinOverlaysPacket() {
|
public PlayerUpdateSkinOverlaysPacket() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerUpdateSkinOverlaysPacket(UUID playerUUID, NBTTagCompound compound) {
|
public PlayerUpdateSkinOverlaysPacket(String playerName, NBTTagCompound compound) {
|
||||||
this.playerUUID = playerUUID == null ? "" : playerUUID.toString();
|
this.playerName = playerName;
|
||||||
this.compound = compound;
|
this.compound = compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,21 +41,18 @@ public final class PlayerUpdateSkinOverlaysPacket extends AbstractPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendData(ByteBuf out) throws IOException {
|
public void sendData(ByteBuf out) throws IOException {
|
||||||
ByteBufUtils.writeString(out, this.playerUUID);
|
ByteBufUtils.writeString(out, this.playerName);
|
||||||
ByteBufUtils.writeNBT(out, this.compound);
|
ByteBufUtils.writeNBT(out, this.compound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@Override
|
@Override
|
||||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||||
String uuid = ByteBufUtils.readString(in);
|
String playerName = ByteBufUtils.readString(in);
|
||||||
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
|
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
|
||||||
if (uuid == null || uuid.isEmpty())
|
EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(playerName);
|
||||||
return;
|
if (sendingPlayer != null) {
|
||||||
|
NoppesUtil.updateSkinOverlayData(sendingPlayer, nbt);
|
||||||
try {
|
|
||||||
NoppesUtil.updateSkinOverlayData(UUID.fromString(uuid), nbt);
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-6
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
|||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
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.AbstractPacket;
|
||||||
import kamkeel.npcs.network.PacketChannel;
|
import kamkeel.npcs.network.PacketChannel;
|
||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
@@ -68,7 +68,7 @@ public final class EnergyChargeSpawnPacket extends AbstractPacket {
|
|||||||
World world = Minecraft.getMinecraft().theWorld;
|
World world = Minecraft.getMinecraft().theWorld;
|
||||||
if (world == null) return;
|
if (world == null) return;
|
||||||
|
|
||||||
EntityEnergyProjectile preview = createPreviewEntity(className, world);
|
EntityEnergyAbility preview = createPreviewEntity(className, world);
|
||||||
if (preview == null) return;
|
if (preview == null) return;
|
||||||
|
|
||||||
preview.setPreviewMode(true);
|
preview.setPreviewMode(true);
|
||||||
@@ -84,22 +84,22 @@ public final class EnergyChargeSpawnPacket extends AbstractPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
private static EntityEnergyProjectile createPreviewEntity(String className, World world) {
|
private static EntityEnergyAbility createPreviewEntity(String className, World world) {
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = Class.forName(className);
|
Class<?> clazz = Class.forName(className);
|
||||||
if (!EntityEnergyProjectile.class.isAssignableFrom(clazz)) {
|
if (!EntityEnergyAbility.class.isAssignableFrom(clazz)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Constructor<?> constructor = clazz.getConstructor(World.class);
|
Constructor<?> constructor = clazz.getConstructor(World.class);
|
||||||
Object instance = constructor.newInstance(world);
|
Object instance = constructor.newInstance(world);
|
||||||
return (EntityEnergyProjectile) instance;
|
return (EntityEnergyAbility) instance;
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
return null;
|
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;
|
if (previewEntity == null || trackingEntity == null) return;
|
||||||
String className = previewEntity.getClass().getName();
|
String className = previewEntity.getClass().getName();
|
||||||
NBTTagCompound nbt = previewEntity.exportSpawnNBT();
|
NBTTagCompound nbt = previewEntity.exportSpawnNBT();
|
||||||
|
|||||||
@@ -9,9 +9,13 @@ import kamkeel.npcs.network.PacketChannel;
|
|||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||||
import kamkeel.npcs.util.ByteBufUtils;
|
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.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
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 noppes.npcs.client.gui.util.IGuiData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -55,6 +59,15 @@ public final class GuiDataPacket extends LargeAbstractPacket {
|
|||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@Override
|
@Override
|
||||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
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 cpw.mods.fml.relauncher.SideOnly;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
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.LargeAbstractPacket;
|
||||||
import kamkeel.npcs.network.PacketChannel;
|
import kamkeel.npcs.network.PacketChannel;
|
||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
@@ -54,7 +54,7 @@ public final class SyncEffectPacket extends LargeAbstractPacket {
|
|||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
NBTTagCompound tag = ByteBufUtils.readBigNBT(data);
|
NBTTagCompound tag = ByteBufUtils.readBigNBT(data);
|
||||||
PlayerEffectSyncHelper.clientSyncEffects(tag);
|
SyncController.clientSyncEffects(tag);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
LogWriter.error(String.format("Attempted to Sync Effects but it was too big"));
|
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.PacketHandler;
|
||||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||||
import kamkeel.npcs.network.enums.SyncType;
|
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||||
import kamkeel.npcs.util.ByteBufUtils;
|
import kamkeel.npcs.util.ByteBufUtils;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -22,13 +22,16 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
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 {
|
public final class SyncPacket extends LargeAbstractPacket {
|
||||||
|
|
||||||
private SyncType syncType;
|
private EnumSyncType enumSyncType;
|
||||||
private EnumSyncAction enumSyncAction;
|
private EnumSyncAction enumSyncAction;
|
||||||
private NBTTagCompound syncData;
|
private NBTTagCompound syncData;
|
||||||
private int operationID;
|
private int operationID;
|
||||||
private String operationKey;
|
|
||||||
private int revision = -1;
|
private int revision = -1;
|
||||||
private byte[] cachedPayload;
|
private byte[] cachedPayload;
|
||||||
private byte[][] cachedChunks;
|
private byte[][] cachedChunks;
|
||||||
@@ -36,21 +39,23 @@ public final class SyncPacket extends LargeAbstractPacket {
|
|||||||
public SyncPacket() {
|
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) {
|
public SyncPacket(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int catId, int revision, NBTTagCompound syncData) {
|
||||||
this.syncType = syncType;
|
this.enumSyncType = enumSyncType;
|
||||||
this.enumSyncAction = enumSyncAction;
|
this.enumSyncAction = enumSyncAction;
|
||||||
this.syncData = syncData;
|
this.syncData = syncData;
|
||||||
this.operationID = operationId;
|
this.operationID = catId;
|
||||||
this.operationKey = operationKey;
|
|
||||||
this.revision = revision;
|
this.revision = revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyncPacket(SyncType syncType, SyncController.CachedSyncPayload payload) {
|
public SyncPacket(EnumSyncType enumSyncType, SyncController.CachedSyncPayload payload) {
|
||||||
this.syncType = syncType;
|
this.enumSyncType = enumSyncType;
|
||||||
this.enumSyncAction = EnumSyncAction.RELOAD;
|
this.enumSyncAction = EnumSyncAction.RELOAD;
|
||||||
this.operationID = -1;
|
this.operationID = -1;
|
||||||
this.revision = payload.getRevision();
|
this.revision = payload.getRevision();
|
||||||
@@ -74,21 +79,13 @@ public final class SyncPacket extends LargeAbstractPacket {
|
|||||||
return cachedPayload;
|
return cachedPayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasKey = operationKey != null;
|
|
||||||
boolean hasNbt = syncData != null;
|
|
||||||
|
|
||||||
ByteBuf buffer = Unpooled.buffer();
|
ByteBuf buffer = Unpooled.buffer();
|
||||||
try {
|
try {
|
||||||
buffer.writeInt(syncType.ordinal());
|
buffer.writeInt(enumSyncType.ordinal());
|
||||||
buffer.writeInt(enumSyncAction.ordinal());
|
buffer.writeInt(enumSyncAction.ordinal());
|
||||||
buffer.writeInt(operationID);
|
buffer.writeInt(operationID);
|
||||||
buffer.writeInt(revision);
|
buffer.writeInt(revision);
|
||||||
|
ByteBufUtils.writeBigNBT(buffer, syncData);
|
||||||
// UPDATE/REMOVE UNIQUE FIELDS
|
|
||||||
buffer.writeBoolean(hasKey);
|
|
||||||
if (hasKey) ByteBufUtils.writeString(buffer, operationKey);
|
|
||||||
buffer.writeBoolean(hasNbt);
|
|
||||||
if (hasNbt) ByteBufUtils.writeBigNBT(buffer, syncData);
|
|
||||||
|
|
||||||
byte[] bytes = new byte[buffer.readableBytes()];
|
byte[] bytes = new byte[buffer.readableBytes()];
|
||||||
buffer.readBytes(bytes);
|
buffer.readBytes(bytes);
|
||||||
@@ -134,40 +131,39 @@ public final class SyncPacket extends LargeAbstractPacket {
|
|||||||
if (CustomNpcs.side() != Side.CLIENT)
|
if (CustomNpcs.side() != Side.CLIENT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Reconstruct everything from the ByteBuf
|
||||||
int syncTypeOrdinal = data.readInt();
|
int syncTypeOrdinal = data.readInt();
|
||||||
int syncActionOrdinal = data.readInt();
|
int syncActionOrdinal = data.readInt();
|
||||||
operationID = data.readInt();
|
int categoryID = data.readInt();
|
||||||
revision = data.readInt();
|
int incomingRevision = data.readInt();
|
||||||
|
|
||||||
|
EnumSyncType type = EnumSyncType.values()[syncTypeOrdinal];
|
||||||
EnumSyncAction action = EnumSyncAction.values()[syncActionOrdinal];
|
EnumSyncAction action = EnumSyncAction.values()[syncActionOrdinal];
|
||||||
|
try {
|
||||||
// These fields only exist for UPDATE/REMOVE
|
NBTTagCompound tag = ByteBufUtils.readBigNBT(data);
|
||||||
if (action != EnumSyncAction.RELOAD) {
|
// Now do your client-side logic (similar to your old clientSync() or clientSyncUpdate() approach)
|
||||||
if (data.readBoolean()) operationKey = ByteBufUtils.readString(data);
|
handleSyncPacketClient(type, action, categoryID, incomingRevision, tag);
|
||||||
if (data.readBoolean()) syncData = ByteBufUtils.readBigNBT(data);
|
} catch (RuntimeException e) {
|
||||||
} else
|
LogWriter.error(String.format("Attempted to Sync %s but it was too big", type.toString()));
|
||||||
syncData = ByteBufUtils.readBigNBT(data);
|
|
||||||
|
|
||||||
|
|
||||||
syncType = SyncType.byOrdinal(syncTypeOrdinal);
|
|
||||||
if (syncType == null) {
|
|
||||||
LogWriter.error("[SyncPacket] Unknown sync type ordinal: " + syncTypeOrdinal + "; skipping");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSync(syncType, action, operationID, operationKey, revision, syncData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSync(SyncType type, EnumSyncAction action, int id, String key, int revision, NBTTagCompound data) {
|
private void handleSyncPacketClient(
|
||||||
switch (action) {
|
EnumSyncType enumSyncType,
|
||||||
|
EnumSyncAction enumSyncAction,
|
||||||
|
int id,
|
||||||
|
int incomingRevision,
|
||||||
|
NBTTagCompound data
|
||||||
|
) {
|
||||||
|
switch (enumSyncAction) {
|
||||||
case RELOAD:
|
case RELOAD:
|
||||||
SyncController.clientHandleAll(type, revision, data);
|
SyncController.clientSync(enumSyncType, incomingRevision, data);
|
||||||
break;
|
break;
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
SyncController.clientHandleUpdate(type, id, key, revision, data);
|
SyncController.clientUpdate(enumSyncType, id, incomingRevision, data);
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
SyncController.clientHandleRemove(type, id, key, revision);
|
SyncController.clientSyncRemove(enumSyncType, id, incomingRevision);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import kamkeel.npcs.network.AbstractPacket;
|
|||||||
import kamkeel.npcs.network.PacketChannel;
|
import kamkeel.npcs.network.PacketChannel;
|
||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||||
import kamkeel.npcs.network.enums.SyncType;
|
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||||
import kamkeel.npcs.util.ByteBufUtils;
|
import kamkeel.npcs.util.ByteBufUtils;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class SyncRevisionInfoPacket extends AbstractPacket {
|
public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||||
@@ -23,12 +23,12 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
|||||||
|
|
||||||
private String serverKey = "";
|
private String serverKey = "";
|
||||||
private String previousServerKey = "";
|
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() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyncRevisionInfoPacket(String serverKey, String previousServerKey, Map<SyncType, Integer> revisions) {
|
public SyncRevisionInfoPacket(String serverKey, String previousServerKey, EnumMap<EnumSyncType, Integer> revisions) {
|
||||||
if (serverKey != null) {
|
if (serverKey != null) {
|
||||||
this.serverKey = serverKey;
|
this.serverKey = serverKey;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
|||||||
ByteBufUtils.writeString(out, serverKey);
|
ByteBufUtils.writeString(out, serverKey);
|
||||||
ByteBufUtils.writeString(out, previousServerKey);
|
ByteBufUtils.writeString(out, previousServerKey);
|
||||||
out.writeShort(revisions.size());
|
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.getKey().ordinal());
|
||||||
out.writeInt(entry.getValue());
|
out.writeInt(entry.getValue());
|
||||||
}
|
}
|
||||||
@@ -71,15 +71,13 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
|||||||
String incomingServerKey = ByteBufUtils.readString(in);
|
String incomingServerKey = ByteBufUtils.readString(in);
|
||||||
String incomingPreviousKey = ByteBufUtils.readString(in);
|
String incomingPreviousKey = ByteBufUtils.readString(in);
|
||||||
int revisionCount = in.readUnsignedShort();
|
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++) {
|
for (int i = 0; i < revisionCount; i++) {
|
||||||
SyncType type = SyncType.byOrdinal(in.readInt());
|
EnumSyncType type = EnumSyncType.values()[in.readInt()];
|
||||||
int revision = 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
|
// Deselect
|
||||||
data.abilityData.setSelectedIndex(-1);
|
data.abilityData.setSelectedIndex(-1);
|
||||||
} else {
|
} 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();
|
data.save();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ public final class CategoryItemsRequestPacket extends AbstractPacket {
|
|||||||
|
|
||||||
// Send tag map for the items
|
// Send tag map for the items
|
||||||
HashMap<String, HashSet<UUID>> tagMap = getTagMapByCat(type, categoryId);
|
HashMap<String, HashSet<UUID>> tagMap = getTagMapByCat(type, categoryId);
|
||||||
if (tagMap != null) {
|
if (tagMap != null && !tagMap.isEmpty()) {
|
||||||
TagController.sendCategoryTagMap((EntityPlayerMP) player, tagMap);
|
TagController.sendCategoryTagMap((EntityPlayerMP) player, tagMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import noppes.npcs.CustomNpcsPermissions;
|
import noppes.npcs.CustomNpcsPermissions;
|
||||||
import noppes.npcs.roles.RoleTrader;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -64,13 +63,7 @@ public final class RoleSavePacket extends AbstractPacket {
|
|||||||
if (!PacketUtil.verifyItemPacket(packetName, EnumItemPacketType.WAND, player))
|
if (!PacketUtil.verifyItemPacket(packetName, EnumItemPacketType.WAND, player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NBTTagCompound roleCompound = ByteBufUtils.readNBT(in);
|
npc.roleInterface.readFromNBT(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.updateClient = true;
|
npc.updateClient = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,8 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import kamkeel.npcs.network.AbstractPacket;
|
import kamkeel.npcs.network.AbstractPacket;
|
||||||
import kamkeel.npcs.network.PacketChannel;
|
import kamkeel.npcs.network.PacketChannel;
|
||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
|
import kamkeel.npcs.network.PacketUtil;
|
||||||
|
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
@@ -36,6 +38,9 @@ public final class TagsGetPacket extends AbstractPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||||
|
if (!PacketUtil.verifyItemPacket(packetName, player, EnumItemPacketType.WAND, EnumItemPacketType.CLONER))
|
||||||
|
return;
|
||||||
|
|
||||||
NoppesUtilServer.sendTagDataAll((EntityPlayerMP) player);
|
NoppesUtilServer.sendTagDataAll((EntityPlayerMP) player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class Register<T> {
|
|||||||
protected final String namespace;
|
protected final String namespace;
|
||||||
protected final Map<String, Supplier<T>> entries = new LinkedHashMap<>();
|
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.registryKey = registryKey;
|
||||||
this.namespace = namespace;
|
this.namespace = namespace;
|
||||||
}
|
}
|
||||||
@@ -36,31 +36,6 @@ public class Register<T> {
|
|||||||
return factory.get();
|
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) {
|
public static boolean isEmpty(String registryKey) {
|
||||||
if (REGISTERED_NAMESPACES.isEmpty()) return true;
|
if (REGISTERED_NAMESPACES.isEmpty()) return true;
|
||||||
|
|
||||||
|
|||||||
@@ -786,14 +786,7 @@ public abstract class AbstractDataAbilities {
|
|||||||
fireTickEvent(currentAbility, target);
|
fireTickEvent(currentAbility, target);
|
||||||
|
|
||||||
// Script may have completed/cancelled the ability during the tick event
|
// Script may have completed/cancelled the ability during the tick event
|
||||||
if (currentAbility == null) return;
|
if (currentAbility == null || !currentAbility.isExecuting()) return;
|
||||||
if (!currentAbility.isExecuting()) {
|
|
||||||
// tick() can end the ability (DAZED -> IDLE)
|
|
||||||
if (phaseChanged && currentAbility.getPhase() == AbilityPhase.IDLE) {
|
|
||||||
handleAbilityCompletion(target);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fire extender tick hook (e.g., per-tick resource drain)
|
// Fire extender tick hook (e.g., per-tick resource drain)
|
||||||
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, entity, target,
|
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, entity, target,
|
||||||
|
|||||||
@@ -225,9 +225,6 @@ public class CommonProxy implements IGuiHandler {
|
|||||||
public void buildPackageIndex() {
|
public void buildPackageIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadComplete() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isScriptingEnabled() {
|
public boolean isScriptingEnabled() {
|
||||||
return ConfigScript.ScriptingEnabled;
|
return ConfigScript.ScriptingEnabled;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,17 +29,7 @@ import kamkeel.npcs.controllers.TelegraphController;
|
|||||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||||
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
||||||
import kamkeel.npcs.developer.Developer;
|
import kamkeel.npcs.developer.Developer;
|
||||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
import kamkeel.npcs.entity.*;
|
||||||
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.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
import kamkeel.npcs.util.BukkitUtil;
|
import kamkeel.npcs.util.BukkitUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@@ -125,7 +115,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
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 {
|
public class CustomNpcs {
|
||||||
|
|
||||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
@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(EntityEnergyDome.class, "energydome", 64, 3, true);
|
||||||
registerNewEntity(EntityEnergyPanel.class, "energypanel", 64, 3, true);
|
registerNewEntity(EntityEnergyPanel.class, "energypanel", 64, 3, true);
|
||||||
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 1, true);
|
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 1, true);
|
||||||
|
registerNewEntity(EntityAbilityPillar.class, "abilitypillar", 64, 1, true);
|
||||||
|
|
||||||
new RecipeController();
|
new RecipeController();
|
||||||
|
|
||||||
@@ -318,9 +309,6 @@ public class CustomNpcs {
|
|||||||
new AttributeController();
|
new AttributeController();
|
||||||
new MagicController();
|
new MagicController();
|
||||||
|
|
||||||
SyncController.register();
|
|
||||||
|
|
||||||
|
|
||||||
APIRegistry.Instance.register("CNPC+ API", "https://kamkeel.github.io/CustomNPC-Plus/");
|
APIRegistry.Instance.register("CNPC+ API", "https://kamkeel.github.io/CustomNPC-Plus/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +331,6 @@ public class CustomNpcs {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void loadComplete(FMLLoadCompleteEvent ev) {
|
public void loadComplete(FMLLoadCompleteEvent ev) {
|
||||||
proxy.loadComplete();
|
|
||||||
proxy.buildPackageIndex();
|
proxy.buildPackageIndex();
|
||||||
|
|
||||||
// Load built-in animations on the client so they're available for ability preview.
|
// 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) {
|
if (maxCooldown > minCooldown) {
|
||||||
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
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) {
|
if (ability.isPerAbilityCooldown() && ability.getCooldownTicks() > 0) {
|
||||||
// Global timer only paces the NPC; the ability tracks its own cooldown
|
long endTime = npc.worldObj.getTotalWorldTime() + ability.getCooldownTicks();
|
||||||
cooldownEndTime = now + baseCooldown;
|
setPerAbilityCooldown(ability.getName(), endTime, ability.getCooldownTicks());
|
||||||
setPerAbilityCooldown(ability.getName(), now + ability.getCooldownTicks(), ability.getCooldownTicks());
|
|
||||||
} else {
|
|
||||||
cooldownEndTime = now + baseCooldown + ability.getCooldownTicks();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void rollChainCooldown(ChainedAbility chain) {
|
protected void rollChainCooldown(ChainedAbility chain) {
|
||||||
long now = npc.worldObj.getTotalWorldTime();
|
|
||||||
boolean perAbility = chain.isPerAbilityCooldown() && chain.getCooldownTicks() > 0;
|
|
||||||
|
|
||||||
if (!chain.isIgnoreCooldown()) {
|
if (!chain.isIgnoreCooldown()) {
|
||||||
int baseCooldown = minCooldown;
|
int baseCooldown = minCooldown;
|
||||||
if (maxCooldown > minCooldown) {
|
if (maxCooldown > minCooldown) {
|
||||||
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
||||||
}
|
}
|
||||||
cooldownEndTime = perAbility ? now + baseCooldown : now + baseCooldown + chain.getCooldownTicks();
|
cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + chain.getCooldownTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (perAbility) {
|
// Additionally set per-ability cooldown if enabled
|
||||||
setPerAbilityCooldown(chain.getName(), now + chain.getCooldownTicks(), chain.getCooldownTicks());
|
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)
|
if (data == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Quest quest = data.quest;
|
if (!data.quest.questInterface.isPartyCompleted(party))
|
||||||
if (quest == null)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!data.quest.questInterface.isPartyCompleted(party))
|
|
||||||
|
Quest quest = data.quest;
|
||||||
|
if (quest == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (data.quest.completion == EnumQuestCompletion.Instant)
|
if (data.quest.completion == EnumQuestCompletion.Instant)
|
||||||
|
|||||||
@@ -343,6 +343,11 @@ public class NoppesUtilServer {
|
|||||||
sendOpenGui(player, gui, npc, 0, 0, 0);
|
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,
|
public static void sendOpenGui(final EntityPlayer player,
|
||||||
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
|
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
|
||||||
if (!(player instanceof EntityPlayerMP))
|
if (!(player instanceof EntityPlayerMP))
|
||||||
@@ -364,6 +369,28 @@ public class NoppesUtilServer {
|
|||||||
ScrollListPacket.sendList((EntityPlayerMP) player, list, EnumScrollData.OPTIONAL);
|
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) {
|
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) {
|
if (gui == EnumGuiType.PlayerFollower || gui == EnumGuiType.PlayerFollowerHire || gui == EnumGuiType.PlayerTrader || gui == EnumGuiType.PlayerTransporter) {
|
||||||
sendRoleData(player, npc);
|
sendRoleData(player, npc);
|
||||||
@@ -613,7 +640,7 @@ public class NoppesUtilServer {
|
|||||||
playerdata.save();
|
playerdata.save();
|
||||||
}
|
}
|
||||||
if (pl != null) {
|
if (pl != null) {
|
||||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||||
}
|
}
|
||||||
sendPlayerData(type, player, name);
|
sendPlayerData(type, player, name);
|
||||||
}
|
}
|
||||||
@@ -1202,7 +1229,7 @@ public class NoppesUtilServer {
|
|||||||
playerdata.save();
|
playerdata.save();
|
||||||
|
|
||||||
if (pl != null) {
|
if (pl != null) {
|
||||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1234,7 +1261,7 @@ public class NoppesUtilServer {
|
|||||||
|
|
||||||
playerdata.save();
|
playerdata.save();
|
||||||
if (pl != null) {
|
if (pl != null) {
|
||||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,9 +9,7 @@ import kamkeel.npcs.addon.DBCAddon;
|
|||||||
import kamkeel.npcs.controllers.AbilityController;
|
import kamkeel.npcs.controllers.AbilityController;
|
||||||
import kamkeel.npcs.controllers.AttributeController;
|
import kamkeel.npcs.controllers.AttributeController;
|
||||||
import kamkeel.npcs.controllers.data.attribute.tracker.PlayerAttributeTracker;
|
import kamkeel.npcs.controllers.data.attribute.tracker.PlayerAttributeTracker;
|
||||||
import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper;
|
import kamkeel.npcs.controllers.SyncController;
|
||||||
import kamkeel.npcs.controllers.sync.handlers.PlayerDataSyncHandler;
|
|
||||||
import kamkeel.npcs.controllers.sync.handlers.PlayerEffectSyncHelper;
|
|
||||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCounter;
|
import kamkeel.npcs.controllers.data.ability.type.AbilityCounter;
|
||||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||||
@@ -143,7 +141,7 @@ public class ScriptPlayerEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (playerData.updateClient) {
|
if (playerData.updateClient) {
|
||||||
PlayerDataSyncHandler.syncPlayerData((EntityPlayerMP) player, true);
|
SyncController.syncPlayerData((EntityPlayerMP) player, true);
|
||||||
playerData.updateClient = false;
|
playerData.updateClient = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +151,8 @@ public class ScriptPlayerEventHandler {
|
|||||||
|
|
||||||
if (player.ticksExisted % 10 == 0) {
|
if (player.ticksExisted % 10 == 0) {
|
||||||
EntityPlayerMP mp = (EntityPlayerMP) player;
|
EntityPlayerMP mp = (EntityPlayerMP) player;
|
||||||
PlayerEffectSyncHelper.syncEffects(mp);
|
SyncController.syncEffects(mp);
|
||||||
PlayerAbilitySyncHelper.syncAbilityCooldowns(mp);
|
SyncController.syncAbilityCooldowns(mp);
|
||||||
PlayerAbilitySyncPacket.sendToPlayer(mp);
|
PlayerAbilitySyncPacket.sendToPlayer(mp);
|
||||||
playerData.abilityData.ensureLockStateClear();
|
playerData.abilityData.ensureLockStateClear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,13 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
|||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import kamkeel.npcs.controllers.SyncController;
|
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.controllers.data.energycharge.EnergyChargeTracker;
|
||||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
||||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
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.ClonerPacket;
|
||||||
import kamkeel.npcs.network.packets.data.MarkDataPacket;
|
import kamkeel.npcs.network.packets.data.MarkDataPacket;
|
||||||
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
|
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
|
||||||
@@ -138,7 +136,7 @@ public class ServerEventsHandler {
|
|||||||
mounted = event.target;
|
mounted = event.target;
|
||||||
if (isRemote)
|
if (isRemote)
|
||||||
CustomNpcs.proxy.openGui(MathHelper.floor_double(mounted.posX), MathHelper.floor_double(mounted.posY), MathHelper.floor_double(mounted.posZ), EnumGuiType.MobSpawnerMounter, event.entityPlayer);
|
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))
|
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.EDIT_VILLAGER))
|
||||||
return;
|
return;
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
@@ -257,22 +255,20 @@ public class ServerEventsHandler {
|
|||||||
|
|
||||||
if (block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
if (block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
||||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||||
SyncType.WORKBENCH_RECIPES,
|
EnumSyncType.WORKBENCH_RECIPES,
|
||||||
EnumSyncAction.RELOAD,
|
EnumSyncAction.RELOAD,
|
||||||
-1,
|
-1,
|
||||||
null,
|
SyncController.getCurrentRevision(EnumSyncType.WORKBENCH_RECIPES),
|
||||||
SyncController.getCurrentServerRevision(SyncType.WORKBENCH_RECIPES),
|
SyncController.workbenchNBT()
|
||||||
WorkbenchRecipeSyncHandler.getInstance().serializeAll()
|
|
||||||
), (EntityPlayerMP) player);
|
), (EntityPlayerMP) player);
|
||||||
}
|
}
|
||||||
if (block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
if (block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
||||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||||
SyncType.CARPENTRY_RECIPES,
|
EnumSyncType.CARPENTRY_RECIPES,
|
||||||
EnumSyncAction.RELOAD,
|
EnumSyncAction.RELOAD,
|
||||||
-1,
|
-1,
|
||||||
null,
|
SyncController.getCurrentRevision(EnumSyncType.CARPENTRY_RECIPES),
|
||||||
SyncController.getCurrentServerRevision(SyncType.CARPENTRY_RECIPES),
|
SyncController.carpentryNBT()
|
||||||
CarpentryRecipeSyncHandler.getInstance().serializeAll()
|
|
||||||
), (EntityPlayerMP) player);
|
), (EntityPlayerMP) player);
|
||||||
}
|
}
|
||||||
if ((block == CustomItems.banner || block == CustomItems.wallBanner || block == CustomItems.sign) && event.action == Action.RIGHT_CLICK_BLOCK) {
|
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 cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||||
import kamkeel.npcs.controllers.ProfileController;
|
import kamkeel.npcs.controllers.ProfileController;
|
||||||
import kamkeel.npcs.controllers.SyncController;
|
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.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
import noppes.npcs.controllers.AuctionController;
|
import noppes.npcs.controllers.AuctionController;
|
||||||
@@ -47,12 +45,13 @@ public class ServerTickHandler {
|
|||||||
playerData.onLogin();
|
playerData.onLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProfileController.Instance.login(player);
|
||||||
SyncController.beginLogin(player);
|
SyncController.beginLogin(player);
|
||||||
PlayerEffectSyncHelper.syncEffects(player);
|
SyncController.syncEffects(player);
|
||||||
ScriptController.Instance.syncClientScripts(player);
|
ScriptController.Instance.syncClientScripts(player);
|
||||||
|
|
||||||
// Sync clean ability state to the new client (after beginLogin initializes sync state)
|
// Sync clean ability state to the new client (after beginLogin initializes sync state)
|
||||||
PlayerAbilitySyncHelper.syncAbilities(player);
|
SyncController.syncAbilities(player);
|
||||||
|
|
||||||
// Send auction notifications on login
|
// Send auction notifications on login
|
||||||
if (AuctionController.Instance != null) {
|
if (AuctionController.Instance != null) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import net.minecraft.nbt.NBTBase;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagInt;
|
import net.minecraft.nbt.NBTTagInt;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import noppes.npcs.constants.EnumPotionType;
|
|
||||||
import noppes.npcs.controllers.data.Line;
|
import noppes.npcs.controllers.data.Line;
|
||||||
import noppes.npcs.controllers.data.Lines;
|
import noppes.npcs.controllers.data.Lines;
|
||||||
import noppes.npcs.entity.EntityNPCInterface;
|
import noppes.npcs.entity.EntityNPCInterface;
|
||||||
@@ -24,13 +23,6 @@ public class VersionCompatibility {
|
|||||||
boolean aimShot = compound.getBoolean("AimWhileShooting");
|
boolean aimShot = compound.getBoolean("AimWhileShooting");
|
||||||
compound.setInteger("AimType", !aimShot ? 0 : 1);
|
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 (npc.npcVersion < 22) {
|
||||||
if (compound.hasKey("CanLeap")) {
|
if (compound.hasKey("CanLeap")) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class EntityAITransform extends EntityAIBase {
|
|||||||
|
|
||||||
public EntityAITransform(EntityNPCInterface npc) {
|
public EntityAITransform(EntityNPCInterface npc) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
setMutexBits(0);
|
setMutexBits(AiMutex.PASSIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ public class BlockBorder extends BlockContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tile.rotation = l;
|
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) {
|
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();
|
ItemStack item = player.inventory.getCurrentItem();
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return true;
|
return true;
|
||||||
|
int meta = world.getBlockMetadata(x, y, z);
|
||||||
|
|
||||||
if ((item.getItem() == Items.flint || item.getItem() == Items.flint_and_steel) && unlitBlock() == this) {
|
if ((item.getItem() == Items.flint || item.getItem() == Items.flint_and_steel) && unlitBlock() == this) {
|
||||||
super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
|
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);
|
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
|
@Override
|
||||||
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {
|
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {
|
||||||
onBlockAdded(par1World, par2, par3, par4);
|
onBlockAdded(par1World, par2, par3, par4);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package noppes.npcs.client;
|
package noppes.npcs.client;
|
||||||
|
|
||||||
import kamkeel.npcs.network.enums.SyncType;
|
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import noppes.npcs.client.controllers.MusicController;
|
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.controllers.data.SkinOverlay;
|
||||||
import noppes.npcs.util.CacheHashMap;
|
import noppes.npcs.util.CacheHashMap;
|
||||||
|
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -32,14 +32,14 @@ public class ClientCacheHandler {
|
|||||||
|
|
||||||
private static String activeServerKey = "";
|
private static String activeServerKey = "";
|
||||||
private static String lastServerKey = "";
|
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 Party party;
|
||||||
|
|
||||||
public static boolean allowProfiles = true;
|
public static boolean allowProfiles = true;
|
||||||
public static boolean allowParties = 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 normalizedKey = serverKey == null ? "" : serverKey;
|
||||||
String previousKey = activeServerKey == null ? "" : activeServerKey;
|
String previousKey = activeServerKey == null ? "" : activeServerKey;
|
||||||
lastServerKey = previousKey;
|
lastServerKey = previousKey;
|
||||||
@@ -54,9 +54,9 @@ public class ClientCacheHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<SyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
|
EnumMap<EnumSyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
|
||||||
activeServerKey,
|
activeServerKey,
|
||||||
ignored -> new LinkedHashMap<>()
|
ignored -> new EnumMap<>(EnumSyncType.class)
|
||||||
);
|
);
|
||||||
if (serverRevisions != null && !serverRevisions.isEmpty()) {
|
if (serverRevisions != null && !serverRevisions.isEmpty()) {
|
||||||
cached.keySet().retainAll(serverRevisions.keySet());
|
cached.keySet().retainAll(serverRevisions.keySet());
|
||||||
@@ -67,19 +67,19 @@ public class ClientCacheHandler {
|
|||||||
return lastServerKey == null ? "" : lastServerKey;
|
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;
|
String key = serverKey == null ? "" : serverKey;
|
||||||
if (key.isEmpty()) {
|
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) {
|
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) {
|
if (revision < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -87,9 +87,9 @@ public class ClientCacheHandler {
|
|||||||
if (key.isEmpty()) {
|
if (key.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Map<SyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
|
EnumMap<EnumSyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
|
||||||
key,
|
key,
|
||||||
ignored -> new LinkedHashMap<>()
|
ignored -> new EnumMap<>(EnumSyncType.class)
|
||||||
);
|
);
|
||||||
revisions.put(type, revision);
|
revisions.put(type, revision);
|
||||||
}
|
}
|
||||||
@@ -126,11 +126,14 @@ public class ClientCacheHandler {
|
|||||||
ClientCacheHandler.playerAnimations.clear();
|
ClientCacheHandler.playerAnimations.clear();
|
||||||
ProfileClientConfig.reset();
|
ProfileClientConfig.reset();
|
||||||
|
|
||||||
|
// Clear Texture Caches
|
||||||
GuiSoundSelection.cachedDomains.clear();
|
GuiSoundSelection.cachedDomains.clear();
|
||||||
GuiTextureSelection.cachedTextures.clear();
|
GuiTextureSelection.cachedTextures.clear();
|
||||||
|
|
||||||
|
// Clear music/bard sounds
|
||||||
MusicController.Instance.stopAllSounds();
|
MusicController.Instance.stopAllSounds();
|
||||||
|
|
||||||
|
// Clear Quest Tracker
|
||||||
HudComponent component = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker);
|
HudComponent component = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker);
|
||||||
if (component != null) {
|
if (component != null) {
|
||||||
component.loadData(new NBTTagCompound());
|
component.loadData(new NBTTagCompound());
|
||||||
@@ -143,6 +146,7 @@ public class ClientCacheHandler {
|
|||||||
ClientCacheHandler.customOverlays.clear();
|
ClientCacheHandler.customOverlays.clear();
|
||||||
ClientCacheHandler.skinOverlays.clear();
|
ClientCacheHandler.skinOverlays.clear();
|
||||||
|
|
||||||
|
// Clear Texture Caches
|
||||||
GuiSoundSelection.cachedDomains.clear();
|
GuiSoundSelection.cachedDomains.clear();
|
||||||
GuiTextureSelection.cachedTextures.clear();
|
GuiTextureSelection.cachedTextures.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Loaded 100 of 158 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user