use of com.lying.variousoddities.species.templates.TemplateOperation in project VariousOddities by Lyinginbedmon.
the class ScreenSelectTemplates method renderHighlightedEntry.
private void renderHighlightedEntry(MatrixStack matrixStack, int mouseX, int mouseY) {
Template template = this.highlightEntry.template;
List<ITextComponent> tooltip = Lists.newArrayList();
if (!template.getPreconditions().isEmpty() && !this.player.isCreative()) {
tooltip.add(new TranslationTextComponent("command." + Reference.ModInfo.MOD_ID + ".species.templates.info_preconditions", template.getPreconditions().size()));
template.getPreconditions().forEach((precondition) -> {
tooltip.add(new StringTextComponent(" ").append(precondition.translate()));
});
}
if (!template.getOperations().isEmpty()) {
if (!tooltip.isEmpty())
tooltip.add(new StringTextComponent(""));
tooltip.add(new TranslationTextComponent("command." + Reference.ModInfo.MOD_ID + ".species.templates.info_operations", template.getOperations().size()));
List<TemplateOperation> totalOperations = Lists.newArrayList();
totalOperations.addAll(template.getOperations());
while (!totalOperations.isEmpty()) {
List<TemplateOperation> group = Lists.newArrayList();
for (TemplateOperation operation : totalOperations) if (group.isEmpty() || operation.canStackWith(group.get(0)))
group.add(operation);
totalOperations.removeAll(group);
if (group.size() > 1)
group.get(0).stackAsList(group).forEach((entry) -> {
tooltip.add(new StringTextComponent(" ").append(entry));
});
else
tooltip.add(new StringTextComponent(" ").append(group.get(0).translate()));
}
}
renderWrappedToolTip(matrixStack, tooltip, mouseX, mouseY, font);
}
use of com.lying.variousoddities.species.templates.TemplateOperation in project VariousOddities by Lyinginbedmon.
the class AbilityStartingItem method onTemplateAdded.
public void onTemplateAdded(SpeciesEvent.TemplateApplied event) {
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
if (player.getEntityWorld().isRemote)
return;
Template template = VORegistries.TEMPLATES.get(event.getTemplate());
if (template != null) {
for (TemplateOperation operation : template.getOperations()) if (operation.getRegistryName() == AbilityOperation.REGISTRY_NAME && operation.action() == Operation.ADD) {
AbilityOperation addAbility = (AbilityOperation) operation;
Ability ability = addAbility.getAbility();
if (ability != null && ability.getRegistryName() == AbilityStartingItem.REGISTRY_NAME)
addItemsFromAbility((AbilityStartingItem) ability, player);
}
}
}
use of com.lying.variousoddities.species.templates.TemplateOperation in project VariousOddities by Lyinginbedmon.
the class Template method fromJson.
public static Template fromJson(@Nullable JsonElement json) {
if (json == null)
return null;
JsonObject object = json.getAsJsonObject();
Template template = new Template();
if (object.has("UUID"))
template.templateID = UUID.fromString(object.get("UUID").getAsString());
if (object.has("Power"))
template.setPower(object.get("Power").getAsInt());
if (object.has("CustomName")) {
String s = object.get("CustomName").getAsString();
try {
template.setDisplayName(ITextComponent.Serializer.getComponentFromJson(s));
} catch (Exception exception) {
VariousOddities.log.warn("Failed to parse template display name {}", s, exception);
}
}
if (object.has("Operations")) {
JsonArray operationList = object.get("Operations").getAsJsonArray();
for (int i = 0; i < operationList.size(); i++) {
TemplateOperation operation = TemplateOperation.getFromJson(operationList.get(i).getAsJsonObject());
if (operation != null)
template.addOperation(operation);
else
VariousOddities.log.error("!! Error loading template operation");
}
}
if (template.getOperations().isEmpty())
VariousOddities.log.warn("Template has no operations, was this intentional?");
if (object.has("Preconditions")) {
JsonArray preconditionList = object.get("Preconditions").getAsJsonArray();
for (int i = 0; i < preconditionList.size(); i++) {
TemplatePrecondition precondition = TemplatePrecondition.getFromJson(preconditionList.get(i).getAsJsonObject());
if (precondition != null)
template.addPrecondition(precondition);
else
VariousOddities.log.error("!! Error loading template precondition");
}
}
return template;
}
use of com.lying.variousoddities.species.templates.TemplateOperation in project VariousOddities by Lyinginbedmon.
the class Template method toJson.
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("UUID", this.templateID.toString());
json.addProperty("Power", getPower());
if (this.customName != null)
json.addProperty("CustomName", ITextComponent.Serializer.toJson(this.customName));
JsonArray operations = new JsonArray();
for (TemplateOperation operation : this.operations) operations.add(operation.writeToJson(new JsonObject()));
json.add("Operations", operations);
JsonArray preconditions = new JsonArray();
for (TemplatePrecondition precondition : this.preconditions) preconditions.add(precondition.writeToJson(new JsonObject()));
json.add("Preconditions", preconditions);
return json;
}
Aggregations