p1ut0nium-git / Rough-Mobs-Revamped

Rough Mobs Revamped for Minecraft
https://www.curseforge.com/minecraft/mc-mods/rough-mobs-revamped
4 stars 8 forks source link

[Feature Request] randomly set complete armor set #8

Closed 0xebjc closed 4 years ago

0xebjc commented 4 years ago

Something that would be nice to have, even if the probability is set low for armor prices it would be nice if this random change might set a complete armor set, so entities don't always have just one or two pieces, and the only way for them to get a complete set is set it so pretty much ever spawn has most or all sets of armor. Here's the code I came up with to make this work:

In EquipHelper just above 'public void equipEntity:

        public boolean getChance(int chanceDenominator) {
            if (chanceDenominator <= 0) {
                return false;
            }
            return Math.random() <= (float)1/(float)chanceDenominator;
        }

And then in the equipEntity function:

            // If chance passes, then equip entity with complete set of armor
            boolean completeArmorSet = getChance(chancePerPiece);

            for (int i = 0; i < pools.length; i++) 
            {
                EquipmentPool pool = pools[i];
                EntityEquipmentSlot slot = EntityEquipmentSlot.values()[i];

                int rnd = i <= 1 ? chancePerWeapon : chancePerPiece;
                if (getChance(rnd) || (completeArmorSet && i > 1))
                {
                    ItemStack stack = pool.getRandom(entity, enchChance, enchMultiplier);

                    if (stack != null) 
                    {
                        entity.setItemStackToSlot(slot, stack);
                        entity.setDropChance(slot, dropChance);
                    }
                }
            }
p1ut0nium-git commented 4 years ago

Nice. Great idea. I'll add it when I get a chance, and credit it to you.

p1ut0nium-git commented 4 years ago

Added in 2.2.9