crafting work
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
austin 2025-04-14 17:38:09 -04:00
parent ccc767618c
commit 7bc23c1c95
13 changed files with 115 additions and 16 deletions

View File

@ -75,7 +75,8 @@
},
"buttonInteraction" : {
"onInteract" : "menu",
"windowTarget" : "crafting"
"windowTarget" : "crafting",
"windowData" : "Workbench"
},
"spawnItem" : {
"graphicsTemplate" : {

View File

@ -2,6 +2,7 @@
"recipes": [
{
"displayName": "Workbench",
"craftingTag" : "HAND",
"ingredients": [
{
"itemType": "Log",
@ -17,6 +18,7 @@
}
],
"files": [
"Data/game/recipes/weapons.json"
"Data/game/recipes/weapons.json",
"Data/game/recipes/tools.json"
]
}

View File

@ -0,0 +1,27 @@
{
"recipes": [
{
"displayName": "Stone Axe",
"craftingTag" : "HAND",
"ingredients": [
{
"itemType": "Stick",
"count": 1
},
{
"itemType": "Rock",
"count": 1
}
],
"products": [
{
"itemType": "Stone Axe",
"count": 1
}
]
}
],
"files": [
]
}

View File

@ -2,6 +2,7 @@
"recipes": [
{
"displayName": "Katana (Two Hand)",
"craftingTag" : "DEBUG",
"ingredients": [
{
"itemType": "katana2H",
@ -17,6 +18,7 @@
},
{
"displayName": "Katana (One Hand)",
"craftingTag" : "DEBUG",
"ingredients": [
{
"itemType": "katana",

View File

@ -1473,6 +1473,8 @@ Voxel type work
Inventory sounds for some materials
Inventory audio work
Comment out script engine file watching for testing purposes
Crafting panel recipe filtering by tag
Stone Axe crafting

View File

@ -54,10 +54,11 @@ public class CraftingPanel {
/**
* Creates the crafting panel component
* @param craftingTag The tag to filter recipes by
* @param onCraft Called when an item is crafted
* @return The component
*/
public static Element createCraftingPanelComponent(Consumer<RecipeData> onCraft){
public static Element createCraftingPanelComponent(String craftingTag, Consumer<RecipeData> onCraft){
//top level element
Div rVal = Div.createCol();
@ -84,7 +85,10 @@ public class CraftingPanel {
//the scrollable containing the list of recipes to select
VirtualScrollable recipeScrollable = new VirtualScrollable(SCROLLABLE_WIDTH, SCROLLABLE_HEIGHT);
Globals.gameConfigCurrent.getRecipeMap().getTypes().forEach((RecipeData recipe) -> {
Globals.gameConfigCurrent.getRecipeMap().getTypes()
.stream()
.filter(recipe -> recipe.getCraftingTag().matches(craftingTag))
.forEach((RecipeData recipe) -> {
Button recipeButton = Button.createButton(recipe.getDisplayName(), () -> {
CraftingPanel.setDetails(rVal, recipeDetailsSection, recipe);
selectedRecipe = recipe;

View File

@ -282,11 +282,12 @@ public class WindowUtils {
/**
* Opens an interaction menu
* @param windowName The name of the window
* @param windowData The data for the window
*/
public static void openInteractionMenu(String windowName){
public static void openInteractionMenu(String windowName, String windowData){
switch(windowName){
case WindowStrings.CRAFTING: {
Window craftingWindow = CraftingWindow.createCraftingWindow();
Window craftingWindow = CraftingWindow.createCraftingWindow(windowData);
Globals.elementService.registerWindow(WindowStrings.CRAFTING, craftingWindow);
WindowUtils.recursiveSetVisible(Globals.elementService.getWindow(WindowStrings.CRAFTING), true);
Globals.elementService.focusFirstElement();

View File

@ -31,11 +31,16 @@ public class CraftingWindow {
*/
public static final int MIN_HEIGHT = 500;
/**
* The data for crafting with your hands
*/
public static final String HAND_CRAFTING_DATA = "HAND";
/**
* Creates a character customizer panel
* @return The panel component
*/
public static Window createCraftingWindow(){
public static Window createCraftingWindow(String data){
int width = MIN_WIDTH;
int height = MIN_HEIGHT;
@ -63,12 +68,22 @@ public class CraftingWindow {
//
//contents
//
rVal.addChild(CraftingPanel.createCraftingPanelComponent((RecipeData recipe) -> {
Globals.clientConnection.queueOutgoingMessage(InventoryMessage.constructclientRequestCraftMessage(
Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId()),
Globals.clientSceneWrapper.mapClientToServerId(Globals.interactionTarget.getId()),
recipe.getId()
));
rVal.addChild(CraftingPanel.createCraftingPanelComponent(
data,
(RecipeData recipe) -> {
if(Globals.interactionTarget != null){
Globals.clientConnection.queueOutgoingMessage(InventoryMessage.constructclientRequestCraftMessage(
Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId()),
Globals.clientSceneWrapper.mapClientToServerId(Globals.interactionTarget.getId()),
recipe.getId()
));
} else {
Globals.clientConnection.queueOutgoingMessage(InventoryMessage.constructclientRequestCraftMessage(
Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId()),
Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId()),
recipe.getId()
));
}
}));
//

View File

@ -15,6 +15,7 @@ import electrosphere.client.ui.components.NaturalInventoryPanel;
import electrosphere.client.ui.components.SpawnSelectionPanel;
import electrosphere.client.ui.components.VoxelSelectionPanel;
import electrosphere.client.ui.menu.WindowUtils;
import electrosphere.client.ui.menu.ingame.CraftingWindow;
import electrosphere.engine.Globals;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.entity.Entity;
@ -167,7 +168,9 @@ public class MenuGeneratorsUITesting {
}));
} break;
case "CraftingPanel": {
formEl.addChild(CraftingPanel.createCraftingPanelComponent((RecipeData recipe) -> {
formEl.addChild(CraftingPanel.createCraftingPanelComponent(
CraftingWindow.HAND_CRAFTING_DATA,
(RecipeData recipe) -> {
System.out.println("Craft " + recipe.getDisplayName());
}));
} break;

View File

@ -14,6 +14,7 @@ import electrosphere.client.interact.ItemActions;
import electrosphere.client.ui.components.PlayerInventoryWindow;
import electrosphere.client.ui.menu.WindowStrings;
import electrosphere.client.ui.menu.WindowUtils;
import electrosphere.client.ui.menu.ingame.CraftingWindow;
import electrosphere.client.ui.menu.ingame.MenuGeneratorsInGame;
import electrosphere.controls.Control;
import electrosphere.controls.Control.ControlMethod;
@ -621,7 +622,7 @@ public class ControlCategoryMainGame {
InteractionData interactionData = CommonEntityUtils.getCommonData(target).getButtonInteraction();
switch(interactionData.getOnInteract()){
case InteractionData.ON_INTERACT_MENU: {
WindowUtils.openInteractionMenu(interactionData.getWindowTarget());
WindowUtils.openInteractionMenu(interactionData.getWindowTarget(), interactionData.getWindowData());
} break;
case InteractionData.ON_INTERACT_HARVEST: {
int serverEntityId = Globals.clientSceneWrapper.mapClientToServerId(target.getId());
@ -735,7 +736,7 @@ public class ControlCategoryMainGame {
inventoryControlList.add(controlMap.get(OPEN_CRAFTING));
controlMap.get(OPEN_CRAFTING).setOnClick(new ControlMethod(){public void execute(MouseState mouseState){
Globals.interactionTarget = null;
WindowUtils.openInteractionMenu(WindowStrings.CRAFTING);
WindowUtils.openInteractionMenu(WindowStrings.CRAFTING, CraftingWindow.HAND_CRAFTING_DATA);
}});
controlMap.get(OPEN_CRAFTING).setRepeatTimeout(0.5f * Main.targetFrameRate);
}

View File

@ -27,6 +27,11 @@ public class InteractionData {
*/
String windowTarget;
/**
* The data to pass alongside the window
*/
String windowData;
/**
* The collidable shape used for ray casting to pick entities to interact with
*/
@ -56,4 +61,14 @@ public class InteractionData {
return interactionShape;
}
/**
* Gets the data to pass alongside the window
* @return the data to pass alongside the window
*/
public String getWindowData() {
return windowData;
}
}

View File

@ -16,6 +16,11 @@ public class RecipeData {
* The display name for the recipe
*/
String displayName;
/**
* The tag to determine when to display this recipe in the crafting menu
*/
String craftingTag;
/**
* The ingredients required for the recipe
@ -83,6 +88,24 @@ public class RecipeData {
return displayName;
}
/**
* Gets the crafting tag
* @return the crafting tag
*/
public String getCraftingTag() {
return craftingTag;
}
/**
* Sets the crafting tag
* @param craftingTag the crafting tag
*/
public void setCraftingTag(String craftingTag) {
this.craftingTag = craftingTag;
}

View File

@ -147,6 +147,9 @@ public class InventoryProtocol implements ServerProtocolTemplate<InventoryMessag
}
if(toolbarInventory != null){
for(Entity itemEnt : toolbarInventory.getItems()){
if(itemEnt == null){
continue;
}
if(itemMap.getItem(itemEnt).getId().matches(ingredient.getItemType())){
found++;
reagentList.add(itemEnt);