Search in sources :

Example 1 with Species

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

the class ScreenSelectSpecies method render.

public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
    renderDirtBackground(0);
    this.speciesList.render(matrixStack, mouseX, mouseY, partialTicks);
    this.abilityList.render(matrixStack, mouseX, mouseY, partialTicks);
    renderBackgroundLayer(matrixStack, partialTicks);
    hideListEdge();
    drawListBorder(matrixStack, this.speciesList, this.height, 0, 180, 6, TEXTURE);
    int yPos = 20;
    drawCenteredString(matrixStack, this.font, this.title, this.width / 2, 12, 16777215);
    yPos += 15;
    if (selectableSpecies.isEmpty())
        return;
    // Draw species display name
    Species currentSpecies = getCurrentSpecies();
    this.selectButton.setMessage(currentSpecies.getDisplayName());
    yPos += this.font.FONT_HEIGHT + 12;
    // Render stars of appropriate colour for power
    drawStars(matrixStack, yPos, currentSpecies.getPower());
    yPos += this.font.FONT_HEIGHT + 3;
    // Display types
    int health = 20;
    if (currentSpecies.hasTypes()) {
        ITextComponent typesHeader = currentSpecies.getTypes().toHeader();
        drawCenteredString(matrixStack, this.font, typesHeader, this.width / 2, yPos, -1);
        health = (int) currentSpecies.getTypes().getPlayerHealth();
    }
    // Health and armour
    yPos += this.font.FONT_HEIGHT + 3;
    double armour = 0;
    List<Ability> abilities = currentSpecies.getFullAbilities();
    if (!abilities.isEmpty())
        for (Ability ability : abilities) {
            if (ability.getRegistryName().equals(AbilityNaturalArmour.REGISTRY_NAME))
                armour += ((AbilityNaturalArmour) ability).amount();
            if (ability.getRegistryName().equals(AbilityModifierCon.REGISTRY_NAME))
                health += ((AbilityModifier) ability).amount();
        }
    ;
    drawHealthAndArmour(matrixStack, this.font, this.width / 2, yPos, health, (int) armour);
    // Display abilities
    yPos += this.font.FONT_HEIGHT + 3;
    this.abilityList.setTop(yPos);
    super.render(matrixStack, mouseX, mouseY, partialTicks);
}
Also used : Ability(com.lying.variousoddities.species.abilities.Ability) ITextComponent(net.minecraft.util.text.ITextComponent) Species(com.lying.variousoddities.species.Species)

Example 2 with Species

use of com.lying.variousoddities.species.Species 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)

Example 3 with Species

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

the class CommandSpecies method setSpecies.

private static int setSpecies(Entity entity, ResourceLocation name, CommandSource source) throws CommandSyntaxException {
    if (entity instanceof LivingEntity) {
        LivingEntity living = (LivingEntity) entity;
        LivingData data = LivingData.forEntity(living);
        Species species = SpeciesRegistry.getSpecies(name);
        if (species != null) {
            data.setSpecies(species);
            source.sendFeedback(new TranslationTextComponent(translationSlug + "set", living.getDisplayName(), name), true);
            return 15;
        } else
            throw SPECIES_INVALID_EXCEPTION.create(name);
    } else
        throw INVALID_ENTITY_EXCEPTION.create();
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) LivingData(com.lying.variousoddities.capabilities.LivingData) Species(com.lying.variousoddities.species.Species)

Example 4 with Species

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

the class VOSpeciesProvider method act.

public void act(DirectoryCache cache) throws IOException {
    Path path = this.dataGenerator.getOutputFolder();
    Map<ResourceLocation, Species> map = Maps.newHashMap();
    SpeciesRegistry.getDefaultSpecies().forEach((species) -> {
        if (map.put(species.getRegistryName(), species) != null)
            throw new IllegalStateException("Duplicate species " + species.getRegistryName());
    });
    map.forEach((name, species) -> {
        Path filePath = getPath(path, name);
        try {
            IDataProvider.save(GSON, cache, species.toJson(), filePath);
        } catch (IOException e) {
            VariousOddities.log.error("Couldn't save species {}", filePath, e);
        }
    });
}
Also used : Path(java.nio.file.Path) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) Species(com.lying.variousoddities.species.Species)

Example 5 with Species

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

the class PacketSyncSpecies method handle.

public static void handle(PacketSyncSpecies msg, Supplier<NetworkEvent.Context> cxt) {
    VORegistries.SPECIES.clear();
    ListNBT data = msg.speciesData.getList("Species", 10);
    for (int i = 0; i < data.size(); i++) {
        Species species = null;
        try {
            species = Species.createFromNBT(data.getCompound(i));
        } catch (Exception e) {
            VariousOddities.log.error("Malformed species received from server, data: " + data.getCompound(i));
        }
        if (species != null && species.getRegistryName() != null)
            VORegistries.SPECIES.put(species.getRegistryName(), species);
    }
    cxt.get().setPacketHandled(true);
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) Species(com.lying.variousoddities.species.Species)

Aggregations

Species (com.lying.variousoddities.species.Species)8 LivingData (com.lying.variousoddities.capabilities.LivingData)3 SpeciesEvent (com.lying.variousoddities.api.event.SpeciesEvent)2 SpeciesInstance (com.lying.variousoddities.species.Species.SpeciesInstance)2 Template (com.lying.variousoddities.species.Template)2 Ability (com.lying.variousoddities.species.abilities.Ability)2 ListNBT (net.minecraft.nbt.ListNBT)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Lists (com.google.common.collect.Lists)1 VariousOddities (com.lying.variousoddities.VariousOddities)1 IDefaultSpecies (com.lying.variousoddities.api.entity.IDefaultSpecies)1 AbilityGetBreathableFluidEvent (com.lying.variousoddities.api.event.AbilityEvent.AbilityGetBreathableFluidEvent)1 TypeApplyEvent (com.lying.variousoddities.api.event.CreatureTypeEvent.TypeApplyEvent)1 TypeRemoveEvent (com.lying.variousoddities.api.event.CreatureTypeEvent.TypeRemoveEvent)1 SpeciesSelected (com.lying.variousoddities.api.event.SpeciesEvent.SpeciesSelected)1 TemplateApplied (com.lying.variousoddities.api.event.SpeciesEvent.TemplateApplied)1 BodyCondition (com.lying.variousoddities.capabilities.PlayerData.BodyCondition)1 Condition (com.lying.variousoddities.condition.Condition)1 ConditionInstance (com.lying.variousoddities.condition.ConditionInstance)1 ConfigVO (com.lying.variousoddities.config.ConfigVO)1