Search in sources :

Example 1 with TemplateOperation

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);
}
Also used : Arrays(java.util.Arrays) AbilityRegistry(com.lying.variousoddities.species.abilities.AbilityRegistry) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) VORegistries(com.lying.variousoddities.init.VORegistries) CompoundNBT(net.minecraft.nbt.CompoundNBT) HashMap(java.util.HashMap) Random(java.util.Random) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) Lists(com.google.common.collect.Lists) PacketSpeciesSelected(com.lying.variousoddities.network.PacketSpeciesSelected) Minecraft(net.minecraft.client.Minecraft) Map(java.util.Map) Types(com.lying.variousoddities.species.types.Types) Button(net.minecraft.client.gui.widget.button.Button) StringTextComponent(net.minecraft.util.text.StringTextComponent) Nonnull(javax.annotation.Nonnull) EnumSet(java.util.EnumSet) Species(com.lying.variousoddities.species.Species) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Ability(com.lying.variousoddities.species.abilities.Ability) Template(com.lying.variousoddities.species.Template) TemplateOperation(com.lying.variousoddities.species.templates.TemplateOperation) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbilityModifier(com.lying.variousoddities.species.abilities.AbilityModifier) Collection(java.util.Collection) AbilityModifierCon(com.lying.variousoddities.species.abilities.AbilityModifierCon) Reference(com.lying.variousoddities.reference.Reference) AbilityNaturalArmour(com.lying.variousoddities.species.abilities.AbilityNaturalArmour) Pair(com.mojang.datafixers.util.Pair) AbstractGui(net.minecraft.client.gui.AbstractGui) PacketHandler(com.lying.variousoddities.network.PacketHandler) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) Tessellator(net.minecraft.client.renderer.Tessellator) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) EnumCreatureType(com.lying.variousoddities.species.types.EnumCreatureType) Comparator(java.util.Comparator) Collections(java.util.Collections) TemplateOperation(com.lying.variousoddities.species.templates.TemplateOperation) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) Template(com.lying.variousoddities.species.Template)

Example 2 with TemplateOperation

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);
        }
    }
}
Also used : TemplateOperation(com.lying.variousoddities.species.templates.TemplateOperation) AbilityOperation(com.lying.variousoddities.species.templates.AbilityOperation) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Template(com.lying.variousoddities.species.Template)

Example 3 with TemplateOperation

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;
}
Also used : JsonArray(com.google.gson.JsonArray) TemplateOperation(com.lying.variousoddities.species.templates.TemplateOperation) JsonObject(com.google.gson.JsonObject) TemplatePrecondition(com.lying.variousoddities.species.templates.TemplatePrecondition)

Example 4 with TemplateOperation

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;
}
Also used : JsonArray(com.google.gson.JsonArray) TemplateOperation(com.lying.variousoddities.species.templates.TemplateOperation) JsonObject(com.google.gson.JsonObject) TemplatePrecondition(com.lying.variousoddities.species.templates.TemplatePrecondition)

Aggregations

TemplateOperation (com.lying.variousoddities.species.templates.TemplateOperation)4 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 Template (com.lying.variousoddities.species.Template)2 TemplatePrecondition (com.lying.variousoddities.species.templates.TemplatePrecondition)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Lists (com.google.common.collect.Lists)1 VORegistries (com.lying.variousoddities.init.VORegistries)1 PacketHandler (com.lying.variousoddities.network.PacketHandler)1 PacketSpeciesSelected (com.lying.variousoddities.network.PacketSpeciesSelected)1 Reference (com.lying.variousoddities.reference.Reference)1 Species (com.lying.variousoddities.species.Species)1 Ability (com.lying.variousoddities.species.abilities.Ability)1 AbilityModifier (com.lying.variousoddities.species.abilities.AbilityModifier)1 AbilityModifierCon (com.lying.variousoddities.species.abilities.AbilityModifierCon)1 AbilityNaturalArmour (com.lying.variousoddities.species.abilities.AbilityNaturalArmour)1 AbilityRegistry (com.lying.variousoddities.species.abilities.AbilityRegistry)1 AbilityOperation (com.lying.variousoddities.species.templates.AbilityOperation)1 EnumCreatureType (com.lying.variousoddities.species.types.EnumCreatureType)1 Types (com.lying.variousoddities.species.types.Types)1