diff --git a/assets/Data/entity/items.json b/assets/Data/entity/items.json index 460b0d49..506696f4 100644 --- a/assets/Data/entity/items.json +++ b/assets/Data/entity/items.json @@ -4,7 +4,8 @@ ], "files" : [ "Data/entity/items/weapons.json", - "Data/entity/items/tools.json", + "Data/entity/items/debug_tools.json", + "Data/entity/items/hand_tools.json", "Data/entity/items/clothing.json", "Data/entity/items/materials.json" ] diff --git a/assets/Data/entity/items/tools.json b/assets/Data/entity/items/debug_tools.json similarity index 100% rename from assets/Data/entity/items/tools.json rename to assets/Data/entity/items/debug_tools.json diff --git a/assets/Data/entity/items/hand_tools.json b/assets/Data/entity/items/hand_tools.json new file mode 100644 index 00000000..313a6bb9 --- /dev/null +++ b/assets/Data/entity/items/hand_tools.json @@ -0,0 +1,37 @@ +{ + "items" : [ + { + "id" : "Stone Shovel", + "tokens" : [ + "GRAVITY", + "TARGETABLE", + "CURSOR" + ], + "equipData": { + "equipClass" : "tool" + }, + "graphicsTemplate": { + "model": { + "path" : "Models/items/weapons/shovel1.glb" + } + }, + "clientSidePrimary": "DIG", + "collidable": { + "type" : "CUBE", + "dimension1" : 0.1, + "dimension2" : 0.1, + "dimension3" : 0.35, + "rotX": 0, + "rotY": 0, + "rotZ": 0, + "rotW": 1, + "offsetX" : 0, + "offsetY" : 0.05, + "offsetZ" : 0 + }, + "iconPath" : "Textures/icons/itemIconItemGeneric.png" + } + ], + "files" : [ + ] +} \ No newline at end of file diff --git a/assets/Scripts/client/clienthooks.ts b/assets/Scripts/client/clienthooks.ts index f67fe1f2..00b3241e 100644 --- a/assets/Scripts/client/clienthooks.ts +++ b/assets/Scripts/client/clienthooks.ts @@ -40,5 +40,11 @@ export const clientHooks: Hook[] = [ callback: (engine: Engine) => { engine.classes.voxelUtils.static.spawnWater() } + }, + { + signal: "DIG", + callback: (engine: Engine) => { + engine.classes.voxelUtils.static.applyEdit() + } } ] \ No newline at end of file diff --git a/assets/Scripts/types/host/client/client-voxel-utils.ts b/assets/Scripts/types/host/client/client-voxel-utils.ts index 2c0d871d..50a06df2 100644 --- a/assets/Scripts/types/host/client/client-voxel-utils.ts +++ b/assets/Scripts/types/host/client/client-voxel-utils.ts @@ -13,4 +13,9 @@ export interface ClientVoxelUtils { */ readonly spawnWater: () => void + /** + * Tries to dig with whatever tool is equipped + */ + readonly dig: () => void + } \ No newline at end of file diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index f31267a0..e6b86beb 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1451,6 +1451,7 @@ Static rocks which harvest into rock items that spawn in forest Stone Axe item Fix human data for RH sword slash attack moves Cursor only for specific items +Added shovel (works inversely of how you would expect currently) diff --git a/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java b/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java index ba13b577..b72122ab 100644 --- a/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java +++ b/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java @@ -83,4 +83,27 @@ public class ScriptClientVoxelUtils { } } + /** + * Tries to dig with whatever tool is equipped + */ + @Export + public static void dig(){ + CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); + Entity camera = Globals.playerCamera; + if( + collisionEngine != null && + camera != null + ){ + Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); + Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); + Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); + if(cursorPos == null){ + cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); + } + if(Globals.clientSelectedVoxelType != null){ + TerrainEditing.removeTerrainGated(cursorPos, 1.1f, Globals.clientSelectedVoxelType.getId(), EDIT_INCREMENT); + } + } + } + } diff --git a/src/main/java/electrosphere/client/terrain/editing/TerrainEditing.java b/src/main/java/electrosphere/client/terrain/editing/TerrainEditing.java index 06b7fce1..09f3db11 100644 --- a/src/main/java/electrosphere/client/terrain/editing/TerrainEditing.java +++ b/src/main/java/electrosphere/client/terrain/editing/TerrainEditing.java @@ -65,5 +65,18 @@ public class TerrainEditing { // } } } + + /** + * Tries to remove terrain with proper game logic checks applied + * @param position The position to perform the edit + * @param editMagnitude The magnitude of the edit to perform + * @param type The type of block to make all edited blocks + * @param weight The weight of the sphere to apply the edit to + */ + public static void removeTerrainGated(Vector3d position, float editMagnitude, int type, float weight){ + if(position != null){ + Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestUseTerrainPaletteMessage(position.x, position.y, position.z, editMagnitude, weight, type)); + } + } }