Search in sources :

Example 1 with SpeciesSelected

use of com.lying.variousoddities.api.event.SpeciesEvent.SpeciesSelected 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

SpeciesEvent (com.lying.variousoddities.api.event.SpeciesEvent)1 SpeciesSelected (com.lying.variousoddities.api.event.SpeciesEvent.SpeciesSelected)1 LivingData (com.lying.variousoddities.capabilities.LivingData)1 Species (com.lying.variousoddities.species.Species)1 SpeciesInstance (com.lying.variousoddities.species.Species.SpeciesInstance)1 Template (com.lying.variousoddities.species.Template)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 World (net.minecraft.world.World)1 NetworkEvent (net.minecraftforge.fml.network.NetworkEvent)1