Search in sources :

Example 1 with Template

use of com.lying.variousoddities.species.Template in project VariousOddities by Lyinginbedmon.

the class ScreenSelectTemplates method removeTemplate.

/**
 * Removes the given template from the applied list and updates the available list
 */
public void removeTemplate(Template template) {
    List<Template> applied = this.listApplied.getTemplates();
    applied.remove(template);
    // Quality control
    boolean noHits = false;
    while (!noHits) {
        // Iterate through applied templates, breaking when invalid found
        List<Template> tested = Lists.newArrayList();
        Template hitFound = null;
        for (Template extant : applied) {
            Pair<Types, Map<ResourceLocation, Ability>> atStep = processTemplates(tested.toArray(new Template[0]));
            if (testTemplate(extant, atStep))
                tested.add(extant);
            else {
                hitFound = extant;
                break;
            }
        }
        if (hitFound != null)
            applied.remove(hitFound);
        else
            noHits = true;
    }
    this.listApplied.setEntries(applied);
    this.listAvailable.setEntries(getViableTemplates());
}
Also used : Types(com.lying.variousoddities.species.types.Types) HashMap(java.util.HashMap) Map(java.util.Map) Template(com.lying.variousoddities.species.Template)

Example 2 with Template

use of com.lying.variousoddities.species.Template 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 3 with Template

use of com.lying.variousoddities.species.Template in project VariousOddities by Lyinginbedmon.

the class ScreenSelectTemplates method getViableTemplates.

/**
 * Returns a list of templates applicable to the current set and within the power budget
 */
public List<Template> getViableTemplates() {
    List<Template> templates = Lists.newArrayList();
    List<Template> applied = this.listApplied == null ? Lists.newArrayList() : this.listApplied.getTemplates();
    if (player.isCreative()) {
        templates.addAll(VORegistries.TEMPLATES.values());
        templates.removeAll(applied);
    } else {
        int currentPower = totalPower();
        for (Template template : VORegistries.TEMPLATES.values()) if (!applied.contains(template))
            if (currentPower + template.getPower() <= this.targetPower && testTemplate(template))
                templates.add(template);
    }
    templates.sort(TEMPLATE_SORT);
    return templates;
}
Also used : Template(com.lying.variousoddities.species.Template)

Example 4 with Template

use of com.lying.variousoddities.species.Template in project VariousOddities by Lyinginbedmon.

the class Abilities method getEntityAbilities.

public Map<ResourceLocation, Ability> getEntityAbilities(@Nullable LivingEntity entityIn) {
    if (entityIn != null) {
        Map<ResourceLocation, Ability> abilityMap = new HashMap<>();
        // Collect abilities from creature's types
        EnumCreatureType.getTypes(entityIn).addAbilitiesToMap(abilityMap);
        // Collect abilities from creature's LivingData
        LivingData bodyData = LivingData.forEntity(entityIn);
        if (bodyData != null) {
            if (bodyData.hasSpecies())
                abilityMap = bodyData.getSpecies().addToMap(abilityMap);
            if (bodyData.hasTemplates())
                for (Template template : bodyData.getTemplates()) template.applyAbilityOperations(abilityMap);
            abilityMap = bodyData.getAbilities().addCustomToMap(abilityMap);
        }
        // Remove any existing temporary abilities (these should never exist in the standard sources)
        List<ResourceLocation> invalid = Lists.newArrayList();
        abilityMap.forEach((mapName, ability) -> {
            if (ability.isTemporary())
                invalid.add(mapName);
        });
        for (ResourceLocation mapName : invalid) abilityMap.remove(mapName);
        GatherAbilitiesEvent event = new GatherAbilitiesEvent(entityIn, abilityMap, cachedAbilities);
        MinecraftForge.EVENT_BUS.post(event);
        abilityMap = event.getAbilityMap();
        // Add in new temporary abilities
        for (Ability ability : event.getTempAbilities().values()) if (!abilityMap.containsKey(ability.getMapName()))
            abilityMap.put(ability.getMapName(), ability);
        List<Ability> subAbilities = gatherSubAbilities(abilityMap.values());
        if (!subAbilities.isEmpty())
            for (Ability ability : subAbilities) if (!abilityMap.containsKey(ability.getMapName()))
                abilityMap.put(ability.getMapName(), ability.clone().setTemporary());
        return abilityMap;
    }
    return new HashMap<>();
}
Also used : Ability(com.lying.variousoddities.species.abilities.Ability) IBonusJumpAbility(com.lying.variousoddities.species.abilities.IBonusJumpAbility) ICompoundAbility(com.lying.variousoddities.species.abilities.ICompoundAbility) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.util.ResourceLocation) GatherAbilitiesEvent(com.lying.variousoddities.api.event.GatherAbilitiesEvent) Template(com.lying.variousoddities.species.Template)

Example 5 with Template

use of com.lying.variousoddities.species.Template in project VariousOddities by Lyinginbedmon.

the class PacketSpeciesSelected method handle.

public static void handle(PacketSpeciesSelected msg, Supplier<NetworkEvent.Context> cxt) {
    NetworkEvent.Context context = cxt.get();
    if (context.getDirection().getReceptionSide().isServer()) {
        World world = context.getSender().getEntityWorld();
        PlayerEntity player = world.getPlayerByUuid(msg.playerID);
        if (player != null) {
            LivingData data = LivingData.forEntity(player);
            if (data != null) {
                if (msg.selectedSpecies == null)
                    data.setSpecies((SpeciesInstance) null);
                else {
                    Species selected = SpeciesRegistry.getSpecies(msg.selectedSpecies);
                    if (!data.hasSpecies() || (data.getSpecies().getRegistryName() != msg.selectedSpecies && selected != null))
                        data.setSpecies(selected);
                }
                data.setSpeciesSelected();
                if (!msg.keepTypes && data.hasCustomTypes())
                    data.clearCustomTypes();
                data.clearTemplates();
                for (ResourceLocation templateName : msg.selectedTemplates) {
                    Template template = VORegistries.TEMPLATES.get(templateName);
                    if (template != null)
                        data.addTemplateInitial(template);
                }
                SpeciesEvent.SpeciesSelected event = new SpeciesSelected(player, msg.selectedSpecies, msg.selectedTemplates);
                MinecraftForge.EVENT_BUS.post(event);
            }
        }
    }
    context.setPacketHandled(true);
}
Also used : SpeciesSelected(com.lying.variousoddities.api.event.SpeciesEvent.SpeciesSelected) SpeciesInstance(com.lying.variousoddities.species.Species.SpeciesInstance) SpeciesEvent(com.lying.variousoddities.api.event.SpeciesEvent) ResourceLocation(net.minecraft.util.ResourceLocation) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) SpeciesSelected(com.lying.variousoddities.api.event.SpeciesEvent.SpeciesSelected) LivingData(com.lying.variousoddities.capabilities.LivingData) World(net.minecraft.world.World) Species(com.lying.variousoddities.species.Species) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Template(com.lying.variousoddities.species.Template)

Aggregations

Template (com.lying.variousoddities.species.Template)11 ResourceLocation (net.minecraft.util.ResourceLocation)6 HashMap (java.util.HashMap)5 Ability (com.lying.variousoddities.species.abilities.Ability)4 Types (com.lying.variousoddities.species.types.Types)4 Map (java.util.Map)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 Species (com.lying.variousoddities.species.Species)3 EnumCreatureType (com.lying.variousoddities.species.types.EnumCreatureType)3 Pair (com.mojang.datafixers.util.Pair)3 Lists (com.google.common.collect.Lists)2 SpeciesEvent (com.lying.variousoddities.api.event.SpeciesEvent)2 VORegistries (com.lying.variousoddities.init.VORegistries)2 PacketHandler (com.lying.variousoddities.network.PacketHandler)2 Reference (com.lying.variousoddities.reference.Reference)2 SpeciesInstance (com.lying.variousoddities.species.Species.SpeciesInstance)2 AbilityRegistry (com.lying.variousoddities.species.abilities.AbilityRegistry)2 TemplateOperation (com.lying.variousoddities.species.templates.TemplateOperation)2 VariousOddities (com.lying.variousoddities.VariousOddities)1 IDefaultSpecies (com.lying.variousoddities.api.entity.IDefaultSpecies)1