diff --git a/ROCAMOCHA_UNUSED_CODE_ANALYSIS.md b/ROCAMOCHA_UNUSED_CODE_ANALYSIS.md new file mode 100644 index 0000000..699c526 --- /dev/null +++ b/ROCAMOCHA_UNUSED_CODE_ANALYSIS.md @@ -0,0 +1,329 @@ +# MochaMix Rocamocha Code - Unused and Deprecated Analysis + +**Analysis Date:** November 15, 2024 +**Project:** MochaMix (rocamocha/MochaMix) +**Scope:** `rocamocha.*` domain code only (excluding third-party libraries) + +--- + +## Executive Summary + +This analysis identifies unused and deprecated code **specifically in the rocamocha domain** (the actual mod code), excluding bundled third-party libraries (rm_javazoom, org.rm_yaml). + +**Total Unused Code Found:** ~419 lines across 4 files + 2 methods + +**Key Findings:** +- 2 example/documentation classes in production source (347 lines) +- 1 unused adapter class (35 lines) +- 1 unused socket class (17 lines) +- 2 unused methods marked with `@SuppressWarnings("unused")` (~20 lines) + +**All other rocamocha code is actively used**, including: +- ✅ All plugin classes (19 plugins) +- ✅ All mixin accessors (LivingEntityAccess, PlayerEntityAccess, BossBarHudAccessor) +- ✅ All adapter classes (except DamageSourceAdapter) +- ✅ All socket classes (except BlockSocket) +- ✅ NativeAccess and supporting infrastructure + +--- + +## 1. Unused Example/Documentation Classes + +### 1.1 ZoneManagementExamples.java (178 lines) + +**Location:** `v1_21_1/src/main/java/rocamocha/mochamix/zones/ZoneManagementExamples.java` + +**Purpose:** Example usage code demonstrating zone management operations + +**Content:** +- Example methods showing zone creation, modification, queries +- Demonstrates spatial operations like overlap detection +- Shows cleanup and batch operations + +**Reason for Removal:** +- ❌ **0 references** in actual code (no imports or method calls) +- This is documentation/tutorial code, not production code +- Similar examples exist in `README.md` in the same directory +- Standard practice is to keep examples in documentation or test directories, not in main source + +**Impact:** None - purely documentation + +**Recommendation:** **MOVE OR REMOVE** +- **Option 1:** Move to `src/test/java` as integration test examples +- **Option 2:** Remove entirely and keep examples only in `README.md` +- **Option 3:** Move to a separate `examples/` directory in the project root + +--- + +### 1.2 ZoneUsageGuide.java (169 lines) + +**Location:** `v1_21_1/src/main/java/rocamocha/mochamix/zones/ZoneUsageGuide.java` + +**Purpose:** Simple usage guide showing common zone operation patterns + +**Content:** +- Quick start examples +- Point testing demonstrations +- Zone creation patterns + +**Reason for Removal:** +- ❌ **0 references** in actual code (no imports or method calls) +- Duplicate of examples in `ZoneManagementExamples.java` +- Content overlaps with `README.md` in the same directory +- Not following Java best practices (example code in production source) + +**Impact:** None - purely documentation + +**Recommendation:** **REMOVE** - Redundant with both `ZoneManagementExamples.java` and `README.md` + +--- + +## 2. Unused Adapter Classes + +### 2.1 DamageSourceAdapter.java (35 lines) + +**Location:** `v1_21_1/src/main/java/rocamocha/mochamix/impl/entity/adapter/DamageSourceAdapter.java` + +**Purpose:** Adapter for Minecraft DamageSource to MochaMix API + +**Content:** +```java +public class DamageSourceAdapter { + protected final DamageSource damageSource; + + public DamageSourceAdapter(DamageSource damageSource) { ... } + public DamageSource asNative() { ... } + public MinecraftEntity source() { ... } + public MinecraftEntity attacker() { ... } + public MinecraftVector3 position() { ... } +} +``` + +**Reason for Removal:** +- ❌ **0 imports** from active code +- ❌ **0 instantiations** (no `new DamageSourceAdapter`) +- There is a TODO comment in `LivingEntitySocket.java` suggesting future use: + ```java + // TODO: Refactor this to use the DamageSourceAdapter class for consistency and ease of maintenance? + ``` +- Currently, damage source information is accessed directly without this adapter + +**Impact:** None currently - this is planned infrastructure that was never adopted + +**Recommendation:** **EVALUATE** +- If the TODO will be addressed: Keep it +- If not planning to refactor: Remove it +- Consider whether the adapter pattern adds value for this use case + +--- + +## 3. Unused Socket Classes + +### 3.1 BlockSocket.java (17 lines) + +**Location:** `v1_21_1/src/main/java/rocamocha/mochamix/impl/block/BlockSocket.java` + +**Purpose:** Socket wrapper for Minecraft Block implementing MinecraftBlock interface + +**Content:** +```java +public class BlockSocket implements MinecraftBlock { + protected final Block b; + protected final IdentityAdapter identity; + + public BlockSocket(Block b) { + this.b = b; + this.identity = new IdentityAdapter(b); + } + + @Override public Block asNative() { return b; } +} +``` + +**Reason for Removal:** +- ❌ **0 imports** from active code +- ❌ **0 instantiations** (no `new BlockSocket`) +- Infrastructure class that was created but never used +- The `MinecraftBlock` interface exists and is used elsewhere, but this implementation is unused + +**Impact:** None - no code depends on this class + +**Recommendation:** **REMOVE** - Clean unused implementation + +--- + +## 4. Unused Methods + +### 4.1 Vector3Math.sqrt() (~10 lines) + +**Location:** `v1_21_1/src/main/java/rocamocha/mochamix/impl/vector3/Vector3Math.java:67` + +```java +@SuppressWarnings("unused") +private double sqrt(double value) { + if (value < 0) throw new IllegalArgumentException("Cannot compute square root of negative number"); + if (value == 0) return 0; + double x = value; + double y = (x + value / x) / 2; + while (Math.abs(y - x) > 1e-10) { + x = y; + y = (x + value / x) / 2; + } + return y; +} +``` + +**Reason for Removal:** +- Explicitly marked with `@SuppressWarnings("unused")` +- Comment: "Currently not used, but kept for potential future use" +- The class already uses `Math.sqrt()` in the `length()` method +- Custom implementation provides "better precision" but is never utilized + +**Impact:** None - standard `Math.sqrt()` is used instead + +**Recommendation:** **REMOVE** - Custom sqrt implementation is unnecessary; Java's `Math.sqrt()` is highly optimized and precise enough + +--- + +### 4.2 RMPlayer.normalizeSongFileName() (~10 lines) + +**Location:** `v1_21_1/src/main/java/rocamocha/reactivemusic/impl/audio/RMPlayer.java:82` + +```java +@SuppressWarnings("unused") +private static String normalizeSongFileName(String logicalId) { + if (logicalId == null || logicalId.isBlank()) return null; + String name = logicalId.replace('\\','/'); // windows-safe + if (!name.contains("/")) name = "music/" + name; + if (!name.endsWith(".mp3")) name = name + ".mp3"; + return name; +} +``` + +**Reason for Removal:** +- Explicitly marked with `@SuppressWarnings("unused")` +- Comment says "included just in case we need it down the road" +- ❌ **0 calls** to this method anywhere in the codebase + +**Impact:** None currently + +**Recommendation:** **REMOVE OR USE** +- **Option 1:** Remove if not needed +- **Option 2:** Keep if this is planned for future song loading features +- The logic seems useful for normalizing song paths - consider using it if relevant + +--- + +## 5. Summary and Recommendations + +### Quick Stats + +| Category | Files | Lines | Status | +|----------|-------|-------|--------| +| Example/Guide Classes | 2 | 347 | ❌ Remove/Move | +| Unused Adapters | 1 | 35 | ⚠️ Evaluate | +| Unused Sockets | 1 | 17 | ❌ Remove | +| Unused Methods | 2 | ~20 | ❌ Remove | +| **Total** | **4 files + 2 methods** | **~419** | | + +### Immediate Removals (High Confidence) + +1. **ZoneUsageGuide.java** (169 lines) - Redundant documentation +2. **BlockSocket.java** (17 lines) - Unused infrastructure +3. **Vector3Math.sqrt()** method (~10 lines) - Unused custom implementation + +**Total Immediate Savings:** ~196 lines of code + +### Conditional Removals (Requires Assessment) + +1. **ZoneManagementExamples.java** (178 lines) - Move to tests or remove +2. **DamageSourceAdapter.java** (35 lines) - Check if TODO will be addressed +3. **RMPlayer.normalizeSongFileName()** (~10 lines) - Decide if keeping for future use + +**Potential Additional Savings:** ~223 lines of code + +### Keep (Actively Used) + +All other rocamocha code is actively used: + +- ✅ **All 19 plugin classes** - Core functionality +- ✅ **All mixin accessors** - Used for accessing private Minecraft fields + - LivingEntityAccess (3 usages) + - PlayerEntityAccess (7 usages) + - BossBarHudAccessor (1 usage) +- ✅ **All adapter classes** (except DamageSourceAdapter) - Used for abstraction +- ✅ **All socket classes** (except BlockSocket) - Used for API implementation +- ✅ **NativeAccess** - Used by 7 API classes +- ✅ **Vector3Math** - Used 18 times (add, subtract, length, offset methods all used) +- ✅ **Zone management classes** - ZoneData, ZoneDataManager, ZoneUtils, ZoneFactory all actively used + +--- + +## 6. Comparison with Previous Analysis + +**Previous Analysis (included third-party libraries):** +- Total: ~2,500 lines across 22 files +- Included rm_javazoom (converter, player classes) +- Included SnakeYAML library files + +**This Analysis (rocamocha code only):** +- Total: ~419 lines across 4 files + 2 methods +- Focus on actual mod code +- Excludes bundled dependencies (which are kept for MP3 playback and YAML parsing) + +**Key Difference:** The previous analysis focused heavily on third-party bundled code. This analysis shows that the actual rocamocha mod code is **very clean** with minimal unused code - mostly just example/documentation classes that should be relocated. + +--- + +## 7. Action Plan + +### Phase 1: Safe Removals (15 minutes, Low Risk) + +```bash +# Remove redundant example file +rm projects/mochamix/v1_21_1/src/main/java/rocamocha/mochamix/zones/ZoneUsageGuide.java + +# Remove unused socket +rm projects/mochamix/v1_21_1/src/main/java/rocamocha/mochamix/impl/block/BlockSocket.java + +# Remove Vector3Math.sqrt() method (manual edit) +# Edit: projects/mochamix/v1_21_1/src/main/java/rocamocha/mochamix/impl/vector3/Vector3Math.java +# Remove lines 62-77 (the sqrt method) +``` + +**Result:** ~196 lines removed safely + +### Phase 2: Evaluation (30 minutes) + +1. **Decide on ZoneManagementExamples.java** + - If keeping: Move to `src/test/java` as integration tests + - If removing: Delete file + +2. **Decide on DamageSourceAdapter.java** + - Review the TODO in `LivingEntitySocket.java` + - If refactoring will happen: Keep it + - If not: Remove it + +3. **Decide on normalizeSongFileName()** + - If song path normalization is planned: Keep and use it + - If not needed: Remove it + +### Phase 3: Testing + +After removals: +1. Run the mod to ensure no runtime issues +2. Test zone management functionality +3. Test music playback +4. Verify no compilation errors + +--- + +## Conclusion + +The rocamocha codebase is **very clean** with only ~419 lines of unused code out of 133 total Java files. The unused code consists primarily of: + +1. **Documentation/example classes** (347 lines) - Should be moved to tests or docs +2. **Incomplete infrastructure** (52 lines) - Started but never adopted +3. **Utility methods kept "just in case"** (~20 lines) - Can be removed + +**Bottom Line:** This is a well-maintained codebase with minimal technical debt in the actual mod code. The previous analysis identified significant unused code in bundled third-party libraries, but those are kept for necessary functionality (MP3 playback, YAML parsing). diff --git a/ROCAMOCHA_UNUSED_SUMMARY.md b/ROCAMOCHA_UNUSED_SUMMARY.md new file mode 100644 index 0000000..0ae2399 --- /dev/null +++ b/ROCAMOCHA_UNUSED_SUMMARY.md @@ -0,0 +1,116 @@ +# Rocamocha Code - Unused Analysis Summary + +**Focus:** Actual mod code only (rocamocha.* domain) +**Excluded:** Third-party libraries (rm_javazoom, org.rm_yaml) + +--- + +## 📊 Quick Stats + +- **Total Unused:** ~419 lines across 4 files + 2 methods +- **Safe to Remove:** ~196 lines (3 items) +- **Needs Evaluation:** ~223 lines (3 items) + +--- + +## ❌ Safe to Remove Immediately + +### 1. ZoneUsageGuide.java (169 lines) +**Path:** `v1_21_1/src/main/java/rocamocha/mochamix/zones/ZoneUsageGuide.java` + +- Example/documentation code in production source +- Redundant with ZoneManagementExamples.java and README.md +- 0 references in code + +### 2. BlockSocket.java (17 lines) +**Path:** `v1_21_1/src/main/java/rocamocha/mochamix/impl/block/BlockSocket.java` + +- Unused socket implementation +- 0 imports, 0 instantiations +- Infrastructure that was never adopted + +### 3. Vector3Math.sqrt() (~10 lines) +**Path:** `v1_21_1/src/main/java/rocamocha/mochamix/impl/vector3/Vector3Math.java:67` + +- Custom square root implementation marked `@SuppressWarnings("unused")` +- Code uses standard `Math.sqrt()` instead +- 0 calls to this method + +--- + +## ⚠️ Evaluate Before Removing + +### 4. ZoneManagementExamples.java (178 lines) +**Path:** `v1_21_1/src/main/java/rocamocha/mochamix/zones/ZoneManagementExamples.java` + +- Example/documentation code in production source +- 0 references but contains useful examples +- **Recommendation:** Move to `src/test/java` as integration tests + +### 5. DamageSourceAdapter.java (35 lines) +**Path:** `v1_21_1/src/main/java/rocamocha/mochamix/impl/entity/adapter/DamageSourceAdapter.java` + +- Adapter for damage sources +- 0 imports, 0 instantiations +- Has TODO comment suggesting future use in `LivingEntitySocket.java` +- **Recommendation:** Keep if TODO will be addressed, otherwise remove + +### 6. RMPlayer.normalizeSongFileName() (~10 lines) +**Path:** `v1_21_1/src/main/java/rocamocha/reactivemusic/impl/audio/RMPlayer.java:82` + +- Song filename normalizer marked `@SuppressWarnings("unused")` +- Comment: "included just in case we need it down the road" +- 0 calls to this method +- **Recommendation:** Remove unless song path normalization is planned + +--- + +## ✅ Everything Else is Used + +The rocamocha codebase is **very clean**. All other code is actively used: + +- ✅ All 19 plugin classes +- ✅ All mixin accessors (LivingEntityAccess, PlayerEntityAccess, BossBarHudAccessor) +- ✅ All adapter classes (except DamageSourceAdapter) +- ✅ All socket classes (except BlockSocket) +- ✅ NativeAccess (7 usages) +- ✅ Vector3Math (18 usages, all methods except sqrt) +- ✅ Zone management (ZoneData, ZoneDataManager, ZoneUtils, ZoneFactory) + +--- + +## 🎯 Quick Action Plan + +### Immediate (15 min) +```bash +rm v1_21_1/src/main/java/rocamocha/mochamix/zones/ZoneUsageGuide.java +rm v1_21_1/src/main/java/rocamocha/mochamix/impl/block/BlockSocket.java +# Edit Vector3Math.java to remove sqrt() method (lines 62-77) +``` + +### Short-term (30 min) +1. Decide: Move or remove ZoneManagementExamples.java +2. Check if DamageSourceAdapter TODO will be addressed +3. Assess if normalizeSongFileName() is needed + +--- + +## 📝 Key Findings + +1. **Rocamocha code is well-maintained** - Only ~419 lines of unused code out of 133 Java files +2. **Most unused code is documentation** - Example classes that should be in tests +3. **Very little abandoned infrastructure** - Just 2 small classes that were never adopted +4. **Previous analysis was misleading** - ~2,500 lines of "unused" code was mostly third-party libraries (which ARE used, just not all parts) + +--- + +## Comparison + +| Category | This Analysis | Previous Analysis | +|----------|---------------|-------------------| +| Scope | Rocamocha code only | All code including libraries | +| Total Unused | ~419 lines | ~2,500 lines | +| Files | 4 files + 2 methods | 22 files + methods | +| Focus | Actual mod code | Included rm_javazoom, SnakeYAML | + +**Conclusion:** The actual mod code is very clean. The bulk of unused code identified previously was in bundled third-party dependencies, which are kept for functionality (MP3 playback, YAML parsing). diff --git a/gradle.properties b/gradle.properties index 26722e3..32e437d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ modmenu_version=15.0.0 yacl_version=3.8.0+1.21.6-fabric -org.gradle.java.home=C:\\Program Files\\Java\\jdk-21 +# org.gradle.java.home=C:\\Program Files\\Java\\jdk-21 # MochaMix Project Context Configuration # Set the active project and adapter for IDE context