Create a "Head Cavity" mod that allows players to perform intricate surgical operations on brains and skulls, featuring a detailed GUI for selecting various surgical tools and customizable brain enhancements that alter player abilities based on the procedures completed. Ensure seamless integration with existing health systems, maintain the default Minecraft punching animation for accessing the skull, and include a comprehensive tutorial guide detailing both positive enhancements and realistic negative effects, such as the implications of transferring brain regions between players and entities that can result in body swaps depending on which brain regions are swapped.
I’ll look up the NeoForge 26.2 signatures this mod needs before writing any Java.Most signatures are confirmed. Three need checking before I write: the attachment codec type (the builder takes a MapCodec, not a Codec), the fill and isClientSide APIs, and the creative-tab accept overloads. I’m checking them in one call.
The remaining API questions are settled. Before writing, I’m checking a last set of details: the Player and Item methods, the hurt and heal calls, the menu field names, and the recipe JSON fields. I’m also generating the nine item textures in parallel.
Four textures generated. The remaining five failed because the account ran out of credits. I’ll give those items vanilla placeholder textures so nothing renders purple, and flag them for regeneration. Next I’m writing the non-Java files and checking the last few signatures.
Two signatures came back different from what I expected: ItemStack.is only takes a holder predicate, and displayClientMessage isn’t on Player. I’m checking the replacements.
I have everything needed to write the Java. Two corrections from the checks: ItemStack.is(Item) doesn’t exist, so I’m comparing getItem() directly. Action-bar messages go through sendOverlayMessage. The mod’s Java goes in two parallel patches, starting with the data, item and menu layers.
The data, item and menu layers are in. One mistake to fix: the HeadCavityData record is missing its closing brace, so I’m patching that and writing the event and client layers in the same call.
Head Cavity is built as a NeoForge 26.2 mod with sedation, surgery, brain regions, body swaps and an in-game guide. I haven’t compiled it. Every API call was checked against the 26.2 source, but please run Compile to confirm.
How it plays
Sedate: right-click a player with a Chloroform Rag. They stay sedated for 30 seconds and get Slowness IV while it lasts.
Open the skull: hold a Surgical Scalpel, Bone Saw or Cranial Retractor and punch a sedated player on the head. The normal swing animation still plays, the punch is cancelled, and the Cranial Surgery screen opens. Punches elsewhere work as normal.
Surgery screen: select a tool at the top, then open or close the cranium, extract a region (you receive its graft), install a graft, or exchange a region with the nearest other open, sedated player within 8 blocks.
Enhancements: Motor gives Speed, Visual gives Night Vision, Vitality gives Regeneration and Reflex gives Jump Boost, all while that region is installed.
Body swaps: exchanging Motor swaps positions, health and inventories. Vitality swaps health only. Visual and Reflex move the enhancement but leave the bodies alone. Both patients get Weakness after an exchange.
Health: each cut deals real damage through the normal damage system and gives Nausea.
Surgeon’s Guide: right-click it for a six-page tutorial covering the benefits and the risks.
Getting each item in survival
Surgical Scalpel: 1 iron ingot + 1 stick.
Bone Saw: 3 iron ingots + 2 sticks.
Cranial Retractor: 4 iron ingots + 1 stick.
Chloroform Rag: string + glass bottle (makes 2).
Surgeon’s Guide: book + red dye.
Cortex grafts: no recipe. They drop from a successful Extract.
Gaps
Body swaps and region transfers work only between players. The mob and entity transplants you asked for are not built.
Image credits ran out after four textures. The Surgeon’s Guide and the four grafts currently use vanilla book and glass-bottle art. Regenerate
surgeons_guide.pngand the four*_graft.pngfiles, then point their models at them.The guide text is hard-coded English in
GuideScreen, not inen_us.json.
To build: click Compile in the top bar, then Compile in the window, then Download the jar.
Now that I got some credits, try implementing the non-player entities part(the missing textures for items can be made later), make sure that there's also player to entity and entity to player compability(if you can't finish it, you can do it in multiple parts, doesn't have to be in just one prompt)
I’ll start by checking the project layout and what already exists for entities.
This is an existing surgery mod (HeadCavity). I need to understand its data model and surgery flow before adding entity support.
The surgery logic is hard-wired to ServerPlayer. Next I’ll read the client side, item and tool code so I know every call site before changing the types.
The mod is a full surgery system, and it’s player-only in four places: the sedation item, the attack hook, the menu/procedure target types, and the per-tick effects. Before I change any types I need to confirm the 26.2 signatures for the entity, equipment, teleport and tick APIs I’ll touch.The tick event fires for every entity, and Mob.setTarget and the equipment and teleport APIs are confirmed. Two more checks: attachment presence lookup (so mob ticks don’t create empty attachments) and the entity-query signature I’ll use for finding exchange partners.I have every signature I need. Here’s the plan for this task:
ChloroformRagItem: sedate any living entity, not just players.ModEvents: surgery trigger accepts any living target; enhancement and sedation ticks run for every living entity viaEntityTickEvent.Post, gated on the attachment being present.SurgeryMenuandSurgeryProcedures: patient and exchange partner becomeLivingEntity. Body swaps between a player and a mob trade positions and health, and trade the player’s armor and hands for the mob’s equipment. Player-to-player swaps keep the full inventory swap.GuideScreen: update the exchange text.
Non-player entities now work as surgery patients and exchange partners, in both directions with players. I read “non-player entities” as any living mob. If you meant a new custom mob, tell me and I’ll build that next.
Sedation:
ChloroformRagItemsedates any living entity, not just players.Surgery trigger:
ModEvents.onAttackopens the surgery screen when a surgical tool hits any sedated, open living entity.Ticking: sedation countdown and region enhancements now run through
EntityTickEvent.Postfor every living entity. It skips entities that have no head-cavity data, so mobs don’t get empty attachments written to them.Menu and procedures:
SurgeryMenuandSurgeryProcedurestakeLivingEntityfor both the patient and the nearest exchange partner.Player to mob and mob to player: all region exchanges work with any pairing. Vitality swaps health, and Motor body swaps positions and health.
Gear on body swaps: player-to-player swaps still trade the full inventory. When a mob is involved, the player’s armor and hands trade with the mob’s equipment.
Guide: the exchange and body-swap pages now describe mob partners.
Limits:
Sedated mobs are slowed but keep attacking, the same as players.
A Motor swap moves the player’s body to the mob’s spot, and the mob’s body is not changed into a player.
Health is clamped to each side’s max health after a swap.
I haven’t compiled the project. Please run Compile and send me any errors.
bug:the "surgeon's guide" item pages don't even appear at all(it's just 2 buttons for next/previous page, but there's no page to even see)
Fixed the guide text: its color values had no alpha channel, so GuiGraphicsExtractor treated them as fully transparent. The page content, title, and page counter now use opaque ARGB colors.
rework the GUI for surgery operations: the options will only be the actions(without including the tool selection), when pressed it just checks for the tool you should need to do it in the inventory to either let the player do it or say it was not successful
Plan:
Remove tool-selection controls and state from the menu.
Have each action check its required tool in the surgeon’s inventory on the server; keep the existing success/failure feedback.
Label the action buttons clearly and adjust the screen layout.
Reworked the surgery GUI to show only procedure actions; removed tool selection. Pressing an action now checks server-side for its required tool anywhere in the player’s inventory, then reports success or failure.
The action labels identify the required tool, and the layout has been tightened to fit the new controls. I haven’t compiled the project.
there's one issue: the install/extract/etc for the motor/visual/etc graft isn't clearly named(it just says the name of the graft, not the procedure)
Updated the surgery buttons to name both the procedure and region—for example, “Extract Motor”, “Install Motor Graft”, and “Exchange Motor”—and widened the layout so the labels fit.
also, i didn't test non-player to non-player support, but if there isn't one, add it
Non-player-to-non-player exchanges are already supported: SurgeryProcedures accepts LivingEntity for both patients, and partner search doesn’t exclude mobs.
To perform one, a player surgeon must have both mobs sedated and their craniums open, with the exchange region installed in one mob but absent in the other. The mobs must be within 8 blocks. Exchanges still require a player to initiate them; mobs don’t perform surgery autonomously.
and testing here, apparently, the non-player entities don't have any cortexes by default. Make them have one with their NBT attached to it when spawning.
Check how cortex data and attachments are initialized and serialized.
Add a default cortex to newly spawned non-player living entities without overwriting existing data.
Preserve that cortex in entity NBT.
New non-player living entities now spawn with one Motor cortex in their head-cavity data. The existing attachment codec saves it to entity NBT, and existing attachment data is left unchanged when entities rejoin the world. Players are unaffected.
make so that the motor cortex works like this on entities and players: if removed, makes the entity completely unable to move or attack(knock back still applies, in case of players they also can't mine), if placed on another entity then gives control of that entity(instead of swapping positions), the other entity only gains control of the other entity if its motor cortex is placed on the other one also, make so that the entities have all cortexes with their NBT by default on them and the entity in control uses them(so if a player's motor cortex, is, for example, placed on a creeper, they will now use the creeper's visual, vital, etc cortexes, on the creeper's body). In a non-player's entity, the motor cortex will store all the AI goals, then if placed on another non-player entity, the AI goal will get replaced(make it like this: when the mod detects the motor cortex being either removed, exchanged or placed, no matter the action, it checks for the goals stored by the entity type from the mob that has that UUID), if there are no goals or there isn't a motor cortex now, remove all AI goals of the entity.
Plan:
Trace cortex storage, surgery mutations, entity AI initialization, and movement/attack/mining hooks.
Implement cortex-aware control and preserve each entity’s cortex state in NBT.
Store/restore mob goals by entity type when motor cortexes move, clearing goals when none apply.
Implemented motor-cortex control: entities now spawn with all cortexes attached in NBT; motor grafts retain their owner UUID; and a player’s graft can give them camera, movement, jump, and melee control of the recipient. Players without their own motor cortex can’t move, attack, or mine, while knockback remains intact. Mob AI goals are cleared when a motor cortex is absent or the mob is player-controlled, then restored when appropriate.
AI transfer limitation: vanilla AI goals are bound to the mob instance they were created for, so they can’t safely be transplanted between different mob types. This preserves and restores each mob’s own goals rather than copying the donor mob’s goals onto the recipient. I haven’t compiled the project.
due to the transfer limitation, try making a separate entity that has the donor's entity type, while constantly teleporting the mob that has recieved it to the invisible mob that represent the donor's AI(make sure that they can't collide, also make so that the actual mob it is supposed to be is invulnerable, so that villagers with a zombie's motor cortex don't commit suicide or self-zombify, also make so that when it first spawns it spawns with the entity that recieved the motor cortex's current health and every attribute it has, make sure that they also get extra armor if the entity that recieved it has armor and that the armor gets set to the entity that recieved it and then give the invisible mob the armor stat change, making a detection for in case it updates to set the armor according to how it should be, and make sure that if the armor is either AIR or NULL it counts as 0, this should check for helmet, chestplate, leggings and boots, the items get instantly sent to the invisible entity so that a skeleton's motor cortex, for example, can use the bow, make the invisible entity 0.1 blocks in front of the entity that recieved it so that it doesn't have issues seeing anything)
Added donor-type AI proxies. A non-player motor cortex now spawns an invisible mob of the donor’s type, copies the recipient’s health, compatible attributes, and equipment, then drives the recipient’s body from about 0.1 blocks behind the proxy. The recipient is invulnerable while remotely controlled; equipment and armor changes are mirrored, with empty, AIR, or null slots treated as empty. A collision mixin prevents proxy/entity collisions while keeping block collision enabled.
The motor donor’s entity type is saved in both the entity attachment and extracted graft, so the proxy can be recreated after reloads. Player motor grafts continue to control the recipient directly. One limitation: attributes that the proxy’s entity type doesn’t support can’t be copied into its attribute map. I haven’t run a build.
add a command for the cortexes to be changed without the need of a player manually doing it(the syntax would be /headcavity (cortex operation) [entity] [second entity if it was exchange, or "inventory" to get a cortex of that type from the player's inventory, the "install" operation will always take it from the player's inventory]), those won't need the operation tools in the player's inventory and won't need the entity's(player or not) skull to be open
Added /headcavity commands that bypass sedation, surgical tools, and the open-cranium requirement:
/headcavity extract <cortex> <entity>— removes the cortex and puts its graft in your inventory./headcavity install <cortex> <entity>— installs a matching graft from your inventory./headcavity exchange <cortex> <entity> <other-entity|inventory>— swaps cortexes between entities, or swaps the entity’s cortex with a graft in your inventory. The replaced graft goes back into your inventory.
Cortex names are motor, visual, vitality, and reflex. Motor graft ownership and entity-type data are preserved during these operations. I haven’t run a build.
also, i believe this won't be fixed since i didn't mention it, but on previous build, launching the mod gave a error, in which it gets a null exception when trying to dispatch the RegisterPayloadHandlersEvent event
Fixed both payload IDs with Identifier.fromNamespaceAndPath("headcavity", ...). CustomPacketPayload.createType(String) treats its argument as a path under the default namespace, so passing headcavity:... is invalid when the payload types are initialized during registration.
The source indicates that this specific mistake should raise an IdentifierException, not a NullPointerException. If startup still fails with an NPE, share the stack trace to pinpoint the separate cause. I haven’t run a build.
there is a issue right now with the mod: if the player dies with the motor cortex on another entity, it causes some inconsistencies (camera back to player when they respawn but they are still in control of the mob), fix this by making the player entity get their death canceled if they have the motor cortex on another mob but "marked for death"(a NBT gets flipped to true on their character), with the chat message saying they died, then get their health set to 1, their collision disabled and they become immune to damage, until the mob they're in control of dies, when it dies they get killed and have all changes reverted and instantly die, being able to respawn normally with their motor cortex back to their character(on the death cancel, don't use a another if check condition other than checking if the motor cortex is on another entity, in case they get somehow killed while invencible)
Cancel player death whenever their motor cortex is on another living entity, without checking the existing marked flag.
Persist the marked state and keep the player at 1 health, non-colliding, and damage-immune.
When that controlled entity dies, restore the player’s motor cortex and normal death/respawn flow.
Implemented the deferred-death flow in ModEvents: a player’s death is canceled whenever their motor cortex controls another living entity, and their marked-for-death NBT state is persisted. They remain at 1 health, immune to damage, and non-colliding. When the controlled entity dies, the player’s motor cortex is restored before they are killed normally, allowing the usual respawn flow.
I haven’t run a build.
package com.example.headcavity;
import com.example.headcavity.data.ModAttachments;
import com.example.headcavity.item.ModItems;
import com.example.headcavity.menu.ModMenus;
import com.example.headcavity.network.ModNetworking;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
@Mod(HeadCavity.MOD_ID)
public class HeadCavity {
public static final String MOD_ID = "headcavity";
public HeadCavity(IEventBus modEventBus) {
ModItems.ITEMS.register(modEventBus);
ModMenus.MENUS.register(modEventBus);
ModAttachments.ATTACHMENTS.register(modEventBus);
modEventBus.addListener(ModNetworking::registerPayloads);
}
}