Skip to content

Refactor to dynamic version detection, remove NMS modules and Wrapper classes#87

Merged
ptthanh02 merged 5 commits into
mainfrom
copilot/refactor-smartspawner-plugin
Oct 31, 2025
Merged

Refactor to dynamic version detection, remove NMS modules and Wrapper classes#87
ptthanh02 merged 5 commits into
mainfrom
copilot/refactor-smartspawner-plugin

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 31, 2025

Removes version-specific NMS modules (v1_21, v1_21_4, v1_21_6) and hard-coded material/entity mappings. Implements dynamic detection that adapts to any Minecraft 1.21+ version at runtime. Adds comprehensive player-configurable mob head textures via YAML.

Changes

New Dynamic Detection System

  • DynamicMaterialDetector - Auto-detects head/skull materials from Material.values() using stream filters
  • DynamicEntityValidator - Validates spawnable entities, excludes PLAYER
  • MobHeadConfig - Manages complete mob_heads.yml with 70+ mob textures

Removed Wrapper Classes

  • Deleted MaterialWrapper - Replaced with direct Material.valueOf() calls
  • Deleted TextureWrapper - Replaced with MobHeadConfig direct integration
  • Deleted ParticleWrapper - Replaced with direct Particle enum usage
  • Deleted SpawnerWrapper - Replaced with DynamicEntityValidator

Simplified Version Handling

  • VersionInitializer - Reduced from 126 to 25 lines, removed reflection-based initialization and wrapper calls
  • Deleted 12 initializer files across 3 NMS modules
  • Updated core/build.gradle and settings.gradle to remove module dependencies

Complete Mob Head Configuration

  • mob_heads.yml - Comprehensive configuration with all Minecraft mobs including:
    • Vanilla mob heads (ZOMBIE, SKELETON, CREEPER, etc.)
    • All custom player head textures (70+ mobs)
    • Version-specific mobs (ARMADILLO, BOGGED, BREEZE, CREAKING, etc.)
    • Texture hashes for direct use with textures.minecraft.net

Configuration Example

# mob_heads.yml - Complete configuration with all mobs
default_material: "SPAWNER"
mob_heads:
  ZOMBIE:
    material: "ZOMBIE_HEAD"
    custom_texture: null
  ENDERMAN:
    material: "PLAYER_HEAD"
    custom_texture: "4f24767c8138b3dfec02f77bd151994d480d4e869664ce09a26b19289212162b"
  BLAZE:
    material: "PLAYER_HEAD"
    custom_texture: "737623f79f7eb4f3f80da65b652cc44b2148eea41f9ffe2e86a23bdf49ab77b1"
  # ... 70+ total mobs configured

Impact

  • -19 files, +4 files (10 modified)
  • VersionInitializer complexity reduced 80%
  • All Wrapper classes removed - Cleaner architecture with direct API usage
  • No code changes required for future Minecraft versions
  • All public APIs unchanged, backward compatible
  • Configuration-driven texture system with complete mob coverage
Original prompt

Refactor the SmartSpawner plugin to remove version-specific modules and hard-coded materials, implementing a dynamic detection system with player-configurable mob head textures.

🎯 OBJECTIVES

1. Remove Deprecated Modules

  • Delete MaterialInitializer, ParticleInitializer, SpawnerInitializer, TextureInitializer
  • Remove NMS modules: v1_21, v1_21_4, v1_21_6
  • Keep VersionInitializer for future compatibility
  • Update core/build.gradle to remove deleted module references in jar task

2. Create Dynamic Material Detection System

File: core/src/main/java/com/example/smartspawner/util/DynamicMaterialDetector.java

/**
 * Dynamically detects valid materials for spawner GUI based on current Minecraft version.
 * Supports automatic detection of:
 * - Player heads
 * - Mob skulls/heads
 * - Spawner blocks
 */
public class DynamicMaterialDetector {
    private static final Set<Material> SPAWNER_INFO_MATERIALS;
    
    static {
        // Auto-detect all head/skull materials from current version
        SPAWNER_INFO_MATERIALS = Arrays.stream(Material.values())
            .filter(material -> {
                String name = material.name();
                return name.equals("PLAYER_HEAD") ||
                       name.equals("SPAWNER") ||
                       name.endsWith("_HEAD") ||
                       name.endsWith("_SKULL");
            })
            .filter(Material::isItem)
            .collect(Collectors.toUnmodifiableSet());
    }
    
    public static Set<Material> getSpawnerInfoMaterials() {
        return SPAWNER_INFO_MATERIALS;
    }
    
    public static boolean isValidSpawnerInfoMaterial(Material material) {
        return SPAWNER_INFO_MATERIALS.contains(material);
    }
}

3. Create Dynamic Entity Type Validator

File: core/src/main/java/com/example/smartspawner/util/DynamicEntityValidator.java

/**
 * Validates spawnable entity types across Minecraft versions. So it only load the availle entity in that version not newer entity in later version
 */
public class DynamicEntityValidator {
    private static final Set<EntityType> VALID_SPAWNABLE_ENTITIES;
    
    static {
        VALID_SPAWNABLE_ENTITIES = Arrays.stream(EntityType.values())
            .filter(type -> type != EntityType.PLAYER)
            .collect(Collectors.toUnmodifiableSet());
    }
    
    public static boolean isValidSpawnerEntity(EntityType type) {
        return VALID_SPAWNABLE_ENTITIES.contains(type);
    }
    
    public static Set<EntityType> getValidEntities() {
        return VALID_SPAWNABLE_ENTITIES;
    }
}

4. Player-Configurable Mob Head Textures

File: core/src/main/resources/mob_heads.yml

# SmartSpawner - Mob Head Texture Configuration
# Players can customize mob head textures for spawner GUI
# Supports both player heads and mob skulls

# Default material for unknown mobs
default_material: "SPAWNER"

# Custom mob head configurations
mob_heads:
  # Vanilla Minecraft Mobs
  ZOMBIE:
    material: "ZOMBIE_HEAD"
    custom_texture: null  # Use vanilla texture
    
  SKELETON:
    material: "SKELETON_SKULL"
    custom_texture: null
    
  CREEPER:
    material: "CREEPER_HEAD"
    custom_texture: null
    
  WITHER_SKELETON:
    material: "WITHER_SKELETON_SKULL"
    custom_texture: null
    
  PIGLIN:
    material: "PIGLIN_HEAD"
    custom_texture: null
    
  # Custom Player Head Textures (Base64 or texture URL)
  ENDERMAN:
    material: "PLAYER_HEAD"
    custom_texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTZjMGIzNmQ1M2ZmZjY5YTQ5YzdkNmY3MTg5YTg2MDMyZGQ0NzFjNjMyMTI0NGJlZDQ5NTc5ZTM1ZjA5YjUifX19"
    
  BLAZE:
    material: "PLAYER_HEAD"
    custom_texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjc4ZWYyZTRjZjU4MGU1OWI0Zjk1MzBhMDFlZDhiYjY0ZjlhNGQ1OTRhZTk3MjA2ODQyZDZhNzFmMmRjODAifX19"
    
  # Fallback for mobs without custom configuration

5. Update Gradle Build Configuration

File: core/build.gradle - Update jar task:

jar {
    archiveBaseName.set("SmartSpawner")
    archiveVersion.set("${version}")

    from { project(':api').sourceSets.main.output }
    // REMOVED: v1_21, v1_21_4, v1_21_6 modules
    from sourceSets.main.output
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
}

6. Update SpawnerMenuAction

Replace hard-coded SPAWNER_INFO_MATERIALS with dynamic detection:

public class SpawnerMenuAction implements Listener {
    private static final Set<Material> SPAWNER_INFO_MATERIALS =
        DynamicMaterialDetector.getSpawnerInfoMaterials();
    
    // Use MobHeadConfig for custom heads
    private final MobHeadConfig mobHeadConfig;
    
    // ...rest of implementation
}

✅ ACCEPTANCE CRITERIA

  1. ✅ All specified initializer classes removed
  2. ✅ NMS version modules deleted
    ...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits October 31, 2025 16:07
Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor SmartSpawner plugin to improve dynamic material detection Refactor to dynamic version detection, remove NMS modules Oct 31, 2025
Copilot AI requested a review from ptthanh02 October 31, 2025 16:16
@ptthanh02
Copy link
Copy Markdown
Contributor

@copilot remove ParticleWrapper, TextureWrapper (already have mob head config) , all the Wrapper. Also wirte a full mob head config file (mob_heads.yml) information can be found in the older commit

Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot remove ParticleWrapper, TextureWrapper (already have mob head config) , all the Wrapper. Also wirte a full mob head config file (mob_heads.yml) information can be found in the older commit

Done! I've removed all Wrapper classes (ParticleWrapper, TextureWrapper, MaterialWrapper, SpawnerWrapper) and expanded mob_heads.yml with complete texture information for all 70+ mobs from the old commits.

Changes in commit 1b817cf:

  • Deleted all 4 Wrapper classes
  • Expanded mob_heads.yml with all mob textures including ARMADILLO, BOGGED, BREEZE, CREAKING, etc.
  • Updated SpawnerMobHeadTexture to use MobHeadConfig directly
  • Replaced particle references with Particle.HAPPY_VILLAGER and Particle.WITCH
  • Updated material lookups to use Material.valueOf()
  • Updated entity list generation to use DynamicEntityValidator

The mob_heads.yml now contains the complete texture hash for each mob (not Base64 encoded) so it can be directly used with the textures.minecraft.net URL.

Copilot AI changed the title Refactor to dynamic version detection, remove NMS modules Refactor to dynamic version detection, remove NMS modules and Wrapper classes Oct 31, 2025
@ptthanh02 ptthanh02 marked this pull request as ready for review October 31, 2025 17:48
@ptthanh02 ptthanh02 merged commit d0313ad into main Oct 31, 2025
2 checks passed
@ptthanh02 ptthanh02 deleted the copilot/refactor-smartspawner-plugin branch October 31, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants