Skip to content

Modding Guide

Samp edited this page Dec 2, 2026 · 5 revisions

SampPhysics Modding Guide (1.0.0)

This page covers everything in the public API (dev.samp.sampphysics.api) and the data pack system, so you can build your own mods on top of SampPhysics!

Anything outside dev.samp.sampphysics.api is internal and can change between updates, so please stick to the api package and the data files below.


1. Setup

Add SampPhysics to your build.gradle using CurseMaven:

repositories {
    exclusiveContent {
        forRepository {
            maven {
                url "https://cursemaven.com"
            }
        }
        filter {
            includeGroup "curse.maven"
        }
    }
}

dependencies {
    // 26.3
    implementation "curse.maven:sampphysics-1829987:9957977"
    // 26.2
    implementation "curse.maven:sampphysics-1829987:9957962"
    // 26.1.2
    implementation "curse.maven:sampphysics-1829987:9957910"
}

Then add SampPhysics to the dependencies in your fabric.mod.json:

"depends": {
  "fabricloader": ">=0.19.2",
  "minecraft": ">=26.3 <26.4",
  "fabric-api": ">=0.163.0",
  "java": ">=25",
  "sampphysics": ">=1.0.0"
}

That example is for 26.3. SampPhysics 1.0.0 is also out for 26.1.2 and 26.2 (Fabric, Java 25+), so change the minecraft line if you're on one of those.

You're welcome to write and publish mods that depend on SampPhysics, under any license you like. Just don't copy SampPhysics code or put the SampPhysics jar inside your own jar. Have players download it from its official page instead.

One thing to know before you start: SampPhysics handles physics, collisions, saving and networking, but it doesn't draw a pod's blocks. Drawing your pods is up to your mod (see Drawing Pods on the Client).


2. Pods & Coordinates

A pod (Pod, ServerPod, ClientPod) is a moving build made of real Minecraft blocks. Every pod has two sides to it:

  • Zone space is where its blocks actually live, in a hidden chunk area (PodZone). Block positions in there work like normal BlockPos coordinates.
  • World space is where the pod really sits, turns and moves in the world (PodPose).

Use Pods and PodWorld to find pods and go between the two:

import dev.samp.sampphysics.api.Pod;
import dev.samp.sampphysics.api.PodPose;
import dev.samp.sampphysics.api.PodWorld;
import dev.samp.sampphysics.api.Pods;
import dev.samp.sampphysics.api.ServerPod;
import dev.samp.sampphysics.api.ServerPods;

ServerPods pods = Pods.in(serverLevel);
ServerPod byId = pods.byId(podUuid);

Pod atPos = Pods.at(level, blockPos);
Pod carryingPlayer = Pods.carrying(player);

Vec3 worldPos = PodWorld.toWorld(level, Vec3.atCenterOf(zonePos));

PodPose pose = pod.pose();
Vec3 inWorld = pose.toWorld(localVec);
Vec3 inZone = pose.toZone(worldVec);

Pods.at(...) also takes a chunk, an entity or a block entity, if you want to check whether one of those belongs to a pod. PodWorld.toWorld takes a Vec3, not a BlockPos, so wrap block positions like above.


3. Making, Managing & Saving Pods

Turning blocks into a pod

Pods.assemble(...) lifts blocks that are already in the world into a new ServerPod:

List<BlockPos> positions = List.of(origin, origin.above());
BoundingBox box = Pods.areaAround(positions);
ServerPod pod = Pods.assemble(serverLevel, origin, positions, box);

You can also make an empty pod at a pose with Pods.in(serverLevel).create(pose).

Handy ServerPod methods

  • pod.rename("My Ship") sets the pod's name.
  • pod.modData() / pod.setModData(tag) store your own CompoundTag right inside the pod's save file.
  • pod.kilograms(), pod.centreOfMass() and pod.inertia() read its mass.
  • pod.reweigh(scale) works the mass out again after you change blocks or weights.
  • pod.refreshBox() works out the pod's bounding box again.
  • pod.setPose(pose) teleports it, and pod.snapLastPose() skips the smoothing so it doesn't glide there on clients.
  • pod.remove() or Pods.in(serverLevel).discard(pod) removes it.
  • Pods.in(serverLevel).keepLoaded(pod, true) keeps a pod loaded and moving even with nobody around, and it stays that way after a restart.

Parked & saved pods

Pods.in(serverLevel).storage() gives you PodStorage. With it you can look at parked and saved pods (parked(), onDisk()), park or unpark one yourself (park(pod, chunkPos), unpark(id)), or read and load SavedPod records.


4. Moving Pods

Force channels (best for forces that keep going)

Register a ForceChannel once when your mod starts, then queue pushes or twists on any ServerPod:

import dev.samp.sampphysics.api.ForceChannel;
import net.minecraft.resources.Identifier;
import org.joml.Vector3d;

public static final ForceChannel THRUSTER =
    ForceChannel.register(Identifier.fromNamespaceAndPath("mymod", "thruster"));

pod.queuePush(THRUSTER, new Vector3d(0.0, 500.0, 0.0));
pod.queueTwist(THRUSTER, new Vector3d(0.0, 20.0, 0.0));
pod.queuePushAt(THRUSTER, new Vector3d(100.0, 0.0, 0.0), worldPoint);

Using the solver directly

For velocities, impulses, waking pods up or links, get the Solver from Pods.in(serverLevel).solver():

Solver solver = Pods.in(serverLevel).solver();

Vector3d vel = solver.velocity(pod, new Vector3d());
Vector3d angVel = solver.spin(pod, new Vector3d());

solver.push(pod, new Vector3d(0.0, 200.0, 0.0));
solver.addVelocity(pod, new Vector3d(2.0, 0.0, 0.0), new Vector3d());
solver.wake(pod);
solver.moveTo(pod, newPosition, newRotation);

You can read the world's gravity and air drag with PodWorld.fallPull() and PodWorld.airDrag().


5. Links

You can connect two pods through the Solver.

Welds (Link) hold two pods together:

Link weld = solver.fix(podA, podB, anchorA, anchorB, relativeRotation);
weld.allowContacts(false);
weld.remove();

allowContacts(false) makes the two pods ignore collisions with each other, and remove() lets them go again.

Slide links (SlideLink) let them slide or turn along the axes you pick, and can drive them like a motor:

SlideLink joint = solver.slide(
    podA, podB,
    anchorA, anchorB,
    frameA, frameB,
    EnumSet.of(Axis.SLIDE_X, Axis.TURN_Y)
);
joint.drive(Axis.SLIDE_X, targetPos, stiffness, damping);
joint.moveFirstEnd(newAnchorA, newFrameA);

The Axis values are SLIDE_X, SLIDE_Y, SLIDE_Z, TURN_X, TURN_Y and TURN_Z.


6. Custom Blocks, Floating & Hit Reactions

Custom block behavior (PodBlock)

Implement PodBlock on your Block class to change how it acts on a pod, no mixins needed:

  • bodyShape(level, state) is the shape the physics uses for collisions.
  • massCentre(level, state) moves the block's center of mass.
  • riderShape(entity, state, level, pos) is the shape entities standing on the pod collide with.
  • beforeMove(...) and afterMove(...) run when the block moves into or out of a pod.

Block values & floating in code (BlockRules & FloatingMaterial)

import dev.samp.sampphysics.api.BlockRules;
import dev.samp.sampphysics.api.FloatingMaterial;

BlockRules.set(MY_BLOCK, BlockRules.Value.WEIGHT, 2.5);
BlockRules.set(MY_BLOCK, BlockRules.Value.BOUNCE, 0.6);
BlockRules.set(MY_BLOCK, BlockRules.Value.GRIP, 1.2);
BlockRules.setShatters(MY_GLASS, true);

Identifier heliumId = Identifier.fromNamespaceAndPath("mymod", "helium");
BlockRules.addFloatingMaterial(heliumId, FloatingMaterial.rising(12.0, true));
BlockRules.setFloatsAs(MY_BALLOON, heliumId, 1.0);

Each value has limits:

Value Lowest Highest
WEIGHT 0 10000
FILL 0.01 1
BOUNCE 0 1
GRIP 0 10
FLOAT_SHARE 0 1

To read the final values for any BlockState, use BlockValues.of(state) or BlockValues.kilograms(level, pos, state).

Custom hit reactions (HitReactions)

Register a reaction kind and attach it to blocks, either in code or with a data pack (see below). How hard a hit is depends on the speed and the mass of both things that hit each other, so a heavy train hits way harder than a light crate going the same speed.

import dev.samp.sampphysics.api.Hit;
import dev.samp.sampphysics.api.HitReactions;

Identifier popId = Identifier.fromNamespaceAndPath("mymod", "pop");

HitReactions.register(popId, (level, pos, state, hit) -> {
    level.destroyBlock(pos, true);
    return true;
});

HitReactions.attach(
    MY_CRATE,
    new HitReactions.Rule(popId, 4.0, 2.0, HitReactions.Place.GROUND)
);

Return true from your reaction when it handled the hit. The Rule takes the kind, the strength needed, the lowest speed, and where the block has to be. HitReactions.Place can be GROUND (only when it's hit in the world), POD (only when it's hit while riding on a pod), or ANY.


7. Events & Watchers

You can hook into what the physics is doing with PodEvents:

  • PodEvents.beforeStep((solver, dt) -> ...) and PodEvents.afterStep((solver, dt) -> ...)
  • PodEvents.onSplit((level, bounds, newPods) -> ...)
  • PodEvents.onBlockMoves(...), with beforeAssemble, moving and moved
  • PodEvents.onLoadGroup(pods -> ...) to add linked pods that should load together
  • PodEvents.onCollision((entity, pod) -> ...), return true to skip a collision between an entity and a pod
  • PodEvents.onShown((player, pod) -> ...) runs when a pod gets sent to a player

To keep track of pods being added, removed or ticked in a level, register a PodWatcher with Pods.in(serverLevel).watch(watcher).


8. Drawing Pods on the Client

Like I said up top, SampPhysics doesn't draw a pod's blocks for you. Here's how to do it yourself:

  1. Go through Pods.in(clientLevel).all(). These come back as plain Pods, so cast each one to ClientPod.
  2. Call clientPod.drawnPose(partialTick) to get the smoothed PodPose for this frame.
  3. Use pose.matrix(new Matrix4d()) (or pose.position(), pose.rotation() and pose.pivot()) to move your pose stack.
  4. Get the pod's blocks from pod.zone().usedBlocks() and pod.zone().localBlocks() (or pod.zone().chunks()).
for (Pod pod : Pods.in(clientLevel).all()) {
    ClientPod clientPod = (ClientPod) pod;
    PodPose pose = clientPod.drawnPose(partialTick);
    Matrix4d matrix = pose.matrix(new Matrix4d());
}

There are a few optional client hooks in EngineHooks too: seatEye, breakEffect and renderBank.


9. Data Packs

SampPhysics loads its own defaults first and every other namespace after, so files in your mod's namespace override the defaults automatically.

Block values (data/<namespace>/sampphysics/block_values/*.json)

{
  "stage": 2,
  "groups": [
    {
      "blocks": ["mymod:heavy_crate", "#mymod:metal_blocks"],
      "weight": 4.0,
      "fill": 1.0,
      "bounce": 0.1,
      "grip": 0.8,
      "shatters": false,
      "halves": true
    },
    {
      "blocks": ["mymod:my_piston"],
      "only": { "extended": "true" },
      "weight": 0.5
    }
  ]
}
  • stage sets the order block value files load in. Lower goes first.
  • only matches specific block state properties.
  • halves: true halves the weight for partial shapes like slabs.

Materials (data/<namespace>/sampphysics/materials/*.json)

Set up materials once, then give blocks a material and how much of the block space they fill:

{
  "materials": {
    "wood": { "weight": 0.5 },
    "metal": { "weight": 4.0 },
    "belt": { "weight": 0.5, "grip": 1.65 }
  },
  "blocks": {
    "mymod:steel_frame": { "of": "metal", "fills": 0.5 },
    "mymod:wooden_seat": { "of": "wood", "fills": 0.375 }
  }
}

Floating (data/<namespace>/sampphysics/floating/*.json)

The data pack version of addFloatingMaterial and setFloatsAs:

{
  "blocks": {
    "mymod:balloon": 0.33
  },
  "fades_with_height": true,
  "air": {
    "moving": { "along_pull": 0.5, "across_pull": 0.5 }
  }
}
  • blocks maps each block ID to its float share (0 to 1).
  • fades_with_height makes lift taper off higher up.
  • air controls drag while moving (along_pull and across_pull).

Hit reactions (data/<namespace>/sampphysics/hit_reactions/*.json)

{
  "rules": [
    {
      "kind": "mymod:pop",
      "blocks": ["mymod:fragile_crate"],
      "strength": 3.0,
      "min_speed": 2.0,
      "struck": "ground"
    }
  ]
}
  • struck can be ground, pod or any, same as HitReactions.Place.
  • Instead of a blocks list, you can use "fragile": true to target SampPhysics's built-in fragile blocks (leaves, melons, ice and so on).
  • unless skips block states with certain properties, the opposite of only. The built-in break rule uses "unless": { "persistent": "true" } so leaves players placed don't break.

The built-in reaction kinds are sampphysics:break, sampphysics:ring, sampphysics:light, sampphysics:note, sampphysics:chime, sampphysics:pulse and sampphysics:spill.

Tags

Block tags:

  • data/<namespace>/tags/block/springy.json for bouncy blocks, like slime blocks
  • data/<namespace>/tags/block/moves_quietly.json for blocks that don't make noise when they move onto or off a pod

Entity type tags:

  • data/<namespace>/tags/entity_type/stays_in_pod.json for entities that stay attached inside a pod's zone
  • data/<namespace>/tags/entity_type/removed_with_pod.json for entities that get removed along with their pod
  • data/<namespace>/tags/entity_type/removed_off_pod.json for entities that get removed when they leave a pod

10. Extras

  • Update checker (UpdateChecker): your mod can use the same opt-in update checker SampPhysics uses. Start it with UpdateChecker.start(modId, displayName, feedUrl, commandWord, settingsFileName, logger) and add its on/off command with UpdateChecker.updatesCommand(modId).
  • Config files (SettingsFile): build .properties config files with comments and limits using new SettingsFile.Builder().

If something's missing from the API or you find a bug, please open an issue on GitHub! :D