Skip to content

Commit a1e6a6e

Browse files
committed
refactor(gui): update ResearchTable and ResearchTree screens for improved UI flow and state synchronization
1 parent 46d138d commit a1e6a6e

7 files changed

Lines changed: 126 additions & 464 deletions

File tree

.github/copilot-instructions.md

Lines changed: 108 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Research is datapack-driven from `data/*/research/*.json` and loaded on server reload.
77
- Server-authoritative flow: UI click -> packet -> server validation -> timed completion -> recipe ID written to drive NBT.
88
- Implementation status: complete and playable (build, UI, networking, fluids, compat integrations, guidebook, advancements).
9+
- Key blocks: **Research Station** (research + unlock recipes), **Drive Crafting Table** (research-gated crafting), **Processing Station** (fluid + item processing).
910

1011
## Stack and key APIs
1112
- NeoForge `21.1.219`
@@ -21,6 +22,28 @@
2122
- Menu sync storage: `SimpleContainerData` must back `ContainerData`
2223
- Research Station tank: `FluidTank` capacity `8000` mB
2324

25+
## GUI Architecture
26+
- **ResearchTableScreen**: Main research station GUI with slot display, fluid tank, progress bar, and "View Research Tree" button.
27+
- View modes: `NORMAL` (see slots + controls) and `TREE` (research tree overlay).
28+
- Control buttons: Start/Cancel research, View Tree, Wipe Tank (when not researching).
29+
- **ResearchTreeScreen**: Displays available research nodes in a tree structure.
30+
- Shows prerequisites, tier, costs, completion status.
31+
- Click to select research; "Start Research" button navigates back with selection.
32+
- Control buttons: Back to table, Start Research (when valid research selected).
33+
- GUI packet flow: Client screen -> packet -> server handler -> block entity logic -> menu sync -> client screen update.
34+
35+
## Recipe Types
36+
Three distinct recipe systems:
37+
1. **`researchcube:drive_crafting`** — Drive Crafting Table recipes (research-locked)
38+
- Shaped: `pattern` (3-row string array) + `key` (char → item map) + `result`
39+
- Shapeless: `ingredients` (list) + `result`
40+
- **Always needs `recipe_id` field** matching `"researchcube:<filename>"`
41+
- Requires drive with matching `recipe_id` in NBT from research unlock
42+
2. **`researchcube:processing`** — Processing Station recipes (freely available unless in research pool)
43+
- Fields: `inputs`, `fluid_inputs`, `outputs`, `fluid_output` (optional), `duration`
44+
- **NO `recipe_id` field** — ID comes from filename
45+
3. **`minecraft:crafting_shaped` / `minecraft:crafting_shapeless`** — vanilla crafting (always available)
46+
2447
## Non-negotiable rules
2548
- Keep all registrations namespaced with `ResearchCubeMod.rl(...)` and mod id `researchcube`.
2649
- Use DeferredRegister in `registry/Mod*` classes and wire in `ResearchCubeMod`.
@@ -29,6 +52,7 @@
2952
- Drives are never consumed by drive crafting; `recipe_id` remains on drive.
3053
- Always log silent research validation failures in `tryStartResearch()` with `[ResearchCube] WARN` and reason.
3154
- For `ResearchTableMenu` sync, use writable `SimpleContainerData` storage; no-op `set()` breaks client state.
55+
- `textures/block/baum.txt` is an inside joke. **Never delete or modify it.**
3256

3357
## Slot and data sync contracts
3458
- Research Station slots:
@@ -119,35 +143,74 @@ Tier colors (`getColor()`):
119143
"result": { "id": "minecraft:iron_block", "count": 1 }
120144
}
121145
```
122-
- Drive with matching `recipe_id` is required and returned unchanged.
123-
- Supports shapeless ingredient list and shaped mode (`pattern` + `key`).
146+
- **CRITICAL**: Drive crafting recipes MUST have `recipe_id` field matching `"researchcube:<filename>"`
147+
- Drive with matching `recipe_id` in NBT is required and returned unchanged
148+
- Supports shapeless (ingredient list) and shaped mode (`pattern` + `key`)
149+
- Player must have completed research that includes this `recipe_id` in its `recipe_pool`
150+
151+
### Processing recipe (`data/{ns}/recipe/*.json`)
152+
```json
153+
{
154+
"type": "researchcube:processing",
155+
"inputs": [{ "item": "minecraft:iron_ingot", "count": 2 }],
156+
"fluid_inputs": [{ "fluid": "researchcube:thinking_fluid", "amount": 100 }],
157+
"outputs": [{ "item": "researchcube:research_chip", "count": 1 }],
158+
"duration": 200
159+
}
160+
```
161+
- **NO `recipe_id` field** — recipe ID comes from filename only
162+
- Most processing recipes are freely available (no research lock)
163+
- Some may be gated via research `recipe_pool` if needed
124164

125165
## Research fluids
126166
Registered fluids (source + flowing + bucket item, no placeable liquid block):
127-
- `researchcube:thinking_fluid` (cyan)
128-
- `researchcube:pondering_fluid` (purple)
129-
- `researchcube:reasoning_fluid` (gold)
130-
- `researchcube:imagination_fluid` (pink)
167+
- `researchcube:thinking_fluid` (cyan) — for UNSTABLE/BASIC tier research
168+
- `researchcube:pondering_fluid` (purple) — for ADVANCED tier research
169+
- `researchcube:reasoning_fluid` (gold) — for PRECISE/FLAWLESS tier research
170+
- `researchcube:imagination_fluid` (pink) — for SELF_AWARE tier research
131171

132172
Fluid behavior:
133173
- Bucket class: `ResearchFluidBucketItem` (`stacksTo(1)`, remainder `Items.BUCKET`).
134174
- Station fills from slot 8, outputs empty bucket to slot 9.
135175
- `WipeTankPacket` drains the tank.
136176
- Both Research Station and Processing Station expose `IFluidHandler` capability.
137177

178+
## Mod Items Reference
179+
- **Drives**: `metadata_unstable`, `metadata_reclaimed`, `metadata_enhanced`, `metadata_elaborate`, `metadata_cybernetic`, `metadata_self_aware`
180+
- **Cubes**: `cube_unstable`, `cube_basic`, `cube_advanced`, `cube_precise`, `cube_flawless`, `cube_self_aware`
181+
- **Blocks**: `research_station_item`, `drive_crafting_table`, `processing_station`
182+
- **Other**: `research_chip`, `research_book`, `*_fluid_bucket` (thinking/pondering/reasoning/imagination)
183+
138184
## Where to look first
185+
### Core Logic
139186
- `src/main/java/com/researchcube/ResearchCubeMod.java`
140187
- `src/main/java/com/researchcube/block/ResearchTableBlockEntity.java`
141188
- `src/main/java/com/researchcube/block/ResearchTableBlock.java`
142189
- `src/main/java/com/researchcube/menu/ResearchTableMenu.java`
143-
- `src/main/java/com/researchcube/client/screen/ResearchTableScreen.java`
144190
- `src/main/java/com/researchcube/research/ResearchManager.java`
145191
- `src/main/java/com/researchcube/research/ResearchSavedData.java`
192+
193+
### GUI and Screens
194+
- `src/main/java/com/researchcube/client/screen/ResearchTableScreen.java`
195+
- `src/main/java/com/researchcube/client/screen/ResearchTreeScreen.java`
196+
197+
### Recipes
146198
- `src/main/java/com/researchcube/recipe/DriveCraftingRecipe.java`
199+
- `src/main/java/com/researchcube/recipe/ProcessingRecipe.java`
200+
201+
### Networking
147202
- `src/main/java/com/researchcube/network/StartResearchPacket.java`
148203
- `src/main/java/com/researchcube/network/CancelResearchPacket.java`
149204
- `src/main/java/com/researchcube/network/WipeTankPacket.java`
205+
206+
### Registry and Fluids
150207
- `src/main/java/com/researchcube/registry/ModFluids.java`
208+
- `src/main/java/com/researchcube/registry/ModBlocks.java`
209+
- `src/main/java/com/researchcube/registry/ModItems.java`
210+
211+
### Data Files
212+
- Research definitions: `src/main/resources/data/researchcube/research/`
213+
- Recipe files: `src/main/resources/data/researchcube/recipe/`
151214

152215
## Build and validation
153216
- Build: `./gradlew.bat build`
@@ -171,3 +234,41 @@ Use Conventional Commits:
171234
- `[MAJOR]` and `[DANGER]` items require explicit user approval.
172235
- `[LOW PRIO]` items can be deferred.
173236
- If adding AI-created tasks, prefix with `[AI]`.
237+
238+
## Common Patterns
239+
### Accessing Drive/Cube NBT
240+
- Use `NbtUtil.getRecipeId(ItemStack)` to read drive recipe ID
241+
- Use `NbtUtil.setRecipeId(ItemStack, ResourceLocation)` to write drive recipe ID
242+
- Use `TierUtil.getCubeTier(ItemStack)` / `getDriveTier(ItemStack)` for tier checks
243+
244+
### Research Validation Flow
245+
1. Check drive tier matches research tier exactly
246+
2. Check cube tier >= research tier
247+
3. Verify prerequisites are completed (check saved data)
248+
4. Verify sufficient item costs in slots 2-7
249+
5. Verify sufficient fluid in tank (matches research fluid type)
250+
6. If any check fails, log warning and return false
251+
252+
### Menu Synchronization
253+
- Always use `SimpleContainerData` with writable backing storage
254+
- Update `containerData.set(index, value)` on server side
255+
- Client reads via `containerData.get(index)` in screen
256+
- Never use no-op storage that ignores `set()` calls
257+
258+
### Packet Handling
259+
- Packets arrive on network thread; always use `source.enqueueWork(() -> {...})`
260+
- Validate player permissions and world state before proceeding
261+
- Return `InteractionResult.SUCCESS` only after successful operation
262+
- Log failures for debugging
263+
264+
### Resource Location Handling
265+
- Use `ResearchCubeMod.rl("path")` for mod namespace
266+
- Recipe IDs must match research `recipe_pool` entries exactly
267+
- Research IDs come from filename (e.g., `basic_circuit.json``researchcube:basic_circuit`)
268+
269+
## Debug Tips
270+
- Research validation failures are logged as `[ResearchCube] WARN` with reason
271+
- Check server logs for packet handling issues
272+
- Use `/researchcube debug` commands to inspect saved data (if implemented)
273+
- Tank sync issues: verify `DATA_FLUID_AMOUNT` and `DATA_FLUID_TYPE` are updated
274+
- Drive not working: verify `recipe_id` exists in drive NBT and matches recipe file

0 commit comments

Comments
 (0)