package com.zivilon.cinder_loe.mixins;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

@Mixin(ItemBlock.class)
public abstract class MixinItemBlock {

    @Shadow
    public final Block field_150939_a;

    public MixinItemBlock(Block block) {
        this.field_150939_a = block;
    }

    @Overwrite(remap = false)
    public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {

        System.out.println("Placing block with metadata " + metadata);
        if (!world.setBlock(x, y, z, field_150939_a, metadata, 3)) {
           return false;
        }

        if (world.getBlock(x, y, z) == field_150939_a) {
           field_150939_a.onBlockPlacedBy(world, x, y, z, player, stack);
           field_150939_a.onPostBlockPlaced(world, x, y, z, metadata);
        }

        return true;
    }
}
