Bridge legacy ItemTemplate to its cache template

Each engine.objects.ItemTemplate gets a cacheTemplate field, filled by
linkCacheTemplates() right after CObjectIndex.build() on both servers,
so consumers can move to CObjectTemplate one field at a time.

ParityCheck gains a static_item_templates comparator: a null bridge is
reported as missing in json, and obj_name and item_type are compared
through the interface to catch a wrong folder pick.

Import convention until the legacy class is removed (Task 1.8): the
legacy engine.objects.ItemTemplate keeps the plain import; the cache
class is always written engine.parsers.objects.ItemTemplate. Migrated
consumers should depend on CObjectTemplate instead.

JSON-Refactor-Plan Task 1.1. No consumers change; no values change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MagicBotandClaude Opus 5.5 committed 2026-10-19 11:21:47 -04:00
1 parent 4765e7993f
commit 765cb9edb6
4 files changed
+44

No files matched your search

+22
View File
@@ -10,6 +10,7 @@ package engine.objects;
import engine.math.Vector3fImmutable;
import engine.mbEnums;
import engine.parsers.objects.CObjectTemplate;
import org.json.JSONArray;
import org.json.JSONObject;
import org.pmw.tinylog.Logger;
@@ -157,6 +158,9 @@ public class ItemTemplate {
public final ArrayList<Integer> rune_helper_monster_types = new ArrayList<>();
public int item_bane_rank;
// Cache JSON counterpart, so consumers can move to the new templates one field at a time.
public CObjectTemplate cacheTemplate;
public ItemTemplate(JSONObject jsonObject) {
try {
@@ -646,4 +650,22 @@ public class ItemTemplate {
}
}
// Run after CObjectIndex.build(); the DB templates load before the cache parsers.
public static void linkCacheTemplates() {
int missingCount = 0;
for (ItemTemplate template : templates.values()) {
template.cacheTemplate = CObjectTemplate.lookup(template.template_id);
if (template.cacheTemplate == null) {
missingCount++;
Logger.warn(template.template_id + ": " + template.obj_name + " has no cache template");
}
}
Logger.info("Linked " + (templates.size() - missingCount) + " of " + templates.size() + " item templates to cache templates");
}
}
+16
View File
@@ -13,6 +13,7 @@ import engine.gameManager.DbManager;
import engine.mbEnums;
import engine.objects.AbstractGameObject;
import engine.objects.BaseClass;
import engine.objects.ItemTemplate;
import engine.parsers.objects.RuneTemplate;
import org.pmw.tinylog.Logger;
@@ -36,6 +37,7 @@ public class ParityCheck {
static {
register("static_rune_baseclass", ParityCheck::compareBaseClasses);
register("static_item_templates", ParityCheck::compareItemTemplates);
}
private ParityCheck(String table) {
@@ -115,4 +117,18 @@ public class ParityCheck {
check.compareField(baseClass.getObjectUUID(), "name", baseClass.getName(), rune.obj_name);
}
}
// A wrong item_type means the bridge picked the wrong folder for an id found in more than one.
private static void compareItemTemplates(ParityCheck check) {
for (ItemTemplate template : ItemTemplate.templates.values()) {
if (!check.compareRow(template.template_id, template.cacheTemplate))
continue;
check.compareField(template.template_id, "obj_name", template.obj_name, template.cacheTemplate.getObjName());
check.compareField(template.template_id, "item_type", template.item_type, template.cacheTemplate.getItemType());
}
}
}
+3
View File
@@ -318,6 +318,9 @@ public class LoginServer {
Logger.info("Indexing Cache Templates");
CObjectIndex.build();
Logger.info("Linking Item Templates to Cache Templates");
ItemTemplate.linkCacheTemplates();
Logger.info("Initializing Network");
Network.init();
+3
View File
@@ -338,6 +338,9 @@ public class WorldServer {
Logger.info("Indexing Cache Templates");
CObjectIndex.build();
Logger.info("Linking Item Templates to Cache Templates");
ItemTemplate.linkCacheTemplates();
Logger.info("Loading PromotionClasses");
DbManager.PromotionQueries.GET_ALL_PROMOTIONS();