diff --git a/assets/Data/entity/items.json b/assets/Data/entity/items.json index 45bd3553..d044f212 100644 --- a/assets/Data/entity/items.json +++ b/assets/Data/entity/items.json @@ -97,6 +97,9 @@ "offset": [0, 0, 0.15] } ] + }, + "itemBlockData": { + }, "equipData": { "equipClass" : "weapon2H" @@ -313,6 +316,33 @@ "offsetZ" : 0 }, "iconPath" : "Textures/icons/itemIconItemGeneric.png" + }, + + { + "id" : "terrainTool", + "modelPath": "Models/basic/geometry/unitvector.glb", + "tokens" : [ + "GRAVITY", + "TARGETABLE" + ], + "equipData": { + "equipClass" : "tool" + }, + "clientSidePrimary": "OPEN_VOXEL", + "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" } diff --git a/assets/Data/game/units/units.json b/assets/Data/game/units/units.json index a0f91f58..94213e86 100644 --- a/assets/Data/game/units/units.json +++ b/assets/Data/game/units/units.json @@ -24,6 +24,16 @@ "itemId" : "Katana2H" } ] + }, + { + "id" : "skeletonSwordsman", + "creatureId" : "skeleton", + "equipment" : [ + { + "pointId" : "handsCombined", + "itemId" : "Katana2H" + } + ] } ] } \ No newline at end of file diff --git a/docs/src/highlevel-design/creatures/individual/humanprogress.md b/docs/src/highlevel-design/creatures/individual/humanprogress.md index f102b09a..5df9c918 100644 --- a/docs/src/highlevel-design/creatures/individual/humanprogress.md +++ b/docs/src/highlevel-design/creatures/individual/humanprogress.md @@ -29,6 +29,11 @@ Progress on the human creature - [ ] CrouchStrafeLeft - [ ] CrouchStrafeRight - [ ] CrouchJump + - [ ] ClimbIdle + - [ ] ClimbUp + - [ ] ClimbLeft + - [ ] ClimbDown + - [ ] ClimbRight - [X] Sit (Ground) - [ ] Sit (Chair) - [X] HoldItemRH diff --git a/docs/src/highlevel-design/creatures/individual/skeletonprogress.md b/docs/src/highlevel-design/creatures/individual/skeletonprogress.md index 54fed3cf..34f77768 100644 --- a/docs/src/highlevel-design/creatures/individual/skeletonprogress.md +++ b/docs/src/highlevel-design/creatures/individual/skeletonprogress.md @@ -29,6 +29,11 @@ Progress on the skeleton creature - [ ] CrouchStrafeLeft - [ ] CrouchStrafeRight - [ ] CrouchJump + - [ ] ClimbIdle + - [ ] ClimbUp + - [ ] ClimbLeft + - [ ] ClimbDown + - [ ] ClimbRight - [X] Sit (Ground) - [ ] Sit (Chair) - [X] HoldItemRH diff --git a/docs/src/progress/currenttarget.md b/docs/src/progress/currenttarget.md index 71c5b300..d784601c 100644 --- a/docs/src/progress/currenttarget.md +++ b/docs/src/progress/currenttarget.md @@ -35,9 +35,13 @@ - Spawn player in a town with a quest to complete a nearby dungeon + bug fixes + Fix ui audio playing at world origin Fix light cluster mapping for foliage shader + Fix lights not being deleted + - Not sending a "light count" var to light calculations, so the data stays in buffer even though it is not being updated Fix ui elements not storing default discrete world size on level editor menu Fix static friction coeff causing player to slide on shallow slopes + - Probably need to look into using capsules Fix skeleton right strafe Fix block tree preventing initiating an attack Fix return to title menu synchronization bug diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index bc53f2b1..925738e2 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -818,6 +818,10 @@ Point light offsets (09/20/2024) Light manager buffer overflow bugfix +Particle Emitter data definitions +Torch w/ particle + lighting +Fix text input collapsing while typing +Voxel selection item # TODO @@ -836,7 +840,6 @@ Bug Fixes - Fix typescript load error - Calculate bounding sphere for meshes by deforming vertices with bone default pose instead of no bone deform - Fix character creation menu - - Fix text input collapsing while typing - Fix threads not synchronizing when returning to main menu (rendering still running when player entity deleted, race condition) Startup Performance diff --git a/src/main/java/electrosphere/client/fluid/cells/FluidCell.java b/src/main/java/electrosphere/client/fluid/cells/FluidCell.java index edf338c4..e3ca3993 100644 --- a/src/main/java/electrosphere/client/fluid/cells/FluidCell.java +++ b/src/main/java/electrosphere/client/fluid/cells/FluidCell.java @@ -11,7 +11,6 @@ import electrosphere.engine.Globals; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; -import electrosphere.entity.EntityUtils; import electrosphere.entity.types.fluid.FluidChunk; import electrosphere.renderer.shader.ShaderProgram; import electrosphere.server.terrain.manager.ServerTerrainChunk; @@ -86,7 +85,7 @@ public class FluidCell { public void destroy(){ CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); collisionEngine.destroyPhysics(modelEntity); - EntityUtils.cleanUpEntity(modelEntity); + ClientEntityUtils.destroyEntity(modelEntity); //destruct model String modelPath = (String)modelEntity.getData(EntityDataStrings.DATA_STRING_MODEL_PATH); Globals.assetManager.deregisterModelPath(modelPath); diff --git a/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java b/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java index 2ee01274..e9073e0d 100644 --- a/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java +++ b/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java @@ -21,6 +21,7 @@ import org.lwjgl.BufferUtils; import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.terrain.cache.ChunkData; import electrosphere.engine.Globals; +import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityUtils; @@ -193,7 +194,7 @@ public class FoliageCell { */ protected void destroy(){ for(Entity entity : containedEntities){ - EntityUtils.cleanUpEntity(entity); + ClientEntityUtils.destroyEntity(entity); } clearEntities(); } diff --git a/src/main/java/electrosphere/client/item/ItemActions.java b/src/main/java/electrosphere/client/item/ItemActions.java index 1516dce5..1c44392c 100644 --- a/src/main/java/electrosphere/client/item/ItemActions.java +++ b/src/main/java/electrosphere/client/item/ItemActions.java @@ -1,6 +1,13 @@ package electrosphere.client.item; +import electrosphere.client.ui.menu.WindowStrings; +import electrosphere.client.ui.menu.WindowUtils; +import electrosphere.client.ui.menu.ingame.MenuGeneratorsTerrainEditing; +import electrosphere.controls.ControlHandler.ControlsState; import electrosphere.engine.Globals; +import electrosphere.entity.Entity; +import electrosphere.entity.state.equip.ClientEquipState; +import electrosphere.game.data.item.type.Item; import electrosphere.net.parser.net.message.InventoryMessage; /** @@ -26,6 +33,19 @@ public class ItemActions { //tell the server we want the secondary hand item to START doing something Globals.clientConnection.queueOutgoingMessage(InventoryMessage.constructclientRequestPerformItemActionMessage("handRight", ITEM_ACTION_CODE_SECONDARY, ITEM_ACTION_CODE_STATE_ON)); //TODO: do any immediate client side calculations here (ie start playing an animation until we get response from server) + ClientEquipState clientEquipState = ClientEquipState.getClientEquipState(Globals.playerEntity); + Entity rightHandItem = clientEquipState.getEquippedItemAtPoint("handRight"); + if(rightHandItem != null && Globals.gameConfigCurrent.getItemMap().getItem(rightHandItem) != null){ + Item data = Globals.gameConfigCurrent.getItemMap().getItem(rightHandItem); + if(data.getClientSidePrimary() != null){ + switch(data.getClientSidePrimary()){ + case "OPEN_VOXEL": { + WindowUtils.replaceWindow(WindowStrings.VOXEL_TYPE_SELECTION,MenuGeneratorsTerrainEditing.createVoxelTypeSelectionPanel()); + Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); + } break; + } + } + } } /** diff --git a/src/main/java/electrosphere/client/terrain/cells/DrawCell.java b/src/main/java/electrosphere/client/terrain/cells/DrawCell.java index e9903dc1..d9221982 100644 --- a/src/main/java/electrosphere/client/terrain/cells/DrawCell.java +++ b/src/main/java/electrosphere/client/terrain/cells/DrawCell.java @@ -9,7 +9,6 @@ import electrosphere.collision.CollisionEngine; import electrosphere.engine.Globals; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; -import electrosphere.entity.EntityUtils; import electrosphere.entity.types.terrain.TerrainChunk; import electrosphere.renderer.meshgen.TransvoxelModelGeneration.TransvoxelChunkData; @@ -98,7 +97,7 @@ public class DrawCell { public void destroy(){ CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); collisionEngine.destroyPhysics(modelEntity); - EntityUtils.cleanUpEntity(modelEntity); + ClientEntityUtils.destroyEntity(modelEntity); } diff --git a/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsInventory.java b/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsInventory.java index 888cce41..7f3739d0 100644 --- a/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsInventory.java +++ b/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsInventory.java @@ -4,6 +4,7 @@ import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; import electrosphere.client.ui.menu.WindowStrings; import electrosphere.client.ui.menu.WindowUtils; import electrosphere.engine.Globals; +import electrosphere.engine.assetmanager.AssetDataStrings; import electrosphere.entity.state.inventory.InventoryUtils; import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.data.item.type.Item; @@ -32,7 +33,7 @@ public class MenuGeneratorsInventory { if(itemData.getItemAudio() != null && itemData.getItemAudio().getUIReleaseAudio() != null){ Globals.virtualAudioSourceManager.createVirtualAudioSource(itemData.getItemAudio().getUIReleaseAudio(), VirtualAudioSourceType.UI, false); } else { - Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/inventorySlotItem.ogg", VirtualAudioSourceType.UI, false); + Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_SFX_ITEM_RELEASE, VirtualAudioSourceType.UI, false); } } //clear ui diff --git a/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsTerrainEditing.java b/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsTerrainEditing.java index ddc0a955..0f993632 100644 --- a/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsTerrainEditing.java +++ b/src/main/java/electrosphere/client/ui/menu/ingame/MenuGeneratorsTerrainEditing.java @@ -5,6 +5,7 @@ import java.util.function.Consumer; import electrosphere.client.ui.menu.WindowStrings; import electrosphere.client.ui.menu.WindowUtils; +import electrosphere.controls.ControlHandler.ControlsState; import electrosphere.engine.Globals; import electrosphere.engine.signal.Signal.SignalType; import electrosphere.game.data.voxel.VoxelData; @@ -69,6 +70,7 @@ public class MenuGeneratorsTerrainEditing { //nav logic terrainEditingSidePanelWindow.setOnNavigationCallback(new NavigationEventCallback() {public boolean execute(NavigationEvent event){ WindowUtils.closeWindow(WindowStrings.VOXEL_TYPE_SELECTION); + Globals.controlHandler.hintUpdateControlState(ControlsState.MAIN_GAME); MenuGeneratorsLevelEditor.voxelWindowOpen = false; return false; }}); diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index 92b81a42..be7b4eaa 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -62,6 +62,7 @@ import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_LEFT; import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_RIGHT; import static org.lwjgl.glfw.GLFW.glfwGetCursorPos; import static org.lwjgl.glfw.GLFW.glfwSetInputMode; +import org.lwjgl.glfw.GLFW; import java.util.Arrays; import java.util.HashMap; @@ -324,7 +325,7 @@ public class ControlHandler { handler.addControl(INPUT_CODE_WALK, new Control(ControlType.KEY,GLFW_KEY_LEFT_ALT,false,"Walk (hold)","Causes the player to walk")); handler.addControl(INPUT_CODE_INTERACT, new Control(ControlType.KEY,GLFW_KEY_E,false,"Interact","Interacts with whatever is targeted currently")); handler.addControl(INPUT_CODE_DROP, new Control(ControlType.KEY,GLFW_KEY_Y,false,"Drop","Drops the currently equipped item")); - handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(ControlType.KEY,GLFW_KEY_I,false,"Inventory","Opens the player's inventory")); + handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(ControlType.KEY,GLFW.GLFW_KEY_TAB,false,"Inventory","Opens the player's inventory")); handler.addControl(ITEM_SECONDARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_RIGHT,false,"Secondary","Uses the secondary equipped item")); /* @@ -856,6 +857,10 @@ public class ControlHandler { } }}); + + /** + * Item actions + */ mainGameControlList.add(controls.get(ITEM_SECONDARY)); controls.get(ITEM_SECONDARY).setOnPress(new ControlMethod() {public void execute() { ItemActions.attemptSecondaryItemAction(); diff --git a/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java b/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java index c52f4a69..3babcfbc 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java +++ b/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java @@ -174,7 +174,7 @@ public class LoadingUtils { template.putAttributeValue(attribute.getAttributeId(), attribute.getVariants().get(0).getId()); } } - template.getCreatureEquipData().setSlotItem("handsCombined",new EquippedItem(71, "Katana2H")); + template.getCreatureEquipData().setSlotItem("handRight",new EquippedItem(71, "terrainTool")); //set player character template serverPlayerConnection.setCreatureTemplate(template); Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage()); diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index 6aa7f748..90befa4b 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -269,6 +269,7 @@ public class EntityDataStrings { Inventory in general */ public static final String NATURAL_INVENTORY = "inventoryNatural"; + public static final String INVENTORY_TOOLBAR = "inventoryToolbar"; public static final String CLIENT_INVENTORY_STATE = "clientInventoryState"; public static final String SERVER_INVENTORY_STATE = "serverInventoryState"; diff --git a/src/main/java/electrosphere/entity/EntityUtils.java b/src/main/java/electrosphere/entity/EntityUtils.java index d2648d98..e7e112ab 100644 --- a/src/main/java/electrosphere/entity/EntityUtils.java +++ b/src/main/java/electrosphere/entity/EntityUtils.java @@ -32,7 +32,7 @@ public class EntityUtils { * Cleans up the entity and deregisters it from all tracking datastructures * @param e The entity to clean up */ - public static void cleanUpEntity(Entity e){ + protected static void cleanUpEntity(Entity e){ //remove from client if(Globals.clientSceneWrapper != null){ Globals.clientSceneWrapper.getScene().deregisterEntity(e); diff --git a/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java b/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java index 26ce2129..ce50e8a2 100644 --- a/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java +++ b/src/main/java/electrosphere/entity/state/equip/ClientEquipState.java @@ -8,6 +8,7 @@ import java.util.Map; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.engine.Globals; +import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityDataStrings; @@ -350,7 +351,7 @@ public class ClientEquipState implements BehaviorTree { } else { //does not depend on the type of creature AttachUtils.clientDetatchEntityFromEntityAtBone(parent, equipped); - EntityUtils.cleanUpEntity(equipped); + ClientEntityUtils.destroyEntity(equipped); } //interrupt animation diff --git a/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java b/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java index 98f5c4e6..ba1698a0 100644 --- a/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java +++ b/src/main/java/electrosphere/entity/state/equip/ServerEquipState.java @@ -418,7 +418,7 @@ public class ServerEquipState implements BehaviorTree { BlockSystem blockData = blockTree.getBlockSystem(); for(EquipPoint point : pointsThatCanBlock){ Entity item = getEquippedItemAtPoint(point.getEquipPointId()); - if(item != null){ + if(item != null && Globals.gameConfigCurrent.getItemMap().getItem(item) != null && Globals.gameConfigCurrent.getItemMap().getItem(item).getItemBlockData() != null){ BlockVariant blockVariant = blockData.getVariantForPointWithItem(point.getEquipPointId(),ItemUtils.getEquipClass(item)); //TODO: refactor to allow sending more than one variant at a time diff --git a/src/main/java/electrosphere/entity/state/inventory/ClientInventoryState.java b/src/main/java/electrosphere/entity/state/inventory/ClientInventoryState.java index c3aba1a4..c79f546e 100644 --- a/src/main/java/electrosphere/entity/state/inventory/ClientInventoryState.java +++ b/src/main/java/electrosphere/entity/state/inventory/ClientInventoryState.java @@ -4,8 +4,8 @@ import java.util.concurrent.CopyOnWriteArrayList; import electrosphere.client.ui.menu.WindowUtils; import electrosphere.engine.Globals; +import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; -import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.types.item.ItemUtils; @@ -85,6 +85,9 @@ public class ClientInventoryState implements BehaviorTree { equipInventory.removeItemSlot(equipPointId); } } break; + case InventoryProtocol.INVENTORY_TYPE_TOOLBAR: { + throw new UnsupportedOperationException("todo"); + } } //once we've switched the items around, redraw the inventory to reflect the updated contents WindowUtils.attemptRedrawInventoryWindows(); @@ -96,7 +99,7 @@ public class ClientInventoryState implements BehaviorTree { Entity entityInSlot = equipState.getEquippedItemAtPoint(message.getequipPointId()); equipState.clientTransformUnequipPoint(message.getequipPointId()); //destroy the in-world manifestation of said item - EntityUtils.cleanUpEntity(entityInSlot); + ClientEntityUtils.destroyEntity(entityInSlot); } } break; case CLIENTREQUESTEQUIPITEM: diff --git a/src/main/java/electrosphere/entity/state/inventory/InventoryUtils.java b/src/main/java/electrosphere/entity/state/inventory/InventoryUtils.java index 566a1e10..6575ef0f 100644 --- a/src/main/java/electrosphere/entity/state/inventory/InventoryUtils.java +++ b/src/main/java/electrosphere/entity/state/inventory/InventoryUtils.java @@ -55,6 +55,11 @@ public class InventoryUtils { return (UnrelationalInventoryState)target.getData(EntityDataStrings.NATURAL_INVENTORY); } + /** + * Checks if the entity has an equip inventory + * @param target The entity + * @return true if it has an equip inventory, false if it does not + */ public static boolean hasEquipInventory(Entity target){ return target.containsKey(EntityDataStrings.EQUIP_INVENTORY); } @@ -80,6 +85,36 @@ public class InventoryUtils { return (RelationalInventoryState)target.getData(EntityDataStrings.EQUIP_INVENTORY); } + /** + * Checks if the entity has a toolbar inventory + * @param target The entity + * @return true if it has a toolbar inventory, false if it does not + */ + public static boolean hasToolbarInventory(Entity target){ + return target.containsKey(EntityDataStrings.INVENTORY_TOOLBAR); + } + + /** + * Sets the toolbar inventory of the entity + * @param target The target + * @param inventoryState The inventory + */ + public static void setToolbarInventory(Entity target, RelationalInventoryState inventoryState){ + target.putData(EntityDataStrings.INVENTORY_TOOLBAR, inventoryState); + } + + /** + * Gets the toolbar inventory of the entity + * @param target The entity + * @return The inventory if it exists, null otherwise + */ + public static RelationalInventoryState getToolbarInventory(Entity target){ + if(!target.containsKey(EntityDataStrings.INVENTORY_TOOLBAR)){ + return null; + } + return (RelationalInventoryState)target.getData(EntityDataStrings.INVENTORY_TOOLBAR); + } + /** * Gets the current inventory state * @param target the entity to get inventory state from diff --git a/src/main/java/electrosphere/entity/state/inventory/RelationalInventoryState.java b/src/main/java/electrosphere/entity/state/inventory/RelationalInventoryState.java index c999df69..f33c6a83 100644 --- a/src/main/java/electrosphere/entity/state/inventory/RelationalInventoryState.java +++ b/src/main/java/electrosphere/entity/state/inventory/RelationalInventoryState.java @@ -11,6 +11,11 @@ import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.logger.LoggerInterface; public class RelationalInventoryState { + + /** + * The size of the toolbar + */ + static final int TOOLBAR_SIZE = 10; Map items = new HashMap(); Map> slotWhitelists = new HashMap>(); @@ -24,6 +29,11 @@ public class RelationalInventoryState { // return rVal; // } + /** + * Builds a relational inventory state based on a list of equip points + * @param points The equip points + * @return The relational inventory state + */ public static RelationalInventoryState buildRelationalInventoryStateFromEquipList(List points){ RelationalInventoryState rVal = new RelationalInventoryState(); for(EquipPoint point : points){ @@ -34,16 +44,44 @@ public class RelationalInventoryState { return rVal; } + /** + * Builds a relational inventory state based on a list of equip points + * @param points The equip points + * @return The relational inventory state + */ + public static RelationalInventoryState buildToolbarInventory(){ + RelationalInventoryState rVal = new RelationalInventoryState(); + for(int i = 0; i < TOOLBAR_SIZE; i ++){ + rVal.items.put("" + i,null); + } + return rVal; + } + + /** + * Adds an item to the relational inventory state + * @param slot The slot to add to + * @param item The item + */ public void addItem(String slot, Entity item){ items.put(slot,item); } + /** + * Removes the item from a slot in the inventory + * @param slot The slot + * @return The item that was removed, or null if no item was removed + */ public Entity removeItemSlot(String slot){ Entity rVal = items.remove(slot); items.put(slot,null); return rVal; } + /** + * Gets the item in a given relational inventory state + * @param slot The slot + * @return The item if it exists, null otherwise + */ public Entity getItemSlot(String slot){ return items.get(slot); } @@ -67,15 +105,29 @@ public class RelationalInventoryState { return null; } + /** + * Checks if the relational inventory has an item in a slot + * @param slot The slot + * @return true if there is an item in that slot, false otherwise + */ public boolean hasItemInSlot(String slot){ //if the slot is a key return if the value at the key isn't null, otherwise return false return items.containsKey(slot) ? items.get(slot) != null : false; } + /** + * Gets the slots in the relational inventory state + * @return The list of slots + */ public List getSlots(){ return new LinkedList(items.keySet()); } + /** + * Tries removing an item from the inventory + * @param item The item + * @return The item if it was removed, null if it was not + */ public Entity tryRemoveItem(Entity item){ if(items.containsValue(item)){ for(String slot : items.keySet()){ diff --git a/src/main/java/electrosphere/entity/state/movement/ProjectileTree.java b/src/main/java/electrosphere/entity/state/movement/ProjectileTree.java index 18a4d1b6..c7c2e3ff 100644 --- a/src/main/java/electrosphere/entity/state/movement/ProjectileTree.java +++ b/src/main/java/electrosphere/entity/state/movement/ProjectileTree.java @@ -43,7 +43,7 @@ public class ProjectileTree implements BehaviorTree { lifeCurrent++; if(lifeCurrent >= maxLife){ - EntityUtils.cleanUpEntity(parent); + // EntityUtils.cleanUpEntity(parent); ServerBehaviorTreeUtils.detatchBTreeFromEntity(parent,this); } diff --git a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java index 5110a1c8..f46ac0da 100644 --- a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java +++ b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java @@ -269,7 +269,8 @@ public class CommonEntityUtils { if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){ ClientEquipState.attachTree(entity, rawType.getEquipPoints()); - entity.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); + InventoryUtils.setEquipInventory(entity, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); + InventoryUtils.setToolbarInventory(entity, RelationalInventoryState.buildToolbarInventory()); } if(rawType.getBlockSystem() != null){ ClientBlockTree.attachTree(entity, rawType.getBlockSystem()); @@ -541,7 +542,8 @@ public class CommonEntityUtils { // if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){ ServerEquipState.attachTree(entity, rawType.getEquipPoints()); - entity.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); + InventoryUtils.setEquipInventory(entity, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); + InventoryUtils.setToolbarInventory(entity, RelationalInventoryState.buildToolbarInventory()); } // diff --git a/src/main/java/electrosphere/entity/types/item/ItemUtils.java b/src/main/java/electrosphere/entity/types/item/ItemUtils.java index 84592e06..e5148178 100644 --- a/src/main/java/electrosphere/entity/types/item/ItemUtils.java +++ b/src/main/java/electrosphere/entity/types/item/ItemUtils.java @@ -9,6 +9,7 @@ import org.ode4j.ode.DBody; import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.collidable.Collidable; import electrosphere.engine.Globals; +import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityDataStrings; @@ -326,6 +327,9 @@ public class ItemUtils { * @return The type */ public static String getType(Entity item){ + if(item == null){ + return null; + } return CommonEntityUtils.getEntitySubtype(item); } @@ -449,7 +453,7 @@ public class ItemUtils { //destroy hitboxes HitboxCollectionState.destroyHitboxState(item); //destroy graphics - EntityUtils.cleanUpEntity(item); + ClientEntityUtils.destroyEntity(item); } } } diff --git a/src/main/java/electrosphere/game/data/item/type/Item.java b/src/main/java/electrosphere/game/data/item/type/Item.java index 9020ef2d..22d8d902 100644 --- a/src/main/java/electrosphere/game/data/item/type/Item.java +++ b/src/main/java/electrosphere/game/data/item/type/Item.java @@ -22,6 +22,16 @@ public class Item extends CommonEntityType { */ ItemAudio itemAudio; + /** + * A function that should be performed client-side when the player uses this as their primary item + */ + String clientSidePrimary; + + /** + * The block data for this item + */ + ItemBlockData itemBlockData; + /** * the idle animation for the item * @return @@ -62,4 +72,20 @@ public class Item extends CommonEntityType { return itemAudio; } + /** + * Gets the client side primary action to perform + * @return The action + */ + public String getClientSidePrimary(){ + return clientSidePrimary; + } + + /** + * Gets the block data for the item + * @return THe block data + */ + public ItemBlockData getItemBlockData(){ + return this.itemBlockData; + } + } diff --git a/src/main/java/electrosphere/game/data/item/type/ItemBlockData.java b/src/main/java/electrosphere/game/data/item/type/ItemBlockData.java new file mode 100644 index 00000000..5468c4aa --- /dev/null +++ b/src/main/java/electrosphere/game/data/item/type/ItemBlockData.java @@ -0,0 +1,9 @@ +package electrosphere.game.data.item.type; + +/** + * Block data for the item + */ +public class ItemBlockData { + + +} diff --git a/src/main/java/electrosphere/game/data/item/type/model/ItemTypeMap.java b/src/main/java/electrosphere/game/data/item/type/model/ItemTypeMap.java index 789bd3c8..3cb93c27 100644 --- a/src/main/java/electrosphere/game/data/item/type/model/ItemTypeMap.java +++ b/src/main/java/electrosphere/game/data/item/type/model/ItemTypeMap.java @@ -1,5 +1,7 @@ package electrosphere.game.data.item.type.model; +import electrosphere.entity.Entity; +import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.data.item.type.Item; import electrosphere.logger.LoggerInterface; @@ -24,5 +26,17 @@ public class ItemTypeMap { } return rVal; } + + /** + * Gets the item data of the item + * @param item The item entity + * @return The type + */ + public Item getItem(Entity item){ + if(item != null && ItemUtils.isItem(item) && ItemUtils.getType(item) != null){ + return getItem(ItemUtils.getType(item)); + } + return null; + } } diff --git a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java index ee421adb..4527d320 100644 --- a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java @@ -9,7 +9,6 @@ import org.joml.Vector3d; import electrosphere.engine.Globals; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; -import electrosphere.entity.EntityUtils; import electrosphere.entity.state.attach.AttachUtils; import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.state.inventory.InventoryUtils; @@ -144,7 +143,7 @@ public class EntityProtocol implements ClientProtocolTemplate { case DESTROY: { Entity entity = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID()); if(entity != null){ - EntityUtils.cleanUpEntity(entity); + ClientEntityUtils.destroyEntity(entity); } } break; diff --git a/src/main/java/electrosphere/net/server/protocol/InventoryProtocol.java b/src/main/java/electrosphere/net/server/protocol/InventoryProtocol.java index 509ac7fb..17f11c38 100644 --- a/src/main/java/electrosphere/net/server/protocol/InventoryProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/InventoryProtocol.java @@ -19,6 +19,8 @@ public class InventoryProtocol implements ServerProtocolTemplate