Search in sources :

Example 1 with PacketMouseClick

use of com.builtbroken.mc.core.network.packet.user.PacketMouseClick in project Engine by VoltzEngine-Project.

the class PlayerKeyHandler method mouseHandler.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void mouseHandler(MouseEvent e) {
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    ItemStack stack = player.getCurrentEquippedItem();
    if (stack != null) {
        final Item item = stack.getItem();
        if (item instanceof IModeItem.IModeScrollItem) {
            if (player.isSneaking() && e.dwheel != 0) {
                int newMode = ((IModeItem.IModeScrollItem) stack.getItem()).cycleMode(stack, player, e.dwheel / 120);
                if (newMode != ((IModeItem.IModeScrollItem) stack.getItem()).getMode(stack)) {
                    Engine.instance.packetHandler.sendToServer(new PacketPlayerItemMode(player.inventory.currentItem, newMode));
                }
                e.setCanceled(true);
            }
        } else if (item instanceof IMouseButtonHandler && e.button != -1) {
            Engine.instance.packetHandler.sendToServer(new PacketMouseClick(player.inventory.currentItem, e.button, e.buttonstate));
            ((IMouseButtonHandler) item).mouseClick(stack, player, e.button, e.buttonstate);
            if (((IMouseButtonHandler) item).shouldCancelMouseEvent(stack, player, e.button, e.buttonstate)) {
                e.setCanceled(true);
            }
        }
    }
}
Also used : IModeItem(com.builtbroken.mc.api.items.tools.IModeItem) Item(net.minecraft.item.Item) PacketPlayerItemMode(com.builtbroken.mc.core.network.packet.user.PacketPlayerItemMode) PacketMouseClick(com.builtbroken.mc.core.network.packet.user.PacketMouseClick) IModeItem(com.builtbroken.mc.api.items.tools.IModeItem) IMouseButtonHandler(com.builtbroken.mc.api.items.IMouseButtonHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

IMouseButtonHandler (com.builtbroken.mc.api.items.IMouseButtonHandler)1 IModeItem (com.builtbroken.mc.api.items.tools.IModeItem)1 PacketMouseClick (com.builtbroken.mc.core.network.packet.user.PacketMouseClick)1 PacketPlayerItemMode (com.builtbroken.mc.core.network.packet.user.PacketPlayerItemMode)1 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1