Skip to content

Commit 5875ee4

Browse files
committed
feature: Added support for moving Sable sublevels using walkways and escalators
1 parent 6b9681d commit 5875ee4

6 files changed

Lines changed: 110 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
Create: Escalated now has compatibility with Sable (Create: Aeronautics) on NeoForge 1.21.1.
66

7+
### Added:
8+
- Added support for moving Sable sublevels using walkways and escalators
9+
710
### Fixed:
811
- Fixed walkways and escalators not working on Sable sublevels
912

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package rbasamoyai.escalated;
2+
3+
import org.objectweb.asm.tree.ClassNode;
4+
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
5+
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
6+
7+
import java.util.List;
8+
import java.util.Set;
9+
10+
public class EscalatedMixinPlugin implements IMixinConfigPlugin {
11+
12+
@Override public void onLoad(String mixinPackage) {}
13+
14+
@Override public String getRefMapperConfig() { return null; }
15+
16+
@Override
17+
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
18+
if (mixinClassName.startsWith("rbasamoyai.escalated.mixin.compat.sable") && !EscalatedModsNeoForge.SABLE.isLoaded())
19+
return false;
20+
return true;
21+
}
22+
23+
@Override public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}
24+
25+
@Override public List<String> getMixins() { return null; }
26+
27+
@Override
28+
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
29+
}
30+
31+
@Override
32+
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
33+
}
34+
35+
}

src/main/java/rbasamoyai/escalated/EscalatedModsNeoForge.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import net.minecraft.core.registries.BuiltInRegistries;
55
import net.minecraft.resources.ResourceLocation;
66
import net.minecraft.world.level.block.Block;
7-
import net.neoforged.fml.ModList;
7+
import net.neoforged.fml.loading.LoadingModList;
88

99
import java.util.Optional;
1010
import java.util.function.Supplier;
@@ -14,16 +14,20 @@ public enum EscalatedModsNeoForge {
1414
SABLE;
1515

1616
private final String id;
17+
private final boolean isLoaded;
1718

18-
EscalatedModsNeoForge() { this.id = CreateLang.asId(name()); }
19+
EscalatedModsNeoForge() {
20+
this.id = CreateLang.asId(name());
21+
this.isLoaded = LoadingModList.get().getModFileById(this.id) != null;
22+
}
1923

2024
public String id() { return this.id; }
2125

2226
public ResourceLocation resource(String path) { return ResourceLocation.fromNamespaceAndPath(this.id, path); }
2327

2428
public Block getBlock(String id) { return BuiltInRegistries.BLOCK.get(this.resource(id)); }
2529

26-
public boolean isLoaded() { return ModList.get().isLoaded(this.id); }
30+
public boolean isLoaded() { return this.isLoaded; }
2731

2832
public <T> Optional<T> runIfInstalled(Supplier<Supplier<T>> toRun) {
2933
return this.isLoaded() ? Optional.of(toRun.get().get()) : Optional.empty();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package rbasamoyai.escalated.compat.sable;
2+
3+
import dev.ryanhcode.sable.api.physics.callback.BlockSubLevelCollisionCallback;
4+
import dev.ryanhcode.sable.sublevel.system.SubLevelPhysicsSystem;
5+
import net.minecraft.core.BlockPos;
6+
import net.minecraft.core.Direction;
7+
import net.minecraft.core.Vec3i;
8+
import net.minecraft.server.level.ServerLevel;
9+
import net.minecraft.world.level.block.state.BlockState;
10+
import org.joml.Vector3d;
11+
import rbasamoyai.escalated.walkways.AbstractWalkwayBlock;
12+
import rbasamoyai.escalated.walkways.WalkwayBlockEntity;
13+
import rbasamoyai.escalated.walkways.WalkwaySlope;
14+
15+
public class WalkwayBlockCallback implements BlockSubLevelCollisionCallback {
16+
17+
public static final WalkwayBlockCallback INSTANCE = new WalkwayBlockCallback();
18+
19+
private WalkwayBlockCallback() {}
20+
21+
// Adapted from BeltBlockCallback#sable$onCollision --ritchie
22+
@Override
23+
public CollisionResult sable$onCollision(BlockPos blockPos, Vector3d pos, double impactVelocity) {
24+
SubLevelPhysicsSystem system = SubLevelPhysicsSystem.getCurrentlySteppingSystem();
25+
ServerLevel level = system.getLevel();
26+
27+
if (!(level.getBlockEntity(blockPos) instanceof WalkwayBlockEntity walkwayBE))
28+
return CollisionResult.NONE;
29+
30+
BlockState state = walkwayBE.getBlockState();
31+
if (!(state.getBlock() instanceof AbstractWalkwayBlock walkwayBlock))
32+
return CollisionResult.NONE;
33+
Direction facing = walkwayBlock.getFacing(state);
34+
WalkwaySlope slope = walkwayBlock.getWalkwaySlope(state);
35+
if (slope == WalkwaySlope.TERMINAL)
36+
return CollisionResult.NONE;
37+
38+
Vec3i normal = Direction.get(Direction.AxisDirection.POSITIVE, facing.getAxis()).getNormal();
39+
float speed = walkwayBE.getWalkwayMovementSpeed() * 20.0f;
40+
41+
if (facing.getAxis() == Direction.Axis.X) {
42+
speed *= -1.0f;
43+
}
44+
45+
final Vector3d velocity = new Vector3d(normal.getX() * speed, normal.getY() * speed, normal.getZ() * speed);
46+
// TODO escalator motion?
47+
48+
return new BlockSubLevelCollisionCallback.CollisionResult(velocity, false);
49+
}
50+
51+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package rbasamoyai.escalated.mixin.compat.sable;
2+
3+
import dev.ryanhcode.sable.api.block.BlockWithSubLevelCollisionCallback;
4+
import dev.ryanhcode.sable.api.physics.callback.BlockSubLevelCollisionCallback;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import rbasamoyai.escalated.compat.sable.WalkwayBlockCallback;
7+
import rbasamoyai.escalated.walkways.AbstractWalkwayBlock;
8+
9+
@Mixin(AbstractWalkwayBlock.class)
10+
public class AbstractWalkwayBlockMixin implements BlockWithSubLevelCollisionCallback {
11+
@Override public BlockSubLevelCollisionCallback sable$getCallback() { return WalkwayBlockCallback.INSTANCE; }
12+
}

src/main/resources/escalated.mixins.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"required": true,
33
"minVersion": "0.8",
44
"package": "rbasamoyai.escalated.mixin",
5+
"plugin": "rbasamoyai.escalated.EscalatedMixinPlugin",
56
"compatibilityLevel": "JAVA_17",
67
"client": [
78
],
89
"mixins": [
10+
"compat.sable.AbstractWalkwayBlockMixin"
911
],
1012
"injectors": {
1113
"defaultRequire": 1

0 commit comments

Comments
 (0)