use of com.minecolonies.api.research.IResearchRequirement in project minecolonies by ldtteam.
the class GlobalResearchFactory method serialize.
@Override
public void serialize(@NotNull IFactoryController controller, IGlobalResearch input, PacketBuffer packetBuffer) {
packetBuffer.writeResourceLocation(input.getParent());
packetBuffer.writeResourceLocation(input.getId());
packetBuffer.writeResourceLocation(input.getBranch());
packetBuffer.writeUtf(input.getName().getKey());
packetBuffer.writeVarInt(input.getDepth());
packetBuffer.writeVarInt(input.getSortOrder());
packetBuffer.writeBoolean(input.hasOnlyChild());
packetBuffer.writeItem(input.getIconItemStack());
packetBuffer.writeResourceLocation(input.getIconTextureResourceLocation());
packetBuffer.writeUtf(input.getSubtitle().getKey());
packetBuffer.writeBoolean(input.isInstant());
packetBuffer.writeBoolean(input.isAutostart());
packetBuffer.writeBoolean(input.isImmutable());
packetBuffer.writeBoolean(input.isHidden());
packetBuffer.writeVarInt(input.getCostList().size());
for (ItemStorage is : input.getCostList()) {
controller.serialize(packetBuffer, is);
}
packetBuffer.writeVarInt(input.getResearchRequirement().size());
for (IResearchRequirement req : input.getResearchRequirement()) {
packetBuffer.writeResourceLocation(req.getRegistryEntry().getRegistryName());
packetBuffer.writeNbt(req.writeToNBT());
}
packetBuffer.writeVarInt(input.getEffects().size());
for (IResearchEffect<?> effect : input.getEffects()) {
packetBuffer.writeResourceLocation(effect.getRegistryEntry().getRegistryName());
packetBuffer.writeNbt(effect.writeToNBT());
}
packetBuffer.writeVarInt(input.getChildren().size());
for (ResourceLocation child : input.getChildren()) {
packetBuffer.writeResourceLocation(child);
}
}
use of com.minecolonies.api.research.IResearchRequirement in project minecolonies by Minecolonies.
the class GlobalResearchFactory method serialize.
@Override
public void serialize(@NotNull IFactoryController controller, IGlobalResearch input, PacketBuffer packetBuffer) {
packetBuffer.writeResourceLocation(input.getParent());
packetBuffer.writeResourceLocation(input.getId());
packetBuffer.writeResourceLocation(input.getBranch());
packetBuffer.writeUtf(input.getName().getKey());
packetBuffer.writeVarInt(input.getDepth());
packetBuffer.writeVarInt(input.getSortOrder());
packetBuffer.writeBoolean(input.hasOnlyChild());
packetBuffer.writeItem(input.getIconItemStack());
packetBuffer.writeResourceLocation(input.getIconTextureResourceLocation());
packetBuffer.writeUtf(input.getSubtitle().getKey());
packetBuffer.writeBoolean(input.isInstant());
packetBuffer.writeBoolean(input.isAutostart());
packetBuffer.writeBoolean(input.isImmutable());
packetBuffer.writeBoolean(input.isHidden());
packetBuffer.writeVarInt(input.getCostList().size());
for (ItemStorage is : input.getCostList()) {
controller.serialize(packetBuffer, is);
}
packetBuffer.writeVarInt(input.getResearchRequirement().size());
for (IResearchRequirement req : input.getResearchRequirement()) {
packetBuffer.writeResourceLocation(req.getRegistryEntry().getRegistryName());
packetBuffer.writeNbt(req.writeToNBT());
}
packetBuffer.writeVarInt(input.getEffects().size());
for (IResearchEffect<?> effect : input.getEffects()) {
packetBuffer.writeResourceLocation(effect.getRegistryEntry().getRegistryName());
packetBuffer.writeNbt(effect.writeToNBT());
}
packetBuffer.writeVarInt(input.getChildren().size());
for (ResourceLocation child : input.getChildren()) {
packetBuffer.writeResourceLocation(child);
}
}
use of com.minecolonies.api.research.IResearchRequirement in project minecolonies by Minecolonies.
the class ResearchListener method parseResearches.
/**
* Parses out a json map for elements containing Researches, validates that they have required fields, and generates a GlobalResearch for each.
*
* @param object A Map containing the resource location of each json file, and the element within that json file.
* @param effectCategories A Map containing the effect categories by effectId.
* @param removeResearches A Collection of researches to remove, if present.
* @param removeBranches A Collection of research branches to remove, including all component researches, if present.
* @param checkResourceLoc If the client should check resource locations at the time. This can not be run on the server.
* @return A Map containing the ResearchIds and the GlobalResearches each ID corresponds to.
*/
private Map<ResourceLocation, GlobalResearch> parseResearches(final Map<ResourceLocation, JsonElement> object, final Map<ResourceLocation, ResearchEffectCategory> effectCategories, final Collection<ResourceLocation> removeResearches, final Collection<ResourceLocation> removeBranches, boolean checkResourceLoc) {
final Map<ResourceLocation, GlobalResearch> researchMap = new HashMap<>();
for (final Map.Entry<ResourceLocation, JsonElement> entry : object.entrySet()) {
// Cancel removed individual researches first, to save parsing time.
if (removeResearches.contains(entry.getKey())) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().info(entry.getKey() + " was removed by data pack.");
}
continue;
}
// Note that we don't actually use the resource folders or file names; those are only for organization purposes.
final JsonObject researchJson = entry.getValue().getAsJsonObject();
// Can ignore those effects json now:
if (researchJson.has(RESEARCH_EFFECT_PROP)) {
continue;
}
// Next, check for remove-type recipes. We don't want to accidentally add them just because they have too much detail.
if (researchJson.has(RESEARCH_REMOVE_PROP) && researchJson.get(RESEARCH_REMOVE_PROP).getAsJsonPrimitive().isString()) {
continue;
}
// And same for research-branch-specific settings, to avoid extraneous warnings.
if (researchJson.has(RESEARCH_BRANCH_NAME_PROP) || researchJson.has(RESEARCH_BASE_TIME_PROP) || researchJson.has(RESEARCH_BRANCH_TYPE_PROP)) {
continue;
}
// Check for absolute minimum required types, and log as warning if malformed.
if (!(researchJson.has(RESEARCH_BRANCH_PROP) && researchJson.get(RESEARCH_BRANCH_PROP).isJsonPrimitive() && researchJson.get(RESEARCH_BRANCH_PROP).getAsJsonPrimitive().isString())) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().warn(entry.getKey() + " is a Research , but does not contain all required fields. Researches must have a branch:string properties.");
}
continue;
} else // Now that we've confirmed a branch exists at all, cancel the add if it's from a removed branch.
if (removeBranches.contains(new ResourceLocation(researchJson.get(RESEARCH_BRANCH_PROP).getAsString()))) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().info(entry.getKey() + " was removed, as its branch had been removed by data pack.");
}
continue;
}
// Missing university level data may not necessarily be a show-stopper, but it is worth warning about.
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get() && !(researchJson.has(RESEARCH_UNIVERSITY_LEVEL_PROP) && researchJson.get(RESEARCH_UNIVERSITY_LEVEL_PROP).getAsJsonPrimitive().isNumber())) {
Log.getLogger().warn(entry.getKey() + " is a Research, but has invalid or no university level requirements.");
}
// Pretty much anything else should be allowed: it's plausible pack designers may want a research type without a cost or effect.
// It's possible we could dynamically derive university levels from parents, but doing so as a rule will prevent research branches that start at T2 or deeper.
final GlobalResearch research = new GlobalResearch(researchJson, entry.getKey(), effectCategories, checkResourceLoc);
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().info("Parsed research recipe from " + entry.getKey() + " [" + research.getBranch() + "/" + research.getId() + "]");
Log.getLogger().info(research.getName() + " at " + research.getDepth() + "/" + research.getParent());
for (IResearchRequirement requirement : research.getResearchRequirement()) {
Log.getLogger().info("Requirement: " + requirement.getDesc());
}
for (ItemStorage itemS : research.getCostList()) {
Log.getLogger().info("Cost: " + itemS.toString());
}
for (IResearchEffect<?> researchEffect : research.getEffects()) {
Log.getLogger().info("Effect: " + researchEffect.getId() + " " + researchEffect.getDesc());
}
}
researchMap.put(research.getId(), research);
}
return researchMap;
}
use of com.minecolonies.api.research.IResearchRequirement in project minecolonies by ldtteam.
the class ResearchListener method parseResearches.
/**
* Parses out a json map for elements containing Researches, validates that they have required fields, and generates a GlobalResearch for each.
*
* @param object A Map containing the resource location of each json file, and the element within that json file.
* @param effectCategories A Map containing the effect categories by effectId.
* @param removeResearches A Collection of researches to remove, if present.
* @param removeBranches A Collection of research branches to remove, including all component researches, if present.
* @param checkResourceLoc If the client should check resource locations at the time. This can not be run on the server.
* @return A Map containing the ResearchIds and the GlobalResearches each ID corresponds to.
*/
private Map<ResourceLocation, GlobalResearch> parseResearches(final Map<ResourceLocation, JsonElement> object, final Map<ResourceLocation, ResearchEffectCategory> effectCategories, final Collection<ResourceLocation> removeResearches, final Collection<ResourceLocation> removeBranches, boolean checkResourceLoc) {
final Map<ResourceLocation, GlobalResearch> researchMap = new HashMap<>();
for (final Map.Entry<ResourceLocation, JsonElement> entry : object.entrySet()) {
// Cancel removed individual researches first, to save parsing time.
if (removeResearches.contains(entry.getKey())) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().info(entry.getKey() + " was removed by data pack.");
}
continue;
}
// Note that we don't actually use the resource folders or file names; those are only for organization purposes.
final JsonObject researchJson = entry.getValue().getAsJsonObject();
// Can ignore those effects json now:
if (researchJson.has(RESEARCH_EFFECT_PROP)) {
continue;
}
// Next, check for remove-type recipes. We don't want to accidentally add them just because they have too much detail.
if (researchJson.has(RESEARCH_REMOVE_PROP) && researchJson.get(RESEARCH_REMOVE_PROP).getAsJsonPrimitive().isString()) {
continue;
}
// And same for research-branch-specific settings, to avoid extraneous warnings.
if (researchJson.has(RESEARCH_BRANCH_NAME_PROP) || researchJson.has(RESEARCH_BASE_TIME_PROP) || researchJson.has(RESEARCH_BRANCH_TYPE_PROP)) {
continue;
}
// Check for absolute minimum required types, and log as warning if malformed.
if (!(researchJson.has(RESEARCH_BRANCH_PROP) && researchJson.get(RESEARCH_BRANCH_PROP).isJsonPrimitive() && researchJson.get(RESEARCH_BRANCH_PROP).getAsJsonPrimitive().isString())) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().warn(entry.getKey() + " is a Research , but does not contain all required fields. Researches must have a branch:string properties.");
}
continue;
} else // Now that we've confirmed a branch exists at all, cancel the add if it's from a removed branch.
if (removeBranches.contains(new ResourceLocation(researchJson.get(RESEARCH_BRANCH_PROP).getAsString()))) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().info(entry.getKey() + " was removed, as its branch had been removed by data pack.");
}
continue;
}
// Missing university level data may not necessarily be a show-stopper, but it is worth warning about.
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get() && !(researchJson.has(RESEARCH_UNIVERSITY_LEVEL_PROP) && researchJson.get(RESEARCH_UNIVERSITY_LEVEL_PROP).getAsJsonPrimitive().isNumber())) {
Log.getLogger().warn(entry.getKey() + " is a Research, but has invalid or no university level requirements.");
}
// Pretty much anything else should be allowed: it's plausible pack designers may want a research type without a cost or effect.
// It's possible we could dynamically derive university levels from parents, but doing so as a rule will prevent research branches that start at T2 or deeper.
final GlobalResearch research = new GlobalResearch(researchJson, entry.getKey(), effectCategories, checkResourceLoc);
if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchDebugLog.get()) {
Log.getLogger().info("Parsed research recipe from " + entry.getKey() + " [" + research.getBranch() + "/" + research.getId() + "]");
Log.getLogger().info(research.getName() + " at " + research.getDepth() + "/" + research.getParent());
for (IResearchRequirement requirement : research.getResearchRequirement()) {
Log.getLogger().info("Requirement: " + requirement.getDesc());
}
for (ItemStorage itemS : research.getCostList()) {
Log.getLogger().info("Cost: " + itemS.toString());
}
for (IResearchEffect<?> researchEffect : research.getEffects()) {
Log.getLogger().info("Effect: " + researchEffect.getId() + " " + researchEffect.getDesc());
}
}
researchMap.put(research.getId(), research);
}
return researchMap;
}
Aggregations