Repository navigation
Modding Guide
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.
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).
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 normalBlockPoscoordinates. -
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.
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).
-
pod.rename("My Ship")sets the pod's name. -
pod.modData()/pod.setModData(tag)store your ownCompoundTagright inside the pod's save file. -
pod.kilograms(),pod.centreOfMass()andpod.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, andpod.snapLastPose()skips the smoothing so it doesn't glide there on clients. -
pod.remove()orPods.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.
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.
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);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().
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.
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(...)andafterMove(...)run when the block moves into or out of a pod.
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).
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.
You can hook into what the physics is doing with PodEvents:
-
PodEvents.beforeStep((solver, dt) -> ...)andPodEvents.afterStep((solver, dt) -> ...) PodEvents.onSplit((level, bounds, newPods) -> ...)-
PodEvents.onBlockMoves(...), withbeforeAssemble,movingandmoved -
PodEvents.onLoadGroup(pods -> ...)to add linked pods that should load together -
PodEvents.onCollision((entity, pod) -> ...), returntrueto 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).
Like I said up top, SampPhysics doesn't draw a pod's blocks for you. Here's how to do it yourself:
- Go through
Pods.in(clientLevel).all(). These come back as plainPods, so cast each one toClientPod. - Call
clientPod.drawnPose(partialTick)to get the smoothedPodPosefor this frame. - Use
pose.matrix(new Matrix4d())(orpose.position(),pose.rotation()andpose.pivot()) to move your pose stack. - Get the pod's blocks from
pod.zone().usedBlocks()andpod.zone().localBlocks()(orpod.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.
SampPhysics loads its own defaults first and every other namespace after, so files in your mod's namespace override the defaults automatically.
{
"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
}
]
}-
stagesets the order block value files load in. Lower goes first. -
onlymatches specific block state properties. -
halves: truehalves the weight for partial shapes like slabs.
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 }
}
}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 }
}
}-
blocksmaps each block ID to its float share (0to1). -
fades_with_heightmakes lift taper off higher up. -
aircontrols drag while moving (along_pullandacross_pull).
{
"rules": [
{
"kind": "mymod:pop",
"blocks": ["mymod:fragile_crate"],
"strength": 3.0,
"min_speed": 2.0,
"struck": "ground"
}
]
}-
struckcan beground,podorany, same asHitReactions.Place. - Instead of a
blockslist, you can use"fragile": trueto target SampPhysics's built-in fragile blocks (leaves, melons, ice and so on). -
unlessskips block states with certain properties, the opposite ofonly. 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.
Block tags:
-
data/<namespace>/tags/block/springy.jsonfor bouncy blocks, like slime blocks -
data/<namespace>/tags/block/moves_quietly.jsonfor 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.jsonfor entities that stay attached inside a pod's zone -
data/<namespace>/tags/entity_type/removed_with_pod.jsonfor entities that get removed along with their pod -
data/<namespace>/tags/entity_type/removed_off_pod.jsonfor entities that get removed when they leave a pod
-
Update checker (
UpdateChecker): your mod can use the same opt-in update checker SampPhysics uses. Start it withUpdateChecker.start(modId, displayName, feedUrl, commandWord, settingsFileName, logger)and add its on/off command withUpdateChecker.updatesCommand(modId). -
Config files (
SettingsFile): build.propertiesconfig files with comments and limits usingnew SettingsFile.Builder().
If something's missing from the API or you find a bug, please open an issue on GitHub! :D