package com.mcmoddev.communitymod.fiskfille.sentientbread;

import com.mcmoddev.communitymod.ISubMod;
import com.mcmoddev.communitymod.SubMod;
import com.mcmoddev.communitymod.SubModLoader;
import com.mcmoddev.communitymod.client.gui.GuiCommunityConfig;
import com.mojang.text2speech.Narrator;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.event.FMLConstructionEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.input.Keyboard;

import java.util.Random;

@SubMod(name = "Sentient Bread",
        description = "Bread will plead for its life if you try to eat it.",
        attribution = "FiskFille",
        clientSideOnly = true,
        requiresMcRestart = false
public class SentientBread implements ISubMod
    private static final String[] MESSAGES_STOP = {
            "Please stop that",
            "Please don't eat me!",
            "Please stop",
            "I have a wife and family!",
            "THE PAIN! IT'S UNBEARABLE!",
            "I beg of you!",
            "I won't tell anyone, just spare me!",
            "Think of my children!",
            "WHY WOULD YOU DO THIS?",
            "You're a MONSTER!",
            "Show me mercy!",
            "Spare me!",
            "Show mercy!",
            "Don't kill me, please!",
            "I'll do whatever you want!",
            "Don't kill me, please!",
            "Please don't kill me!",
            "I'm just a poor dough, I need no sympathy",
            "End my suffering"

    private static final Narrator NARRATOR = Narrator.getNarrator();
    private static boolean isLoaded;

    public void onConstruction(FMLConstructionEvent event)
        isLoaded = SubModLoader.isSubModLoaded(this);

    public static void onClientTick(TickEvent.ClientTickEvent event)
        Minecraft mc = Minecraft.getMinecraft();

        if (!isLoaded)

        if (event.phase == TickEvent.Phase.END && != null && !mc.isGamePaused())
            ItemStack stack = mc.player.getActiveItemStack();

            if (!stack.isEmpty() && stack.getItem() == Items.BREAD)
                Random rand =;

                if (rand.nextFloat() < 0.04)
                    String msg = MESSAGES_STOP[rand.nextInt(MESSAGES_STOP.length)];
                    int i = mc.gameSettings.narrator;

                    if ( && (i == 0 || i == 3)) // Don't narrate if the setting is already turned on

                    mc.player.sendMessage(stack.getTextComponent().appendSibling(new TextComponentString(": " + msg)));

    public void onLoadStateChanged(boolean unload)
        isLoaded = !unload;