Search in sources :

Example 11 with BuildingEntry

use of com.minecolonies.api.colony.buildings.registry.BuildingEntry in project minecolonies by ldtteam.

the class ClientEventHandler method handleCrafterRecipeTooltips.

/**
 * Display crafter recipe-related information on the client.
 * @param colony   The colony to check against, if one is present.
 * @param toolTip  The tooltip to add the text onto.
 * @param item     The item that will have the tooltip text added.
 */
private static void handleCrafterRecipeTooltips(@Nullable final IColony colony, final List<ITextComponent> toolTip, final Item item) {
    final List<CustomRecipe> recipes = CustomRecipeManager.getInstance().getRecipeByOutput(item);
    if (recipes.isEmpty()) {
        return;
    }
    for (CustomRecipe rec : recipes) {
        if (!rec.getShowTooltip() || rec.getCrafter().length() < 2) {
            continue;
        }
        final BuildingEntry craftingBuilding = crafterToBuilding.get().get(rec.getCrafter());
        if (craftingBuilding == null)
            continue;
        final ITextComponent craftingBuildingName = getFullBuildingName(craftingBuilding);
        if (rec.getMinBuildingLevel() > 0) {
            final String schematicName = craftingBuilding.getRegistryName().getPath();
            // the above is not guaranteed to match (and indeed doesn't for a few buildings), but
            // does match for all currently interesting crafters, at least.  there doesn't otherwise
            // appear to be an easy way to get the schematic name from a BuildingEntry ... or
            // unless we can change how colony.hasBuilding uses its parameter...
            final IFormattableTextComponent reqLevelText = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_BUILDLEVEL_TOOLTIP_GUI, craftingBuildingName, rec.getMinBuildingLevel());
            if (colony != null && colony.hasBuilding(schematicName, rec.getMinBuildingLevel(), true)) {
                reqLevelText.setStyle(Style.EMPTY.withColor(TextFormatting.AQUA));
            } else {
                reqLevelText.setStyle(Style.EMPTY.withColor(TextFormatting.RED));
            }
            toolTip.add(reqLevelText);
        } else {
            final IFormattableTextComponent reqBuildingTxt = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_AVAILABLE_TOOLTIP_GUI, craftingBuildingName).setStyle(Style.EMPTY.withItalic(true).withColor(TextFormatting.GRAY));
            toolTip.add(reqBuildingTxt);
        }
        if (rec.getRequiredResearchId() != null) {
            final Set<IGlobalResearch> researches;
            if (IMinecoloniesAPI.getInstance().getGlobalResearchTree().hasResearch(rec.getRequiredResearchId())) {
                researches = new HashSet<>();
                researches.add(IMinecoloniesAPI.getInstance().getGlobalResearchTree().getResearch(rec.getRequiredResearchId()));
            } else {
                researches = IMinecoloniesAPI.getInstance().getGlobalResearchTree().getResearchForEffect(rec.getRequiredResearchId());
            }
            if (researches != null) {
                final TextFormatting researchFormat;
                if (colony != null && (colony.getResearchManager().getResearchTree().hasCompletedResearch(rec.getRequiredResearchId()) || colony.getResearchManager().getResearchEffects().getEffectStrength(rec.getRequiredResearchId()) > 0)) {
                    researchFormat = TextFormatting.AQUA;
                } else {
                    researchFormat = TextFormatting.RED;
                }
                for (IGlobalResearch research : researches) {
                    toolTip.add(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ITEM_REQUIRES_RESEARCH_TOOLTIP_GUI, research.getName()).setStyle(Style.EMPTY.withColor(researchFormat)));
                }
            }
        }
    }
}
Also used : CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) IGlobalResearch(com.minecolonies.api.research.IGlobalResearch)

Example 12 with BuildingEntry

use of com.minecolonies.api.colony.buildings.registry.BuildingEntry in project minecolonies by ldtteam.

the class BuildingDataManager method createViewFrom.

@Override
public IBuildingView createViewFrom(final IColonyView colony, final BlockPos position, final PacketBuffer networkBuffer) {
    final ResourceLocation buildingName = new ResourceLocation(networkBuffer.readUtf(32767));
    final BuildingEntry entry = IBuildingRegistry.getInstance().getValue(buildingName);
    if (entry == null) {
        Log.getLogger().error(String.format("Unknown building type '%s'.", buildingName), new Exception());
        return null;
    }
    final IBuildingView view = entry.produceBuildingView(position, colony);
    if (view != null) {
        view.deserialize(networkBuffer);
    }
    return view;
}
Also used : BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) ResourceLocation(net.minecraft.util.ResourceLocation) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView)

Aggregations

BuildingEntry (com.minecolonies.api.colony.buildings.registry.BuildingEntry)12 ResourceLocation (net.minecraft.util.ResourceLocation)8 AnimalHerdingModule (com.minecolonies.coremod.colony.buildings.modules.AnimalHerdingModule)4 ItemStack (net.minecraft.item.ItemStack)4 IMinecoloniesAPI (com.minecolonies.api.IMinecoloniesAPI)2 ModBlocks (com.minecolonies.api.blocks.ModBlocks)2 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 ISchematicProvider (com.minecolonies.api.colony.buildings.ISchematicProvider)2 ModBuildings (com.minecolonies.api.colony.buildings.ModBuildings)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 ColonyEventDescriptionTypeRegistryEntry (com.minecolonies.api.colony.colonyEvents.registry.ColonyEventDescriptionTypeRegistryEntry)2 ColonyEventTypeRegistryEntry (com.minecolonies.api.colony.colonyEvents.registry.ColonyEventTypeRegistryEntry)2 GuardType (com.minecolonies.api.colony.guardtype.GuardType)2 ModGuardTypes (com.minecolonies.api.colony.guardtype.registry.ModGuardTypes)2 InteractionResponseHandlerEntry (com.minecolonies.api.colony.interactionhandling.registry.InteractionResponseHandlerEntry)2 ModJobs (com.minecolonies.api.colony.jobs.ModJobs)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)2 StandardFactoryController (com.minecolonies.api.colony.requestsystem.StandardFactoryController)2 CompatibilityManager (com.minecolonies.api.compatibility.CompatibilityManager)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2