Wiki 9Minecraft Wiki 9Minecraft

MyTown Protections System

Guides 7FAQ 10Related mods 48
DownloadMyTown Mod

Get the files on 9Minecraft

MyTown's compatibility with other mods comes from a data-driven protection system. Instead of hardcoding support for each mod, the system reads a set of JSON "protection" files, one per mod, that describe how that mod's content should be treated. The mod ships compatible with a wide range of other mods, and additional protection files can be dropped into config/MyTown/protections (all subdirectories are scanned). Incompatible or invalid protection files are skipped, and if a single protection errors during play, only the affected entity, tile entity, item, or block is disabled rather than the whole system.

Each protection file declares a modid, a minimum compatible version (checked with a startsWith match against the mod's version), and an array of segments. A segment describes one thing in the mod — an entity, tile entity, item, or block — via its class, its type, and the flags it should be checked against, with an optional condition expression. For example, a block-breaker machine would most reasonably be tied to the modify flag.

Segments use "getters" (cascading method, field, formula, or NBT lookups) to read information from the game object so the system can decide whether to allow an action. Entity segments use actions such as TRACKED (checked every tick, ideal for keeping hostile mobs out of towns), PROTECT (checked on interaction), and PVP (checked when the entity hits a player). Item segments use actions like BREAK_BLOCK, RIGHT_CLICK_BLOCK, RIGHT_CLICK_AIR, RIGHT_CLICK_ENTITY, and LEFT_CLICK_BLOCK, and block segments use LEFT_CLICK, RIGHT_CLICK, or ANY_CLICK. Tile-entity segments can define a bounding box (xMin/yMin/zMin to xMax/yMax/zMax) and a retainsOwner option so that, for instance, a quarry is checked against the permissions of the player who placed it. The admin command /townadmin debug itemClass prints the class hierarchy of a held item or block to help build these segments.