recipes in parent entities support
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-14 14:36:43 -04:00
parent c9691beaa9
commit 2f51269148
10 changed files with 81 additions and 35 deletions

View File

@ -85,6 +85,15 @@
"model": {
"path" : "Models/objects/furniture/workbench1.glb"
}
},
"recipe" : {
"craftingTag" : "HAND",
"ingredients": [
{
"itemType": "mat:Log",
"count": 1
}
]
}
},
"gridAlignedData" : {

View File

@ -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",

View File

@ -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

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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<RecipeIngredientData> 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<RecipeIngredientData>();
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

View File

@ -24,15 +24,6 @@ public class RecipeDataMap {
*/
Map<Integer,RecipeData> idRecipeMap = new HashMap<Integer,RecipeData>();
/**
* 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<RecipeData> parsedTypeList = recursiveReadRecipeLoader(filepath);
List<RecipeData> 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<RecipeData> typeList = recursiveReadRecipeLoader(initialPath);
List<RecipeData> 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);
}
}

View File

@ -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

View File

@ -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);
}
}
}
}