Skip to content

Commit

Permalink
Update commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorax5 committed Sep 3, 2024
1 parent f594582 commit 1a30ce0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 25 deletions.
22 changes: 22 additions & 0 deletions src/main/java/fr/phylisiumstudio/bullet/BulletWorldPhysics.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class BulletWorldPhysics extends WorldPhysics {

private float timespan = 1.0f / 20.0f;
private int maxSubSteps = 30;
private boolean timeFreeze = false;

public BulletWorldPhysics(World bukkitWorld, DiscreteDynamicsWorld bulletWorld) {
this.bulletWorld = bulletWorld;
Expand All @@ -49,6 +50,7 @@ public BulletWorldPhysics(World bukkitWorld, DiscreteDynamicsWorld bulletWorld)
*/
@Override
public void stepSimulation() {
if (timeFreeze) return;
bulletWorld.stepSimulation(timespan, maxSubSteps);
}

Expand Down Expand Up @@ -313,6 +315,26 @@ public void setMaxSubSteps(int maxSubSteps) {
this.maxSubSteps = maxSubSteps;
}

/**
* set freeze
*
* @param freeze the freeze
*/
@Override
public void setFreeze(boolean freeze) {
this.timeFreeze = freeze;
}

/**
* is frozen
*
* @return is frozen
*/
@Override
public boolean isFrozen() {
return timeFreeze;
}


private void addFace(CompoundShape compoundShape, Vector3f blockPos, Vector3f normal) {
Vector3f halfExtents = new Vector3f(0.5f, 0.5f, 0.5f);
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/fr/phylisiumstudio/logic/WorldPhysics.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ public Lock getLock() {
}

/**
* Get the time freeze
* Get the time span
*/
public abstract float getTimespan();

/**
* Set the time freeze
* Set the time span
*/
public abstract void setTimespan(float timeFreeze);
public abstract void setTimespan(float timespan);

/**
* Get Max substeps
Expand All @@ -109,4 +109,16 @@ public Lock getLock() {
* Set Max substeps
*/
public abstract void setMaxSubSteps(int maxSubSteps);

/**
* set freeze
* @param freeze the freeze
*/
public abstract void setFreeze(boolean freeze);

/**
* is frozen
* @return is frozen
*/
public abstract boolean isFrozen();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.sk89q.worldedit.session.SessionManager;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import fr.phylisiumstudio.logic.WorldPhysics;
import fr.phylisiumstudio.soraxPhysic.ItemLinkerManager;
import fr.phylisiumstudio.soraxPhysic.PhysicsManager;
import org.bukkit.Material;
Expand All @@ -23,6 +24,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import javax.vecmath.Vector3f;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -48,7 +50,7 @@ private class CreateCommands extends BaseCommand {
@Description("Create a box shape")
@CommandPermission("physics.create.box")
public void createBox(Player sender, Material block, float mass, float xscale, float yscale, float zscale){
physicsManager.createBoxShape(sender.getEyeLocation(), block, mass, xscale, yscale, zscale);
physicsManager.createBox(sender.getEyeLocation(), block.createBlockData(), mass, xscale, yscale, zscale);
sender.sendMessage("Box created");
}

Expand All @@ -57,11 +59,11 @@ public void createBox(Player sender, Material block, float mass, float xscale, f
@Description("Create a sphere shape")
@CommandPermission("physics.create.sphere")
public void createSphere(Player sender, Material block, float mass, float radius){
physicsManager.createsphereShape(sender.getEyeLocation(), block, mass, radius);
physicsManager.createSphere(sender.getEyeLocation(), block.createBlockData(), mass, radius);
sender.sendMessage("Sphere created");
}

@Subcommand("convert")
/*@Subcommand("convert")
@Description("Convert the WorldEdit selection to physics shapes (beta feature do not use if you don't know what you are doing)")
@CommandPermission("physics.create.convert")
public void convertSelection(Player player, float impulse, float damping, float tau){
Expand Down Expand Up @@ -124,57 +126,71 @@ public void convertSelection(Player player, float impulse, float damping, float
}
player.sendMessage("Selection converted");
}
}

@Subcommand("tools")
@Description("Don't work for the moment")
private class ToolsCommands extends BaseCommand {
@Subcommand("linker")
public void createLinker(Player sender){
ItemStack linker = itemLinkerManager.CreateLinker(sender.getUniqueId());
sender.getInventory().addItem(linker);
}
}*/
}

@Subcommand("clear")
@Description("Clear all shapes in the physics engine")
@CommandPermission("physics.clear")
public void clearShapes(Player sender){
physicsManager.clearAll();
sender.sendMessage("Shapes cleared");
WorldPhysics worldPhysics = physicsManager.getWorldPhysics(sender.getWorld().getUID());
if(worldPhysics == null){
throw new IllegalArgumentException("The world is not managed by the physics engine");
}
worldPhysics.clear();
sender.sendMessage("Shapes cleared for the world " + sender.getWorld().getName());
}

@Subcommand("freeze")
@Description("Freeze the time in the physics engine")
@CommandPermission("physics.freeze")
public void freezeTime(Player sender){
physicsManager.setTimeFreeze(!physicsManager.isTimeFreeze());
WorldPhysics worldPhysics = physicsManager.getWorldPhysics(sender.getWorld().getUID());
if(worldPhysics == null){
throw new IllegalArgumentException("The world is not managed by the physics engine");
}
boolean freeze = !worldPhysics.isFrozen();
worldPhysics.setFreeze(freeze);
sender.sendMessage("Time " + (freeze ? "frozen" : "unfrozen") + " for the world " + sender.getWorld().getName());
}

@Subcommand("timespan")
@CommandCompletion("@range:0.1-1")
@Description("Set the timespan for the physics engine (do not touch if you don't know what you are doing)")
@CommandPermission("physics.timespan")
public void setTimeSpan(Player sender, float timespan){
physicsManager.setTimespan(timespan);
sender.sendMessage("Timespan set to " + timespan);
WorldPhysics worldPhysics = physicsManager.getWorldPhysics(sender.getWorld().getUID());
if(worldPhysics == null){
throw new IllegalArgumentException("The world is not managed by the physics engine");
}
worldPhysics.setTimespan(timespan);
sender.sendMessage("Timespan set to " + timespan + "s for the world " + sender.getWorld().getName());
}

@Subcommand("substeps")
@CommandCompletion("@range:1-60")
@Description("Set the number of substeps for the physics engine (do not touch if you don't know what you are doing)")
@CommandPermission("physics.substeps")
public void setMaxSubSteps(Player sender, int maxSubSteps){
physicsManager.setMaxSubSteps(maxSubSteps);
sender.sendMessage("Max substeps set to " + maxSubSteps);
WorldPhysics worldPhysics = physicsManager.getWorldPhysics(sender.getWorld().getUID());
if(worldPhysics == null){
throw new IllegalArgumentException("The world is not managed by the physics engine");
}
worldPhysics.setMaxSubSteps(maxSubSteps);
sender.sendMessage("Max substeps set to " + maxSubSteps + " for the world " + sender.getWorld().getName());
}

@Subcommand("chunk")
@Description("Convert the chunk where the player is standing to a physics chunk")
@CommandPermission("physics.chunk")
public void convertChunk(Player sender){
physicsManager.ConvertChunk(sender.getLocation().getChunk());
WorldPhysics worldPhysics = physicsManager.getWorldPhysics(sender.getWorld().getUID());
if(worldPhysics == null){
throw new IllegalArgumentException("The world is not managed by the physics engine");
}
Vector3f pos1 = new Vector3f(sender.getLocation().getBlockX(), sender.getLocation().getBlockY(), sender.getLocation().getBlockZ());
Vector3f pos2 = new Vector3f(sender.getLocation().getBlockX() + 16, sender.getLocation().getBlockY() + 16, sender.getLocation().getBlockZ() + 16);
worldPhysics.convertChunk(pos1, pos2);
sender.sendMessage("Chunk converted");
}

Expand Down

0 comments on commit 1a30ce0

Please sign in to comment.