From 2d8b172f1636eb873e3e5aa282fcb898b938aa6c Mon Sep 17 00:00:00 2001 From: austin Date: Sat, 30 Nov 2024 12:20:36 -0500 Subject: [PATCH] water spawner work --- docs/src/progress/renderertodo.md | 4 +++ .../client/item/ItemActions.java | 32 +++++++++++++++++++ .../client/script/ScriptClientVoxelUtils.java | 6 ++++ .../categories/ControlCategoryMainGame.java | 4 +++ .../fluid/manager/ServerFluidManager.java | 6 ++++ 5 files changed, 52 insertions(+) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 3769b0d1..8e73d634 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1193,6 +1193,10 @@ Remove concurrent datastructure usage in cell management Auto close prepared queries that are iterated over Fix viewport loading +(11/30/2024) +Water spawner firing on repeat + + # TODO diff --git a/src/main/java/electrosphere/client/item/ItemActions.java b/src/main/java/electrosphere/client/item/ItemActions.java index 0e59011c..bdd0b37c 100644 --- a/src/main/java/electrosphere/client/item/ItemActions.java +++ b/src/main/java/electrosphere/client/item/ItemActions.java @@ -157,6 +157,38 @@ public class ItemActions { } } + /** + * Repeats the secondary item action + */ + public static void repeatSecondaryItemAction(){ + Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)); + Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3d cursorPos = Globals.clientSceneWrapper.getCollisionEngine().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).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); + } + //tell the server we want the secondary hand item to STOP doing something + Globals.clientConnection.queueOutgoingMessage(InventoryMessage.constructclientRequestPerformItemActionMessage( + "handRight", + ITEM_ACTION_CODE_SECONDARY, + ITEM_ACTION_CODE_STATE_REPEAT, + cursorPos.x, + cursorPos.y, + cursorPos.z + )); + //TODO: do any immediate client side calculations here (ie start playing an animation until we get response from server) + if(Globals.playerEntity != null){ + ClientToolbarState clientToolbarState = ClientToolbarState.getClientToolbarState(Globals.playerEntity); + Entity primaryEntity = clientToolbarState.getCurrentPrimaryItem(); + if(primaryEntity != null && Globals.gameConfigCurrent.getItemMap().getItem(primaryEntity) != null){ + Item data = Globals.gameConfigCurrent.getItemMap().getItem(primaryEntity); + if(data.getClientSideSecondary() != null){ + ClientScriptUtils.fireSignal(data.getClientSideSecondary()); + } + } + } + } + /** * Releases the secondary item action */ diff --git a/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java b/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java index c4bd2db3..c061b37b 100644 --- a/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java +++ b/src/main/java/electrosphere/client/script/ScriptClientVoxelUtils.java @@ -35,6 +35,9 @@ public class ScriptClientVoxelUtils { 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.editTerrain(cursorPos, 1.1f, Globals.clientSelectedVoxelType.getId(), EDIT_INCREMENT); } @@ -59,6 +62,9 @@ public class ScriptClientVoxelUtils { 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)); + } Vector3i worldPos = new Vector3i( (int)(cursorPos.x / ServerTerrainChunk.CHUNK_DIMENSION), (int)(cursorPos.y / ServerTerrainChunk.CHUNK_DIMENSION), diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java b/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java index 4775e429..7270668f 100644 --- a/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java @@ -584,6 +584,10 @@ public class ControlCategoryMainGame { controlMap.get(ITEM_SECONDARY).setOnPress(new ControlMethod() {public void execute(MouseState mouseState) { ItemActions.attemptSecondaryItemAction(); }}); + controlMap.get(ITEM_SECONDARY).setOnRepeat(new ControlMethod() {public void execute(MouseState mouseState) { + ItemActions.attemptSecondaryItemAction(); + }}); + controlMap.get(ITEM_SECONDARY).setRepeatTimeout(0.5f * Main.targetFrameRate); controlMap.get(ITEM_SECONDARY).setOnRelease(new ControlMethod() {public void execute(MouseState mouseState) { ItemActions.releaseSecondaryItemAction(); }}); diff --git a/src/main/java/electrosphere/server/fluid/manager/ServerFluidManager.java b/src/main/java/electrosphere/server/fluid/manager/ServerFluidManager.java index 06274a42..89a76476 100644 --- a/src/main/java/electrosphere/server/fluid/manager/ServerFluidManager.java +++ b/src/main/java/electrosphere/server/fluid/manager/ServerFluidManager.java @@ -269,6 +269,12 @@ public class ServerFluidManager { * @param value The value to set it to */ public void deformFluidAtLocationToValue(Vector3i worldPos, Vector3i voxelPos, float weight, int value){ + if(voxelPos.x < 0 || voxelPos.y < 0 || voxelPos.z < 0){ + return; + } + if(worldPos.x < 0 || worldPos.y < 0 || worldPos.z < 0){ + return; + } // TerrainModification modification = new TerrainModification(worldPos,voxelPos,weight,value); // //could be null if, for instance, arena mode // if(model != null){