Search in sources :

Example 1 with PacketRelicAbility

use of it.hurts.sskirillss.relics.network.PacketRelicAbility in project relics by SSKirillSS.

the class HUDEventHandler method onKeyPressed.

@SubscribeEvent
public static void onKeyPressed(InputEvent.KeyInputEvent event) {
    ClientPlayerEntity player = Minecraft.getInstance().player;
    if (player == null)
        return;
    if (relics.size() > slots) {
        if (HotkeyRegistry.HUD_UP.isDown()) {
            animation = 500;
            offset = offset - slots;
            if (offset < 0)
                offset = (relics.size() - 1) / slots * slots;
            player.getCommandSenderWorld().playSound(player, player.blockPosition(), SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, 1.0F, 1.0F);
        } else if (HotkeyRegistry.HUD_DOWN.isDown()) {
            animation = 500;
            offset = offset + slots;
            if (offset >= relics.size())
                offset = 0;
            player.getCommandSenderWorld().playSound(player, player.blockPosition(), SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, 1.0F, 1.0F);
        }
    }
    for (int i = 0; i < keyBindings.size(); i++) {
        KeyBinding key = keyBindings.get(i);
        if (!key.isDown())
            continue;
        animation = 500;
        int id = i + offset;
        if (id >= relics.size())
            continue;
        ImmutablePair<ItemStack, Integer> pair = relics.get(i + offset);
        ItemStack stack = pair.getLeft();
        if (!(stack.getItem() instanceof RelicItem))
            continue;
        RelicItem<?> relic = (RelicItem<?>) stack.getItem();
        if (!relic.getData().hasAbility())
            continue;
        NetworkHandler.sendToServer(new PacketRelicAbility(pair.getRight()));
        relic.castAbility(player, stack);
    }
}
Also used : RelicItem(it.hurts.sskirillss.relics.items.relics.base.RelicItem) KeyBinding(net.minecraft.client.settings.KeyBinding) PacketRelicAbility(it.hurts.sskirillss.relics.network.PacketRelicAbility) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

RelicItem (it.hurts.sskirillss.relics.items.relics.base.RelicItem)1 PacketRelicAbility (it.hurts.sskirillss.relics.network.PacketRelicAbility)1 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)1 KeyBinding (net.minecraft.client.settings.KeyBinding)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1