11package dev .emortal ;
22
3- import com .jme3 .bullet .PhysicsSpace ;
4- import com .jme3 .bullet .collision .PhysicsRayTestResult ;
53import com .jme3 .bullet .collision .shapes .BoxCollisionShape ;
64import com .jme3 .bullet .collision .shapes .CollisionShape ;
75import com .jme3 .bullet .objects .PhysicsBody ;
86import com .jme3 .bullet .objects .PhysicsRigidBody ;
97import com .jme3 .math .Vector3f ;
108import dev .emortal .commands .*;
119import dev .emortal .objects .BlockRigidBody ;
12- import dev .emortal .objects .ChainPhysics ;
1310import dev .emortal .objects .LanternPhysics ;
1411import dev .emortal .objects .MinecraftPhysicsObject ;
1512import dev .emortal .tools .*;
4946import net .minestom .server .sound .SoundEvent ;
5047import net .minestom .server .timer .TaskSchedule ;
5148import net .minestom .server .world .DimensionType ;
52- import org .jetbrains .annotations .NotNull ;
5349import org .slf4j .Logger ;
5450import org .slf4j .LoggerFactory ;
5551
@@ -66,10 +62,6 @@ public class Main {
6662
6763 private static final Set <Point > BLOCKS_IN_SPHERE = SphereUtil .getBlocksInSphere (5 );
6864
69-
70-
71- public static boolean paused = false ;
72-
7365 public static void main (String [] args ) throws Exception {
7466 LibraryInfo info = new LibraryInfo (
7567 new DirectoryPath ("linux/x86-64/com/github/stephengold" ),
@@ -88,10 +80,13 @@ public static void main(String[] args) throws Exception {
8880
8981 System .setProperty ("minestom.tps" , "60" );
9082
83+
9184 MinecraftServer server = MinecraftServer .init ();
9285 MojangAuth .init ();
9386
9487
88+
89+
9590 DimensionType fullbrightDimension = DimensionType .builder ().ambientLight (1f ).build ();
9691 var fullbright = MinecraftServer .getDimensionTypeRegistry ().register (Key .key ("fullbright" ), fullbrightDimension );
9792
@@ -124,8 +119,8 @@ public static void main(String[] args) throws Exception {
124119 e .getPlayer ().getInventory ().setItemStack (6 , new PlayerSpawnerTool (e .getPlayer (), physicsHandler ).getItem ());
125120 e .getPlayer ().getInventory ().setItemStack (5 , new GrabberTool (e .getPlayer (), physicsHandler ).getItem ());
126121 e .getPlayer ().getInventory ().setItemStack (4 , new WeldTool (e .getPlayer (), physicsHandler ).getItem ());
122+ e .getPlayer ().getInventory ().setItemStack (3 , new ChainTool (e .getPlayer (), physicsHandler ).getItem ());
127123
128- e .getPlayer ().getInventory ().setItemStack (3 , ItemStack .of (Material .CHAIN ));
129124 e .getPlayer ().getInventory ().setItemStack (2 , ItemStack .of (Material .TNT ));
130125 e .getPlayer ().getInventory ().setItemStack (1 , ItemStack .of (Material .STONE ));
131126
@@ -146,18 +141,7 @@ public static void main(String[] args) throws Exception {
146141 e .getPlayer ().setRespawnPoint (new Pos (0 , 20 , 0 ));
147142 });
148143
149- instance .scheduler ().buildTask (new Runnable () {
150- long lastRan = System .nanoTime ();
151- @ Override
152- public void run () {
153- long diff = System .nanoTime () - lastRan ;
154- float deltaTime = diff / 1_000_000_000f ;
155-
156- lastRan = System .nanoTime ();
157- if (paused ) return ;
158- physicsHandler .update (deltaTime );
159- }
160- }).repeat (TaskSchedule .tick (1 )).schedule ();
144+ physicsHandler .start ();
161145
162146 global .addListener (ItemDropEvent .class , e -> {
163147 e .setCancelled (true );
@@ -201,18 +185,6 @@ public void run() {
201185 lantern .setInstance ();
202186 }
203187
204- if (e .getBlock ().compare (Block .CHAIN )) {
205- e .setCancelled (true );
206-
207- MinecraftPhysicsObject first = new ChainPhysics (physicsHandler , null , new Vec (0.1f , 0.5f , 0.1f ), 1 , new Vector3f (e .getBlockPosition ().blockX () + 0.5f , e .getBlockPosition ().blockY () + 0.5f , e .getBlockPosition ().blockZ () + 0.5f ));
208- MinecraftPhysicsObject lastLink = first ;
209- for (int links = 0 ; links < ChainLengthCommand .CHAIN_LENGTH ; links ++) {
210- lastLink = new ChainPhysics (physicsHandler , (PhysicsRigidBody ) lastLink .getCollisionObject (), new Vec (0.1f , 0.5f , 0.1f ), 1 , new Vector3f (e .getBlockPosition ().blockX () + 0.5f , e .getBlockPosition ().blockY () + 0.5f + (ChainLengthCommand .CHAIN_LENGTH -links ) * 1.1f , e .getBlockPosition ().blockZ () + 0.5f ));
211- lastLink .setInstance ();
212- }
213- // Main.paused = true;
214- }
215-
216188 if (e .getBlock ().compare (Block .TNT )) {
217189 e .setCancelled (true );
218190
@@ -236,7 +208,7 @@ public void run() {
236208
237209 PhysicsRigidBody cubeRigidBody = (PhysicsRigidBody ) cube .getCollisionObject ();
238210
239- Vec velocity = Vec . fromPoint ( cube .getEntity ().getPosition ().sub (blockPos .add (0.5 ))).normalize ().mul (4 , 8 , 4 ).mul (rand .nextDouble (1.2 , 2 )).mul (TntStrengthCommand .TNT_STRENGTH );
211+ Vec velocity = cube .getEntity ().getPosition ().sub (blockPos .add (0.5 )). asVec ( ).normalize ().mul (4 , 8 , 4 ).mul (rand .nextDouble (1.2 , 2 )).mul (TntStrengthCommand .TNT_STRENGTH );
240212 cube .getCollisionObject ().activate (true );
241213
242214 Vector3f linearVelocity = new Vector3f ();
@@ -252,7 +224,7 @@ public void run() {
252224 cube .setInstance ();
253225 PhysicsRigidBody cubeRigidBody = (PhysicsRigidBody ) cube .getCollisionObject ();
254226
255- Vec velocity = Vec . fromPoint ( nearbyBlock .position ().sub (blockPos .add (0.5 ))).normalize ().mul (4 , 8 , 4 ).mul (rand .nextDouble (1.2 , 2 )).mul (TntStrengthCommand .TNT_STRENGTH );
227+ Vec velocity = nearbyBlock .position ().sub (blockPos .add (0.5 )). asVec ( ).normalize ().mul (4 , 8 , 4 ).mul (rand .nextDouble (1.2 , 2 )).mul (TntStrengthCommand .TNT_STRENGTH );
256228 cube .getCollisionObject ().activate (true );
257229 Vector3f linearVelocity = new Vector3f ();
258230 cubeRigidBody .getLinearVelocity (linearVelocity );
@@ -297,11 +269,4 @@ public void run() {
297269 server .start ("0.0.0.0" , 25565 );
298270 }
299271
300- public static List <PhysicsRayTestResult > raycastEntity (PhysicsSpace physicsSpace , @ NotNull Point startPoint , @ NotNull Point direction , double maxDistance ) {
301- Point endPoint = startPoint .add (Vec .fromPoint (direction ).normalize ().mul (maxDistance ));
302- List <PhysicsRayTestResult > results = physicsSpace .rayTest (new Vector3f ((float ) startPoint .x (), (float ) startPoint .y (), (float ) startPoint .z ()), new Vector3f ((float ) endPoint .x (), (float ) endPoint .y (), (float ) endPoint .z ()));
303-
304- return results ;
305- }
306-
307- }
272+ }
0 commit comments