All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.magistuarmory.util.MobEquipment Maven / Gradle / Ivy

There is a newer version: 8.10
Show newest version
package com.magistuarmory.util;

import com.magistuarmory.EpicKnights;
import com.magistuarmory.config.MobEquipmentConfig;
import net.minecraft.class_1299;
import net.minecraft.class_1304;
import net.minecraft.class_1309;
import net.minecraft.class_1738;
import net.minecraft.class_1792;
import net.minecraft.class_1819;
import net.minecraft.class_1937;
import net.minecraft.class_2960;
import net.minecraft.class_3218;
import net.minecraft.class_5321;
import net.minecraft.class_5819;
import net.minecraft.class_7923;
import net.minecraft.class_7924;
import net.minecraft.server.MinecraftServer;
import java.util.*;

public class MobEquipment
{
    public static final MobEquipmentConfig MOBS_EQUIPMENT_CONFIG = EpicKnights.CONFIG.mobEquipments;
    static Map, class_5321>, List> EQUIPMENTS = new HashMap<>();

    public List> entities = new ArrayList<>();
    
    public List> dimensions;
    
    public List helmets = new ArrayList<>();
    public List chestplates = new ArrayList<>();
    public List leggings = new ArrayList<>();
    public List boots = new ArrayList<>();
    
    public List weapons = new ArrayList<>();
    public List shields = new ArrayList<>();
    
    public double chance;

    @SuppressWarnings("unchecked")
    MobEquipment(MinecraftServer server, String[] ids)
    {
        List> dimensions = new ArrayList<>();
        this.chance = EpicKnights.GENERAL_CONFIG.equipChance;
        
        for (String id : ids)
        {
            class_2960 resloc = new class_2960(id);

            Optional> entityoptional = class_7923.field_41177.method_17966(resloc);
            if (entityoptional.isPresent())
            {
                try
                {
                    this.entities.add((class_1299) entityoptional.get());
                    continue;
                }
                catch (ClassCastException e)
                {
                    System.out.println("[Epic-Knights Mob Equipment] Non-living entity type \"" + id + "\" is not allowed");
                }
            }

            Optional itemoptional = class_7923.field_41178.method_17966(resloc);
            if (itemoptional.isPresent())
            {
                if (itemoptional.get() instanceof class_1738 armor)
                {
                    switch (armor.method_48398().method_48399())
                    {
                        case field_6169 -> this.helmets.add(armor);
                        case field_6174 -> this.chestplates.add(armor);
                        case field_6172 -> this.leggings.add(armor);
                        case field_6166 -> this.boots.add(armor);
                    }
                    continue;
                }
                if (itemoptional.get() instanceof class_1819 shield)
                {
                    this.shields.add(shield);
                    continue;
                }
                this.weapons.add(itemoptional.get());
                continue;
            }

            class_5321 resourcekey = class_5321.method_29179(class_7924.field_41223, resloc);
            class_3218 serverlevel = server.method_3847(resourcekey);
            if (serverlevel != null)
            {
                dimensions.add(serverlevel.method_27983());
                continue;
            }

            if (id.matches("[-+]?[0-9]*\\.?[0-9]+"))
            {
                this.chance = Double.parseDouble(id);
                continue;
            }
        }
        
        if (dimensions.size() == 0)
            server.method_3738().forEach(serverlevel -> dimensions.add(serverlevel.method_27983()));
        this.dimensions = dimensions;
    }

    public void equip(class_1309 entity, class_5819 rand)
    {
        MobEquipmentHelper.setRandomItemSlot(entity, class_1304.field_6169, this.helmets, this.chance, rand);
        MobEquipmentHelper.setRandomItemSlot(entity, class_1304.field_6174, this.chestplates, this.chance, rand);
        MobEquipmentHelper.setRandomItemSlot(entity, class_1304.field_6172, this.leggings, this.chance, rand);
        MobEquipmentHelper.setRandomItemSlot(entity, class_1304.field_6166, this.boots, this.chance, rand);
        MobEquipmentHelper.setRandomItemSlot(entity, class_1304.field_6173, this.weapons, this.chance, rand);
        MobEquipmentHelper.setRandomItemSlot(entity, class_1304.field_6171, this.shields, 0.5f * chance, rand);
    }
    
    public static void setup(MinecraftServer server)
    {
        for (String ids : MOBS_EQUIPMENT_CONFIG.equipments)
        {
            MobEquipment equipment = new MobEquipment(server, ids.split(" "));
            equipment.entities.forEach(type -> equipment.dimensions.forEach(dimension -> {
                DualKey, class_5321> key = new DualKey<>(type, dimension);
                EQUIPMENTS.putIfAbsent(key, new ArrayList<>());
                EQUIPMENTS.get(key).add(equipment);
            }));
        }
    }
    
    public static List get(class_1309 entity)
    {
        return EQUIPMENTS.getOrDefault(new DualKey<>(entity.method_5864(), entity.method_37908().method_27983()), new ArrayList<>());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy