package com.jaquadro.minecraft.storagedrawers.block;

import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersComp;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockReader;

public class BlockCompDrawers extends BlockDrawers implements INetworked
{
    public static final EnumProperty<EnumCompDrawer> SLOTS = EnumProperty.create("slots", EnumCompDrawer.class);

    //@SideOnly(Side.CLIENT)
    //private StatusModelData statusInfo;

    public BlockCompDrawers (int storageUnits, Block.Properties properties) {
        super(3, false, storageUnits, properties);
        this.setDefaultState(getDefaultState()
            .with(SLOTS, EnumCompDrawer.OPEN1));
    }

    public BlockCompDrawers (Block.Properties properties) {
        this(32, properties);
    }

    @Override
    protected void fillStateContainer (StateContainer.Builder<Block, BlockState> builder) {
        super.fillStateContainer(builder);
        builder.add(SLOTS);
    }

    @Override
    @SuppressWarnings("deprecation")
    public boolean causesSuffocation (BlockState state, IBlockReader worldIn, BlockPos pos) {
        return false;
    }

    /*@Override
    @SideOnly(Side.CLIENT)
    public void initDynamic () {
        ResourceLocation location = new ResourceLocation(StorageDrawers.MOD_ID + ":models/dynamic/compDrawers.json");
        statusInfo = new StatusModelData(3, location);
    }*/

    /*@Override
    public StatusModelData getStatusInfo (IBlockState state) {
        return statusInfo;
    }*/

    @Override
    protected int getDrawerSlot (Direction side, Vec3d hit) {
        if (hitTop(hit.y))
            return 0;

        if (hitLeft(side, hit.x, hit.z))
            return 1;
        else
            return 2;
    }

    /*@Override
    public IBlockState getStateForPlacement (World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
        return getDefaultState();
    }*/

    /*@Override
    public BlockType retrimType () {
        return null;
    }*/

    @Override
    public TileEntityDrawers createTileEntity (BlockState state, IBlockReader world) {
        return new TileEntityDrawersComp.Slot3();
    }

    /*@Override
    protected BlockStateContainer createBlockState () {
        return new ExtendedBlockState(this, new IProperty[] { SLOTS, FACING }, new IUnlistedProperty[] { STATE_MODEL });
    }*/
}

@@ -47,16 +47,153 @@
 block;%0A%0A
+import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;%0Aimport com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;%0A
 import c
@@ -253,16 +253,16 @@
 worked;%0A
-
 import c
@@ -480,16 +480,95 @@
 kState;%0A
+import net.minecraft.entity.LivingEntity;%0Aimport net.minecraft.item.ItemStack;%0A
 import n
@@ -759,16 +759,16 @@
 .Vec3d;%0A
-
 import n
@@ -799,16 +799,50 @@
 kReader;
+%0Aimport net.minecraft.world.World;
 %0A%0Apublic
@@ -2379,32 +2379,668 @@
 eturn 2;%0A    %7D%0A%0A
+    @Override%0A    public void onBlockPlacedBy (World world, BlockPos pos, BlockState state, LivingEntity entity, ItemStack stack) %7B%0A        super.onBlockPlacedBy(world, pos, state, entity, stack);%0A%0A        TileEntityDrawers tile = getTileEntity(world, pos);%0A        if (tile != null) %7B%0A            IDrawerGroup group = tile.getGroup();%0A            for (int i = group.getDrawerCount() - 1; i %3E= 0; i--) %7B%0A                if (!group.getDrawer(i).isEmpty()) %7B%0A                    world.setBlockState(pos, state.with(SLOTS, EnumCompDrawer.byOpenSlots(i + 1)), 3);%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A
     /*@Override%0A

Fix content-holding compacting drawers being palced back into world with wrong slot visuals