diff --git a/assets/Data/entity/objects/furniture.json b/assets/Data/entity/objects/furniture.json index b172d2d9..35489fc6 100644 --- a/assets/Data/entity/objects/furniture.json +++ b/assets/Data/entity/objects/furniture.json @@ -85,6 +85,15 @@ "model": { "path" : "Models/objects/furniture/workbench1.glb" } + }, + "recipe" : { + "craftingTag" : "HAND", + "ingredients": [ + { + "itemType": "mat:Log", + "count": 1 + } + ] } }, "gridAlignedData" : { diff --git a/assets/Data/game/recipes.json b/assets/Data/game/recipes.json index ecd0979d..44b60097 100644 --- a/assets/Data/game/recipes.json +++ b/assets/Data/game/recipes.json @@ -1,21 +1,5 @@ { "recipes": [ - { - "displayName": "Workbench", - "craftingTag" : "HAND", - "ingredients": [ - { - "itemType": "mat:Log", - "count": 1 - } - ], - "products": [ - { - "itemType": "Workbench", - "count": 1 - } - ] - } ], "files": [ "Data/game/recipes/weapons.json", diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 02a0d247..c1a79913 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1768,6 +1768,7 @@ Fix styling for inventory panel ui element Fix content serialization bug with attached items Fix playing audio without item defined in natural inventory panel Fix window framebuffer scrunching bug +Recipes for spawn items defined in parent entity diff --git a/src/main/java/electrosphere/client/interact/ItemActions.java b/src/main/java/electrosphere/client/interact/ItemActions.java index 1a50baa8..8500a8f0 100644 --- a/src/main/java/electrosphere/client/interact/ItemActions.java +++ b/src/main/java/electrosphere/client/interact/ItemActions.java @@ -84,7 +84,7 @@ public class ItemActions { BlockEditing.destroyBlock(); Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.INTERACT_SFX_BLOCK_PLACE, VirtualAudioSourceType.CREATURE, false); } - if(data.getPrimaryUsage().getSuppressServerRequest()){ + if(data.getPrimaryUsage().getSuppressServerRequest() != null && data.getPrimaryUsage().getSuppressServerRequest() == true){ sendServerMessage = false; } } @@ -185,7 +185,7 @@ public class ItemActions { BlockEditing.editBlock((short)(int)data.getSecondaryUsage().getBlockId(),(short)0); Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.INTERACT_SFX_BLOCK_PLACE, VirtualAudioSourceType.CREATURE, false); } - if(data.getSecondaryUsage().getSuppressServerRequest() != null){ + if(data.getSecondaryUsage().getSuppressServerRequest() != null && data.getSecondaryUsage().getSuppressServerRequest() == true){ sendServerMessage = false; } } @@ -233,7 +233,7 @@ public class ItemActions { if(data.getSecondaryUsage().getClientHook() != null){ ClientScriptUtils.fireSignal(data.getSecondaryUsage().getClientHook()); } - if(data.getSecondaryUsage().getSuppressServerRequest()){ + if(data.getSecondaryUsage().getSuppressServerRequest() != null && data.getSecondaryUsage().getSuppressServerRequest() == true){ sendServerMessage = false; } } diff --git a/src/main/java/electrosphere/data/Config.java b/src/main/java/electrosphere/data/Config.java index 8d4d5353..2407f002 100644 --- a/src/main/java/electrosphere/data/Config.java +++ b/src/main/java/electrosphere/data/Config.java @@ -127,7 +127,7 @@ public class Config { config.structureData = StructureDataLoader.loadStructureFiles("Data/game/structure.json"); //create procedural item types - ItemDataMap.loadSpawnItems(config.itemMap, config.objectTypeLoader); + ItemDataMap.loadSpawnItems(config.itemMap, config.recipeMap, config.objectTypeLoader); ItemDataMap.generateBlockItems(config.itemMap, config.blockData); ItemDataMap.generateVoxelItems(config.itemMap, config.voxelData); diff --git a/src/main/java/electrosphere/data/common/item/SpawnItemDescription.java b/src/main/java/electrosphere/data/common/item/SpawnItemDescription.java index 23a34a5c..749a1655 100644 --- a/src/main/java/electrosphere/data/common/item/SpawnItemDescription.java +++ b/src/main/java/electrosphere/data/common/item/SpawnItemDescription.java @@ -1,5 +1,6 @@ package electrosphere.data.common.item; +import electrosphere.data.crafting.RecipeData; import electrosphere.data.graphics.GraphicsTemplate; /** @@ -17,6 +18,11 @@ public class SpawnItemDescription { */ GraphicsTemplate graphicsTemplate; + /** + * The recipe to create the spawn item + */ + RecipeData recipe; + /** * Gets the item icon for this spawn item * @return The item icon @@ -33,6 +39,13 @@ public class SpawnItemDescription { return graphicsTemplate; } + /** + * Gets the recipe data + * @return The recipe data + */ + public RecipeData getRecipeData(){ + return recipe; + } } diff --git a/src/main/java/electrosphere/data/crafting/RecipeData.java b/src/main/java/electrosphere/data/crafting/RecipeData.java index 945f6f1f..39d5cbe2 100644 --- a/src/main/java/electrosphere/data/crafting/RecipeData.java +++ b/src/main/java/electrosphere/data/crafting/RecipeData.java @@ -1,7 +1,10 @@ package electrosphere.data.crafting; +import java.util.LinkedList; import java.util.List; +import electrosphere.data.item.Item; + /** * Data on a crafting recipe */ @@ -32,6 +35,26 @@ public class RecipeData { */ List products; + /** + * Creates a spawn item recipe from an existing recipe and the spawn item definition + * @param existingRecipe The existing recipe + * @param spawnItem The spawn item definition + * @param count The number of the spawn item to create + * @return The spawn item recipe + */ + public static RecipeData createSpawnItemRecipe(RecipeData existingRecipe, Item spawnItem, int count){ + RecipeData rVal = new RecipeData(); + rVal.displayName = spawnItem.getDisplayName(); + rVal.craftingTag = existingRecipe.craftingTag; + rVal.ingredients = existingRecipe.ingredients; + rVal.products = new LinkedList(); + if(existingRecipe.products != null){ + rVal.products.addAll(existingRecipe.products); + } + rVal.products.add(new RecipeIngredientData(spawnItem.getId(),count)); + return rVal; + } + /** * Gets the ingredients required for the recipe * @return The ingredients required for the recipe diff --git a/src/main/java/electrosphere/data/crafting/RecipeDataMap.java b/src/main/java/electrosphere/data/crafting/RecipeDataMap.java index fc7e09c6..501fd6a9 100644 --- a/src/main/java/electrosphere/data/crafting/RecipeDataMap.java +++ b/src/main/java/electrosphere/data/crafting/RecipeDataMap.java @@ -24,15 +24,6 @@ public class RecipeDataMap { */ Map idRecipeMap = new HashMap(); - /** - * Adds recipe data to the loader - * @param name The id of the recipe - * @param type The recipe data - */ - public void putType(int id, RecipeData type){ - idRecipeMap.put(id,type); - } - /** * Gets recipe data from the id of the recipe * @param id The id of the recipe @@ -69,12 +60,10 @@ public class RecipeDataMap { //push the types from this file for(RecipeData type : loaderFile.getRecipes()){ typeList.add(type); - type.setId(idIncrementer); - idIncrementer++; } //push types from any other files for(String filepath : loaderFile.getFiles()){ - List parsedTypeList = recursiveReadRecipeLoader(filepath); + List parsedTypeList = RecipeDataMap.recursiveReadRecipeLoader(filepath); for(RecipeData type : parsedTypeList){ typeList.add(type); } @@ -89,11 +78,21 @@ public class RecipeDataMap { */ public static RecipeDataMap loadRecipeFiles(String initialPath) { RecipeDataMap rVal = new RecipeDataMap(); - List typeList = recursiveReadRecipeLoader(initialPath); + List typeList = RecipeDataMap.recursiveReadRecipeLoader(initialPath); for(RecipeData type : typeList){ - rVal.putType(type.getId(), type); + rVal.registerRecipe(type); } return rVal; } + /** + * Registers a recipe + * @param data The recipe + */ + public void registerRecipe(RecipeData data){ + data.setId(idIncrementer); + idIncrementer++; + idRecipeMap.put(data.getId(),data); + } + } diff --git a/src/main/java/electrosphere/data/crafting/RecipeIngredientData.java b/src/main/java/electrosphere/data/crafting/RecipeIngredientData.java index 73415d62..35ee8701 100644 --- a/src/main/java/electrosphere/data/crafting/RecipeIngredientData.java +++ b/src/main/java/electrosphere/data/crafting/RecipeIngredientData.java @@ -15,6 +15,16 @@ public class RecipeIngredientData { */ int count; + /** + * Creates a recipe ingredient definition + * @param type The type of item + * @param count The count of that item + */ + public RecipeIngredientData(String type, int count){ + this.itemType = type; + this.count = count; + } + /** * Gets the type of item for the recipe * @return The type of item for the recipe diff --git a/src/main/java/electrosphere/data/item/ItemDataMap.java b/src/main/java/electrosphere/data/item/ItemDataMap.java index 1ffbb3e9..cdd13f9a 100644 --- a/src/main/java/electrosphere/data/item/ItemDataMap.java +++ b/src/main/java/electrosphere/data/item/ItemDataMap.java @@ -11,6 +11,8 @@ import electrosphere.data.block.BlockData; import electrosphere.data.block.BlockType; import electrosphere.data.common.CommonEntityMap; import electrosphere.data.common.CommonEntityType; +import electrosphere.data.crafting.RecipeData; +import electrosphere.data.crafting.RecipeDataMap; import electrosphere.data.voxel.VoxelData; import electrosphere.data.voxel.VoxelType; import electrosphere.entity.Entity; @@ -124,12 +126,17 @@ public class ItemDataMap { * @param itemDataMap The item data map * @param objectMap The object map that contains furniture */ - public static void loadSpawnItems(ItemDataMap itemDataMap, CommonEntityMap objectMap){ + public static void loadSpawnItems(ItemDataMap itemDataMap, RecipeDataMap recipeMap, CommonEntityMap objectMap){ for(CommonEntityType objectData : objectMap.getTypes()){ if(objectData.getSpawnItem() != null){ Item spawnItem = Item.createSpawnItem(objectData); //create spawn items itemDataMap.putType(spawnItem.getId(), spawnItem); + //add recipe if present + if(objectData.getSpawnItem().getRecipeData() != null){ + RecipeData recipeData = RecipeData.createSpawnItemRecipe(objectData.getSpawnItem().getRecipeData(), spawnItem, 1); + recipeMap.registerRecipe(recipeData); + } } } }