📄
pasted-code-1777610477486.txt
txt
137 lines
▶
Create a complete Minecraft mod (Fabric 1.21.4) named "PvPScenarioTrainer".
The mod should add a full PvP training system based on real combat scenarios.
=====================
CORE FEATURES
=====================
1. Scenario Practice System:
Create multiple PvP scenarios that players can select from a INVENTORY GUI:
- Low HP Clutch:
Player starts at 3 hearts vs full health bot.
- Combo Escape:
Player gets stuck in a combo and must escape using movement and timing.
- 1v2 Fight:
Player fights against two AI opponents.
- Edge Knockback Survival:
Player is near void/edge and must survive knockback attacks.
- No Armor Duel:
Pure aim + timing fight with no armor.
Each scenario must reset automatically after completion.
=====================
2. Smart AI Bots
=====================
- Bots must simulate real PvP behavior:
- Strafing left/right
- Sprint reset (W-tap)
- Randomized attack timing
- Jump hits
- Combo chaining
- Difficulty Levels:
EASY → slow reaction, low accuracy
NORMAL → realistic player behavior
HARD → fast combos, aggressive playstyle
=====================
3. INVENTORY GUI SYSTEM
=====================
- Add a custom INVENTORY GUI menu when player types:
/pvptrainer
Menu options:
- Select Scenario
- Select Difficulty
- Start Training
- View Stats
INVENTORY GUI should be clean and modern (use chest INVENTORY GUI or custom screen).
=====================
4. STAT TRACKING
=====================
Track and display after each session:
- Accuracy %
- Hits landed
- Hits missed
- Longest combo
- Damage taken vs dealt
- Survival time
Show results in a summary screen after each scenario.
=====================
5. FEEDBACK SYSTEM
=====================
After each match, display tips like:
- "You missed too many hits — improve aim"
- "Work on sprint reset timing"
- "You panic when low HP"
=====================
6. TRAINING LOOP
=====================
- Instant restart button
- No loading screens
- Smooth transitions between scenarios
=====================
7. COMMANDS
=====================
/pvptrainer → open menu
/pvp start
/pvp difficulty
=====================
8. PERFORMANCE
=====================
- Must be optimized (no lag)
- Use efficient tick handling
- Avoid unnecessary entity spam
=====================
9. CODE STRUCTURE
=====================
- Use clean architecture:
- ScenarioManager
- BotAIController
- GUIHandler
- StatsTracker
- Well-commented code
- Modular design for easy expansion
=====================
10. EXTRA FEATURES (OPTIONAL)
=====================
- Sound effects on combo
- Progress system (levels/ranks)
- Daily training challenges
=====================
OUTPUT REQUIREMENTS:
- Full working Fabric mod code
- Gradle setup included
- All classes separated properly
- No pseudo code — real working code only
I’ll read the required docs before writing any code.
Here is the complete implementation plan before writing any code:
Build files: Standard Fabric 1.21.4 Loom setup with split source sets
Core classes:
ScenarioManager(singleton, manages all active play),BotAIController(tick-based strafe/W-tap/jump AI),StatsTracker(event-driven hit/damage recording),GuiHandler+ 4 screen handler subclasses extendingGenericContainerScreenHandler(no super call inonSlotClick= no item movement, click routing instead)Bots: Vanilla
ZombieEntity— no custom entity type needed (zero renderer registration hassle); target is reset every tick to override vanilla targeting AI; strafe is lateral velocity, W-tap is sprint flicker, jump hit is manual Y velocityEvents used:
ServerTickEvents.END_SERVER_TICKfor bot AI ticks,ServerLivingEntityEvents.ALLOW_DAMAGE+ALLOW_DEATHfor stats and clean bot removal (no drops viadiscard())Edge Knockback: Temporary 5×5 stone platform built at Y=200 from chunks of air; restored on scenario end; extra knockback applied via manual velocity in damage callback
Now writing all files:
Now the complete mod is written. Here’s a summary of every system:
Architecture overview:
Class | Responsibility |
|---|---|
PvpTrainerMod | Registers events (damage, death, disconnect, tick) and initializes the singleton ScenarioManager |
ScenarioManager | Owns all session state; handles setup, per-tick logic, and teardown for every player |
BotAIController | Called once per bot per tick — drives lateral strafe velocity, W-tap sprint flicker, and upward jump-hit impulse |
ScenarioInstance | One active session — holds bots, platform blocks, snapshot, and stats |
PlayerSnapshot | Captures and fully restores player inventory/health/food/position/gamemode |
SessionStats | Hit/damage/combo accumulator; generateTip() produces contextual feedback |
BotState | Per-bot timer state (strafe direction, W-tap cooldown, jump cooldown) |
MainMenuHandler / ScenarioSelectHandler / DifficultySelectHandler / StatsDisplayHandler | Extend GenericContainerScreenHandler with onSlotClick overridden (no super call) — zero item movement, pure button routing |
GuiHandler | Static factory methods using SimpleNamedScreenHandlerFactory |
PvpCommand | Registers /pvptrainer and /pvp start <scenario> / /pvp difficulty <level> |
Bot AI behavior: Every tick, BotAIController forces bot.setTarget(player) (overriding vanilla targeting), adds a perpendicular XZ velocity component for strafing (direction flips every 0.75–2.25 s), suppresses sprinting for 3 ticks every N ticks (W-tap), and adds 0.42 Y velocity when within 3.5 blocks on the ground (jump hit). All magnitudes scale with Difficulty.
Bot death/drops: ALLOW_DEATH returns false for bots and calls entity.discard() — bots vanish silently with no item or XP drops.
Edge Knockback platform: A 5×5 stone floor is placed at Y=200 at the player’s XZ; 4 air layers above are cleared; all BlockPos are stored in ScenarioInstance.placedBlocks and restored (air) on scenario end. Extra 2.2× horizontal knockback is injected in ALLOW_DAMAGE for this scenario type.
package com.pvpscenariotrainer;
import net.fabricmc.api.ClientModInitializer;
/**
* Client-side initializer. No custom entity renderers are needed since the mod
* uses vanilla ZombieEntity for bots, which are already registered on the client.
*/
public class PvpTrainerClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// No client-only registration required for this mod.
}
}