/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.mod.mixin.core.event.player;

import com.google.common.base.Optional;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import org.spongepowered.api.entity.EntityInteractionType;
import org.spongepowered.api.entity.EntityInteractionTypes;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.entity.player.PlayerInteractBlockEvent;
import org.spongepowered.api.util.annotation.NonnullByDefault;
import org.spongepowered.api.world.Location;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.common.util.VecHelper;

@NonnullByDefault
@Mixin(value = net.minecraftforge.event.entity.player.PlayerInteractEvent.class, remap = false)
public abstract class MixinEventPlayerInteractBlock extends PlayerEvent implements PlayerInteractBlockEvent {

    @Shadow
    public Action action;

    @Shadow
    public World world;

    @Shadow
    public BlockPos pos;

    public MixinEventPlayerInteractBlock(EntityPlayer player, Action action, BlockPos pos, EnumFacing face, World world) {
        super(player);
    }

    @Override
    public Location getBlock() {
        return new Location((org.spongepowered.api.world.World) this.world, VecHelper.toVector(this.pos).toDouble());
    }

    @Override
    public EntityInteractionType getInteractionType() {
        if (this.action == Action.LEFT_CLICK_BLOCK) {
            return EntityInteractionTypes.ATTACK;
        } else if (this.action == Action.RIGHT_CLICK_AIR || this.action == Action.RIGHT_CLICK_BLOCK) {
            return EntityInteractionTypes.USE;
        } else {
            return EntityInteractionTypes.PICK_BLOCK;
        }
    }

    @Override
    public Optional<Cause> getCause() {
        return Optional.fromNullable(new Cause(null, this.entityPlayer, null));
    }

}

@@ -1865,24 +1865,69 @@
 BlockEvent;%0A
+import org.spongepowered.api.util.Direction;%0A
 import org.s
@@ -1977,16 +1977,16 @@
 efault;%0A
-
 import o
@@ -2107,16 +2107,117 @@
 Shadow;%0A
+import org.spongepowered.common.Sponge;%0Aimport org.spongepowered.common.registry.SpongeGameRegistry;%0A
 import o
@@ -2596,16 +2596,53 @@
 s pos;%0A%0A
+    @Shadow public EnumFacing face;%0A%0A
     publ
@@ -3349,24 +3349,24 @@
 PICK_BLOCK;%0A
-
         %7D%0A  
@@ -3362,32 +3362,272 @@
        %7D%0A    %7D%0A%0A
+    @Override%0A    public Direction getSide() %7B%0A        if (this.face != null) %7B%0A            return ((SpongeGameRegistry) Sponge.getGame().getRegistry()).directionMap.inverse().get(this.face);%0A        %7D%0A        return Direction.NONE;%0A    %7D%0A%0A
     @Override%0A  

Implement PlayerInteractBlockEvent#getSide