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

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent> <parent>
<artifactId>mc-mesh-master</artifactId> <artifactId>mc-mesh-plugin</artifactId>
<groupId>com.aaaaahhhhhhh.bananapuncher714</groupId> <groupId>com.aaaaahhhhhhh.bananapuncher714</groupId>
<version>1.0.0</version> <version>0.0.1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>mc-mesh-plugin</artifactId> <artifactId>mc-mesh-plugin-environment</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<build> <build>
<plugins> <plugins>
@@ -29,25 +29,13 @@
<release>21</release> <release>21</release>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.aaaaahhhhhhh.bananapuncher714.minietest.MeshingTest6</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.21.10-R0.1-SNAPSHOT</version> <version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
@@ -67,25 +55,17 @@
<groupId>org.ow2.asm</groupId> <groupId>org.ow2.asm</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>jackson-annotations</artifactId> <artifactId>lz4-java</artifactId>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>at.yawk.lz4</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>jackson-core</artifactId> <artifactId>azure-json</artifactId>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.azure</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>oshi-core</artifactId> <artifactId>oshi-core</artifactId>
<groupId>com.github.oshi</groupId> <groupId>com.github.oshi</groupId>
</exclusion> </exclusion>
<exclusion>
<artifactId>jcip-annotations</artifactId>
<groupId>com.github.stephenc.jcip</groupId>
</exclusion>
<exclusion> <exclusion>
<artifactId>msal4j</artifactId> <artifactId>msal4j</artifactId>
<groupId>com.microsoft.azure</groupId> <groupId>com.microsoft.azure</groupId>
@@ -110,22 +90,6 @@
<artifactId>logging</artifactId> <artifactId>logging</artifactId>
<groupId>com.mojang</groupId> <groupId>com.mojang</groupId>
</exclusion> </exclusion>
<exclusion>
<artifactId>content-type</artifactId>
<groupId>com.nimbusds</groupId>
</exclusion>
<exclusion>
<artifactId>lang-tag</artifactId>
<groupId>com.nimbusds</groupId>
</exclusion>
<exclusion>
<artifactId>nimbus-jose-jwt</artifactId>
<groupId>com.nimbusds</groupId>
</exclusion>
<exclusion>
<artifactId>oauth2-oidc-sdk</artifactId>
<groupId>com.nimbusds</groupId>
</exclusion>
<exclusion> <exclusion>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
@@ -135,7 +99,11 @@
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>netty-codec</artifactId> <artifactId>netty-codec-base</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>netty-codec-compression</artifactId>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
@@ -162,6 +130,10 @@
<artifactId>netty-transport-classes-epoll</artifactId> <artifactId>netty-transport-classes-epoll</artifactId>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
</exclusion> </exclusion>
<exclusion>
<artifactId>netty-transport-classes-kqueue</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion> <exclusion>
<artifactId>netty-transport-native-epoll</artifactId> <artifactId>netty-transport-native-epoll</artifactId>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
@@ -170,6 +142,14 @@
<artifactId>netty-transport-native-epoll</artifactId> <artifactId>netty-transport-native-epoll</artifactId>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
</exclusion> </exclusion>
<exclusion>
<artifactId>netty-transport-native-kqueue</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<artifactId>netty-transport-native-kqueue</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion> <exclusion>
<artifactId>netty-transport-native-unix-common</artifactId> <artifactId>netty-transport-native-unix-common</artifactId>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
@@ -186,14 +166,6 @@
<artifactId>jna-platform</artifactId> <artifactId>jna-platform</artifactId>
<groupId>net.java.dev.jna</groupId> <groupId>net.java.dev.jna</groupId>
</exclusion> </exclusion>
<exclusion>
<artifactId>accessors-smart</artifactId>
<groupId>net.minidev</groupId>
</exclusion>
<exclusion>
<artifactId>json-smart</artifactId>
<groupId>net.minidev</groupId>
</exclusion>
<exclusion> <exclusion>
<artifactId>jopt-simple</artifactId> <artifactId>jopt-simple</artifactId>
<groupId>net.sf.jopt-simple</groupId> <groupId>net.sf.jopt-simple</groupId>
@@ -215,8 +187,8 @@
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>lz4-java</artifactId> <artifactId>jspecify</artifactId>
<groupId>org.lz4</groupId> <groupId>org.jspecify</groupId>
</exclusion> </exclusion>
<exclusion> <exclusion>
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>

View File

@@ -14,7 +14,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.21.10-R0.1-SNAPSHOT</version> <version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@@ -1,46 +0,0 @@
package com.aaaaahhhhhhh.bananapuncher714.mesh.environment;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.objects.ChunkLocation;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.objects.ChunkMesh;
import com.aaaaahhhhhhh.bananapuncher714.mesh.environment.util.ChunkMeshUtil;
public class ChunkMeshCache {
File directory;
public ChunkMeshCache( File directory ) {
this.directory = directory;
}
public ChunkMesh load( ChunkLocation location ) {
final File file = new File( directory, location.getWorldName() + "/" + location.getX() + "/" + location.getZ() + ".cmesh" );
if ( file.exists() ) {
try {
final byte[] data = Files.readAllBytes( file.toPath() );
final ChunkMesh mesh = ChunkMeshUtil.deserialize( data );
return mesh;
} catch ( IOException e ) {
e.printStackTrace();
}
}
return null;
}
public void save( ChunkLocation location, ChunkMesh mesh ) {
final File file = new File( directory, location.getWorldName() + "/" + location.getX() + "/" + location.getZ() + ".cmesh" );
file.getParentFile().mkdirs();
final byte[] data = ChunkMeshUtil.serialize( mesh );
try {
Files.write( file.toPath(), data, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE, StandardOpenOption.WRITE );
} catch ( IOException e ) {
e.printStackTrace();
}
}
}

View File

@@ -2,8 +2,8 @@ package com.aaaaahhhhhhh.bananapuncher714.mesh.environment.util;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_21_R6.CraftWorld; import org.bukkit.craftbukkit.v1_21_R7.CraftWorld;
import org.bukkit.craftbukkit.v1_21_R6.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_21_R7.block.data.CraftBlockData;
import org.bukkit.util.BoundingBox; import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;

View File

@@ -1,6 +1,7 @@
name: MC-Mesh-Environment name: Mc-Mesh-Environment
main: com.aaaaahhhhhhh.bananapuncher714.mesh.environment.McMeshEnvironmentPlugin main: com.aaaaahhhhhhh.bananapuncher714.mesh.environment.McMeshEnvironmentPlugin
version: 0.0.1 version: 0.0.1
description: BulletJME and MC-Mesh integration description: BulletJME and MC-Mesh integration
author: BananaPuncher714 author: BananaPuncher714
api-version: 1.13 api-version: 1.13
load: STARTUP

View File

@@ -14,7 +14,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.21.10-R0.1-SNAPSHOT</version> <version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -27,19 +27,6 @@
<build> <build>
<plugins> <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> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>

View File

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

View File

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

View File

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