Incorporate environment into the main plugin

This commit is contained in:
2026-03-18 22:03:40 -04:00
parent 3f4b4c6975
commit 5b4076edab
11 changed files with 1093 additions and 1158 deletions

View File

@@ -14,7 +14,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.21.10-R0.1-SNAPSHOT</version>
<version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -27,19 +27,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>

View File

@@ -1,6 +1,5 @@
package com.aaaaahhhhhhh.bananapuncher714.mesh.physics;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -30,7 +29,7 @@ import com.aaaaahhhhhhh.bananapuncher714.mesh.command.validator.InputValidatorDo
import com.aaaaahhhhhhh.bananapuncher714.mesh.command.validator.InputValidatorInt;
import com.aaaaahhhhhhh.bananapuncher714.mesh.command.validator.sender.SenderValidatorPlayer;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.EnvironmentHandler;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.MeshEnvironment;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.McMeshEnvironmentPlugin;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.objects.ChunkLocation;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.objects.ChunkMesh;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.util.NmsUtil;
@@ -52,15 +51,12 @@ import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
public class McMeshPhysicsPlugin extends JavaPlugin {
private static final int TIME_STEPS = 5;
private static final int TIME_STEPS = 10;
private static final float SIMULATION_SPEED = 1f;
private MeshEnvironment environment;
private PhysicsSpace space;
private boolean paused = false;
private boolean teleportOnDeactivate = false;
private float tick = 0;
private Map< PhysicsCollisionObject, AuxiliaryDisplayStruct > linkedDisplays = new HashMap< PhysicsCollisionObject, AuxiliaryDisplayStruct >();
private Set< PhysicsCollisionObject > active = new HashSet< PhysicsCollisionObject >();
private Map< ChunkLocation, PhysicsRigidBody > chunks = new HashMap< ChunkLocation, PhysicsRigidBody >();
@@ -72,10 +68,13 @@ public class McMeshPhysicsPlugin extends JavaPlugin {
space = new PhysicsSpace( BroadphaseType.DBVT );
space.setAccuracy( 1f / ( TIME_STEPS * 20f ) );
environment = new MeshEnvironment( this, new File( getDataFolder(), "environment" ) );
environment.setHandler( new EnvironmentHandler() {
JavaPlugin.getPlugin( McMeshEnvironmentPlugin.class ).registerHandler( new EnvironmentHandler() {
@Override
public void onMeshLoad( ChunkLocation location, ChunkMesh mesh ) {
if ( !location.getWorld().getName().equalsIgnoreCase( "world" ) ) {
return;
}
// Now, create a physics object from the chunk mesh
final IndexedMesh nativeMesh = mesh.toIndexedMesh();
// Enable quantized AABB compression... hopefully that doesn't mess with the accuracy or anything...
@@ -99,12 +98,20 @@ public class McMeshPhysicsPlugin extends JavaPlugin {
@Override
public void onMeshUnload( ChunkLocation location, ChunkMesh mesh ) {
space.removeCollisionObject( chunks.get( location ) );
if ( !location.getWorld().getName().equalsIgnoreCase( "world" ) ) {
return;
}
space.removeCollisionObject( chunks.remove( location ) );
}
@Override
public void onMeshUpdate( ChunkLocation location, ChunkMesh mesh ) {
// Now, create a physics object from the chunk mesh
if ( !location.getWorld().getName().equalsIgnoreCase( "world" ) ) {
return;
}
// Now, create a physics object from the chunk mesh
final IndexedMesh nativeMesh = mesh.toIndexedMesh();
// Enable quantized AABB compression... hopefully that doesn't mess with the accuracy or anything...
final MeshCollisionShape meshCollision = new MeshCollisionShape( true, nativeMesh );
@@ -132,7 +139,7 @@ public class McMeshPhysicsPlugin extends JavaPlugin {
if ( !paused ) {
// Update the real world with the physics space objects
space.distributeEvents();
space.update( tick, TIME_STEPS );
space.update( SIMULATION_SPEED / 20f, TIME_STEPS );
for ( Iterator< Entry< PhysicsCollisionObject, AuxiliaryDisplayStruct > > it = linkedDisplays.entrySet().iterator(); it.hasNext(); ) {
Entry< PhysicsCollisionObject, AuxiliaryDisplayStruct > entry = it.next();
@@ -187,8 +194,6 @@ public class McMeshPhysicsPlugin extends JavaPlugin {
disp.display.setInterpolationDuration( 2 );
disp.display.setTransformationMatrix( transMat.mul( transformRot ) );
}
tick += SIMULATION_SPEED / 20f;
}
}, 0, 1 );
}

View File

@@ -35,8 +35,8 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_21_R6.CraftWorld;
import org.bukkit.craftbukkit.v1_21_R6.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_21_R7.CraftWorld;
import org.bukkit.craftbukkit.v1_21_R7.block.data.CraftBlockData;
import org.bukkit.entity.BlockDisplay;
import org.bukkit.entity.Display;
import org.bukkit.entity.Player;

View File

@@ -5,6 +5,7 @@ description: BulletJME and MC-Mesh integration
author: BananaPuncher714
api-version: 1.13
depend: [ "Mc-Mesh-Environment" ]
load: STARTUP
#libraries:
#- com.github.stephengold:Minie:7.5.0