package joshie.mariculture.core.util.item;
import joshie.mariculture.core.util.block.MCBlock;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockMC extends ItemBlock implements MCItem {
private final MCBlock mcBlock;
public ItemBlockMC(MCBlock block) {
super((Block) block);
this.mcBlock = block;
setHasSubtypes(true);
}
@Override
public String getItemStackDisplayName(ItemStack stack) {
return mcBlock.getItemStackDisplayName(stack);
}
@Override
public int getMetadata(int damage) {
return damage;
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
if (!block.isReplaceable(worldIn, pos)) {
pos = pos.offset(facing);
}
if (stack.stackSize != 0 && playerIn.canPlayerEdit(pos, facing, stack)
&& worldIn.canBlockBePlaced(this.block, pos, false, facing, null, stack) &&
mcBlock.canPlaceBlockAt(playerIn, stack, worldIn, pos, facing)) {
int i = this.getMetadata(stack.getMetadata());
IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, i, playerIn);
if (placeBlockAt(stack, playerIn, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1)) {
SoundType soundtype = this.block.getSoundType();
worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
--stack.stackSize;
}
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
}
@Override
public int getSortValue(ItemStack stack) {
return mcBlock.getSortValue(stack);
}
@SideOnly(Side.CLIENT)
@Override
public void registerModels(Item item) {
mcBlock.registerModels(item);
}
}