-
Bug
-
Resolution: Cannot Reproduce
-
Minor
-
None
-
None
-
None
-
This server is running CraftBukkit version 3669-Spigot-454acb7-f150cfb (MC: 1.19.3) (Implementing API version 1.19.3-R0.1-SNAPSHOT)
-
Yes
I'm using the StructureManager to load vanilla structures (templates actually) with loadStructure and a Namespaced key so I can place them. The placing works well, but the loading does not work unless the template is already loaded/registered and in the list from StructureManager#getStructures() So, the loadStructure is not actually loading.
The already loaded structures varies, and can increase depending where players are in the world. For example, I flew to a Savanna biome and the Savanna Village templates became available through getStructures().
The only guaranteed workaround for getting a template in the list is to use the `/place` command in-game to place the template, then it will be available.
There is a dearth of documentation or others using the API on the Internet so I'm not sure if I'm using the API correctly. Is there something I need to do to get the vanilla structures to be loadable?
Example code:
// Load Structure Structure s = Bukkit.getStructureManager().loadStructure(NamespacedKey.fromString("minecraft:woodland_mansion/indoors_door_1"));
Here is the minimal plugin (binary attached):
public class TestPlugin extends JavaPlugin implements Listener { @Override public void onEnable() { Bukkit.getPluginManager().registerEvents(this, this); showLoaded(); } private void showLoaded() { Map<NamespacedKey, Structure> map = Bukkit.getStructureManager().getStructures(); this.getLogger().log(Level.INFO, "Loaded structures are : "); map.forEach((nameSpace, structure) -> { this.getLogger().log(Level.INFO, nameSpace.getKey() + " loaded already"); }); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerJoin(PlayerJoinEvent e) { showLoaded(); Structure s = Bukkit.getStructureManager().loadStructure(NamespacedKey.fromString("pillager_outpost/feature_cage2")); if (s == null) { this.getLogger().log(Level.INFO, "pillager_outpost/feature_cage2 could not be loaded. Load it manually in-game using '/place template pillager_outpost/feature_cage2' and the re-login and this will work."); } else { this.getLogger().log(Level.INFO, "pillager_outpost/feature_cage2 loaded - but it was already loaded"); } } }
In this plugin, when you login for the first time, it will try to load "pillager_outpost/feature_cage2" and fail. A log will show. If you then use the /place template command to place the template, the server will load the structure and the next time you log in, the Structure will be available. So, the loadStructure only works if the structures have already been loaded somehow.
Any pointers would be greatly welcome.