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