Search in sources :

Example 1 with ModuleData

use of mekanism.api.gear.ModuleData in project Mekanism by mekanism.

the class ModuleHelper method mapSupportedModules.

private void mapSupportedModules(String imcMethod, IItemProvider moduleContainer, Map<ModuleData<?>, ImmutableSet.Builder<Item>> supportedContainersBuilderMap) {
    ImmutableSet.Builder<ModuleData<?>> supportedModulesBuilder = ImmutableSet.builder();
    InterModComms.getMessages(Mekanism.MODID, imcMethod::equals).forEach(message -> {
        Object body = message.getMessageSupplier().get();
        if (body instanceof IModuleDataProvider) {
            IModuleDataProvider<?> moduleDataProvider = (IModuleDataProvider<?>) body;
            supportedModulesBuilder.add(moduleDataProvider.getModuleData());
            logDebugReceivedIMC(imcMethod, message.getSenderModId(), moduleDataProvider);
        } else if (body instanceof IModuleDataProvider[]) {
            for (IModuleDataProvider<?> moduleDataProvider : ((IModuleDataProvider<?>[]) body)) {
                supportedModulesBuilder.add(moduleDataProvider.getModuleData());
                logDebugReceivedIMC(imcMethod, message.getSenderModId(), moduleDataProvider);
            }
        } else {
            Mekanism.logger.warn("Received IMC message for '{}' from mod '{}' with an invalid body.", imcMethod, message.getSenderModId());
        }
    });
    Set<ModuleData<?>> supported = supportedModulesBuilder.build();
    if (!supported.isEmpty()) {
        Item item = moduleContainer.getItem();
        supportedModules.put(item, supported);
        for (ModuleData<?> data : supported) {
            supportedContainersBuilderMap.computeIfAbsent(data, d -> ImmutableSet.builder()).add(item);
        }
    }
}
Also used : MekanismAPI(mekanism.api.MekanismAPI) TextUtils(mekanism.common.util.text.TextUtils) OnOff(mekanism.common.util.text.BooleanStateDisplay.OnOff) Item(net.minecraft.item.Item) ICustomModule(mekanism.api.gear.ICustomModule) CompoundNBT(net.minecraft.nbt.CompoundNBT) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) ArrayList(java.util.ArrayList) ItemDataUtils(mekanism.common.util.ItemDataUtils) ITextComponent(net.minecraft.util.text.ITextComponent) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) MekanismItems(mekanism.common.registries.MekanismItems) InterModComms(net.minecraftforge.fml.InterModComms) Nullable(javax.annotation.Nullable) Mekanism(mekanism.common.Mekanism) IItemProvider(mekanism.api.providers.IItemProvider) ImmutableSet(com.google.common.collect.ImmutableSet) MethodsReturnNonnullByDefault(mcp.MethodsReturnNonnullByDefault) MekanismIMC(mekanism.api.MekanismIMC) IModule(mekanism.api.gear.IModule) Collection(java.util.Collection) Set(java.util.Set) ModuleData(mekanism.api.gear.ModuleData) IModuleHelper(mekanism.api.gear.IModuleHelper) ItemModule(mekanism.common.item.ItemModule) List(java.util.List) NBT(net.minecraftforge.common.util.Constants.NBT) IHUDElement(mekanism.api.gear.IHUDElement) HUDColor(mekanism.api.gear.IHUDElement.HUDColor) NBTConstants(mekanism.api.NBTConstants) ResourceLocation(net.minecraft.util.ResourceLocation) IModuleDataProvider(mekanism.api.providers.IModuleDataProvider) Collections(java.util.Collections) Item(net.minecraft.item.Item) ImmutableSet(com.google.common.collect.ImmutableSet) ModuleData(mekanism.api.gear.ModuleData) IModuleDataProvider(mekanism.api.providers.IModuleDataProvider)

Example 2 with ModuleData

use of mekanism.api.gear.ModuleData in project Mekanism by mekanism.

the class MekaSuitArmor method key.

public QuickHash key(LivingEntity player) {
    Object2BooleanMap<ModuleModelSpec> modules = new Object2BooleanOpenHashMap<>();
    Set<EquipmentSlotType> wornParts = EnumSet.noneOf(EquipmentSlotType.class);
    IModuleHelper moduleHelper = MekanismAPI.getModuleHelper();
    for (EquipmentSlotType slotType : EnumUtils.ARMOR_SLOTS) {
        ItemStack wornItem = player.getItemBySlot(slotType);
        if (!wornItem.isEmpty() && wornItem.getItem() instanceof ItemMekaSuitArmor) {
            wornParts.add(slotType);
            for (Map.Entry<ModuleData<?>, ModuleModelSpec> entry : moduleModelSpec.row(slotType).entrySet()) {
                if (moduleHelper.isEnabled(wornItem, entry.getKey())) {
                    ModuleModelSpec spec = entry.getValue();
                    modules.put(spec, spec.isActive(player));
                }
            }
        }
    }
    return new QuickHash(modules.isEmpty() ? Object2BooleanMaps.emptyMap() : modules, wornParts.isEmpty() ? Collections.emptySet() : wornParts, MekanismUtils.getItemInHand(player, HandSide.LEFT).getItem() instanceof ItemMekaTool, MekanismUtils.getItemInHand(player, HandSide.RIGHT).getItem() instanceof ItemMekaTool);
}
Also used : ItemMekaSuitArmor(mekanism.common.item.gear.ItemMekaSuitArmor) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) QuickHash(mekanism.client.render.obj.TransmitterBakedModel.QuickHash) Object2BooleanOpenHashMap(it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap) ItemMekaTool(mekanism.common.item.gear.ItemMekaTool) ModuleData(mekanism.api.gear.ModuleData) IModuleHelper(mekanism.api.gear.IModuleHelper) ItemStack(net.minecraft.item.ItemStack) Object2BooleanMap(it.unimi.dsi.fastutil.objects.Object2BooleanMap) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) Object2BooleanOpenHashMap(it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap) EnumMap(java.util.EnumMap)

Aggregations

Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)2 Map (java.util.Map)2 IModuleHelper (mekanism.api.gear.IModuleHelper)2 ModuleData (mekanism.api.gear.ModuleData)2 ItemStack (net.minecraft.item.ItemStack)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Object2BooleanMap (it.unimi.dsi.fastutil.objects.Object2BooleanMap)1 Object2BooleanOpenHashMap (it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumMap (java.util.EnumMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)1 MethodsReturnNonnullByDefault (mcp.MethodsReturnNonnullByDefault)1 MekanismAPI (mekanism.api.MekanismAPI)1 MekanismIMC (mekanism.api.MekanismIMC)1