Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
2.1 kB
2
Indexable
Never
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.item.ItemStack;
import crafttweaker.api.data.MapData;
import crafttweaker.api.data.ListData;
import crafttweaker.api.event.CTEventManager;
import crafttweaker.api.event.ItemCraftedEvent;

// Define the possible affixes and their ranges
val affixes as string[] = [
    "apotheosis:attack_damage",
    "apotheosis:attack_speed",
    "apotheosis:reach_distance",
    "apotheosis:crit_chance",
    "apotheosis:crit_damage",
    "apotheosis:life_steal"
];

val minValues as double[] = [0.5, 0.1, 0.5, 0.05, 0.1, 0.01];
val maxValues as double[] = [5.0, 1.0, 2.0, 0.25, 0.5, 0.1];

// Function to generate random affixes
function generateRandomAffixes() as MapData {
    val affixData = new MapData();
    val affixList = new ListData();
    
    for i in 0 .. 3 { // Generate 3 random affixes
        val randomIndex = Math.floor(Math.random() * affixes.length) as int;
        val affix = affixes[randomIndex];
        val minValue = minValues[randomIndex];
        val maxValue = maxValues[randomIndex];
        val randomValue = minValue + (Math.random() * (maxValue - minValue));
        
        val affixEntry = new MapData();
        affixEntry.put("id", affix);
        affixEntry.put("value", randomValue);
        affixList.add(affixEntry);
    }
    
    affixData.put("affixes", affixList);
    return affixData;
}

// Event listener for item crafting
CTEventManager.register<ItemCraftedEvent>((event) => {
    val player = event.player;
    val output = event.crafting;
    
    // Check if the crafted item is a diamond sword
    if (output.registryName == <item:minecraft:diamond_sword>.registryName) {
        // Generate random affixes
        val affixes = generateRandomAffixes();
        
        // Apply affixes to the item
        val newItem = output.withTag(affixes);
        
        // Replace the crafted item with the affixed version
        player.give(newItem);
        output.mutable().shrink(1);
    }
});
Leave a Comment