use of com.minecolonies.api.research.IGlobalResearch in project minecolonies by Minecolonies.
the class GenericRecipeUtils method getResearchDisplayName.
@NotNull
private static ITextComponent getResearchDisplayName(@NotNull final ResourceLocation researchId) {
final IGlobalResearchTree researchTree = IGlobalResearchTree.getInstance();
// first, try to see if this is a research id
final IGlobalResearch research = researchTree.getResearch(researchId);
if (research != null) {
return research.getName();
}
// next, see if it's an effect id
final Set<IGlobalResearch> researches = researchTree.getResearchForEffect(researchId);
if (researches != null && !researches.isEmpty()) {
// there might be more than one, but this should be sufficient for now
return researches.iterator().next().getName();
}
// otherwise it may be an effect with no research (perhaps disabled via datapack)
return new StringTextComponent("???");
}
use of com.minecolonies.api.research.IGlobalResearch in project minecolonies by Minecolonies.
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.research.IGlobalResearch in project minecolonies by Minecolonies.
the class GlobalResearchFactory method deserialize.
@NotNull
@Override
public IGlobalResearch deserialize(@NotNull final IFactoryController controller, @NotNull final CompoundNBT nbt) {
final ResourceLocation parent = new ResourceLocation(nbt.getString(TAG_PARENT));
final ResourceLocation id = new ResourceLocation(nbt.getString(TAG_ID));
final ResourceLocation branch = new ResourceLocation(nbt.getString(TAG_BRANCH));
final TranslationTextComponent desc = new TranslationTextComponent(nbt.getString(TAG_NAME));
final int depth = nbt.getInt(TAG_RESEARCH_LVL);
final int sortOrder = nbt.getInt(TAG_RESEARCH_SORT);
final boolean onlyChild = nbt.getBoolean(TAG_ONLY_CHILD);
final ResourceLocation iconTexture = new ResourceLocation(nbt.getString(TAG_ICON_TEXTURE));
final String[] iconStackParts = nbt.getString(TAG_ICON_ITEM_STACK).split(":");
final ItemStack iconStack = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(iconStackParts[0], iconStackParts[1])));
iconStack.setCount(Integer.parseInt(iconStackParts[2]));
final TranslationTextComponent subtitle = new TranslationTextComponent(nbt.getString(TAG_SUBTITLE_NAME));
final boolean instant = nbt.getBoolean(TAG_INSTANT);
final boolean autostart = nbt.getBoolean(TAG_AUTOSTART);
final boolean immutable = nbt.getBoolean(TAG_IMMUTABLE);
final boolean hidden = nbt.getBoolean(TAG_HIDDEN);
final IGlobalResearch research = getNewInstance(id, branch, parent, desc, depth, sortOrder, iconTexture, iconStack, subtitle, onlyChild, hidden, autostart, instant, immutable);
NBTUtils.streamCompound(nbt.getList(TAG_COSTS, Constants.NBT.TAG_COMPOUND)).forEach(compound -> {
String[] costParts = compound.getString(TAG_COST_ITEM).split(":");
if (costParts.length == 3) {
final ItemStack is = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(costParts[0], costParts[1])));
is.setCount(Integer.parseInt(costParts[2]));
if (compound.hasUUID(TAG_COST_NBT)) {
is.setTag(compound.getCompound(TAG_COST_NBT));
}
research.addCost(new ItemStorage(is, false, !is.hasTag()));
}
});
NBTUtils.streamCompound(nbt.getList(TAG_REQS, Constants.NBT.TAG_COMPOUND)).forEach(compound -> research.addRequirement(Objects.requireNonNull(IResearchRequirementRegistry.getInstance().getValue(ResourceLocation.tryParse(compound.getString(TAG_REQ_TYPE)))).readFromNBT(compound.getCompound(TAG_REQ_ITEM))));
NBTUtils.streamCompound(nbt.getList(TAG_EFFECTS, Constants.NBT.TAG_COMPOUND)).forEach(compound -> research.addEffect(Objects.requireNonNull(IResearchEffectRegistry.getInstance().getValue(ResourceLocation.tryParse(compound.getString(TAG_EFFECT_TYPE)))).readFromNBT(compound.getCompound(TAG_EFFECT_ITEM))));
NBTUtils.streamCompound(nbt.getList(TAG_CHILDS, Constants.NBT.TAG_COMPOUND)).forEach(compound -> research.addChild(new ResourceLocation(compound.getString(TAG_RESEARCH_CHILD))));
return research;
}
use of com.minecolonies.api.research.IGlobalResearch in project minecolonies by Minecolonies.
the class GlobalResearchFactory method serialize.
@NotNull
@Override
public CompoundNBT serialize(@NotNull final IFactoryController controller, @NotNull final IGlobalResearch research) {
final CompoundNBT compound = new CompoundNBT();
compound.putString(TAG_PARENT, research.getParent().toString());
compound.putString(TAG_ID, research.getId().toString());
compound.putString(TAG_BRANCH, research.getBranch().toString());
compound.putString(TAG_NAME, research.getName().getKey());
compound.putInt(TAG_RESEARCH_LVL, research.getDepth());
compound.putInt(TAG_RESEARCH_SORT, research.getSortOrder());
compound.putBoolean(TAG_ONLY_CHILD, research.hasOnlyChild());
compound.putString(TAG_ICON_TEXTURE, research.getIconTextureResourceLocation().toString());
compound.putString(TAG_ICON_ITEM_STACK, research.getIconItemStack().getItem().getRegistryName() + ":" + research.getIconItemStack().getCount());
compound.putString(TAG_SUBTITLE_NAME, research.getSubtitle().getKey());
compound.putBoolean(TAG_INSTANT, research.isInstant());
compound.putBoolean(TAG_AUTOSTART, research.isAutostart());
compound.putBoolean(TAG_IMMUTABLE, research.isImmutable());
compound.putBoolean(TAG_HIDDEN, research.isHidden());
@NotNull final ListNBT costTagList = research.getCostList().stream().map(is -> {
final CompoundNBT costCompound = new CompoundNBT();
costCompound.putString(TAG_COST_ITEM, Objects.requireNonNull(is.getItem().getRegistryName()).toString() + ":" + is.getItemStack().getCount());
if (is.getItemStack().getTag() != null) {
costCompound.put(TAG_COST_NBT, is.getItemStack().getTag());
}
return costCompound;
}).collect(NBTUtils.toListNBT());
compound.put(TAG_COSTS, costTagList);
@NotNull final ListNBT reqTagList = research.getResearchRequirement().stream().map(req -> {
final CompoundNBT reqCompound = new CompoundNBT();
reqCompound.putString(TAG_REQ_TYPE, req.getRegistryEntry().getRegistryName().toString());
reqCompound.put(TAG_REQ_ITEM, req.writeToNBT());
return reqCompound;
}).collect(NBTUtils.toListNBT());
compound.put(TAG_REQS, reqTagList);
@NotNull final ListNBT effectTagList = research.getEffects().stream().map(eff -> {
final CompoundNBT effectCompound = new CompoundNBT();
effectCompound.putString(TAG_EFFECT_TYPE, eff.getRegistryEntry().getRegistryName().toString());
effectCompound.put(TAG_EFFECT_ITEM, eff.writeToNBT());
return effectCompound;
}).collect(NBTUtils.toListNBT());
compound.put(TAG_EFFECTS, effectTagList);
@NotNull final ListNBT childTagList = research.getChildren().stream().map(child -> {
final CompoundNBT childCompound = new CompoundNBT();
childCompound.putString(TAG_RESEARCH_CHILD, child.toString());
return childCompound;
}).collect(NBTUtils.toListNBT());
compound.put(TAG_CHILDS, childTagList);
return compound;
}
use of com.minecolonies.api.research.IGlobalResearch in project minecolonies by ldtteam.
the class TryResearchMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final BuildingUniversity building) {
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
final IGlobalResearch research = IGlobalResearchTree.getInstance().getResearch(branch, researchId);
if (reset) {
if (colony.getResearchManager().getResearchTree().getResearch(branch, researchId) != null) {
colony.getResearchManager().getResearchTree().attemptResetResearch(player, colony, colony.getResearchManager().getResearchTree().getResearch(branch, researchId));
}
} else {
if ((research.canResearch(building.getBuildingLevel() == building.getMaxBuildingLevel() ? Integer.MAX_VALUE : building.getBuildingLevel(), colony.getResearchManager().getResearchTree())) || player.isCreative()) {
colony.getResearchManager().getResearchTree().attemptBeginResearch(player, colony, research);
}
}
}
Aggregations