Search in sources :

Example 1 with Abilities

use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.

the class VOBusClient method onLivingJump.

@SubscribeEvent
public static void onLivingJump(LivingUpdateEvent event) {
    if (event.getEntityLiving() == mc.player) {
        ClientPlayerEntity player = (ClientPlayerEntity) event.getEntityLiving();
        LivingData data = LivingData.forEntity(event.getEntityLiving());
        Abilities abilities = data.getAbilities();
        Map<ResourceLocation, Ability> abilityMap = AbilityRegistry.getCreatureAbilities(player);
        if (player.movementInput.jump && abilities.canBonusJump) {
            if (AbilitySwim.isEntitySwimming(player)) {
                if (abilityMap.containsKey(AbilitySwim.REGISTRY_NAME)) {
                    abilities.doWaterJump();
                    PacketHandler.sendToServer(new PacketBonusJump(false));
                }
            } else if (!player.isOnGround()) {
                if (abilityMap.containsKey(AbilityFlight.REGISTRY_NAME) && abilityMap.get(AbilityFlight.REGISTRY_NAME).isActive()) {
                    abilities.doAirJump();
                    player.connection.sendPacket(new CEntityActionPacket(player, CEntityActionPacket.Action.START_FALL_FLYING));
                    PacketHandler.sendToServer(new PacketBonusJump());
                }
            }
        }
    }
}
Also used : Ability(com.lying.variousoddities.species.abilities.Ability) IPhasingAbility(com.lying.variousoddities.species.abilities.IPhasingAbility) Abilities(com.lying.variousoddities.capabilities.Abilities) ResourceLocation(net.minecraft.util.ResourceLocation) LivingData(com.lying.variousoddities.capabilities.LivingData) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) CEntityActionPacket(net.minecraft.network.play.client.CEntityActionPacket) PacketBonusJump(com.lying.variousoddities.network.PacketBonusJump) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with Abilities

use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.

the class AbilityStartingItem method onSpeciesSelected.

public void onSpeciesSelected(SpeciesEvent.SpeciesSelected event) {
    PlayerEntity player = (PlayerEntity) event.getEntityLiving();
    if (player.getEntityWorld().isRemote)
        return;
    Abilities abilities = LivingData.forEntity(player).getAbilities();
    for (Ability ability : abilities.getEntityAbilities(player).values()) if (ability.getRegistryName().equals(REGISTRY_NAME))
        addItemsFromAbility((AbilityStartingItem) ability, player);
}
Also used : Abilities(com.lying.variousoddities.capabilities.Abilities) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 3 with Abilities

use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.

the class GuiHandler method drawFavouritedAbilities.

private static void drawFavouritedAbilities(MatrixStack matrix, MainWindow window, float partialTicks, EnumCorner corner) {
    profiler.startSection("abilities");
    Map<ResourceLocation, Ability> abilityMap = AbilityRegistry.getCreatureAbilities(player);
    Abilities abilities = LivingData.forEntity(player).getAbilities();
    float posXStart = 5F;
    float posYStart = 5F;
    float posXInc = 3F;
    float posYInc = 11F;
    switch(corner) {
        case TOP_LEFT:
            posXStart = (Abilities.FAVOURITE_SLOTS * 3F);
            break;
        case BOTTOM_LEFT:
            posXInc = -3F;
            posYStart = (float) (window.getScaledHeight() - (Abilities.FAVOURITE_SLOTS * posYInc) - 5F);
            break;
        case BOTTOM_RIGHT:
            posXStart = (float) (window.getScaledWidth() - (Abilities.FAVOURITE_SLOTS * 3F));
            posYStart = (float) (window.getScaledHeight() - (Abilities.FAVOURITE_SLOTS * posYInc) - 5F);
            break;
        case TOP_RIGHT:
            posXStart = (float) (window.getScaledWidth() - (Abilities.FAVOURITE_SLOTS * 3F) - ICON_SIZE);
            posXInc = -3F;
            break;
    }
    matrix.push();
    float posX = posXStart;
    float posY = posYStart;
    int maxFav = 0;
    for (int i = 0; i < Abilities.FAVOURITE_SLOTS; i++) {
        ResourceLocation mapName = abilities.getFavourite(i);
        if (mapName != null) {
            maxFav = Math.max(maxFav, i);
            ActivatedAbility ability = (ActivatedAbility) abilityMap.get(mapName);
            if (ability != null)
                drawAbility(ability, abilities.getCooldown(mapName), posX, posY, matrix, corner.textSide);
        }
        posX -= posXInc;
        posY += posYInc;
    }
    List<Ability> activatedAbilities = Lists.newArrayList();
    activatedAbilities.addAll(abilityMap.values());
    activatedAbilities.removeIf(new Predicate<Ability>() {

        public boolean apply(Ability input) {
            return input.passive();
        }
    });
    if (!activatedAbilities.isEmpty()) {
        // Draw either as many slots as you can fill OR up to the highest index of slots in use
        int slots = Math.max(maxFav, activatedAbilities.size());
        posX = posXStart;
        posY = posYStart;
        for (int i = 0; i < Math.min(Abilities.FAVOURITE_SLOTS, slots); i++) {
            drawAbilitySlot(matrix, posX, posY);
            posX -= posXInc;
            posY += posYInc;
        }
    }
    matrix.pop();
    profiler.endSection();
}
Also used : ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility) Ability(com.lying.variousoddities.species.abilities.Ability) Abilities(com.lying.variousoddities.capabilities.Abilities) ResourceLocation(net.minecraft.util.ResourceLocation) ActivatedAbility(com.lying.variousoddities.species.abilities.ActivatedAbility)

Example 4 with Abilities

use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.

the class PacketSyncAbilities method handle.

public static void handle(PacketSyncAbilities msg, Supplier<NetworkEvent.Context> cxt) {
    NetworkEvent.Context context = cxt.get();
    if (context.getDirection().getReceptionSide().isClient()) {
        PlayerEntity player = ((CommonProxy) VariousOddities.proxy).getPlayerEntity(context);
        if (player != null) {
            World world = player.getEntityWorld();
            if (world != null) {
                LivingEntity entity = null;
                for (LivingEntity living : world.getEntitiesWithinAABB(LivingEntity.class, Minecraft.getInstance().player.getBoundingBox().grow(64D))) if (living.getUniqueID().equals(msg.uuid)) {
                    entity = living;
                    break;
                }
                if (entity != null) {
                    LivingData data = LivingData.forEntity(entity);
                    data.getAbilities().deserializeNBT(msg.abilitiesData);
                }
            }
        }
    } else {
        ServerPlayerEntity sender = context.getSender();
        if (sender != null) {
            Abilities abilities = LivingData.forEntity(sender).getAbilities();
            abilities.forceRecache();
            CompoundNBT data = abilities.serializeNBT();
            PacketHandler.sendToNearby(sender.getEntityWorld(), sender, new PacketSyncAbilities(sender.getUniqueID(), data));
        }
    }
    context.setPacketHandled(true);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Abilities(com.lying.variousoddities.capabilities.Abilities) CompoundNBT(net.minecraft.nbt.CompoundNBT) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) CommonProxy(com.lying.variousoddities.proxy.CommonProxy) LivingData(com.lying.variousoddities.capabilities.LivingData) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 5 with Abilities

use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.

the class PlayerEntityMixin method startElytraFlying.

@Inject(method = "tryToStartFallFlying()Z", at = @At("HEAD"), cancellable = true)
public void startElytraFlying(final CallbackInfoReturnable<Boolean> ci) {
    PlayerEntity player = (PlayerEntity) (Object) this;
    Abilities abilities = LivingData.forEntity(player).getAbilities();
    Map<ResourceLocation, Ability> abilityMap = AbilityRegistry.getCreatureAbilities(player);
    if (abilityMap.containsKey(AbilityFlight.REGISTRY_NAME) && abilityMap.get(AbilityFlight.REGISTRY_NAME).isActive()) {
        if (!player.isOnGround() && !player.isElytraFlying() && abilities.canBonusJump) {
            player.startFallFlying();
            ci.setReturnValue(true);
        }
    }
}
Also used : Ability(com.lying.variousoddities.species.abilities.Ability) Abilities(com.lying.variousoddities.capabilities.Abilities) ResourceLocation(net.minecraft.util.ResourceLocation) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Abilities (com.lying.variousoddities.capabilities.Abilities)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 LivingData (com.lying.variousoddities.capabilities.LivingData)5 CommonProxy (com.lying.variousoddities.proxy.CommonProxy)4 Ability (com.lying.variousoddities.species.abilities.Ability)4 NetworkEvent (net.minecraftforge.fml.network.NetworkEvent)4 ResourceLocation (net.minecraft.util.ResourceLocation)3 AbilityRemoveEvent (com.lying.variousoddities.api.event.AbilityEvent.AbilityRemoveEvent)1 PacketBonusJump (com.lying.variousoddities.network.PacketBonusJump)1 ActivatedAbility (com.lying.variousoddities.species.abilities.ActivatedAbility)1 IPhasingAbility (com.lying.variousoddities.species.abilities.IPhasingAbility)1 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 CEntityActionPacket (net.minecraft.network.play.client.CEntityActionPacket)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1