promotional bannermobile promotional banner

CorpseJS

CorpseJS is a Forge 1.20.1 integration mod that lets KubeJS scripts create and customize Corpse bodies
DxEVIL | CorpseJS
Create a server, get 25% off your first monthaffiliate logo
Create Server
affiliate banner image

CorpseJS

CorpseJS connects the Corpse mod with KubeJS and provides a simple, scriptable way to create and customize corpse entities.

Simple Enemy and CustomNPCs entities do not create corpses automatically. Scripts explicitly decide when a corpse should be created through the CorpseJS API. When the source entity is a supported Simple Enemy or CustomNPC humanoid, CorpseJS automatically selects the matching corpse model. Other entities use the generic corpse renderer, which reuses the source entity's registered renderer.

Features

  • Create a corpse for any server-side entity through a Java API or KubeJS.
  • Add initial items when creating a corpse.
  • Customize corpse contents after creation with replaceItems, addItems, or setItems.
  • Cancel corpse creation before the corpse entity is constructed.
  • Identify the original entity with sourceEntity, sourceEntityId, and sourcePersistentData.
  • Preserve the source entity's KubeJS persistentData on the corpse.
  • Use dedicated models for Simple Enemy units and supported CustomNPC humanoids.
  • Prevent duplicate normal death drops when a corpse is created during the same game tick.
  • Remove a corpse without dropping or returning its contents.

KubeJS API

KubeJS support is optional. When KubeJS is installed, CorpseJS provides the global CorpseJS binding:

EntityEvents.death(event => {
  if (event.entity.type == 'minecraft:zombie') {
    const corpse = CorpseJS.spawn(event.entity, [
      Item.of('minecraft:rotten_flesh', 3),
      Item.of('minecraft:iron_ingot')
    ])
  }
})

Available methods:

  • CorpseJS.spawn(entity) creates an empty corpse.
  • CorpseJS.spawn(entity, items) creates a corpse with the supplied items.
  • CorpseJS.removeCorpse(corpse) silently removes a corpse and clears its contents.
  • CorpseJS.remove(corpse) is a short alias for removeCorpse.

The API is server-side only. It returns the new corpse entity on success and null when creation fails, the source is client-side, or a corpse was already created for that source during the current game tick.

Complete KubeJS Example

The following example demonstrates the complete workflow: create a corpse from a death event, cancel selected sources before creation, replace or add items, distribute items across random inventory slots, and remove a corpse without dropping its contents.

// Create a corpse with initial items when a zombie dies.
EntityEvents.death(event => {
  if (event.entity.type != 'minecraft:zombie') return

  CorpseJS.spawn(event.entity, [
    Item.of('minecraft:rotten_flesh', 3),
    Item.of('minecraft:iron_ingot')
  ])
})

// This event runs before the corpse entity is constructed.
CorpseJSEvents.beforeCorpseCreated(event => {
  if (event.entityId == 'simpleenemymod:pmcunit') {
    event.cancel()
  }
})

// This event runs after a new corpse has been added to the world.
CorpseJSEvents.corpseCreated(event => {
  if (event.sourceEntityId != 'minecraft:zombie') return

  // Replace all existing corpse contents and use random main-inventory slots.
  event.replaceItems([
    Item.of('minecraft:diamond_sword'),
    Item.of('minecraft:bread', 4)
  ], true)

  // Add items without clearing existing contents, also using random slots.
  event.addItems([
    Item.of('minecraft:gold_ingot', 2),
    Item.of('minecraft:paper')
  ], true)

  // Equivalent explicit mode API:
  // event.setItems('replace', [Item.of('minecraft:diamond')], true)
  // event.setItems('add', [Item.of('minecraft:emerald')], true)
})

// Remove a corpse silently, including all of its stored items.
CorpseJSEvents.corpseCreated(event => {
  if (event.sourceEntityId == 'minecraft:zombie' && Math.random() < 0.1) {
    CorpseJS.removeCorpse(event.entity)
  }
})

replaceItems clears the main inventory, armor, off-hand, additional items, and equipment before inserting new items. addItems preserves existing contents and puts overflow into the additional-items page. Pass true as the second argument to randomize the main-inventory slots. setItems accepts replace or add modes and supports the same random-slot argument.

KubeJS Events

CorpseJS provides one global event group: CorpseJSEvents.

CorpseJSEvents.beforeCorpseCreated(event => {
  if (event.entityId == 'simpleenemymod:pmcunit') {
    event.cancel()
  }
})

CorpseJSEvents.corpseCreated(event => {
  if (event.sourceEntityId == 'minecraft:zombie') {
    event.addItems(Item.of('minecraft:paper'))
  }
})

beforeCorpseCreated runs before the corpse entity exists and can cancel creation. corpseCreated runs once after a newly created corpse is added to the world and can modify its contents.

Use event.entityId in beforeCorpseCreated and event.sourceEntityId in corpseCreated to apply rules to specific source entity types.

Supported Models

  • Simple Enemy entities use the matching Simple Enemy unit model.
  • Supported CustomNPC humanoids use their matching CustomNPC model.
  • Players use the player corpse model.
  • Other entities use their registered entity renderer through the generic corpse model.

Requirements

  • Minecraft 1.20.1
  • Minecraft Forge 47+
  • Corpse, for the corpse entity and inventory implementation
  • KubeJS Forge 2001.6 or newer, only if KubeJS scripting support is needed
  • Simple Enemy and CustomNPCs are optional compatibility integrations

CorpseJS is distributed under LGPL-3.0 license.

The CorpseJS Team

profile avatar
Owner
  • 1
    Followers
  • 18
    Projects
  • 15.7K
    Downloads

More from DxEVILView all