From e68e637a846ea61a4fb3db51d22326fe99d45cc3 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 13 May 2025 14:15:45 -0400 Subject: [PATCH] inventory data definition --- assets/Data/entity/creatures/editor.json | 4 +++- assets/Data/entity/creatures/human.json | 4 +++- assets/Data/entity/creatures/skeleton.json | 4 +++- docs/src/progress/renderertodo.md | 2 ++ .../data/common/CommonEntityType.java | 14 +++++++++++++ .../common/item/InventoryDescription.java | 21 +++++++++++++++++++ .../types/common/CommonEntityUtils.java | 21 ++++++++++++------- .../ServerHitboxResolutionCallback.java | 8 +++++-- 8 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 src/main/java/electrosphere/data/common/item/InventoryDescription.java diff --git a/assets/Data/entity/creatures/editor.json b/assets/Data/entity/creatures/editor.json index 4e805e50..26e0a940 100644 --- a/assets/Data/entity/creatures/editor.json +++ b/assets/Data/entity/creatures/editor.json @@ -7,7 +7,6 @@ "tokens" : [ "TARGETABLE", "CAN_EQUIP", - "INVENTORY", "OUTLINE", "PLAYABLE", "UNIT_CONTROLS", @@ -47,6 +46,9 @@ "primarySlot" : "handRight", "combinedSlot" : "handsCombined" }, + "inventoryData" : { + "naturalSize" : 10 + }, "attackMoves" : [], "healthSystem" : { "maxHealth" : 100, diff --git a/assets/Data/entity/creatures/human.json b/assets/Data/entity/creatures/human.json index 577b4b77..742b1495 100644 --- a/assets/Data/entity/creatures/human.json +++ b/assets/Data/entity/creatures/human.json @@ -74,11 +74,13 @@ "GRAVITY", "TARGETABLE", "CAN_EQUIP", - "INVENTORY", "OUTLINE", "PLAYABLE", "UNIT_CONTROLS" ], + "inventoryData" : { + "naturalSize" : 10 + }, "visualAttributes" : [ { "attributeId" : "TorsoHeight", diff --git a/assets/Data/entity/creatures/skeleton.json b/assets/Data/entity/creatures/skeleton.json index 89281c10..d4f8eaf7 100644 --- a/assets/Data/entity/creatures/skeleton.json +++ b/assets/Data/entity/creatures/skeleton.json @@ -61,11 +61,13 @@ "GRAVITY", "TARGETABLE", "CAN_EQUIP", - "INVENTORY", "OUTLINE", "PLAYABLE", "UNIT_CONTROLS" ], + "inventoryData" : { + "naturalSize" : 10 + }, "visualAttributes" : [ ], "movementSystems" : [ diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index fa9a242b..2e4ad962 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1744,6 +1744,8 @@ Crops replace loot pool on completion of growth Display name for all common entity data Enitity id collision validation Full-sized wheat plants spawn in forest now +Natural inventory size explicitly defined in data +Fix server life tree missing nullcheck diff --git a/src/main/java/electrosphere/data/common/CommonEntityType.java b/src/main/java/electrosphere/data/common/CommonEntityType.java index fb8dbccf..a8fdf88e 100644 --- a/src/main/java/electrosphere/data/common/CommonEntityType.java +++ b/src/main/java/electrosphere/data/common/CommonEntityType.java @@ -6,6 +6,7 @@ import electrosphere.data.collidable.CollidableTemplate; import electrosphere.data.collidable.HitboxData; import electrosphere.data.common.camera.CameraData; import electrosphere.data.common.interact.InteractionData; +import electrosphere.data.common.item.InventoryDescription; import electrosphere.data.common.item.SpawnItemDescription; import electrosphere.data.common.life.HealthSystem; import electrosphere.data.common.light.PointLightDescription; @@ -173,6 +174,11 @@ public class CommonEntityType { */ GrowthData growthData; + /** + * The data on the inventory of this entity + */ + InventoryDescription inventoryData; + /** * Gets the id for this creature type * @return The id @@ -453,5 +459,13 @@ public class CommonEntityType { return growthData; } + /** + * Gets the inventory data for this object + * @return The inventory data + */ + public InventoryDescription getInventoryData(){ + return inventoryData; + } + } diff --git a/src/main/java/electrosphere/data/common/item/InventoryDescription.java b/src/main/java/electrosphere/data/common/item/InventoryDescription.java new file mode 100644 index 00000000..6f5fabeb --- /dev/null +++ b/src/main/java/electrosphere/data/common/item/InventoryDescription.java @@ -0,0 +1,21 @@ +package electrosphere.data.common.item; + +/** + * Describes the inventory on an inventory + */ +public class InventoryDescription { + + /** + * The size of the natural inventory + */ + Integer naturalSize; + + /** + * Gets the size of the natural inventory + * @return The size of the natural inventory + */ + public Integer getNaturalSize(){ + return naturalSize; + } + +} diff --git a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java index 8955234c..7f0ed0c6 100644 --- a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java +++ b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java @@ -387,10 +387,6 @@ public class CommonEntityUtils { case "TARGETABLE": { Globals.clientScene.registerEntityToTag(entity, EntityTags.TARGETABLE); } break; - case "INVENTORY": - entity.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10)); - InventoryUtils.clientSetInventoryState(entity, ClientInventoryState.clientCreateInventoryState(entity)); - break; case "OUTLINE": { entity.putData(EntityDataStrings.DRAW_OUTLINE, true); } break; @@ -445,6 +441,12 @@ public class CommonEntityUtils { ClientLifeTree.attachTree(entity,rawType.getHealthSystem()); Globals.clientScene.registerEntityToTag(entity, EntityTags.LIFE_STATE); } + if(rawType.getInventoryData() != null){ + if(rawType.getInventoryData().getNaturalSize() != null){ + entity.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(rawType.getInventoryData().getNaturalSize())); + InventoryUtils.clientSetInventoryState(entity, ClientInventoryState.clientCreateInventoryState(entity)); + } + } return entity; } @@ -698,10 +700,6 @@ public class CommonEntityUtils { case "TARGETABLE": { ServerEntityTagUtils.attachTagToEntity(entity, EntityTags.TARGETABLE); } break; - case "INVENTORY": { - entity.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10)); - InventoryUtils.serverSetInventoryState(entity, ServerInventoryState.serverCreateInventoryState(entity)); - } break; case "OUTLINE": { entity.putData(EntityDataStrings.DRAW_OUTLINE, true); } break; @@ -762,6 +760,13 @@ public class CommonEntityUtils { ServerGrowthComponent.attachTree(entity, rawType.getGrowthData()); } + if(rawType.getInventoryData() != null){ + if(rawType.getInventoryData().getNaturalSize() != null){ + entity.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(rawType.getInventoryData().getNaturalSize())); + InventoryUtils.serverSetInventoryState(entity, ServerInventoryState.serverCreateInventoryState(entity)); + } + } + /// /// /// AI (This SHOULD only be applied on the server with the way AI architected currently) diff --git a/src/main/java/electrosphere/server/physics/collision/ServerHitboxResolutionCallback.java b/src/main/java/electrosphere/server/physics/collision/ServerHitboxResolutionCallback.java index 3d5a1fc6..5a6c1bc4 100644 --- a/src/main/java/electrosphere/server/physics/collision/ServerHitboxResolutionCallback.java +++ b/src/main/java/electrosphere/server/physics/collision/ServerHitboxResolutionCallback.java @@ -166,11 +166,15 @@ public class ServerHitboxResolutionCallback implements CollisionResolutionCallba if(isItem){ if(hitboxAttachParent != receiverEntity){ ServerLifeTree serverLifeTree = ServerLifeTree.getServerLifeTree(receiverEntity); - serverLifeTree.addCollisionEvent(impactorEntity, impactorShapeStatus, receiverShapeStatus, worldPos, isDamageEvent, isBlockEvent); + if(serverLifeTree != null){ + serverLifeTree.addCollisionEvent(impactorEntity, impactorShapeStatus, receiverShapeStatus, worldPos, isDamageEvent, isBlockEvent); + } } } else if(isCreature){ ServerLifeTree serverLifeTree = ServerLifeTree.getServerLifeTree(receiverEntity); - serverLifeTree.addCollisionEvent(impactorEntity, impactorShapeStatus, receiverShapeStatus, worldPos, isDamageEvent, isBlockEvent); + if(serverLifeTree != null){ + serverLifeTree.addCollisionEvent(impactorEntity, impactorShapeStatus, receiverShapeStatus, worldPos, isDamageEvent, isBlockEvent); + } } //