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);
}
}
}
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);
}
Aggregations